@nodii/outbox-dispatcher 0.0.1 → 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/README.md +82 -2
- package/dist/cli/migrate-gen.d.ts +3 -0
- package/dist/cli/migrate-gen.d.ts.map +1 -0
- package/dist/cli/migrate-gen.js +97 -0
- package/dist/cli/migrate-gen.js.map +1 -0
- package/dist/define-dispatcher.d.ts +21 -0
- package/dist/define-dispatcher.d.ts.map +1 -0
- package/dist/define-dispatcher.js +65 -0
- package/dist/define-dispatcher.js.map +1 -0
- package/dist/drainer.d.ts +26 -0
- package/dist/drainer.d.ts.map +1 -0
- package/dist/drainer.js +339 -0
- package/dist/drainer.js.map +1 -0
- package/dist/envelope.d.ts +27 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +77 -0
- package/dist/envelope.js.map +1 -0
- package/dist/hwm.d.ts +15 -0
- package/dist/hwm.d.ts.map +1 -0
- package/dist/hwm.js +51 -0
- package/dist/hwm.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -0
- package/dist/lease.d.ts +27 -0
- package/dist/lease.d.ts.map +1 -0
- package/dist/lease.js +97 -0
- package/dist/lease.js.map +1 -0
- package/dist/migrations/index.d.ts +12 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +88 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/sql-builders.d.ts +20 -0
- package/dist/sql-builders.d.ts.map +1 -0
- package/dist/sql-builders.js +70 -0
- package/dist/sql-builders.js.map +1 -0
- package/dist/start.d.ts +25 -0
- package/dist/start.d.ts.map +1 -0
- package/dist/start.js +74 -0
- package/dist/start.js.map +1 -0
- package/dist/test-doubles/index.d.ts +56 -0
- package/dist/test-doubles/index.d.ts.map +1 -0
- package/dist/test-doubles/index.js +145 -0
- package/dist/test-doubles/index.js.map +1 -0
- package/dist/types.d.ts +195 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/dist/uuid.d.ts +2 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +28 -0
- package/dist/uuid.js.map +1 -0
- package/package.json +40 -3
- package/src/migrations/001-outbox-dispatcher.sql +60 -0
package/dist/start.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type DispatcherRunnerHandle } from "./drainer.js";
|
|
2
|
+
import { type ResolvedDispatcher, type StartDispatcherConfig } from "./types.js";
|
|
3
|
+
export interface DispatcherHandle {
|
|
4
|
+
/** Latest XADD id emitted for `stream` across all runners, or null (§ 5.3). */
|
|
5
|
+
currentHwm(stream: string): string | null;
|
|
6
|
+
/** Max p95 lag-seconds across runners. */
|
|
7
|
+
lag(): number;
|
|
8
|
+
/** Per-dispatcher runner handles, keyed by serviceName. */
|
|
9
|
+
readonly runners: ReadonlyMap<string, DispatcherRunnerHandle>;
|
|
10
|
+
/** Graceful shutdown of every runner (drain + release). */
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Start one or more dispatchers. Each gets its own DispatcherRunner (lease,
|
|
15
|
+
* poll loop, HWM tracker, metrics). The returned handle aggregates
|
|
16
|
+
* `currentHwm`/`lag`/`stop` across them.
|
|
17
|
+
*
|
|
18
|
+
* A SIGTERM handler is installed by default that calls `stop()` (graceful
|
|
19
|
+
* drain bounded by `drainDeadlineSeconds`). Pass `installSignalHandler:false`
|
|
20
|
+
* to manage shutdown yourself (tests do this).
|
|
21
|
+
*/
|
|
22
|
+
export declare function startDispatcher(dispatchers: ResolvedDispatcher[], config: StartDispatcherConfig): Promise<DispatcherHandle>;
|
|
23
|
+
export type { DispatcherRunnerHandle } from "./drainer.js";
|
|
24
|
+
export type { ResolvedDispatcher };
|
|
25
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,KAAK,kBAAkB,EAEvB,KAAK,qBAAqB,EAE3B,MAAM,YAAY,CAAC;AAUpB,MAAM,WAAW,gBAAgB;IAC/B,+EAA+E;IAC/E,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC1C,0CAA0C;IAC1C,GAAG,IAAI,MAAM,CAAC;IACd,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAC9D,2DAA2D;IAC3D,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,WAAW,EAAE,kBAAkB,EAAE,EACjC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CA0D3B;AAED,YAAY,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/start.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// startDispatcher([...]) — boots the polling + lease loop for one or more
|
|
2
|
+
// dispatchers. Per § 5.1. Returns an aggregate handle exposing currentHwm,
|
|
3
|
+
// lag, and a graceful stop() across all runners.
|
|
4
|
+
import { startDispatcherRunner, } from "./drainer.js";
|
|
5
|
+
import { DispatcherNotWired, } from "./types.js";
|
|
6
|
+
/** No-op telemetry default — every call is a no-op (used only when the
|
|
7
|
+
* caller does not wire @nodii/telemetry). This is NOT a stubbed I/O path:
|
|
8
|
+
* PG + Redis are always real (caller-provided); telemetry is observability
|
|
9
|
+
* and degrades to silent rather than failing the drain. */
|
|
10
|
+
const NOOP_TELEMETRY = {
|
|
11
|
+
recordMetric() { },
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Start one or more dispatchers. Each gets its own DispatcherRunner (lease,
|
|
15
|
+
* poll loop, HWM tracker, metrics). The returned handle aggregates
|
|
16
|
+
* `currentHwm`/`lag`/`stop` across them.
|
|
17
|
+
*
|
|
18
|
+
* A SIGTERM handler is installed by default that calls `stop()` (graceful
|
|
19
|
+
* drain bounded by `drainDeadlineSeconds`). Pass `installSignalHandler:false`
|
|
20
|
+
* to manage shutdown yourself (tests do this).
|
|
21
|
+
*/
|
|
22
|
+
export async function startDispatcher(dispatchers, config) {
|
|
23
|
+
if (!config.redis) {
|
|
24
|
+
throw new DispatcherNotWired("startDispatcher requires a redis client");
|
|
25
|
+
}
|
|
26
|
+
if (!config.pgPool && !config.dbRls) {
|
|
27
|
+
throw new DispatcherNotWired("startDispatcher requires either pgPool or dbRls");
|
|
28
|
+
}
|
|
29
|
+
const resolved = {
|
|
30
|
+
pgPool: config.pgPool,
|
|
31
|
+
dbRls: config.dbRls,
|
|
32
|
+
redis: config.redis,
|
|
33
|
+
telemetry: config.telemetry ?? NOOP_TELEMETRY,
|
|
34
|
+
};
|
|
35
|
+
const runners = new Map();
|
|
36
|
+
for (const dispatcher of dispatchers) {
|
|
37
|
+
const runner = await startDispatcherRunner({ dispatcher, start: resolved });
|
|
38
|
+
runners.set(dispatcher.serviceName, runner);
|
|
39
|
+
}
|
|
40
|
+
let sigtermHandler;
|
|
41
|
+
const handle = {
|
|
42
|
+
currentHwm(stream) {
|
|
43
|
+
for (const runner of runners.values()) {
|
|
44
|
+
const id = runner.currentHwm(stream);
|
|
45
|
+
if (id !== null)
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
lag() {
|
|
51
|
+
let max = 0;
|
|
52
|
+
for (const runner of runners.values())
|
|
53
|
+
max = Math.max(max, runner.lag());
|
|
54
|
+
return max;
|
|
55
|
+
},
|
|
56
|
+
runners,
|
|
57
|
+
async stop() {
|
|
58
|
+
if (sigtermHandler) {
|
|
59
|
+
process.removeListener("SIGTERM", sigtermHandler);
|
|
60
|
+
process.removeListener("SIGINT", sigtermHandler);
|
|
61
|
+
}
|
|
62
|
+
await Promise.all([...runners.values()].map((r) => r.stop()));
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
if (config.installSignalHandler !== false) {
|
|
66
|
+
sigtermHandler = () => {
|
|
67
|
+
void handle.stop().then(() => process.exit(0), () => process.exit(1));
|
|
68
|
+
};
|
|
69
|
+
process.on("SIGTERM", sigtermHandler);
|
|
70
|
+
process.on("SIGINT", sigtermHandler);
|
|
71
|
+
}
|
|
72
|
+
return handle;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,iDAAiD;AAEjD,OAAO,EAEL,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,GAKnB,MAAM,YAAY,CAAC;AAEpB;;;4DAG4D;AAC5D,MAAM,cAAc,GAAqB;IACvC,YAAY,KAAI,CAAC;CAClB,CAAC;AAaF;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,WAAiC,EACjC,MAA6B;IAE7B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,CAAC,yCAAyC,CAAC,CAAC;IAC1E,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,IAAI,kBAAkB,CAC1B,iDAAiD,CAClD,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAwB;QACpC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,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CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;KACF,CAAC;IAEF,IAAI,MAAM,CAAC,oBAAoB,KAAK,KAAK,EAAE,CAAC;QAC1C,cAAc,GAAG,GAAG,EAAE;YACpB,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,CACrB,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EACrB,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CACtB,CAAC;QACJ,CAAC,CAAC;QACF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACtC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { RedisLike, TelemetryAdapter } from "../types.js";
|
|
2
|
+
interface MetricCall {
|
|
3
|
+
kind: string;
|
|
4
|
+
name: string;
|
|
5
|
+
value?: number;
|
|
6
|
+
attributes?: Record<string, string | number | boolean | undefined>;
|
|
7
|
+
}
|
|
8
|
+
/** Records every metric + audit call for assertions. */
|
|
9
|
+
export declare class RecordingTelemetry implements TelemetryAdapter {
|
|
10
|
+
readonly metrics: MetricCall[];
|
|
11
|
+
readonly audits: Array<{
|
|
12
|
+
action: string;
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
}>;
|
|
15
|
+
recordMetric(args: MetricCall): void;
|
|
16
|
+
emitAudit(args: {
|
|
17
|
+
action: string;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}): void;
|
|
20
|
+
logger: {
|
|
21
|
+
debug(): void;
|
|
22
|
+
info(): void;
|
|
23
|
+
warn(): void;
|
|
24
|
+
error(): void;
|
|
25
|
+
};
|
|
26
|
+
/** Sum of `value` for a counter, optionally filtered by attribute subset. */
|
|
27
|
+
counterTotal(name: string, attrs?: Record<string, string | number | boolean>): number;
|
|
28
|
+
/** Latest gauge value for a name (optionally filtered). */
|
|
29
|
+
lastGauge(name: string, attrs?: Record<string, string | number | boolean>): number | undefined;
|
|
30
|
+
countAudits(action: string): number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* In-memory Redis double — implements just enough of RedisLike to drive
|
|
34
|
+
* lease + XADD in unit tests. Streams are appended to an in-memory array.
|
|
35
|
+
* NOT a production client.
|
|
36
|
+
*/
|
|
37
|
+
export declare class InMemoryRedis implements RedisLike {
|
|
38
|
+
private readonly kv;
|
|
39
|
+
private readonly expiry;
|
|
40
|
+
private seq;
|
|
41
|
+
/** stream key → list of [id, fields[]]. */
|
|
42
|
+
readonly streams: Map<string, [string, string[]][]>;
|
|
43
|
+
set(key: string, value: string, ...args: (string | number)[]): Promise<string | null>;
|
|
44
|
+
get(key: string): Promise<string | null>;
|
|
45
|
+
del(...keys: string[]): Promise<number>;
|
|
46
|
+
eval(script: string, _numKeys: number, ...keysAndArgs: (string | number)[]): Promise<unknown>;
|
|
47
|
+
xadd(key: string, ...args: (string | number)[]): Promise<string | null>;
|
|
48
|
+
/** Read all entries on a stream (test helper, not part of RedisLike). */
|
|
49
|
+
streamEntries(key: string): Array<{
|
|
50
|
+
id: string;
|
|
51
|
+
event: string;
|
|
52
|
+
}>;
|
|
53
|
+
private gc;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-doubles/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,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,MAAM,CAAC,EAAE,GAC3B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAiBnB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKxC,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IASvC,IAAI,CACR,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,GAAG,WAAW,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAClC,OAAO,CAAC,OAAO,CAAC;IAoBb,IAAI,CACR,GAAG,EAAE,MAAM,EACX,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAC3B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAwBzB,yEAAyE;IACzE,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAOhE,OAAO,CAAC,EAAE;CAOX"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Test doubles — for UNIT tests ONLY. These are NEVER wired as defaults in
|
|
2
|
+
// any shipped boot path (R1). Integration + contract tests run against real
|
|
3
|
+
// Postgres :5433 + real Redis :6379.
|
|
4
|
+
/** Records every metric + audit call for assertions. */
|
|
5
|
+
export class RecordingTelemetry {
|
|
6
|
+
metrics = [];
|
|
7
|
+
audits = [];
|
|
8
|
+
recordMetric(args) {
|
|
9
|
+
this.metrics.push(args);
|
|
10
|
+
}
|
|
11
|
+
emitAudit(args) {
|
|
12
|
+
this.audits.push(args);
|
|
13
|
+
}
|
|
14
|
+
logger = {
|
|
15
|
+
debug() { },
|
|
16
|
+
info() { },
|
|
17
|
+
warn() { },
|
|
18
|
+
error() { },
|
|
19
|
+
};
|
|
20
|
+
/** Sum of `value` for a counter, optionally filtered by attribute subset. */
|
|
21
|
+
counterTotal(name, attrs) {
|
|
22
|
+
return this.metrics
|
|
23
|
+
.filter((m) => m.name === name && matchAttrs(m.attributes, attrs))
|
|
24
|
+
.reduce((acc, m) => acc + (m.value ?? 0), 0);
|
|
25
|
+
}
|
|
26
|
+
/** Latest gauge value for a name (optionally filtered). */
|
|
27
|
+
lastGauge(name, attrs) {
|
|
28
|
+
const hits = this.metrics.filter((m) => m.kind === "gauge" &&
|
|
29
|
+
m.name === name &&
|
|
30
|
+
matchAttrs(m.attributes, attrs));
|
|
31
|
+
return hits.at(-1)?.value;
|
|
32
|
+
}
|
|
33
|
+
countAudits(action) {
|
|
34
|
+
return this.audits.filter((a) => a.action === action).length;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function matchAttrs(actual, expected) {
|
|
38
|
+
if (!expected)
|
|
39
|
+
return true;
|
|
40
|
+
if (!actual)
|
|
41
|
+
return false;
|
|
42
|
+
return Object.entries(expected).every(([k, v]) => actual[k] === v);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* In-memory Redis double — implements just enough of RedisLike to drive
|
|
46
|
+
* lease + XADD in unit tests. Streams are appended to an in-memory array.
|
|
47
|
+
* NOT a production client.
|
|
48
|
+
*/
|
|
49
|
+
export class InMemoryRedis {
|
|
50
|
+
kv = new Map();
|
|
51
|
+
expiry = new Map();
|
|
52
|
+
seq = 0;
|
|
53
|
+
/** stream key → list of [id, fields[]]. */
|
|
54
|
+
streams = new Map();
|
|
55
|
+
async set(key, value, ...args) {
|
|
56
|
+
let nx = false;
|
|
57
|
+
let exSeconds;
|
|
58
|
+
for (let i = 0; i < args.length; i++) {
|
|
59
|
+
const a = String(args[i]).toUpperCase();
|
|
60
|
+
if (a === "NX")
|
|
61
|
+
nx = true;
|
|
62
|
+
if (a === "EX")
|
|
63
|
+
exSeconds = Number(args[i + 1]);
|
|
64
|
+
}
|
|
65
|
+
this.gc(key);
|
|
66
|
+
if (nx && this.kv.has(key))
|
|
67
|
+
return null;
|
|
68
|
+
this.kv.set(key, value);
|
|
69
|
+
if (exSeconds !== undefined) {
|
|
70
|
+
this.expiry.set(key, Date.now() + exSeconds * 1000);
|
|
71
|
+
}
|
|
72
|
+
return "OK";
|
|
73
|
+
}
|
|
74
|
+
async get(key) {
|
|
75
|
+
this.gc(key);
|
|
76
|
+
return this.kv.get(key) ?? null;
|
|
77
|
+
}
|
|
78
|
+
async del(...keys) {
|
|
79
|
+
let n = 0;
|
|
80
|
+
for (const k of keys) {
|
|
81
|
+
if (this.kv.delete(k))
|
|
82
|
+
n++;
|
|
83
|
+
this.expiry.delete(k);
|
|
84
|
+
}
|
|
85
|
+
return n;
|
|
86
|
+
}
|
|
87
|
+
async eval(script, _numKeys, ...keysAndArgs) {
|
|
88
|
+
const key = String(keysAndArgs[0]);
|
|
89
|
+
const argv1 = String(keysAndArgs[1]);
|
|
90
|
+
this.gc(key);
|
|
91
|
+
const current = this.kv.get(key);
|
|
92
|
+
// Lua CAS: renew (EXPIRE) vs release (DEL) — both guard GET==me.
|
|
93
|
+
if (current !== argv1)
|
|
94
|
+
return 0;
|
|
95
|
+
if (/EXPIRE/.test(script)) {
|
|
96
|
+
const ttl = Number(keysAndArgs[2]);
|
|
97
|
+
this.expiry.set(key, Date.now() + ttl * 1000);
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
if (/DEL/.test(script)) {
|
|
101
|
+
this.kv.delete(key);
|
|
102
|
+
this.expiry.delete(key);
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
async xadd(key, ...args) {
|
|
108
|
+
// Skip MAXLEN ~ N and the * id placeholder; collect field/value pairs.
|
|
109
|
+
const fields = [];
|
|
110
|
+
let i = 0;
|
|
111
|
+
while (i < args.length) {
|
|
112
|
+
const a = String(args[i]);
|
|
113
|
+
if (a.toUpperCase() === "MAXLEN") {
|
|
114
|
+
i += 3; // MAXLEN ~ N
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (a === "*") {
|
|
118
|
+
i += 1;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
fields.push(a);
|
|
122
|
+
i += 1;
|
|
123
|
+
}
|
|
124
|
+
const id = `${Date.now()}-${this.seq++}`;
|
|
125
|
+
const list = this.streams.get(key) ?? [];
|
|
126
|
+
list.push([id, fields]);
|
|
127
|
+
this.streams.set(key, list);
|
|
128
|
+
return id;
|
|
129
|
+
}
|
|
130
|
+
/** Read all entries on a stream (test helper, not part of RedisLike). */
|
|
131
|
+
streamEntries(key) {
|
|
132
|
+
return (this.streams.get(key) ?? []).map(([id, fields]) => {
|
|
133
|
+
const idx = fields.indexOf("event");
|
|
134
|
+
return { id, event: idx >= 0 ? (fields[idx + 1] ?? "") : "" };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
gc(key) {
|
|
138
|
+
const exp = this.expiry.get(key);
|
|
139
|
+
if (exp !== undefined && Date.now() >= exp) {
|
|
140
|
+
this.kv.delete(key);
|
|
141
|
+
this.expiry.delete(key);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test-doubles/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,qCAAqC;AAWrC,wDAAwD;AACxD,MAAM,OAAO,kBAAkB;IACpB,OAAO,GAAiB,EAAE,CAAC;IAC3B,MAAM,GAGV,EAAE,CAAC;IAER,YAAY,CAAC,IAAgB;QAC3B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,SAAS,CAAC,IAGT;QACC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,GAAG;QACP,KAAK,KAAI,CAAC;QACV,IAAI,KAAI,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,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YACxD,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACpC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,EAAE,CAAC,GAAW;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC;YAC3C,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical replication-event envelope as the CONSUMER reads it.
|
|
3
|
+
*
|
|
4
|
+
* Field-name parity with @nodii/replica-consumer's `ReplicationEvent`
|
|
5
|
+
* (ts/replica-consumer/src/types.ts) — the consumer's `consumeOneEvent`
|
|
6
|
+
* reads exactly these keys. NOTE: the outbox *row* stores the source
|
|
7
|
+
* version under the column `source_entity_version`; the consumer reads it
|
|
8
|
+
* off the envelope under `entity_version`. This library maps the column to
|
|
9
|
+
* the envelope key (see § 5.2 ambiguity note in the README). Drift filed
|
|
10
|
+
* if the feature_doc's literal `source_entity_version` envelope key is ever
|
|
11
|
+
* reinstated on the consumer side.
|
|
12
|
+
*/
|
|
13
|
+
export interface ReplicationEnvelope {
|
|
14
|
+
/** Globally-unique event id (UUIDv7 in practice). Consumer dedupe key. */
|
|
15
|
+
event_id: string;
|
|
16
|
+
/** Source topic (e.g. `tenant.tenant.created.v1`). */
|
|
17
|
+
topic: string;
|
|
18
|
+
/** Source aggregate kind (e.g. `tenant`). */
|
|
19
|
+
aggregate_kind: string;
|
|
20
|
+
/** Source aggregate id. */
|
|
21
|
+
aggregate_id: string;
|
|
22
|
+
/** Monotonic source-aggregate version. Consumer LWW key. */
|
|
23
|
+
entity_version: number;
|
|
24
|
+
/** Free-form payload. Library does NOT validate the shape. */
|
|
25
|
+
payload: Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Reserved synthetic id slot on the envelope (consumer uses the live
|
|
28
|
+
* Redis-Streams id off the wire for the cursor, NOT this field — this is
|
|
29
|
+
* always the empty string from the producer side, mirroring the absence
|
|
30
|
+
* of a pre-assigned id). Present for shape-parity with the consumer's
|
|
31
|
+
* `ReplicationEvent`.
|
|
32
|
+
*/
|
|
33
|
+
stream_id: string;
|
|
34
|
+
/** Source committed_at (ms epoch) — drives the consumer lag metric. */
|
|
35
|
+
committed_at: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A single outbox row as drained from the `<service>_outbox` table.
|
|
39
|
+
*
|
|
40
|
+
* Column shape per `09-replication-doctrine § 2.2`. The library reads these
|
|
41
|
+
* columns; the producing service writes them in the same business tx as the
|
|
42
|
+
* source mutation. `payload` + `telemetry_envelope` are JSONB in Postgres
|
|
43
|
+
* (returned as parsed objects by postgres.js / a string we parse).
|
|
44
|
+
*/
|
|
45
|
+
export interface OutboxRow {
|
|
46
|
+
id: string;
|
|
47
|
+
event_id: string;
|
|
48
|
+
aggregate_kind: string;
|
|
49
|
+
aggregate_id: string;
|
|
50
|
+
source_entity_version: number;
|
|
51
|
+
topic: string;
|
|
52
|
+
payload: Record<string, unknown>;
|
|
53
|
+
/** Optional telemetry envelope stamped by the producer. */
|
|
54
|
+
telemetry_envelope?: Record<string, unknown> | null;
|
|
55
|
+
occurred_at: string | Date;
|
|
56
|
+
dispatched_at?: string | Date | null;
|
|
57
|
+
stream_id?: string | null;
|
|
58
|
+
publish_attempts: number;
|
|
59
|
+
last_error?: string | null;
|
|
60
|
+
last_attempt_at?: string | Date | null;
|
|
61
|
+
}
|
|
62
|
+
/** Generic SQL exec arg list — postgres.js-shaped. */
|
|
63
|
+
export type SqlExecArgs = readonly unknown[];
|
|
64
|
+
export type SqlExecResult = any;
|
|
65
|
+
export interface SqlExecutor {
|
|
66
|
+
unsafe(sql: string, args?: SqlExecArgs): Promise<SqlExecResult>;
|
|
67
|
+
}
|
|
68
|
+
export interface SqlTxExecutor extends SqlExecutor {
|
|
69
|
+
}
|
|
70
|
+
export interface SqlPoolExecutor extends SqlExecutor {
|
|
71
|
+
/** Run `fn` inside a single transaction (BEGIN/COMMIT/ROLLBACK). */
|
|
72
|
+
begin<T>(fn: (tx: SqlTxExecutor) => Promise<T>): Promise<T>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Minimum Redis surface the library calls. ioredis fits. Matches the
|
|
76
|
+
* @nodii/replica-consumer `RedisLike` so the same client satisfies both
|
|
77
|
+
* the producer (XADD) and the consumer (XREADGROUP) sides.
|
|
78
|
+
*/
|
|
79
|
+
export interface RedisLike {
|
|
80
|
+
set(key: string, value: string, ...args: (string | number)[]): Promise<string | null>;
|
|
81
|
+
get(key: string): Promise<string | null>;
|
|
82
|
+
del(...keys: string[]): Promise<number>;
|
|
83
|
+
eval(script: string, numKeys: number, ...keysAndArgs: (string | number)[]): Promise<unknown>;
|
|
84
|
+
/** `XADD <key> [MAXLEN ~ N] <id|*> <field> <value> [...]`. */
|
|
85
|
+
xadd(key: string, ...args: (string | number)[]): Promise<string | null>;
|
|
86
|
+
}
|
|
87
|
+
/** Optional `@nodii/db-rls` integration surface (per 08-rls § 4). */
|
|
88
|
+
export interface DbRlsLike {
|
|
89
|
+
withSystemContext<T>(args: {
|
|
90
|
+
tenantId: string;
|
|
91
|
+
}, fn: (db: SqlPoolExecutor) => Promise<T>): Promise<T>;
|
|
92
|
+
}
|
|
93
|
+
/** Telemetry adapter — minimum surface the library calls. */
|
|
94
|
+
export interface TelemetryAdapter {
|
|
95
|
+
recordMetric(args: {
|
|
96
|
+
kind: "counter" | "histogram" | "gauge";
|
|
97
|
+
name: string;
|
|
98
|
+
value?: number;
|
|
99
|
+
attributes?: Record<string, string | number | boolean | undefined>;
|
|
100
|
+
}): void;
|
|
101
|
+
emitAudit?(args: {
|
|
102
|
+
action: string;
|
|
103
|
+
metadata?: Record<string, unknown>;
|
|
104
|
+
}): void | Promise<void>;
|
|
105
|
+
logger?: {
|
|
106
|
+
debug(msg: string, ctx?: Record<string, unknown>): void;
|
|
107
|
+
info(msg: string, ctx?: Record<string, unknown>): void;
|
|
108
|
+
warn(msg: string, ctx?: Record<string, unknown>): void;
|
|
109
|
+
error(msg: string, ctx?: Record<string, unknown>): void;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Declarative dispatcher config — `defineDispatcher({...})`. Per § 5.1.
|
|
114
|
+
*/
|
|
115
|
+
export interface DispatcherConfig {
|
|
116
|
+
serviceName: string;
|
|
117
|
+
/** Source outbox table name. Default `outbox`. */
|
|
118
|
+
outboxTable?: string;
|
|
119
|
+
/** DLQ table name. Default `<serviceName-snake>_outbox_dlq`. */
|
|
120
|
+
dlqTable?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Maps an outbox row to its destination stream key. Per
|
|
123
|
+
* `01-comms § 9.2` stream-naming (`<service>.<domain>`). E.g.
|
|
124
|
+
* `(row) => \`tenant.\${row.topic.split('.')[1]}\``.
|
|
125
|
+
*/
|
|
126
|
+
streamFor: (row: OutboxRow) => string;
|
|
127
|
+
/** D209 SET-NX-EX lease key. Default `lock:outbox:<serviceName>`. */
|
|
128
|
+
leaseKey?: string;
|
|
129
|
+
/** Lease TTL (ms). Renewal cadence is ttl/2. Default 30_000. */
|
|
130
|
+
leaseTtlMs?: number;
|
|
131
|
+
/** Poll interval (ms) when idle / not lease holder. Default 500 (§ 9.2). */
|
|
132
|
+
pollMs?: number;
|
|
133
|
+
/** Rows claimed per FOR UPDATE SKIP LOCKED batch. Default 50 (§ 9.2). */
|
|
134
|
+
batchSize?: number;
|
|
135
|
+
/** Publish attempts before DLQ. Default 8. */
|
|
136
|
+
publishMaxAttempts?: number;
|
|
137
|
+
/** Graceful-drain deadline (s) on SIGTERM. Default 30. */
|
|
138
|
+
drainDeadlineSeconds?: number;
|
|
139
|
+
/** Per-stream MAXLEN ~ approximation. Default 1_000_000 (doctrine § 3). */
|
|
140
|
+
streamMaxLenApprox?: number;
|
|
141
|
+
/**
|
|
142
|
+
* tenant_id for the optional @nodii/db-rls SELECT context. When set AND a
|
|
143
|
+
* dbRls handle is wired at start, the drain SELECT runs inside
|
|
144
|
+
* `withSystemContext({ tenantId })` (08-rls § 4). Omit for platform-tenant
|
|
145
|
+
* outbox tables (raw pool).
|
|
146
|
+
*/
|
|
147
|
+
tenantId?: string;
|
|
148
|
+
}
|
|
149
|
+
/** Resolved dispatcher (defaults inlined). */
|
|
150
|
+
export interface ResolvedDispatcher {
|
|
151
|
+
serviceName: string;
|
|
152
|
+
outboxTable: string;
|
|
153
|
+
dlqTable: string;
|
|
154
|
+
streamFor: (row: OutboxRow) => string;
|
|
155
|
+
leaseKey: string;
|
|
156
|
+
leaseTtlMs: number;
|
|
157
|
+
pollMs: number;
|
|
158
|
+
batchSize: number;
|
|
159
|
+
publishMaxAttempts: number;
|
|
160
|
+
drainDeadlineSeconds: number;
|
|
161
|
+
streamMaxLenApprox: number;
|
|
162
|
+
tenantId?: string;
|
|
163
|
+
}
|
|
164
|
+
/** Process-global wiring passed to `startDispatcher`. Per § 5.1. */
|
|
165
|
+
export interface StartDispatcherConfig {
|
|
166
|
+
/** EITHER a raw pool OR a db-rls handle. At least one required. */
|
|
167
|
+
pgPool?: SqlPoolExecutor;
|
|
168
|
+
dbRls?: DbRlsLike;
|
|
169
|
+
redis: RedisLike;
|
|
170
|
+
telemetry?: TelemetryAdapter;
|
|
171
|
+
/**
|
|
172
|
+
* Install a SIGTERM handler that drains + releases gracefully. Default
|
|
173
|
+
* true. Tests pass false to keep the runner alive.
|
|
174
|
+
*/
|
|
175
|
+
installSignalHandler?: boolean;
|
|
176
|
+
}
|
|
177
|
+
/** Resolved start config (telemetry default applied). */
|
|
178
|
+
export interface ResolvedStartConfig {
|
|
179
|
+
pgPool?: SqlPoolExecutor;
|
|
180
|
+
dbRls?: DbRlsLike;
|
|
181
|
+
redis: RedisLike;
|
|
182
|
+
telemetry: TelemetryAdapter;
|
|
183
|
+
}
|
|
184
|
+
export declare class OutboxDispatcherError extends Error {
|
|
185
|
+
constructor(message: string, opts?: {
|
|
186
|
+
cause?: unknown;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
export declare class InvalidDispatcherConfig extends OutboxDispatcherError {
|
|
190
|
+
constructor(message: string);
|
|
191
|
+
}
|
|
192
|
+
export declare class DispatcherNotWired extends OutboxDispatcherError {
|
|
193
|
+
constructor(message: string);
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,2BAA2B;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;IACvB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAC;C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
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @nodii/outbox-dispatcher — public type surface.
|
|
2
|
+
//
|
|
3
|
+
// Spec: planning hub feature_doc serviceId=nodii-libs docKey=outbox-dispatcher.
|
|
4
|
+
// Producer-side Pattern-3 drainer; symmetric peer of @nodii/replica-consumer.
|
|
5
|
+
//
|
|
6
|
+
// The XADD envelope this library emits MUST be byte-identical to what
|
|
7
|
+
// @nodii/replica-consumer reads off the stream (its `publishReplicationEvent`
|
|
8
|
+
// + worker `parseXReadGroup`): a single field named `event` whose value is
|
|
9
|
+
// `JSON.stringify(ReplicationEvent)`, with the canonical ReplicationEvent
|
|
10
|
+
// key set. See `envelope.ts` for the stamping + the contract test for proof.
|
|
11
|
+
// ── Typed errors ────────────────────────────────────────────────────
|
|
12
|
+
export class OutboxDispatcherError extends Error {
|
|
13
|
+
constructor(message, opts) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "OutboxDispatcherError";
|
|
16
|
+
if (opts?.cause !== undefined) {
|
|
17
|
+
this.cause = opts.cause;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class InvalidDispatcherConfig extends OutboxDispatcherError {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "InvalidDispatcherConfig";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class DispatcherNotWired extends OutboxDispatcherError {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = "DispatcherNotWired";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,EAAE;AACF,sEAAsE;AACtE,8EAA8E;AAC9E,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAgN7E,uEAAuE;AAEvE,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe,EAAE,IAA0B;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,IAAI,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,IAA4B,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACnD,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,qBAAqB;IAChE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,qBAAqB;IAC3D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
|
package/dist/uuid.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,IAAI,MAAM,CAyB/B"}
|
package/dist/uuid.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// UUIDv7 generator — RFC 9562. Inlined for self-containment, byte-parity
|
|
2
|
+
// with ts/replica-consumer/src/uuid.ts.
|
|
3
|
+
export function uuidv7() {
|
|
4
|
+
const ts = BigInt(Date.now());
|
|
5
|
+
const tsHex = ts.toString(16).padStart(12, "0");
|
|
6
|
+
const randBytes = new Uint8Array(10);
|
|
7
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
8
|
+
crypto.getRandomValues(randBytes);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
for (let i = 0; i < randBytes.length; i++) {
|
|
12
|
+
randBytes[i] = Math.floor(Math.random() * 256);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
randBytes[0] = (randBytes[0] & 0x0f) | 0x70; // version 7
|
|
16
|
+
randBytes[2] = (randBytes[2] & 0x3f) | 0x80; // variant 10
|
|
17
|
+
let randHex = "";
|
|
18
|
+
for (const b of randBytes)
|
|
19
|
+
randHex += b.toString(16).padStart(2, "0");
|
|
20
|
+
return [
|
|
21
|
+
tsHex.slice(0, 8),
|
|
22
|
+
tsHex.slice(8, 12),
|
|
23
|
+
randHex.slice(0, 4),
|
|
24
|
+
randHex.slice(4, 8),
|
|
25
|
+
randHex.slice(8, 20),
|
|
26
|
+
].join("-");
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=uuid.js.map
|
package/dist/uuid.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wCAAwC;AAExC,MAAM,UAAU,MAAM;IACpB,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAEhD,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;QAC5D,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA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