@substrat-run/kernel 0.215.0 → 0.217.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.
Files changed (72) hide show
  1. package/dist/attachment-gate.d.ts +42 -0
  2. package/dist/attachment-gate.d.ts.map +1 -0
  3. package/dist/attachment-gate.js +36 -0
  4. package/dist/attachment-gate.js.map +1 -0
  5. package/dist/broker-erasure.d.ts +51 -0
  6. package/dist/broker-erasure.d.ts.map +1 -0
  7. package/dist/broker-erasure.js +161 -0
  8. package/dist/broker-erasure.js.map +1 -0
  9. package/dist/broker-relay-erasure.d.ts +27 -0
  10. package/dist/broker-relay-erasure.d.ts.map +1 -0
  11. package/dist/broker-relay-erasure.js +115 -0
  12. package/dist/broker-relay-erasure.js.map +1 -0
  13. package/dist/broker-relay.d.ts +292 -0
  14. package/dist/broker-relay.d.ts.map +1 -0
  15. package/dist/broker-relay.js +494 -0
  16. package/dist/broker-relay.js.map +1 -0
  17. package/dist/broker-schema.d.ts +25 -0
  18. package/dist/broker-schema.d.ts.map +1 -0
  19. package/dist/broker-schema.js +198 -0
  20. package/dist/broker-schema.js.map +1 -0
  21. package/dist/broker-telemetry.d.ts +288 -0
  22. package/dist/broker-telemetry.d.ts.map +1 -0
  23. package/dist/broker-telemetry.js +334 -0
  24. package/dist/broker-telemetry.js.map +1 -0
  25. package/dist/cost-rollup.d.ts +6 -0
  26. package/dist/cost-rollup.d.ts.map +1 -1
  27. package/dist/cost-rollup.js +22 -1
  28. package/dist/cost-rollup.js.map +1 -1
  29. package/dist/delivery-broker.d.ts +278 -0
  30. package/dist/delivery-broker.d.ts.map +1 -0
  31. package/dist/delivery-broker.js +516 -0
  32. package/dist/delivery-broker.js.map +1 -0
  33. package/dist/delivery-policy.d.ts +105 -0
  34. package/dist/delivery-policy.d.ts.map +1 -0
  35. package/dist/delivery-policy.js +105 -0
  36. package/dist/delivery-policy.js.map +1 -0
  37. package/dist/directory-lake.d.ts +7 -3
  38. package/dist/directory-lake.d.ts.map +1 -1
  39. package/dist/directory-lake.js +14 -5
  40. package/dist/directory-lake.js.map +1 -1
  41. package/dist/index.d.ts +13 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +6 -0
  44. package/dist/index.js.map +1 -1
  45. package/dist/job-run.d.ts +21 -1
  46. package/dist/job-run.d.ts.map +1 -1
  47. package/dist/job-run.js +6 -0
  48. package/dist/job-run.js.map +1 -1
  49. package/dist/outbox-prune.d.ts +8 -1
  50. package/dist/outbox-prune.d.ts.map +1 -1
  51. package/dist/outbox-prune.js +6 -2
  52. package/dist/outbox-prune.js.map +1 -1
  53. package/dist/platform-sweep.d.ts +31 -3
  54. package/dist/platform-sweep.d.ts.map +1 -1
  55. package/dist/platform-sweep.js +40 -2
  56. package/dist/platform-sweep.js.map +1 -1
  57. package/dist/scope-host.d.ts +33 -8
  58. package/dist/scope-host.d.ts.map +1 -1
  59. package/dist/scope-host.js.map +1 -1
  60. package/dist/store-driver-releases.d.ts +9 -2
  61. package/dist/store-driver-releases.d.ts.map +1 -1
  62. package/dist/store-driver-releases.js +12 -7
  63. package/dist/store-driver-releases.js.map +1 -1
  64. package/dist/subject-keys.d.ts +7 -0
  65. package/dist/subject-keys.d.ts.map +1 -1
  66. package/dist/subject-keys.js +29 -5
  67. package/dist/subject-keys.js.map +1 -1
  68. package/dist/subject-redaction.d.ts +7 -0
  69. package/dist/subject-redaction.d.ts.map +1 -1
  70. package/dist/subject-redaction.js +34 -27
  71. package/dist/subject-redaction.js.map +1 -1
  72. package/package.json +2 -2
@@ -0,0 +1,198 @@
1
+ export const BROKER_SCHEMA = [
2
+ {
3
+ by: '#3467 (A1): messages and the handoff marks',
4
+ statements: [
5
+ `CREATE TABLE IF NOT EXISTS broker_messages (
6
+ id TEXT PRIMARY KEY,
7
+ kind TEXT NOT NULL,
8
+ tenant_id TEXT NOT NULL,
9
+ scope_id TEXT NOT NULL,
10
+ type TEXT NOT NULL,
11
+ body TEXT NOT NULL,
12
+ committed_at TEXT NOT NULL,
13
+ received_at INTEGER NOT NULL,
14
+ attempts INTEGER NOT NULL DEFAULT 0,
15
+ next_at INTEGER,
16
+ last_error TEXT,
17
+ delivered_at INTEGER
18
+ )`,
19
+ 'CREATE INDEX IF NOT EXISTS broker_messages_due ON broker_messages (next_at) WHERE next_at IS NOT NULL',
20
+ `CREATE TABLE IF NOT EXISTS broker_marks (
21
+ tenant_id TEXT NOT NULL,
22
+ scope_id TEXT NOT NULL,
23
+ kind TEXT NOT NULL,
24
+ mark TEXT NOT NULL,
25
+ PRIMARY KEY (tenant_id, scope_id, kind)
26
+ )`,
27
+ ],
28
+ },
29
+ {
30
+ by: '#3470 (A4): a delivery per (message, receiver), a breaker per receiver, the ordering key',
31
+ statements: [
32
+ // The sender's ordering key (RFC §4.5). NULL: the message is unordered at every receiver.
33
+ 'ALTER TABLE broker_messages ADD COLUMN ordering_key TEXT',
34
+ // One row per (message, receiver) the message is for. A message with none is held: the broker
35
+ // had no receiver when it arrived. The message row keeps the content; this keeps the fate.
36
+ `CREATE TABLE broker_deliveries (
37
+ message_id TEXT NOT NULL,
38
+ receiver TEXT NOT NULL,
39
+ -- the message's ordering key when this receiver's subscription asks for order, else NULL
40
+ lane TEXT,
41
+ -- 'pending' | 'delivered' | 'dead' | 'discarded' | 'expired'
42
+ state TEXT NOT NULL,
43
+ attempts INTEGER NOT NULL DEFAULT 0,
44
+ -- pending: epoch ms of the next attempt. NULL in every other state
45
+ next_at INTEGER,
46
+ last_error TEXT,
47
+ -- the receiver's HTTP status on the last failure, when it gave one
48
+ last_status INTEGER,
49
+ -- dead: when the broker gave up on it
50
+ dead_at INTEGER,
51
+ -- delivered, discarded, expired: when it settled
52
+ settled_at INTEGER,
53
+ -- how many times a dead letter was resent
54
+ resends INTEGER NOT NULL DEFAULT 0,
55
+ PRIMARY KEY (message_id, receiver)
56
+ )`,
57
+ "CREATE INDEX broker_deliveries_due ON broker_deliveries (next_at) WHERE state = 'pending'",
58
+ // A lane's head: the lowest message id still pending or dead, per (receiver, lane).
59
+ `CREATE INDEX broker_deliveries_lane ON broker_deliveries (receiver, lane, message_id)
60
+ WHERE lane IS NOT NULL AND state IN ('pending', 'dead')`,
61
+ "CREATE INDEX broker_deliveries_dead ON broker_deliveries (dead_at) WHERE state = 'dead'",
62
+ // The pause per receiver (circuit breaker) and its slow-down (429, Retry-After).
63
+ `CREATE TABLE broker_receivers (
64
+ receiver TEXT PRIMARY KEY,
65
+ -- consecutive failures that count toward the pause; a success or a refusal resets it
66
+ failures INTEGER NOT NULL DEFAULT 0,
67
+ -- 1 while paused: once blocked_until passes, the next send is the one probe
68
+ open INTEGER NOT NULL DEFAULT 0,
69
+ -- the pause now in force, which a failed probe grows
70
+ pause_ms INTEGER,
71
+ -- epoch ms before which nothing is sent: a pause, or a slow-down
72
+ blocked_until INTEGER
73
+ )`,
74
+ // A1's single receiver becomes the subscription named 'default'; its state moves over.
75
+ `INSERT INTO broker_deliveries (message_id, receiver, state, attempts, next_at, last_error, settled_at)
76
+ SELECT id, 'default',
77
+ CASE WHEN delivered_at IS NOT NULL THEN 'delivered' ELSE 'pending' END,
78
+ attempts,
79
+ CASE WHEN delivered_at IS NULL THEN next_at END,
80
+ last_error,
81
+ delivered_at
82
+ FROM broker_messages WHERE delivered_at IS NOT NULL OR next_at IS NOT NULL`,
83
+ 'DROP INDEX broker_messages_due',
84
+ 'ALTER TABLE broker_messages DROP COLUMN attempts',
85
+ 'ALTER TABLE broker_messages DROP COLUMN next_at',
86
+ 'ALTER TABLE broker_messages DROP COLUMN last_error',
87
+ 'ALTER TABLE broker_messages DROP COLUMN delivered_at',
88
+ ],
89
+ },
90
+ {
91
+ by: '#3484: subject erasure, the tombstone a late handoff is screened against',
92
+ statements: [
93
+ // One row per erased (tenant, scope, subject), kept for good (`broker-erasure.ts`).
94
+ `CREATE TABLE broker_erased_subjects (
95
+ tenant_id TEXT NOT NULL,
96
+ scope_id TEXT NOT NULL,
97
+ subject_id TEXT NOT NULL,
98
+ erased_at TEXT NOT NULL,
99
+ PRIMARY KEY (tenant_id, scope_id, subject_id)
100
+ )`,
101
+ ],
102
+ },
103
+ {
104
+ by: '#3469 (A3): broker to broker, and request-reply',
105
+ // The relay's tables (`broker-relay.ts`). None is the store's, and the store reads none of them.
106
+ // - broker_relay_hops: the sending side of an event, one row per (message, receiving app). The
107
+ // row with app = '' records that the subscribers were resolved, so a retry asks only when not.
108
+ // - broker_relay_outgoing: the requests and replies this broker originates (no outbox row has them).
109
+ // - broker_relay_inbox: what another app's broker relayed here, once per (calling app, id). A
110
+ // reply settles as it arrives; refusal keeps why one was refused, so a repeat is answered alike.
111
+ // - broker_waits: who waits for which request, until when, and what they were handed.
112
+ statements: [
113
+ `CREATE TABLE broker_relay_hops (
114
+ message_id TEXT NOT NULL,
115
+ app TEXT NOT NULL,
116
+ -- owed | accepted | no-broker | refused | unexported
117
+ state TEXT NOT NULL,
118
+ attempts INTEGER NOT NULL DEFAULT 0,
119
+ last_error TEXT,
120
+ updated_at INTEGER NOT NULL,
121
+ PRIMARY KEY (message_id, app)
122
+ )`,
123
+ `CREATE TABLE broker_relay_outgoing (
124
+ id TEXT PRIMARY KEY,
125
+ kind TEXT NOT NULL,
126
+ tenant_id TEXT NOT NULL,
127
+ scope_id TEXT NOT NULL,
128
+ to_app TEXT NOT NULL,
129
+ type TEXT NOT NULL,
130
+ body TEXT NOT NULL,
131
+ committed_at TEXT NOT NULL,
132
+ request_id TEXT,
133
+ deadline INTEGER,
134
+ -- due | accepted | no-broker | refused | abandoned
135
+ state TEXT NOT NULL,
136
+ attempts INTEGER NOT NULL DEFAULT 0,
137
+ next_at INTEGER,
138
+ last_error TEXT,
139
+ created_at INTEGER NOT NULL,
140
+ settled_at INTEGER
141
+ )`,
142
+ 'CREATE INDEX broker_relay_outgoing_due ON broker_relay_outgoing (next_at) WHERE next_at IS NOT NULL',
143
+ `CREATE TABLE broker_relay_inbox (
144
+ caller_app TEXT NOT NULL,
145
+ id TEXT NOT NULL,
146
+ kind TEXT NOT NULL,
147
+ -- the envelope as the router handed it, its message's body within: content erasure reaches
148
+ envelope_body TEXT NOT NULL,
149
+ received_at INTEGER NOT NULL,
150
+ attempts INTEGER NOT NULL DEFAULT 0,
151
+ -- epoch ms of the next delivery to the scope, NULL once settled
152
+ next_at INTEGER,
153
+ last_error TEXT,
154
+ refusal TEXT,
155
+ settled_at INTEGER,
156
+ PRIMARY KEY (caller_app, id)
157
+ )`,
158
+ 'CREATE INDEX broker_relay_inbox_due ON broker_relay_inbox (next_at) WHERE next_at IS NOT NULL',
159
+ `CREATE TABLE broker_waits (
160
+ request_id TEXT PRIMARY KEY,
161
+ tenant_id TEXT NOT NULL,
162
+ scope_id TEXT NOT NULL,
163
+ to_app TEXT NOT NULL,
164
+ resume TEXT NOT NULL,
165
+ deadline INTEGER NOT NULL,
166
+ -- waiting | answered | expired
167
+ state TEXT NOT NULL,
168
+ reason TEXT,
169
+ reply_id TEXT,
170
+ -- the paired reply, its body within: content erasure reaches
171
+ reply_body TEXT,
172
+ settled_at INTEGER,
173
+ resume_attempts INTEGER NOT NULL DEFAULT 0,
174
+ resume_next_at INTEGER,
175
+ resume_error TEXT,
176
+ resumed_at INTEGER
177
+ )`,
178
+ `CREATE INDEX broker_waits_waiting ON broker_waits (deadline) WHERE state = 'waiting'`,
179
+ 'CREATE INDEX broker_waits_resume ON broker_waits (resume_next_at) WHERE resume_next_at IS NOT NULL',
180
+ ],
181
+ },
182
+ ];
183
+ /** Run the steps a broker's database has not run yet, each in one transaction. */
184
+ export function migrateBrokerStore(sql) {
185
+ sql.run('CREATE TABLE IF NOT EXISTS broker_schema (version INTEGER NOT NULL)');
186
+ const row = sql.all('SELECT version FROM broker_schema')[0];
187
+ const ran = Number(row?.version ?? 0);
188
+ if (!row)
189
+ sql.run('INSERT INTO broker_schema (version) VALUES (0)');
190
+ for (let i = ran; i < BROKER_SCHEMA.length; i++) {
191
+ sql.transaction(() => {
192
+ for (const statement of BROKER_SCHEMA[i].statements)
193
+ sql.run(statement);
194
+ sql.run('UPDATE broker_schema SET version = ?', i + 1);
195
+ });
196
+ }
197
+ }
198
+ //# sourceMappingURL=broker-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-schema.js","sourceRoot":"","sources":["../src/broker-schema.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAC,MAAM,aAAa,GAAgC;IACxD;QACE,EAAE,EAAE,4CAA4C;QAChD,UAAU,EAAE;YACV;;;;;;;;;;;;;SAaG;YACH,uGAAuG;YACvG;;;;;;SAMG;SACJ;KACF;IACD;QACE,EAAE,EAAE,0FAA0F;QAC9F,UAAU,EAAE;YACV,0FAA0F;YAC1F,0DAA0D;YAC1D,8FAA8F;YAC9F,2FAA2F;YAC3F;;;;;;;;;;;;;;;;;;;;SAoBG;YACH,2FAA2F;YAC3F,oFAAoF;YACpF;iEAC2D;YAC3D,yFAAyF;YACzF,iFAAiF;YACjF;;;;;;;;;;SAUG;YACH,uFAAuF;YACvF;;;;;;;sFAOgF;YAChF,gCAAgC;YAChC,kDAAkD;YAClD,iDAAiD;YACjD,oDAAoD;YACpD,sDAAsD;SACvD;KACF;IACD;QACE,EAAE,EAAE,0EAA0E;QAC9E,UAAU,EAAE;YACV,oFAAoF;YACpF;;;;;;SAMG;SACJ;KACF;IACD;QACE,EAAE,EAAE,iDAAiD;QACrD,iGAAiG;QACjG,+FAA+F;QAC/F,iGAAiG;QACjG,qGAAqG;QACrG,8FAA8F;QAC9F,mGAAmG;QACnG,sFAAsF;QACtF,UAAU,EAAE;YACV;;;;;;;;;SASG;YACH;;;;;;;;;;;;;;;;;;SAkBG;YACH,qGAAqG;YACrG;;;;;;;;;;;;;;SAcG;YACH,+FAA+F;YAC/F;;;;;;;;;;;;;;;;;;SAkBG;YACH,sFAAsF;YACtF,oGAAoG;SACrG;KACF;CACF,CAAC;AAEF,kFAAkF;AAClF,MAAM,UAAU,kBAAkB,CAAC,GAAc;IAC/C,GAAG,CAAC,GAAG,CAAC,qEAAqE,CAAC,CAAC;IAC/E,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAsB,mCAAmC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjF,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,GAAG,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IACpE,KAAK,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChD,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE;YACnB,KAAK,MAAM,SAAS,IAAI,aAAa,CAAC,CAAC,CAAE,CAAC,UAAU;gBAAE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACzE,GAAG,CAAC,GAAG,CAAC,sCAAsC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,288 @@
1
+ /**
2
+ * #3474 (RFC broker-and-tenant-isolation §9.1): what a delivery broker tells the platform about the
3
+ * messages it owns, and the state it is in. Shared by both adapters, so the two cannot report
4
+ * differently.
5
+ *
6
+ * Two kinds of record, one sink:
7
+ *
8
+ * - **A data point per step** — the scope's handoff, the broker's receipt, each delivery attempt
9
+ * (delivered, or failed and retried), and, once #3470 decides them, dead letter and a receiver's
10
+ * pause starting and ending. Each names the tenant, the app, the scope, the receiver, the channel
11
+ * (the message's kind), the outcome, its timing and the trace id where one is known.
12
+ * - **The broker's state, when it changes** — queue depth, the oldest waiting message's age, paused
13
+ * receivers, dead-letter count. Reported by the broker as it moves, never polled, so an alarm such
14
+ * as "dead letter growing for app X" is a query over these points and needs no pass.
15
+ *
16
+ * **Never content.** No body, no event payload, no error text (a receiver's error may echo what it
17
+ * was given), no event type, no principal: only ids the platform mints (tenant, scope, message,
18
+ * trace), the app's slug, and enumerated steps and outcomes. Exact counts for billing are not these
19
+ * points' job: they come from the broker's own store, into the lake (K-70).
20
+ *
21
+ * **Cost.** A sink write is in-memory and never awaited. A handoff adds one primary-key read per 50
22
+ * ids it carries (`BrokerStore.held`), to tell a new message from a repeat, and keeps the state in
23
+ * memory from there; the one aggregate read (`BrokerStore.stats`) runs once per object wake and once
24
+ * after each delivery pass, beside the pass's own reads. A delivery pass writes one point per
25
+ * attempt (and one per pause change), bounded by `BROKER_DELIVERY_BATCH`, so an invocation stays far
26
+ * under Analytics Engine's per-invocation point limit. A sink that throws drops the point and never fails the broker.
27
+ *
28
+ * **Dead letter and pause** are read off what #3470's store decided: `BrokerStore.failed`'s outcome
29
+ * and the receiver's breaker (`BrokerStore.paused`), after each attempt. A dead letter resent or
30
+ * discarded moves the state, which the adapter settles after the call.
31
+ */
32
+ import type { BrokerMessage, BrokerMessageKind, BrokerStats, BrokerStore, DeliveryObserver, HandOffAnswer } from './delivery-broker.js';
33
+ /**
34
+ * The Analytics Engine dataset binding the broker and the scopes that hand off to it write through.
35
+ * No binding, no points: the broker runs unobserved, as it does with the switch off.
36
+ */
37
+ export declare const BROKER_TELEMETRY_BINDING = "SUBSTRAT_BROKER_TELEMETRY";
38
+ /** Where a message is in its life, as a point names it. `state` is the broker's state report. */
39
+ export type BrokerStep = 'handoff' | 'receipt' | 'delivery' | 'retry' | 'dead-letter' | 'pause-start' | 'pause-end' | 'state';
40
+ /** The outcomes each step may carry: enumerated, so no free text reaches a point. */
41
+ export type BrokerOutcome =
42
+ /** handoff: every message acknowledged. */
43
+ 'acked'
44
+ /** handoff: some acknowledged; the rest go again. */
45
+ | 'partial'
46
+ /** handoff: the broker refused or was unreachable; the scope alarm retries. */
47
+ | 'failed'
48
+ /** receipt: the broker now holds the batch (`duplicates` says how many it held already). */
49
+ | 'stored'
50
+ /** delivery: the receiver took it. */
51
+ | 'delivered'
52
+ /** retry: the attempt failed and the next is scheduled (`wait_ms`). */
53
+ | 'scheduled'
54
+ /** retry: the receiver asked to slow down; nothing spent, the next attempt waits (`wait_ms`). */
55
+ | 'slowed'
56
+ /** dead-letter: the message stops being retried (#3470). */
57
+ | 'dead'
58
+ /** pause-start / pause-end (#3470). */
59
+ | 'paused' | 'resumed'
60
+ /** state: the broker's state moved. */
61
+ | 'changed';
62
+ /** One step, as it leaves. Every count and time is a number; a field not known is null. */
63
+ export interface BrokerPoint {
64
+ step: BrokerStep;
65
+ outcome: BrokerOutcome;
66
+ tenantId: string;
67
+ app: string;
68
+ scopeId: string | null;
69
+ /** The receiver (the subscription's name) a delivery step is about, or a pause is of. */
70
+ receiver: string | null;
71
+ channel: BrokerMessageKind | null;
72
+ /** The W3C trace id (32 hex) of the request that committed, where the step runs inside it. */
73
+ traceId: string | null;
74
+ /** The message, for a step about one. */
75
+ messageId: string | null;
76
+ /** How many messages the point stands for. */
77
+ messages: number;
78
+ /** receipt: how many of them the broker already held. */
79
+ duplicates: number;
80
+ /** The step's own time: the handoff call, the delivery attempt, a pause's length. */
81
+ durationMs: number;
82
+ /** Since the message committed (the oldest of a batch). */
83
+ ageMs: number;
84
+ attempts: number;
85
+ /** retry: until the next attempt. */
86
+ waitMs: number;
87
+ }
88
+ /** The broker's state, as it leaves. */
89
+ export interface BrokerStateReport extends BrokerStats {
90
+ tenantId: string;
91
+ app: string;
92
+ /** Age of the oldest waiting message at the report, or 0 with none. */
93
+ oldestAgeMs: number;
94
+ }
95
+ /** Where points go: Analytics Engine on the Durable Object, a recorder in a test. */
96
+ export interface BrokerTelemetrySink {
97
+ point(point: BrokerPoint): void;
98
+ state(report: BrokerStateReport): void;
99
+ }
100
+ /**
101
+ * Where each field lands in an Analytics Engine data point. **A published shape**, as the scope-work
102
+ * and router layouts are: it only ever GROWS, a new field taking the next ordinal; no position is
103
+ * reordered, renamed or reused. Its own dataset. Every reader filters on `substrat.broker.step`,
104
+ * because state reports and step points share it; a state report's step fields hold their `absent`.
105
+ *
106
+ * "Dead letter growing for app X" reads, for instance:
107
+ * `SELECT index1 AS tenant, blob1 AS app, max(double10) FROM <dataset> WHERE blob2 = 'state'
108
+ * AND timestamp > NOW() - INTERVAL '1' HOUR GROUP BY tenant, app`.
109
+ */
110
+ export declare const BROKER_DATA_POINT_LAYOUT: {
111
+ readonly indexes: readonly [{
112
+ readonly ordinal: 'index1';
113
+ readonly name: 'substrat.tenant.id';
114
+ readonly unit: null;
115
+ readonly absent: '';
116
+ }];
117
+ readonly blobs: readonly [{
118
+ readonly ordinal: 'blob1';
119
+ readonly name: 'substrat.vertical';
120
+ readonly unit: null;
121
+ readonly absent: '';
122
+ }, {
123
+ readonly ordinal: 'blob2';
124
+ readonly name: 'substrat.broker.step';
125
+ readonly unit: null;
126
+ readonly absent: '';
127
+ }, {
128
+ readonly ordinal: 'blob3';
129
+ readonly name: 'substrat.broker.outcome';
130
+ readonly unit: null;
131
+ readonly absent: '';
132
+ }, {
133
+ readonly ordinal: 'blob4';
134
+ readonly name: 'substrat.scope.id';
135
+ readonly unit: null;
136
+ readonly absent: '';
137
+ }, {
138
+ readonly ordinal: 'blob5';
139
+ readonly name: 'substrat.broker.receiver';
140
+ readonly unit: null;
141
+ readonly absent: '';
142
+ }, {
143
+ readonly ordinal: 'blob6';
144
+ readonly name: 'substrat.broker.channel';
145
+ readonly unit: null;
146
+ readonly absent: '';
147
+ }, {
148
+ readonly ordinal: 'blob7';
149
+ readonly name: 'trace.id';
150
+ readonly unit: null;
151
+ readonly absent: '';
152
+ }, {
153
+ readonly ordinal: 'blob8';
154
+ readonly name: 'substrat.message.id';
155
+ readonly unit: null;
156
+ readonly absent: '';
157
+ }];
158
+ readonly doubles: readonly [{
159
+ readonly ordinal: 'double1';
160
+ readonly name: 'substrat.broker.messages';
161
+ readonly unit: '{message}';
162
+ readonly absent: 0;
163
+ }, {
164
+ readonly ordinal: 'double2';
165
+ readonly name: 'substrat.broker.duplicates';
166
+ readonly unit: '{message}';
167
+ readonly absent: 0;
168
+ }, {
169
+ readonly ordinal: 'double3';
170
+ readonly name: 'substrat.broker.duration';
171
+ readonly unit: 'ms';
172
+ readonly absent: 0;
173
+ }, {
174
+ readonly ordinal: 'double4';
175
+ readonly name: 'substrat.broker.age';
176
+ readonly unit: 'ms';
177
+ readonly absent: 0;
178
+ }, {
179
+ readonly ordinal: 'double5';
180
+ readonly name: 'substrat.broker.attempts';
181
+ readonly unit: '{attempt}';
182
+ readonly absent: 0;
183
+ }, {
184
+ readonly ordinal: 'double6';
185
+ readonly name: 'substrat.broker.wait';
186
+ readonly unit: 'ms';
187
+ readonly absent: 0;
188
+ }, {
189
+ readonly ordinal: 'double7';
190
+ readonly name: 'substrat.broker.queue.depth';
191
+ readonly unit: '{message}';
192
+ readonly absent: 0;
193
+ }, {
194
+ readonly ordinal: 'double8';
195
+ readonly name: 'substrat.broker.queue.oldest_age';
196
+ readonly unit: 'ms';
197
+ readonly absent: 0;
198
+ }, {
199
+ readonly ordinal: 'double9';
200
+ readonly name: 'substrat.broker.paused_receivers';
201
+ readonly unit: '{receiver}';
202
+ readonly absent: 0;
203
+ }, {
204
+ readonly ordinal: 'double10';
205
+ readonly name: 'substrat.broker.dead_letters';
206
+ readonly unit: '{message}';
207
+ readonly absent: 0;
208
+ }];
209
+ };
210
+ /** A step point or a state report as the data point it becomes, built from the layout. */
211
+ export declare function brokerDataPoint(record: BrokerPoint | BrokerStateReport): {
212
+ indexes: string[];
213
+ blobs: string[];
214
+ doubles: number[];
215
+ };
216
+ /** The trace id of a W3C `traceparent` (`00-<trace>-<span>-<flags>`), or null. */
217
+ export declare function traceIdOf(traceparent: string | undefined): string | null;
218
+ /**
219
+ * A handoff round's outcome, by how many of the sent messages the broker acknowledged: all, some (the
220
+ * rest go again), or none. Not by whether the marks moved: they stop at the first unacknowledged id,
221
+ * so an answer acknowledging only later ids moves no mark and is still `partial`.
222
+ */
223
+ export declare function handoffOutcome(sent: readonly BrokerMessage[], answer: HandOffAnswer): 'acked' | 'partial' | 'failed';
224
+ /**
225
+ * The scope's side: one point per handoff round, written where the scope calls its broker. A
226
+ * failed round carries what it tried to send. Never throws.
227
+ */
228
+ export declare function reportHandoff(sink: BrokerTelemetrySink, ids: {
229
+ tenantId: string;
230
+ app: string;
231
+ scopeId: string;
232
+ }, round: {
233
+ sent: readonly BrokerMessage[];
234
+ outcome: Extract<BrokerOutcome, 'acked' | 'partial' | 'failed'>;
235
+ startedAt: number;
236
+ at: number;
237
+ traceId: string | null;
238
+ }): void;
239
+ /**
240
+ * The broker's side, over its store: receipts, attempts, the #3470 seams, and the state report.
241
+ * One per broker object. Every method swallows a sink's throw (counted in `dropped`).
242
+ */
243
+ export declare class BrokerTelemetry {
244
+ private readonly store;
245
+ private readonly sink;
246
+ private readonly ids;
247
+ /** Points the sink refused. */
248
+ dropped: number;
249
+ /** The state as last read or moved; null until the first read after a wake. */
250
+ private known;
251
+ private lastReported;
252
+ constructor(store: BrokerStore, sink: BrokerTelemetrySink, ids: {
253
+ tenantId: string;
254
+ app: string;
255
+ });
256
+ /** Before `accept`: which of the messages the store holds already, or null when the read failed (unknown). */
257
+ heldBefore(messages: readonly BrokerMessage[]): Set<string> | null;
258
+ /**
259
+ * After `accept` committed: one receipt per (scope, channel) in the batch, and the state moved by
260
+ * the new messages in memory (read whole once, on the first receipt after a wake). With `heldBefore`
261
+ * unknown (its probe failed), the receipts count no duplicates and the state is read whole instead.
262
+ */
263
+ received(messages: readonly BrokerMessage[], heldBefore: ReadonlySet<string> | null, at: number, traceId?: string | null): void;
264
+ /**
265
+ * What `runDeliveryPass` tells of each attempt, after the store recorded it: a delivery, a retry
266
+ * (with the wait the store scheduled), a slow-down, or a dead letter; and a receiver's pause starting
267
+ * or ending, read off its breaker (one primary-key read per attempt). The pauses already open when
268
+ * the object woke are read once, when its first pass starts, so one that ends after a wake reports its end
269
+ * (with no length: when it began is not kept) and none is reported starting twice.
270
+ */
271
+ passObserver(): DeliveryObserver;
272
+ /** A receiver's breaker, against what this object last saw: a pause starting or ending is a point. */
273
+ private notePause;
274
+ /** Open pauses, by receiver: when this object saw each start, or null for one open before it woke. */
275
+ private readonly openSince;
276
+ private openLoaded;
277
+ private read;
278
+ /** Read the state whole (`BrokerStore.stats`) and report it if it moved: after a pass, or on wake. */
279
+ settle(at: number): void;
280
+ /** The state as known now, for a staff read (`state()` on the broker); read whole if not yet known. */
281
+ current(at: number): BrokerStateReport;
282
+ private reportOf;
283
+ /** On change only: the same depth, oldest, pauses and dead letters write nothing. */
284
+ private report;
285
+ private about;
286
+ private write;
287
+ }
288
+ //# sourceMappingURL=broker-telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-telemetry.d.ts","sourceRoot":"","sources":["../src/broker-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAExI;;;GAGG;AACH,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AAEpE,iGAAiG;AACjG,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,SAAS,GACT,UAAU,GACV,OAAO,GACP,aAAa,GACb,aAAa,GACb,WAAW,GACX,OAAO,CAAC;AAEZ,qFAAqF;AACrF,MAAM,MAAM,aAAa;AACvB,2CAA2C;AACzC,OAAO;AACT,qDAAqD;GACnD,SAAS;AACX,+EAA+E;GAC7E,QAAQ;AACV,4FAA4F;GAC1F,QAAQ;AACV,sCAAsC;GACpC,WAAW;AACb,uEAAuE;GACrE,WAAW;AACb,iGAAiG;GAC/F,QAAQ;AACV,4DAA4D;GAC1D,MAAM;AACR,uCAAuC;GACrC,QAAQ,GACR,SAAS;AACX,uCAAuC;GACrC,SAAS,CAAC;AAEd,2FAA2F;AAC3F,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IAC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