@kumiai/rpc 0.4.1 → 0.4.3

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/lib/protocol.d.ts CHANGED
@@ -6,16 +6,29 @@ import type { ChannelProcedureDefinition, EventProcedureDefinition, RequestProce
6
6
  */
7
7
  export type Retention = 'log' | 'ephemeral';
8
8
  /**
9
- * An event procedure that may opt into log retention. `retain: 'log'` makes every dispatch of
10
- * the procedure retained and pullable regardless of call site; absent, dispatches are ephemeral.
9
+ * An event procedure, the only kind that may choose. `retain: 'log'` makes every dispatch of the
10
+ * procedure retained and pullable regardless of call site; `'ephemeral'` and absence both mean
11
+ * live push, and are the same declaration said two ways — one for a definition that prefers to
12
+ * state its choice, one for a definition that leaves it to the default.
11
13
  */
12
14
  export type RetainableEventProcedureDefinition = EventProcedureDefinition & {
13
- retain?: 'log';
15
+ retain?: Retention;
14
16
  };
15
17
  /**
16
- * A single procedure of a group protocol. Only `event` procedures may carry `retain`.
18
+ * Correlation traffic, which has exactly one retention available to it and so is typed with the
19
+ * literal rather than the union. Writing `retain: 'ephemeral'` on one of these says what was
20
+ * already true; `'log'` is not a value it has, so the mistake is a type error at the procedure
21
+ * rather than a rule applied to it afterwards.
17
22
  */
18
- export type GroupProcedureDefinition = RetainableEventProcedureDefinition | RequestProcedureDefinition | StreamProcedureDefinition | ChannelProcedureDefinition;
23
+ export type EphemeralProcedureDefinition = (RequestProcedureDefinition | StreamProcedureDefinition | ChannelProcedureDefinition) & {
24
+ retain?: 'ephemeral';
25
+ };
26
+ /**
27
+ * A single procedure of a group protocol. Only `event` procedures may declare `retain: 'log'`,
28
+ * and the `type` discriminant is what enforces it: each member carries the retention it is
29
+ * allowed, so a retained request fails to match any member of the union.
30
+ */
31
+ export type GroupProcedureDefinition = RetainableEventProcedureDefinition | EphemeralProcedureDefinition;
19
32
  /**
20
33
  * A protocol run over a group broadcast substrate, where only `event` procedures may declare
21
34
  * `retain: 'log'`. Correlation traffic (`request`/`stream`/`channel`) is always ephemeral:
@@ -24,29 +37,25 @@ export type GroupProcedureDefinition = RetainableEventProcedureDefinition | Requ
24
37
  * superset of the underlying Enkaku protocol definition for everything else.
25
38
  */
26
39
  export type GroupProtocolDefinition = Record<string, GroupProcedureDefinition>;
27
- /**
28
- * Per-entry retention rule used as a constraint: an `event` procedure is unconstrained (retain
29
- * allowed); every other procedure must carry no `retain` (`retain?: never`), so a `retain` on a
30
- * request/stream/channel fails the constraint and the definition is rejected at the type level.
31
- */
32
- type RetainRule<Procedure> = Procedure extends {
33
- type: 'event';
34
- } ? unknown : {
35
- retain?: never;
36
- };
37
40
  /**
38
41
  * Identity helper that returns the protocol definition unchanged while preserving its literal
39
- * type for downstream inference — extended over the underlying broadcast helper so an `event`
40
- * procedure may declare `retain: 'log'`. Declaring `retain` on a non-`event` procedure is a type
41
- * error (the `RetainRule` constraint) AND throws here at definition time, so a JS caller or an
42
- * erased type cannot slip a retained request/stream/channel past the guardrail.
42
+ * type for downstream inference.
43
+ *
44
+ * The retention guardrail lives in {@link GroupProcedureDefinition}, not here: each member of that
45
+ * union carries the retention its kind is allowed, so a retained request matches no member and is
46
+ * refused by the constraint itself. An earlier shape enforced it with a mapped type over the
47
+ * parameter, and that mapped type referenced the type parameter it was constraining — read while
48
+ * inference was still running, so every procedure was treated as a non-event and every retain-free
49
+ * `request` was rejected. Nothing caught it: the only request in the suite carried a
50
+ * `@ts-expect-error` aimed at `retain`, which absorbed the error meant for `type`. Prefer a
51
+ * constraint the discriminant can enforce over a rule applied on top of one.
52
+ *
53
+ * The throw survives for the caller who never met the type — plain JS, or types erased across a
54
+ * boundary. It fires only on `retain: 'log'`, since `'ephemeral'` is legal on every kind.
43
55
  */
44
- export declare function defineGroupProtocol<const Definition extends GroupProtocolDefinition & {
45
- [Name in keyof Definition]: RetainRule<Definition[Name]>;
46
- }>(definition: Definition): Definition;
56
+ export declare function defineGroupProtocol<const Definition extends GroupProtocolDefinition>(definition: Definition): Definition;
47
57
  /**
48
58
  * The retention a procedure was declared with in its group protocol definition. `'log'` only for
49
59
  * an `event` procedure carrying `retain: 'log'`; `'ephemeral'` for everything else (the default).
50
60
  */
51
61
  export declare function retentionOf(protocol: GroupProtocolDefinition, procedureName: string): Retention;
52
- export {};
package/lib/protocol.js CHANGED
@@ -1,14 +1,23 @@
1
1
  /**
2
2
  * Identity helper that returns the protocol definition unchanged while preserving its literal
3
- * type for downstream inference — extended over the underlying broadcast helper so an `event`
4
- * procedure may declare `retain: 'log'`. Declaring `retain` on a non-`event` procedure is a type
5
- * error (the `RetainRule` constraint) AND throws here at definition time, so a JS caller or an
6
- * erased type cannot slip a retained request/stream/channel past the guardrail.
3
+ * type for downstream inference.
4
+ *
5
+ * The retention guardrail lives in {@link GroupProcedureDefinition}, not here: each member of that
6
+ * union carries the retention its kind is allowed, so a retained request matches no member and is
7
+ * refused by the constraint itself. An earlier shape enforced it with a mapped type over the
8
+ * parameter, and that mapped type referenced the type parameter it was constraining — read while
9
+ * inference was still running, so every procedure was treated as a non-event and every retain-free
10
+ * `request` was rejected. Nothing caught it: the only request in the suite carried a
11
+ * `@ts-expect-error` aimed at `retain`, which absorbed the error meant for `type`. Prefer a
12
+ * constraint the discriminant can enforce over a rule applied on top of one.
13
+ *
14
+ * The throw survives for the caller who never met the type — plain JS, or types erased across a
15
+ * boundary. It fires only on `retain: 'log'`, since `'ephemeral'` is legal on every kind.
7
16
  */ export function defineGroupProtocol(definition) {
8
17
  for (const [name, procedure] of Object.entries(definition)){
9
18
  const proc = procedure;
10
- if (proc.retain !== undefined && proc.type !== 'event') {
11
- throw new Error(`defineGroupProtocol: procedure "${name}" has type "${String(proc.type)}" and declares retain; only 'event' procedures may be retained, request/stream/channel traffic is always ephemeral`);
19
+ if (proc.retain === 'log' && proc.type !== 'event') {
20
+ throw new Error(`defineGroupProtocol: procedure "${name}" has type "${String(proc.type)}" and declares retain: 'log'; only 'event' procedures may be retained, request/stream/channel traffic is always ephemeral`);
12
21
  }
13
22
  }
14
23
  return definition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/rpc",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "High-level MLS-aware group RPC for Enkaku: bus broadcast/anycast/gather plus directed RPC over the pub/sub hub",
5
5
  "keywords": [
6
6
  "rpc",
@@ -26,23 +26,23 @@
26
26
  "lib/*"
27
27
  ],
28
28
  "dependencies": {
29
- "@enkaku/client": "^0.19.0",
30
- "@enkaku/protocol": "^0.19.0",
31
- "@enkaku/server": "^0.19.0",
32
- "@enkaku/transport": "^0.19.1",
29
+ "@enkaku/client": "^0.20.0",
30
+ "@enkaku/protocol": "^0.20.0",
31
+ "@enkaku/server": "^0.20.0",
32
+ "@enkaku/transport": "^0.20.0",
33
33
  "@noble/hashes": "^2.0.0",
34
34
  "@sozai/codec": "^0.2.0",
35
35
  "@sozai/log": "^0.2.0",
36
36
  "@sozai/runtime": "^0.1.0",
37
- "@kumiai/broadcast": "^0.4.0",
38
- "@kumiai/hub-tunnel": "^0.4.0",
39
- "@kumiai/hub-protocol": "^0.4.0"
37
+ "@kumiai/broadcast": "^0.4.1",
38
+ "@kumiai/hub-protocol": "^0.4.1",
39
+ "@kumiai/hub-tunnel": "^0.4.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@noble/curves": "^2.0.1",
43
43
  "vitest": "^4.1.10",
44
- "@kumiai/rpc-conformance": "^0.4.0",
45
- "@kumiai/hub-conformance": "^0.4.0"
44
+ "@kumiai/hub-conformance": "^0.4.1",
45
+ "@kumiai/rpc-conformance": "^0.4.1"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",