@theokit/gateway 0.6.1 → 0.7.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/CHANGELOG.md +37 -0
- package/dist/index.d.cts +144 -10
- package/dist/index.d.ts +144 -10
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 74a79b5: A gateway can now be authored, published and consumed outside this repository.
|
|
8
|
+
|
|
9
|
+
`PlatformName` and `MessageEvent` derive from a new exported `PlatformEventRegistry`, an interface
|
|
10
|
+
other packages extend through TypeScript declaration merging:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
declare module "@theokit/gateway" {
|
|
14
|
+
interface PlatformEventRegistry {
|
|
15
|
+
signal: SignalMessageEvent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Exhaustive narrowing survives, including over platforms the core has never heard of: forget a
|
|
21
|
+
`case` for a third-party platform and the build breaks, exactly as it does for the ten shipped
|
|
22
|
+
here. A misspelled platform name is still a compile error — the union is opened to extension, not
|
|
23
|
+
to arbitrary strings.
|
|
24
|
+
|
|
25
|
+
Both sides of an augmentation are gated. An entry typed `any`, registered under an index signature,
|
|
26
|
+
carrying a non-literal discriminator, or disagreeing with its own key is excluded rather than
|
|
27
|
+
admitted. Each of those was measured to break narrowing for **every** consumer before the guards
|
|
28
|
+
existed — an index signature made the whole union resolve to `never`, and an optional entry injected
|
|
29
|
+
`undefined` into it. Twelve augmentation shapes are compiled in CI against the published
|
|
30
|
+
declaration to keep it that way.
|
|
31
|
+
|
|
32
|
+
**Behaviour change:** `BaseMessageEvent.platform` is now `string` rather than `PlatformName`. Every
|
|
33
|
+
concrete variant still narrows it to its own literal, so code holding a `MessageEvent` is
|
|
34
|
+
unaffected. Code that assigns `.platform` off a bare `BaseMessageEvent` into a `PlatformName` slot
|
|
35
|
+
will need a narrowing step. This is required by the derivation: `PlatformName` now comes from the
|
|
36
|
+
guarded union, and naming it on the base would make the two reference each other.
|
|
37
|
+
|
|
38
|
+
See `docs/adr/0002-platform-event-registry.md`, which supersedes `docs/adr/0001-message-event-closed-union.md`.
|
|
39
|
+
|
|
3
40
|
## 0.6.1
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/dist/index.d.cts
CHANGED
|
@@ -12,20 +12,31 @@
|
|
|
12
12
|
* }
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
15
|
-
* This union is
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* This union is **open to extension and closed to corruption**. It is derived from
|
|
16
|
+
* {@link PlatformEventRegistry}, an interface a package outside this repository extends through
|
|
17
|
+
* declaration merging — so a gateway can be authored, published and consumed without editing this
|
|
18
|
+
* file, while narrowing still holds over platforms declared here and elsewhere alike. Entries that
|
|
19
|
+
* are not well-formed event shapes agreeing with their own key are excluded rather than admitted.
|
|
20
|
+
*
|
|
21
|
+
* It was closed until 2026-08-23. `docs/adr/0001-message-event-closed-union.md` records why, and
|
|
22
|
+
* `docs/adr/0002-platform-event-registry.md` records what changed and what the guard costs.
|
|
18
23
|
*
|
|
19
24
|
* @public
|
|
20
25
|
*/
|
|
21
|
-
/** Closed enum of supported transport platforms. */
|
|
22
|
-
type PlatformName = "telegram" | "discord" | "slack" | "whatsapp" | "teams" | "email" | "sms" | "mattermost" | "line" | "matrix";
|
|
23
26
|
/** Fields common to every platform's inbound event. */
|
|
24
27
|
interface BaseMessageEvent {
|
|
25
28
|
/** Stable id used as a session-key segment and for dedup. */
|
|
26
29
|
readonly id: string;
|
|
27
|
-
/**
|
|
28
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Discriminator.
|
|
32
|
+
*
|
|
33
|
+
* Typed `string` here and narrowed to a literal by every variant. It cannot be `PlatformName`:
|
|
34
|
+
* that type is derived from the guarded union below, and the union is built out of shapes that
|
|
35
|
+
* extend this interface — naming it here would make the two reference each other (`TS2456`).
|
|
36
|
+
* Widening it is also what lets `PlatformName` be derived from the FILTERED union rather than
|
|
37
|
+
* from `keyof`, so a name and an event can never disagree about which platforms exist.
|
|
38
|
+
*/
|
|
39
|
+
readonly platform: string;
|
|
29
40
|
/** Sender identity (opaque, platform-namespaced). */
|
|
30
41
|
readonly sender: {
|
|
31
42
|
readonly id: string;
|
|
@@ -219,8 +230,131 @@ interface MatrixMessageEvent extends BaseMessageEvent {
|
|
|
219
230
|
readonly raw: unknown;
|
|
220
231
|
};
|
|
221
232
|
}
|
|
222
|
-
/**
|
|
223
|
-
|
|
233
|
+
/**
|
|
234
|
+
* The open registry every platform's inbound event is filed under.
|
|
235
|
+
*
|
|
236
|
+
* **This is an `interface` on purpose, and it must stay one.** An interface can be extended from
|
|
237
|
+
* another package through declaration merging; a type alias cannot. That single property is what
|
|
238
|
+
* lets a gateway be authored, published and consumed without editing this file — the capability
|
|
239
|
+
* B-008 measured as impossible (`TS2416`, compiled against the published declaration) and ADR-0002
|
|
240
|
+
* decided to unlock. Collapsing it back into a type alias would silently remove that capability
|
|
241
|
+
* while every test in this package still passed.
|
|
242
|
+
*
|
|
243
|
+
* A third-party gateway registers itself from its own package:
|
|
244
|
+
*
|
|
245
|
+
* ```typescript
|
|
246
|
+
* declare module "@theokit/gateway" {
|
|
247
|
+
* interface PlatformEventRegistry {
|
|
248
|
+
* signal: SignalMessageEvent;
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @public
|
|
254
|
+
*/
|
|
255
|
+
interface PlatformEventRegistry {
|
|
256
|
+
telegram: TelegramMessageEvent;
|
|
257
|
+
discord: DiscordMessageEvent;
|
|
258
|
+
slack: SlackMessageEvent;
|
|
259
|
+
whatsapp: WhatsAppMessageEvent;
|
|
260
|
+
teams: TeamsMessageEvent;
|
|
261
|
+
email: EmailMessageEvent;
|
|
262
|
+
sms: SMSMessageEvent;
|
|
263
|
+
mattermost: MattermostMessageEvent;
|
|
264
|
+
line: LineMessageEvent;
|
|
265
|
+
matrix: MatrixMessageEvent;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* `true` only for `any` — the one type that would otherwise swallow the union.
|
|
269
|
+
*
|
|
270
|
+
* `any extends X` distributes to both branches of a conditional, so an ordinary
|
|
271
|
+
* `T extends BaseMessageEvent ? T : never` does NOT keep `any` out. This does: nothing but `any`
|
|
272
|
+
* makes `1 & T` accept `0`.
|
|
273
|
+
*/
|
|
274
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
275
|
+
/**
|
|
276
|
+
* A registry key must be a literal, never the broad `string` an index signature produces.
|
|
277
|
+
*
|
|
278
|
+
* Measured in review: `interface PlatformEventRegistry { [key: string]: BaseMessageEvent }` is a
|
|
279
|
+
* LEGAL augmentation — every existing variant is assignable to the base — and without this it
|
|
280
|
+
* widens the whole platform name to `string`, so every typo becomes valid and every consumer's
|
|
281
|
+
* `switch` stops narrowing. That is the same collapse an `any` VALUE causes, arriving through the
|
|
282
|
+
* key side, and it is why both sides are gated.
|
|
283
|
+
*/
|
|
284
|
+
type LiteralKey<K> = string extends K ? never : K;
|
|
285
|
+
/**
|
|
286
|
+
* The registry's LITERAL keys — index signatures dropped before `keyof` ever sees them.
|
|
287
|
+
*
|
|
288
|
+
* Filtering the value was not enough, measured twice. `keyof` over a registry carrying
|
|
289
|
+
* `{ [key: string]: BaseMessageEvent }` is `string | number`, and indexing a mapped type by that
|
|
290
|
+
* yields `never` for BOTH the union and the platform name: a hostile augmentation did not merely
|
|
291
|
+
* fail to join, it annihilated the union and broke every first-party narrowing site with
|
|
292
|
+
* `TS2339: Property 'telegram' does not exist on type 'never'`.
|
|
293
|
+
*
|
|
294
|
+
* It also fixes a second measured defect for free. Mapping over `keyof` directly is HOMOMORPHIC, so
|
|
295
|
+
* an OPTIONAL entry (`signal?: Event`, a shape an author writes by accident) kept its modifier and
|
|
296
|
+
* injected `undefined` into the union — `TS18048: 'e' is possibly 'undefined'` on a plain `switch`.
|
|
297
|
+
* Mapping over a computed key set is not homomorphic and drops the modifier. A `-?` was written
|
|
298
|
+
* here first as an explicit belt; the gate showed it could not be made to matter while this type is
|
|
299
|
+
* in place, so it was removed rather than kept as decoration nothing can fail without.
|
|
300
|
+
*/
|
|
301
|
+
type LiteralKeysOf<R> = keyof {
|
|
302
|
+
[K in keyof R as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: 0;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* A registry entry joins {@link MessageEvent} only if it is a real event shape
|
|
306
|
+
* (`docs/adr/0002-platform-event-registry.md`).
|
|
307
|
+
*
|
|
308
|
+
* Measured, not anticipated: without this guard a single entry typed `any` collapses the whole
|
|
309
|
+
* union, and `tsc --strict` then accepts `event.completelyMadeUpField.nested.nonsense` on EVERY
|
|
310
|
+
* consumer — ours included — with no error in any package and nothing red in any suite. The closed
|
|
311
|
+
* union could not fail that way, so the guard is what keeps the new capability from costing a
|
|
312
|
+
* safety property the old design had.
|
|
313
|
+
*
|
|
314
|
+
* A malformed entry is EXCLUDED rather than admitted. It is NOT free for anybody else, and an
|
|
315
|
+
* earlier version of this docblock said it was — measured false twice over. Filtering the VALUE
|
|
316
|
+
* alone left two shapes that break every consumer rather than only their author:
|
|
317
|
+
* `{ [key: string]: … }` made `keyof` yield `string | number`, so the union and the platform name
|
|
318
|
+
* both collapsed to `never`; and `signal?: …` kept its optional modifier through a homomorphic
|
|
319
|
+
* mapping and injected `undefined` into the union. Both are handled above — the first by
|
|
320
|
+
* {@link LiteralKeysOf}, the second by the `-?` on the mapping. What remains true, and is the
|
|
321
|
+
* honest version of the original claim:
|
|
322
|
+
* a `Record<PlatformName, T>` written against the ten still fails to compile, because the rejected
|
|
323
|
+
* key is gone from `PlatformName` while the consumer's literal map is not. What the exclusion buys
|
|
324
|
+
* is that the failure is a missing-key error at the consumer's own map rather than a silent loss
|
|
325
|
+
* of narrowing everywhere.
|
|
326
|
+
*
|
|
327
|
+
* Exported for the contract test in `tests/types/registry-guard.test.ts`, which asserts against
|
|
328
|
+
* this type rather than a copy of it — a copy would stay green with the guard deleted. It is
|
|
329
|
+
* deliberately NOT re-exported from the package barrel; it is an implementation detail of the
|
|
330
|
+
* derivation, not part of the published surface.
|
|
331
|
+
*/
|
|
332
|
+
type Registered<K, T> = IsAny<T> extends true ? never : [T] extends [BaseMessageEvent] ? [T] extends [{
|
|
333
|
+
readonly platform: LiteralKey<K>;
|
|
334
|
+
}] ? [LiteralKey<K>] extends [never] ? never : T : never : never;
|
|
335
|
+
/**
|
|
336
|
+
* The canonical inbound event: every guarded entry in {@link PlatformEventRegistry}.
|
|
337
|
+
*
|
|
338
|
+
* Derived rather than written, so third-party platforms are included automatically and exhaustive
|
|
339
|
+
* narrowing still holds over all of them.
|
|
340
|
+
*
|
|
341
|
+
* @public
|
|
342
|
+
*/
|
|
343
|
+
type MessageEvent = {
|
|
344
|
+
[K in LiteralKeysOf<PlatformEventRegistry>]: Registered<K, PlatformEventRegistry[K]>;
|
|
345
|
+
}[LiteralKeysOf<PlatformEventRegistry>];
|
|
346
|
+
/**
|
|
347
|
+
* Every platform that actually has a well-formed event in {@link PlatformEventRegistry}.
|
|
348
|
+
*
|
|
349
|
+
* Derived from the GUARDED union rather than from `keyof`, so `PlatformName` and
|
|
350
|
+
* `MessageEvent["platform"]` are the same set by construction. Deriving from `keyof` let a rejected
|
|
351
|
+
* entry keep contributing its key, which produced names no event could ever carry — an adapter
|
|
352
|
+
* could register for a platform that cannot exist.
|
|
353
|
+
*
|
|
354
|
+
* Still a union of string literals, so `switch (event.platform)` narrows and a misspelled name is
|
|
355
|
+
* a compile error.
|
|
356
|
+
*/
|
|
357
|
+
type PlatformName = MessageEvent["platform"];
|
|
224
358
|
|
|
225
359
|
/**
|
|
226
360
|
* `BasePlatformAdapter` — contract every transport adapter implements
|
|
@@ -723,4 +857,4 @@ interface ChunkByGraphemeOptions {
|
|
|
723
857
|
*/
|
|
724
858
|
declare function chunkByGrapheme(text: string, options: ChunkByGraphemeOptions): string[];
|
|
725
859
|
|
|
726
|
-
export { type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type ChunkByGraphemeOptions, type ChunkTextOptions, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type EmailMessageEvent, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type HookDecision, HookExecutor, type HookName, type LineMessageEvent, type MatrixMessageEvent, type MattermostMessageEvent, type MessageEvent, type OnErrorContext, type OutboundMessage, type PlatformName, type PostOutboundContext, type PreInboundContext, type SMSMessageEvent, type SendResult, SessionRouter, type SlackMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type WhatsAppMessageEvent, chunkByGrapheme, chunkText, defaultStrategy };
|
|
860
|
+
export { type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type ChunkByGraphemeOptions, type ChunkTextOptions, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type EmailMessageEvent, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type HookDecision, HookExecutor, type HookName, type LineMessageEvent, type MatrixMessageEvent, type MattermostMessageEvent, type MessageEvent, type OnErrorContext, type OutboundMessage, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type SMSMessageEvent, type SendResult, SessionRouter, type SlackMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type WhatsAppMessageEvent, chunkByGrapheme, chunkText, defaultStrategy };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,20 +12,31 @@
|
|
|
12
12
|
* }
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
15
|
-
* This union is
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* This union is **open to extension and closed to corruption**. It is derived from
|
|
16
|
+
* {@link PlatformEventRegistry}, an interface a package outside this repository extends through
|
|
17
|
+
* declaration merging — so a gateway can be authored, published and consumed without editing this
|
|
18
|
+
* file, while narrowing still holds over platforms declared here and elsewhere alike. Entries that
|
|
19
|
+
* are not well-formed event shapes agreeing with their own key are excluded rather than admitted.
|
|
20
|
+
*
|
|
21
|
+
* It was closed until 2026-08-23. `docs/adr/0001-message-event-closed-union.md` records why, and
|
|
22
|
+
* `docs/adr/0002-platform-event-registry.md` records what changed and what the guard costs.
|
|
18
23
|
*
|
|
19
24
|
* @public
|
|
20
25
|
*/
|
|
21
|
-
/** Closed enum of supported transport platforms. */
|
|
22
|
-
type PlatformName = "telegram" | "discord" | "slack" | "whatsapp" | "teams" | "email" | "sms" | "mattermost" | "line" | "matrix";
|
|
23
26
|
/** Fields common to every platform's inbound event. */
|
|
24
27
|
interface BaseMessageEvent {
|
|
25
28
|
/** Stable id used as a session-key segment and for dedup. */
|
|
26
29
|
readonly id: string;
|
|
27
|
-
/**
|
|
28
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Discriminator.
|
|
32
|
+
*
|
|
33
|
+
* Typed `string` here and narrowed to a literal by every variant. It cannot be `PlatformName`:
|
|
34
|
+
* that type is derived from the guarded union below, and the union is built out of shapes that
|
|
35
|
+
* extend this interface — naming it here would make the two reference each other (`TS2456`).
|
|
36
|
+
* Widening it is also what lets `PlatformName` be derived from the FILTERED union rather than
|
|
37
|
+
* from `keyof`, so a name and an event can never disagree about which platforms exist.
|
|
38
|
+
*/
|
|
39
|
+
readonly platform: string;
|
|
29
40
|
/** Sender identity (opaque, platform-namespaced). */
|
|
30
41
|
readonly sender: {
|
|
31
42
|
readonly id: string;
|
|
@@ -219,8 +230,131 @@ interface MatrixMessageEvent extends BaseMessageEvent {
|
|
|
219
230
|
readonly raw: unknown;
|
|
220
231
|
};
|
|
221
232
|
}
|
|
222
|
-
/**
|
|
223
|
-
|
|
233
|
+
/**
|
|
234
|
+
* The open registry every platform's inbound event is filed under.
|
|
235
|
+
*
|
|
236
|
+
* **This is an `interface` on purpose, and it must stay one.** An interface can be extended from
|
|
237
|
+
* another package through declaration merging; a type alias cannot. That single property is what
|
|
238
|
+
* lets a gateway be authored, published and consumed without editing this file — the capability
|
|
239
|
+
* B-008 measured as impossible (`TS2416`, compiled against the published declaration) and ADR-0002
|
|
240
|
+
* decided to unlock. Collapsing it back into a type alias would silently remove that capability
|
|
241
|
+
* while every test in this package still passed.
|
|
242
|
+
*
|
|
243
|
+
* A third-party gateway registers itself from its own package:
|
|
244
|
+
*
|
|
245
|
+
* ```typescript
|
|
246
|
+
* declare module "@theokit/gateway" {
|
|
247
|
+
* interface PlatformEventRegistry {
|
|
248
|
+
* signal: SignalMessageEvent;
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @public
|
|
254
|
+
*/
|
|
255
|
+
interface PlatformEventRegistry {
|
|
256
|
+
telegram: TelegramMessageEvent;
|
|
257
|
+
discord: DiscordMessageEvent;
|
|
258
|
+
slack: SlackMessageEvent;
|
|
259
|
+
whatsapp: WhatsAppMessageEvent;
|
|
260
|
+
teams: TeamsMessageEvent;
|
|
261
|
+
email: EmailMessageEvent;
|
|
262
|
+
sms: SMSMessageEvent;
|
|
263
|
+
mattermost: MattermostMessageEvent;
|
|
264
|
+
line: LineMessageEvent;
|
|
265
|
+
matrix: MatrixMessageEvent;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* `true` only for `any` — the one type that would otherwise swallow the union.
|
|
269
|
+
*
|
|
270
|
+
* `any extends X` distributes to both branches of a conditional, so an ordinary
|
|
271
|
+
* `T extends BaseMessageEvent ? T : never` does NOT keep `any` out. This does: nothing but `any`
|
|
272
|
+
* makes `1 & T` accept `0`.
|
|
273
|
+
*/
|
|
274
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
275
|
+
/**
|
|
276
|
+
* A registry key must be a literal, never the broad `string` an index signature produces.
|
|
277
|
+
*
|
|
278
|
+
* Measured in review: `interface PlatformEventRegistry { [key: string]: BaseMessageEvent }` is a
|
|
279
|
+
* LEGAL augmentation — every existing variant is assignable to the base — and without this it
|
|
280
|
+
* widens the whole platform name to `string`, so every typo becomes valid and every consumer's
|
|
281
|
+
* `switch` stops narrowing. That is the same collapse an `any` VALUE causes, arriving through the
|
|
282
|
+
* key side, and it is why both sides are gated.
|
|
283
|
+
*/
|
|
284
|
+
type LiteralKey<K> = string extends K ? never : K;
|
|
285
|
+
/**
|
|
286
|
+
* The registry's LITERAL keys — index signatures dropped before `keyof` ever sees them.
|
|
287
|
+
*
|
|
288
|
+
* Filtering the value was not enough, measured twice. `keyof` over a registry carrying
|
|
289
|
+
* `{ [key: string]: BaseMessageEvent }` is `string | number`, and indexing a mapped type by that
|
|
290
|
+
* yields `never` for BOTH the union and the platform name: a hostile augmentation did not merely
|
|
291
|
+
* fail to join, it annihilated the union and broke every first-party narrowing site with
|
|
292
|
+
* `TS2339: Property 'telegram' does not exist on type 'never'`.
|
|
293
|
+
*
|
|
294
|
+
* It also fixes a second measured defect for free. Mapping over `keyof` directly is HOMOMORPHIC, so
|
|
295
|
+
* an OPTIONAL entry (`signal?: Event`, a shape an author writes by accident) kept its modifier and
|
|
296
|
+
* injected `undefined` into the union — `TS18048: 'e' is possibly 'undefined'` on a plain `switch`.
|
|
297
|
+
* Mapping over a computed key set is not homomorphic and drops the modifier. A `-?` was written
|
|
298
|
+
* here first as an explicit belt; the gate showed it could not be made to matter while this type is
|
|
299
|
+
* in place, so it was removed rather than kept as decoration nothing can fail without.
|
|
300
|
+
*/
|
|
301
|
+
type LiteralKeysOf<R> = keyof {
|
|
302
|
+
[K in keyof R as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: 0;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* A registry entry joins {@link MessageEvent} only if it is a real event shape
|
|
306
|
+
* (`docs/adr/0002-platform-event-registry.md`).
|
|
307
|
+
*
|
|
308
|
+
* Measured, not anticipated: without this guard a single entry typed `any` collapses the whole
|
|
309
|
+
* union, and `tsc --strict` then accepts `event.completelyMadeUpField.nested.nonsense` on EVERY
|
|
310
|
+
* consumer — ours included — with no error in any package and nothing red in any suite. The closed
|
|
311
|
+
* union could not fail that way, so the guard is what keeps the new capability from costing a
|
|
312
|
+
* safety property the old design had.
|
|
313
|
+
*
|
|
314
|
+
* A malformed entry is EXCLUDED rather than admitted. It is NOT free for anybody else, and an
|
|
315
|
+
* earlier version of this docblock said it was — measured false twice over. Filtering the VALUE
|
|
316
|
+
* alone left two shapes that break every consumer rather than only their author:
|
|
317
|
+
* `{ [key: string]: … }` made `keyof` yield `string | number`, so the union and the platform name
|
|
318
|
+
* both collapsed to `never`; and `signal?: …` kept its optional modifier through a homomorphic
|
|
319
|
+
* mapping and injected `undefined` into the union. Both are handled above — the first by
|
|
320
|
+
* {@link LiteralKeysOf}, the second by the `-?` on the mapping. What remains true, and is the
|
|
321
|
+
* honest version of the original claim:
|
|
322
|
+
* a `Record<PlatformName, T>` written against the ten still fails to compile, because the rejected
|
|
323
|
+
* key is gone from `PlatformName` while the consumer's literal map is not. What the exclusion buys
|
|
324
|
+
* is that the failure is a missing-key error at the consumer's own map rather than a silent loss
|
|
325
|
+
* of narrowing everywhere.
|
|
326
|
+
*
|
|
327
|
+
* Exported for the contract test in `tests/types/registry-guard.test.ts`, which asserts against
|
|
328
|
+
* this type rather than a copy of it — a copy would stay green with the guard deleted. It is
|
|
329
|
+
* deliberately NOT re-exported from the package barrel; it is an implementation detail of the
|
|
330
|
+
* derivation, not part of the published surface.
|
|
331
|
+
*/
|
|
332
|
+
type Registered<K, T> = IsAny<T> extends true ? never : [T] extends [BaseMessageEvent] ? [T] extends [{
|
|
333
|
+
readonly platform: LiteralKey<K>;
|
|
334
|
+
}] ? [LiteralKey<K>] extends [never] ? never : T : never : never;
|
|
335
|
+
/**
|
|
336
|
+
* The canonical inbound event: every guarded entry in {@link PlatformEventRegistry}.
|
|
337
|
+
*
|
|
338
|
+
* Derived rather than written, so third-party platforms are included automatically and exhaustive
|
|
339
|
+
* narrowing still holds over all of them.
|
|
340
|
+
*
|
|
341
|
+
* @public
|
|
342
|
+
*/
|
|
343
|
+
type MessageEvent = {
|
|
344
|
+
[K in LiteralKeysOf<PlatformEventRegistry>]: Registered<K, PlatformEventRegistry[K]>;
|
|
345
|
+
}[LiteralKeysOf<PlatformEventRegistry>];
|
|
346
|
+
/**
|
|
347
|
+
* Every platform that actually has a well-formed event in {@link PlatformEventRegistry}.
|
|
348
|
+
*
|
|
349
|
+
* Derived from the GUARDED union rather than from `keyof`, so `PlatformName` and
|
|
350
|
+
* `MessageEvent["platform"]` are the same set by construction. Deriving from `keyof` let a rejected
|
|
351
|
+
* entry keep contributing its key, which produced names no event could ever carry — an adapter
|
|
352
|
+
* could register for a platform that cannot exist.
|
|
353
|
+
*
|
|
354
|
+
* Still a union of string literals, so `switch (event.platform)` narrows and a misspelled name is
|
|
355
|
+
* a compile error.
|
|
356
|
+
*/
|
|
357
|
+
type PlatformName = MessageEvent["platform"];
|
|
224
358
|
|
|
225
359
|
/**
|
|
226
360
|
* `BasePlatformAdapter` — contract every transport adapter implements
|
|
@@ -723,4 +857,4 @@ interface ChunkByGraphemeOptions {
|
|
|
723
857
|
*/
|
|
724
858
|
declare function chunkByGrapheme(text: string, options: ChunkByGraphemeOptions): string[];
|
|
725
859
|
|
|
726
|
-
export { type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type ChunkByGraphemeOptions, type ChunkTextOptions, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type EmailMessageEvent, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type HookDecision, HookExecutor, type HookName, type LineMessageEvent, type MatrixMessageEvent, type MattermostMessageEvent, type MessageEvent, type OnErrorContext, type OutboundMessage, type PlatformName, type PostOutboundContext, type PreInboundContext, type SMSMessageEvent, type SendResult, SessionRouter, type SlackMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type WhatsAppMessageEvent, chunkByGrapheme, chunkText, defaultStrategy };
|
|
860
|
+
export { type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type ChunkByGraphemeOptions, type ChunkTextOptions, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type EmailMessageEvent, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type HookDecision, HookExecutor, type HookName, type LineMessageEvent, type MatrixMessageEvent, type MattermostMessageEvent, type MessageEvent, type OnErrorContext, type OutboundMessage, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type SMSMessageEvent, type SendResult, SessionRouter, type SlackMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type WhatsAppMessageEvent, chunkByGrapheme, chunkText, defaultStrategy };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theokit/gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Multi-platform messaging gateway core for @theokit/sdk — transport-agnostic primitives (BasePlatformAdapter, MessageEvent, SessionRouter, DeliveryRouter, GatewayRunner, hooks). Inspired by hermes-agent/gateway. ADRs D170-D181.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"CHANGELOG.md"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@theokit/sdk": "
|
|
37
|
+
"@theokit/sdk": ">=2.18.0 <5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@stryker-mutator/core": "10",
|
|
41
41
|
"@stryker-mutator/vitest-runner": "10",
|
|
42
|
-
"@theokit/sdk": "^
|
|
42
|
+
"@theokit/sdk": "^4.53.1",
|
|
43
43
|
"tsup": "^8.5.0",
|
|
44
44
|
"typescript": "^5.8.0",
|
|
45
45
|
"vitest": "^4.1.8",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsup",
|
|
54
54
|
"typecheck": "tsc --noEmit",
|
|
55
|
-
"test": "vitest run",
|
|
55
|
+
"test": "tsc --noEmit && vitest run",
|
|
56
56
|
"test:mutation": "stryker run"
|
|
57
57
|
}
|
|
58
58
|
}
|