@sharpee/channel-service 1.0.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.
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * @sharpee/channel-service/wire — client-side decoder
4
+ *
5
+ * Owner context: wire-protocol module. A small state machine the
6
+ * consumer feeds incoming packets through. Enforces the ordering
7
+ * invariants from ADR-163 §11 / AC-11:
8
+ *
9
+ * 1. The first server-bound packet a consumer accepts is `cmgt`.
10
+ * 2. `turn` packets are accepted only after `cmgt`.
11
+ * 3. `hello` and `command` are not server-bound — receiving one is a
12
+ * protocol error.
13
+ *
14
+ * The decoder does NOT render — it only validates ordering and exposes
15
+ * the negotiated manifest. Renderer dispatch is the consumer's
16
+ * concern (per ADR-165).
17
+ *
18
+ * @see ADR-163 §11 — bootstrap order invariants
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.createDecoder = createDecoder;
22
+ class DecoderImpl {
23
+ state = { status: 'awaiting-cmgt' };
24
+ lastTurn = null;
25
+ ingest(packet) {
26
+ if (this.state.status === 'error') {
27
+ // Stay in error; protocol violations are unrecoverable.
28
+ return this;
29
+ }
30
+ switch (packet.kind) {
31
+ case 'cmgt': {
32
+ if (this.state.status !== 'awaiting-cmgt') {
33
+ this.state = {
34
+ status: 'error',
35
+ reason: 'cmgt received after session already live',
36
+ };
37
+ return this;
38
+ }
39
+ this.state = { status: 'live', cmgt: packet };
40
+ return this;
41
+ }
42
+ case 'turn': {
43
+ if (this.state.status !== 'live') {
44
+ this.state = {
45
+ status: 'error',
46
+ reason: 'turn received before cmgt — bootstrap order requires cmgt first (ADR-163 §11, AC-11d)',
47
+ };
48
+ this.lastTurn = null;
49
+ return this;
50
+ }
51
+ this.lastTurn = packet;
52
+ return this;
53
+ }
54
+ case 'hello':
55
+ case 'command': {
56
+ // Both are client→server. Receiving one as a server→client
57
+ // packet is a protocol violation regardless of state.
58
+ this.state = {
59
+ status: 'error',
60
+ reason: `unexpected client→server packet '${packet.kind}' on server→client stream`,
61
+ };
62
+ this.lastTurn = null;
63
+ return this;
64
+ }
65
+ }
66
+ }
67
+ }
68
+ /**
69
+ * Create a fresh client-side decoder in the `awaiting-cmgt` state.
70
+ */
71
+ function createDecoder() {
72
+ return new DecoderImpl();
73
+ }
74
+ //# sourceMappingURL=decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decoder.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/channel-service/src/wire/decoder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AA2FH,sCAEC;AAvDD,MAAM,WAAW;IACf,KAAK,GAAiB,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IAClD,QAAQ,GAAsB,IAAI,CAAC;IAEnC,MAAM,CAAC,MAAkB;QACvB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;YAClC,wDAAwD;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,eAAe,EAAE,CAAC;oBAC1C,IAAI,CAAC,KAAK,GAAG;wBACX,MAAM,EAAE,OAAO;wBACf,MAAM,EAAE,0CAA0C;qBACnD,CAAC;oBACF,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,IAAI,CAAC,KAAK,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gBAC9C,OAAO,IAAI,CAAC;YACd,CAAC;YACD,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;oBACjC,IAAI,CAAC,KAAK,GAAG;wBACX,MAAM,EAAE,OAAO;wBACf,MAAM,EACJ,uFAAuF;qBAC1F,CAAC;oBACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;oBACrB,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;gBACvB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,KAAK,OAAO,CAAC;YACb,KAAK,SAAS,CAAC,CAAC,CAAC;gBACf,2DAA2D;gBAC3D,sDAAsD;gBACtD,IAAI,CAAC,KAAK,GAAG;oBACX,MAAM,EAAE,OAAO;oBACf,MAAM,EAAE,oCAAoC,MAAM,CAAC,IAAI,2BAA2B;iBACnF,CAAC;gBACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACrB,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAI,WAAW,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @sharpee/channel-service/wire
3
+ *
4
+ * Wire-protocol module — re-exports the wire-protocol types from
5
+ * `@sharpee/if-domain`, the canonical home for channel type contracts
6
+ * (CLAUDE.md rule 7b, ADR-163 §14).
7
+ *
8
+ * Why this subpath still exists: a number of consumers historically
9
+ * imported wire types from `@sharpee/channel-service/wire`. Keeping the
10
+ * subpath stable means those imports continue to resolve after the
11
+ * R1 rewrite. New code should import from `@sharpee/if-domain` directly.
12
+ *
13
+ * The decoder is the only runtime symbol exported here — its
14
+ * implementation stays in this package because it carries
15
+ * bootstrap-order enforcement state.
16
+ */
17
+ export type { HelloPacket, CmgtPacket, TurnPacket, CommandPacket, WirePacket, ChannelDefinition, ChannelContentType, ChannelMode, ChannelEmitPolicy, ClientCapabilities, } from "../../if-domain/index";
18
+ export { createDecoder, type Decoder, type DecoderState } from './decoder';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/channel-service/src/wire/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,YAAY,EAEV,WAAW,EACX,UAAU,EACV,UAAU,EACV,aAAa,EACb,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EAEjB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC"}
package/wire/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * @sharpee/channel-service/wire
4
+ *
5
+ * Wire-protocol module — re-exports the wire-protocol types from
6
+ * `@sharpee/if-domain`, the canonical home for channel type contracts
7
+ * (CLAUDE.md rule 7b, ADR-163 §14).
8
+ *
9
+ * Why this subpath still exists: a number of consumers historically
10
+ * imported wire types from `@sharpee/channel-service/wire`. Keeping the
11
+ * subpath stable means those imports continue to resolve after the
12
+ * R1 rewrite. New code should import from `@sharpee/if-domain` directly.
13
+ *
14
+ * The decoder is the only runtime symbol exported here — its
15
+ * implementation stays in this package because it carries
16
+ * bootstrap-order enforcement state.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.createDecoder = void 0;
20
+ var decoder_1 = require("./decoder");
21
+ Object.defineProperty(exports, "createDecoder", { enumerable: true, get: function () { return decoder_1.createDecoder; } });
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/channel-service/src/wire/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAkBH,qCAA2E;AAAlE,wGAAA,aAAa,OAAA"}