hikoutei 0.8.63 → 0.8.65
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 +244 -30
- package/dist/api/Hikoutei.js.map +1 -1
- package/dist/api/internalEntityManager.d.ts.map +1 -1
- package/dist/api/internalEntityManager.js +152 -53
- package/dist/api/internalEntityManager.js.map +1 -1
- package/dist/application/sync/outbound/SheetsEffectDispatcher.d.ts +41 -0
- package/dist/application/sync/outbound/SheetsEffectDispatcher.d.ts.map +1 -1
- package/dist/application/sync/outbound/SheetsEffectDispatcher.js +85 -3
- package/dist/application/sync/outbound/SheetsEffectDispatcher.js.map +1 -1
- package/dist/application/sync/outbound/reconciliation/ReconciliationScanner.d.ts.map +1 -1
- package/dist/application/sync/outbound/reconciliation/ReconciliationScanner.js +39 -17
- package/dist/application/sync/outbound/reconciliation/ReconciliationScanner.js.map +1 -1
- package/dist/application/sync/outbound/reconciliation/diff.d.ts +19 -2
- package/dist/application/sync/outbound/reconciliation/diff.d.ts.map +1 -1
- package/dist/application/sync/outbound/reconciliation/diff.js +60 -17
- package/dist/application/sync/outbound/reconciliation/diff.js.map +1 -1
- package/dist/application/sync/outbound/reconciliation/repair.d.ts +35 -4
- package/dist/application/sync/outbound/reconciliation/repair.d.ts.map +1 -1
- package/dist/application/sync/outbound/reconciliation/repair.js +124 -62
- package/dist/application/sync/outbound/reconciliation/repair.js.map +1 -1
- package/dist/application/sync/outbound/reconciliation/shared.d.ts +20 -0
- package/dist/application/sync/outbound/reconciliation/shared.d.ts.map +1 -1
- package/dist/application/sync/outbound/reconciliation/shared.js +35 -0
- package/dist/application/sync/outbound/reconciliation/shared.js.map +1 -1
- package/dist/application/sync/service/SyncPollingSupervisor.d.ts +16 -0
- package/dist/application/sync/service/SyncPollingSupervisor.d.ts.map +1 -1
- package/dist/application/sync/service/SyncPollingSupervisor.js +24 -0
- package/dist/application/sync/service/SyncPollingSupervisor.js.map +1 -1
- package/dist/application/sync/service/SyncServiceBootstrap.d.ts.map +1 -1
- package/dist/application/sync/service/SyncServiceBootstrap.js +26 -1
- package/dist/application/sync/service/SyncServiceBootstrap.js.map +1 -1
- package/dist/application/sync/service/effectSupervisor.d.ts.map +1 -1
- package/dist/application/sync/service/effectSupervisor.js +114 -9
- package/dist/application/sync/service/effectSupervisor.js.map +1 -1
- package/dist/application/sync/service/pollingSupervisor.d.ts +17 -0
- package/dist/application/sync/service/pollingSupervisor.d.ts.map +1 -1
- package/dist/application/sync/service/pollingSupervisor.js +103 -3
- package/dist/application/sync/service/pollingSupervisor.js.map +1 -1
- package/dist/application/sync/service/serviceOptions.d.ts.map +1 -1
- package/dist/application/sync/service/serviceOptions.js +23 -20
- package/dist/application/sync/service/serviceOptions.js.map +1 -1
- package/dist/application/sync/service/shutdown.d.ts.map +1 -1
- package/dist/application/sync/service/shutdown.js +6 -2
- package/dist/application/sync/service/shutdown.js.map +1 -1
- package/dist/application/sync/service/syncAutoStart.d.ts +69 -14
- package/dist/application/sync/service/syncAutoStart.d.ts.map +1 -1
- package/dist/application/sync/service/syncAutoStart.js +176 -46
- package/dist/application/sync/service/syncAutoStart.js.map +1 -1
- package/dist/application/sync/sheetsContract/mutationCoordinator/CoordinatedSheetsProvider.d.ts +37 -1
- package/dist/application/sync/sheetsContract/mutationCoordinator/CoordinatedSheetsProvider.d.ts.map +1 -1
- package/dist/application/sync/sheetsContract/mutationCoordinator/CoordinatedSheetsProvider.js +57 -3
- package/dist/application/sync/sheetsContract/mutationCoordinator/CoordinatedSheetsProvider.js.map +1 -1
- package/package.json +2 -2
|
@@ -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,EAA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wB,GAChC,OAAO,CAAC,QAAQ,CAAC,CAsCnB;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 });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
settleAttempt({ ok: true });
|
|
43
136
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
}
|
|
187
|
+
}
|
|
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;
|
|
47
215
|
}
|
|
48
|
-
|
|
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
|
/**
|
|
@@ -100,23 +293,44 @@ export function validateTypedSheetsOptions(options) {
|
|
|
100
293
|
* `entities` here applies the same defaults as `createTypedSheets()`.
|
|
101
294
|
*/
|
|
102
295
|
export async function createLocalTypedSheetsRuntime(options) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
296
|
+
const startedAt = Date.now();
|
|
297
|
+
try {
|
|
298
|
+
const dbName = options.dbName ?? resolveDefaultDbPath();
|
|
299
|
+
const entities = options.entities ?? getRegisteredEntityTokens();
|
|
300
|
+
const descriptors = resolveEntityDescriptors(entities, throwHikouteiResolutionError);
|
|
301
|
+
// Load the current provider only when a runtime is opened. Importing the
|
|
302
|
+
// root package alone must not require MikroORM or expose its module graph.
|
|
303
|
+
const [engineModule, providerModule, runtimeModule] = await Promise.all([
|
|
304
|
+
import("../adapter/persistence/providers/mikro-orm/engine/MikroOrmScalarStorage.js"),
|
|
305
|
+
import("../adapter/persistence/providers/mikro-orm/api/MikroOrmScalarPersistenceProvider.js"),
|
|
306
|
+
import("../adapter/persistence/providers/mikro-orm/engine/MikroOrmScalarEntityRuntime.js"),
|
|
307
|
+
]);
|
|
308
|
+
const generated = runtimeModule.createMikroOrmScalarEntityRuntime(entities);
|
|
309
|
+
const storage = await engineModule.initializeMikroOrmScalarStorage({
|
|
310
|
+
dbName,
|
|
311
|
+
entities: generated.entities,
|
|
312
|
+
});
|
|
313
|
+
const provider = new providerModule.MikroOrmScalarPersistenceProvider(storage, generated.bindings);
|
|
314
|
+
const hikoutei = createInternalHikoutei(provider, descriptors);
|
|
315
|
+
logHikouteiInternalEvent({
|
|
316
|
+
event: HIKOUTEI_LOG_EVENTS.RUNTIME_OPENED,
|
|
317
|
+
level: "info",
|
|
318
|
+
component: HIKOUTEI_LOG_COMPONENTS.RUNTIME,
|
|
319
|
+
durationMs: Date.now() - startedAt,
|
|
320
|
+
counts: { entities: descriptors.size },
|
|
321
|
+
});
|
|
322
|
+
return hikoutei;
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
logHikouteiInternalEvent({
|
|
326
|
+
event: HIKOUTEI_LOG_EVENTS.RUNTIME_OPEN_FAILED,
|
|
327
|
+
level: "error",
|
|
328
|
+
component: HIKOUTEI_LOG_COMPONENTS.RUNTIME,
|
|
329
|
+
durationMs: Date.now() - startedAt,
|
|
330
|
+
...describeErrorForInternalLog(error),
|
|
331
|
+
});
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
120
334
|
}
|
|
121
335
|
/**
|
|
122
336
|
* Opens the local SQLite runtime for the declared scalar entities.
|
package/dist/api/Hikoutei.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hikoutei.js","sourceRoot":"","sources":["../../src/api/Hikoutei.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,yBAAyB,GAG1B,MAAM,aAAa,CAAC;A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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internalEntityManager.d.ts","sourceRoot":"","sources":["../../src/api/internalEntityManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"internalEntityManager.d.ts","sourceRoot":"","sources":["../../src/api/internalEntityManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAmBxD,OAAO,KAAK,EAEV,+BAA+B,EAKhC,MAAM,4CAA4C,CAAC;AA4WpD,kFAAkF;AAClF,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,+BAA+B,EACzC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,gCAAgC,CAAC,GACjE,aAAa,CAEf"}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
import { getEntityDescriptor } from "./entity.js";
|
|
12
12
|
import { normalizeEntityFindOneQuery, normalizeEntityQuery, } from "./queryNormalization.js";
|
|
13
13
|
import { HIKOUTEI_ERROR_CODES, HikouteiError } from "./errors.js";
|
|
14
|
+
import { describeErrorForInternalLog, logHikouteiInternalEvent, } from "../shared/observability/internalLog.js";
|
|
15
|
+
import { HIKOUTEI_LOG_COMPONENTS, HIKOUTEI_LOG_EVENTS, } from "../shared/observability/logEvents.js";
|
|
14
16
|
import { readEntityValues, ScalarEntityUnitOfWork, } from "../application/orm/persistence/scalar/unitOfWork.js";
|
|
15
17
|
/** Internal Unit-of-Work implementation behind the public interface. */
|
|
16
18
|
class EntityManagerImpl {
|
|
@@ -37,70 +39,114 @@ class EntityManagerImpl {
|
|
|
37
39
|
*/
|
|
38
40
|
create(entity, data) {
|
|
39
41
|
const descriptor = this.requireDescriptor(entity);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
try {
|
|
43
|
+
const instance = promoteManagedEntity(buildEntityInstance(descriptor, data));
|
|
44
|
+
this.entityDescriptors.set(instance, descriptor);
|
|
45
|
+
this.unitOfWork.manageNew(descriptor, instance);
|
|
46
|
+
this.rememberIdentity(descriptor, instance);
|
|
47
|
+
return instance;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
logLifecycleFailure(descriptor.tableName, error);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
/** Reads every entity matching one validated local query. */
|
|
47
55
|
async find(entity, where, options) {
|
|
48
56
|
const descriptor = this.requireDescriptor(entity);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
try {
|
|
58
|
+
const query = normalizeEntityQuery(descriptor, effectiveFilter(where), options);
|
|
59
|
+
const reader = this.activeTransaction ?? this.provider;
|
|
60
|
+
const rows = await reader.read(query);
|
|
61
|
+
return this.materializeRows(descriptor, rows);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
logQueryFailure(descriptor.tableName, error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
53
67
|
}
|
|
54
68
|
/** Reads one entity matching a validated query, or null when none match. */
|
|
55
69
|
async findOne(entity, where, options) {
|
|
56
70
|
const descriptor = this.requireDescriptor(entity);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
try {
|
|
72
|
+
const query = normalizeEntityFindOneQuery(descriptor, where, options);
|
|
73
|
+
const reader = this.activeTransaction ?? this.provider;
|
|
74
|
+
const rows = await reader.read(query);
|
|
75
|
+
const row = rows[0];
|
|
76
|
+
return row === undefined
|
|
77
|
+
? null
|
|
78
|
+
: promoteManagedEntity(this.materialize(descriptor, row));
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
logQueryFailure(descriptor.tableName, error);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
64
84
|
}
|
|
65
85
|
/** Counts all rows matching a validated filter without changing the identity map. */
|
|
66
86
|
async count(entity, where) {
|
|
67
87
|
const descriptor = this.requireDescriptor(entity);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
try {
|
|
89
|
+
const query = countQuery(normalizeEntityQuery(descriptor, effectiveFilter(where), undefined));
|
|
90
|
+
const reader = this.activeTransaction ?? this.provider;
|
|
91
|
+
return await reader.count(query);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
logQueryFailure(descriptor.tableName, error);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
71
97
|
}
|
|
72
98
|
/** Reads one page and its unpaged total from the same SQLite snapshot. */
|
|
73
99
|
async findAndCount(entity, where, options) {
|
|
74
100
|
const descriptor = this.requireDescriptor(entity);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
try {
|
|
102
|
+
const query = normalizeEntityQuery(descriptor, effectiveFilter(where), options);
|
|
103
|
+
const operation = async (reader) => {
|
|
104
|
+
const rows = await reader.read(query);
|
|
105
|
+
const total = await reader.count(countQuery(query));
|
|
106
|
+
return [rows, total];
|
|
107
|
+
};
|
|
108
|
+
const [rows, total] = this.activeTransaction === undefined
|
|
109
|
+
? await this.provider.readSnapshot(operation)
|
|
110
|
+
: await operation(this.activeTransaction);
|
|
111
|
+
return [this.materializeRows(descriptor, rows), total];
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
logQueryFailure(descriptor.tableName, error);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
85
117
|
}
|
|
86
118
|
/** Marks one entity or iterable of entities for insertion or update at flush. */
|
|
87
119
|
persist(input) {
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
120
|
+
try {
|
|
121
|
+
for (const entity of toEntities(input)) {
|
|
122
|
+
const descriptor = this.resolveDescriptorFor(entity);
|
|
123
|
+
this.entityDescriptors.set(entity, descriptor);
|
|
124
|
+
this.unitOfWork.persist(descriptor, entity);
|
|
125
|
+
this.rememberIdentity(descriptor, entity);
|
|
126
|
+
}
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
logLifecycleFailure(undefined, error);
|
|
131
|
+
throw error;
|
|
93
132
|
}
|
|
94
|
-
return this;
|
|
95
133
|
}
|
|
96
134
|
/** Marks one entity or iterable of entities for removal at the next flush. */
|
|
97
135
|
remove(input) {
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
136
|
+
try {
|
|
137
|
+
for (const entity of toEntities(input)) {
|
|
138
|
+
const canceledInsert = this.unitOfWork.remove(entity);
|
|
139
|
+
if (canceledInsert)
|
|
140
|
+
this.forgetIdentity(entity);
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
// Removal can reject for unmanaged/unknown entities; the public error
|
|
146
|
+
// is rethrown unchanged after the redacted boundary record.
|
|
147
|
+
logLifecycleFailure(undefined, error);
|
|
148
|
+
throw error;
|
|
102
149
|
}
|
|
103
|
-
return this;
|
|
104
150
|
}
|
|
105
151
|
/**
|
|
106
152
|
* Commits every pending insert, update, and delete in one provider transaction.
|
|
@@ -111,20 +157,47 @@ class EntityManagerImpl {
|
|
|
111
157
|
* outbox failure leaves the Unit of Work retryable.
|
|
112
158
|
*/
|
|
113
159
|
async flush() {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
160
|
+
const startedAt = Date.now();
|
|
161
|
+
// Inside transactional() an explicit flush joins the active transaction;
|
|
162
|
+
// only the transactional boundary logs so a joined-flush failure is never
|
|
163
|
+
// reported twice.
|
|
164
|
+
const joinsActiveTransaction = this.activeTransaction !== undefined;
|
|
165
|
+
let plan;
|
|
166
|
+
let changedTableCount = 0;
|
|
167
|
+
try {
|
|
168
|
+
// Flush-plan collection validates every pending change (primary keys,
|
|
169
|
+
// identity conflicts, unmanaged entities); failures are boundary
|
|
170
|
+
// records here, rethrown unchanged.
|
|
171
|
+
plan = this.unitOfWork.collectFlushPlan();
|
|
172
|
+
if (plan.changes.length === 0)
|
|
173
|
+
return;
|
|
174
|
+
changedTableCount = new Set(plan.changes.map((change) => change.row.tableName)).size;
|
|
175
|
+
const flushPlan = plan;
|
|
176
|
+
if (this.activeTransaction !== undefined) {
|
|
177
|
+
await applyFlushPlan(this.activeTransaction, flushPlan);
|
|
178
|
+
await this.activeTransaction.flush();
|
|
179
|
+
this.completeFlush(flushPlan);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
await this.provider.beginTransaction(async (transaction) => {
|
|
183
|
+
await applyFlushPlan(transaction, flushPlan);
|
|
184
|
+
await transaction.flush();
|
|
185
|
+
});
|
|
186
|
+
this.completeFlush(flushPlan);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
if (!joinsActiveTransaction) {
|
|
190
|
+
logHikouteiInternalEvent({
|
|
191
|
+
event: HIKOUTEI_LOG_EVENTS.EM_FLUSH_FAILED,
|
|
192
|
+
level: "error",
|
|
193
|
+
component: HIKOUTEI_LOG_COMPONENTS.ENTITY_MANAGER,
|
|
194
|
+
...describeErrorForInternalLog(error),
|
|
195
|
+
durationMs: Date.now() - startedAt,
|
|
196
|
+
counts: { changes: plan?.changes.length ?? 0, tables: changedTableCount },
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
throw error;
|
|
122
200
|
}
|
|
123
|
-
await this.provider.beginTransaction(async (transaction) => {
|
|
124
|
-
await applyFlushPlan(transaction, plan);
|
|
125
|
-
await transaction.flush();
|
|
126
|
-
});
|
|
127
|
-
this.completeFlush(plan);
|
|
128
201
|
}
|
|
129
202
|
/**
|
|
130
203
|
* Runs entity work in one transaction and flushes pending changes on success.
|
|
@@ -160,6 +233,12 @@ class EntityManagerImpl {
|
|
|
160
233
|
// A provider can reject after an explicit inner flush (for example when
|
|
161
234
|
// the outer callback throws). Restore snapshots, values, and identity
|
|
162
235
|
// keys so entities loaded inside the failed callback remain retryable.
|
|
236
|
+
logHikouteiInternalEvent({
|
|
237
|
+
event: HIKOUTEI_LOG_EVENTS.EM_TRANSACTIONAL_FAILED,
|
|
238
|
+
level: "error",
|
|
239
|
+
component: HIKOUTEI_LOG_COMPONENTS.ENTITY_MANAGER,
|
|
240
|
+
...describeErrorForInternalLog(error),
|
|
241
|
+
});
|
|
163
242
|
this.unitOfWork.restore(checkpoint);
|
|
164
243
|
this.identityMap.clear();
|
|
165
244
|
for (const [key, entity] of identityCheckpoint)
|
|
@@ -240,6 +319,26 @@ class EntityManagerImpl {
|
|
|
240
319
|
export function createEntityManager(provider, descriptors) {
|
|
241
320
|
return new EntityManagerImpl(provider, descriptors);
|
|
242
321
|
}
|
|
322
|
+
/** Logs one read-path failure with a sanitized table scope (fail-open). */
|
|
323
|
+
function logQueryFailure(tableName, error) {
|
|
324
|
+
logHikouteiInternalEvent({
|
|
325
|
+
event: HIKOUTEI_LOG_EVENTS.EM_QUERY_FAILED,
|
|
326
|
+
level: "warn",
|
|
327
|
+
component: HIKOUTEI_LOG_COMPONENTS.ENTITY_MANAGER,
|
|
328
|
+
table: tableName,
|
|
329
|
+
...describeErrorForInternalLog(error),
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/** Logs one lifecycle validation failure (create/persist) (fail-open). */
|
|
333
|
+
function logLifecycleFailure(tableName, error) {
|
|
334
|
+
logHikouteiInternalEvent({
|
|
335
|
+
event: HIKOUTEI_LOG_EVENTS.EM_LIFECYCLE_INVALID,
|
|
336
|
+
level: "warn",
|
|
337
|
+
component: HIKOUTEI_LOG_COMPONENTS.ENTITY_MANAGER,
|
|
338
|
+
...(tableName === undefined ? {} : { table: tableName }),
|
|
339
|
+
...describeErrorForInternalLog(error),
|
|
340
|
+
});
|
|
341
|
+
}
|
|
243
342
|
function buildEntityInstance(descriptor, data) {
|
|
244
343
|
const declared = new Set(descriptor.properties.map((property) => property.name));
|
|
245
344
|
for (const propertyName of Object.keys(data)) {
|