From 8b961dfe4a3574fcba2fbaf3c4fdc837117cd940 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 17 Sep 2026 04:02:37 -0700 Subject: [PATCH] fix(types): attach registry checks to OpKind --- src/types.ts | 29 +++++++++++++-------------- test/type-negatives.test.ts | 2 +- test/types/invalid-states.negative.ts | 8 ++++++++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/types.ts b/src/types.ts index 4ac9e737..3922689c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -62,9 +62,6 @@ export const DEFERRED_OPS = ["reset_doc"] as const; */ export const BATCHABLE_OPS = ["add_node", "connect", "disconnect", "set_widget", "delete_node"] as const; -/** Every kind the vocabulary defines — implemented ({@link Op}) plus deferred ({@link DeferredOp}). */ -export type OpKind = WireOp["op"]; - /** A kind `applyOps` implements. */ export type FrozenOpKind = (typeof FROZEN_OPS)[number]; @@ -478,18 +475,20 @@ export type WireOp = Op | DeferredOp; // --------------------------------------------------------------------------- type Equals = [A] extends [B] ? ([B] extends [A] ? true : false) : false; -type Assert = T; - -/** `FROZEN_OPS` names exactly the kinds `applyOps` implements. */ -type _FrozenIsExactlyTheImplementedUnion = Assert>; -/** `DEFERRED_OPS` names exactly the kinds declared-but-not-implemented. */ -type _DeferredIsExactlyTheDeferredUnion = Assert>; -/** Every declared kind is exactly once in FROZEN_OPS or DEFERRED_OPS. */ -type _OpKindsArePartitioned = Assert>; -/** No kind is both implemented and deferred. */ -type _FrozenAndDeferredAreDisjoint = Assert>; -/** Batchable kinds are a subset of the implemented kinds. */ -type _BatchableIsSubsetOfFrozen = Assert, never>>; +type Checked = T & + (Checks[number] extends true ? unknown : never); + +/** Every kind the vocabulary defines — implemented ({@link Op}) plus deferred ({@link DeferredOp}). */ +export type OpKind = Checked< + WireOp["op"], + [ + Equals, + Equals, + Equals, + Equals, + Equals, never>, + ] +>; // --------------------------------------------------------------------------- // Widget catalog (pinned object_info projection) diff --git a/test/type-negatives.test.ts b/test/type-negatives.test.ts index ebd91844..6fe5256d 100644 --- a/test/type-negatives.test.ts +++ b/test/type-negatives.test.ts @@ -49,7 +49,7 @@ const negatives = join(root, "test", "types", "invalid-states.negative.ts"); * tests green. An exact count also means ADDING a state without updating this * constant fails, which is the reminder you want. */ -const EXPECTED_DIRECTIVES = 13; +const EXPECTED_DIRECTIVES = 14; const DIRECTIVE = /^[ \t]*\/\/ @ts-expect-error\b/gm; describe("invalid op states are unrepresentable (issue #17)", () => { diff --git a/test/types/invalid-states.negative.ts b/test/types/invalid-states.negative.ts index 2c70f777..8498bd51 100644 --- a/test/types/invalid-states.negative.ts +++ b/test/types/invalid-states.negative.ts @@ -27,6 +27,7 @@ import type { GrowConnectOp, InteriorSetWidgetOp, Op, + OpKind, ResetDocOp, SetWidgetOp, TopLevelSetWidgetOp, @@ -196,6 +197,13 @@ declare function applyOpsSignature(ops: Op[]): void; // @ts-expect-error #17: the applier cannot be handed an op it always refuses. applyOpsSignature([reset]); +// The public vocabulary projection accepts every declared kind and no value +// outside the wire union. This is an external-consumer check through index.ts. +const okImplementedKind: OpKind = "add_node"; +const okDeferredKind: OpKind = "reset_doc"; +// @ts-expect-error #21: undeclared operation kinds are not public OpKind values. +const unknownKind: OpKind = "unknown_op"; + // --------------------------------------------------------------------------- // Positive controls — these MUST compile, or the gate above is vacuous // ---------------------------------------------------------------------------