Rebrand TypeDef to AlkType in code, keyword strings, and docs

Rename all 19 JSON Schema custom keyword strings from "TypeDef:*"
to "AlkType:*" (e.g., "TypeDef:Struct" -> "AlkType:Struct")
across source, tests, and docs. This is a breaking change to the
schema format itself — existing schemas using the old keywords
must be updated.

Rename the Rust identifiers:
- TypedefEngine -> AlkTypeEngine
- TypedefError -> AlkTypeError
- TypeDefKind -> AlkTypeKind
- TYPEDEF_PREFIX -> ALKTYPE_PREFIX
- get_typedef_kind{,_loose,_loose_enum,_enum} ->
  get_alktype_kind{,_loose,_loose_enum,_enum}

Update error message strings ("unknown TypeDef kind" ->
"unknown AlkType kind"), 11 test function names containing
typedef_kind/to_typedef_error, and doc-comment prose ("TypeDef
kind" -> "AlkType kind", "typedef engine" -> "alktype
engine", "typedef schema" -> "alktype schema"). Fix the broken
docs/architecture/crates/typedef/ path references in source doc
comments to point at docs/architecture/ directly. Rebrand the
typedef:annotation test fixture and the "not-a-typedef" test
string to their alktype equivalents.

Update ~20 generic "typedef" prose references in the architecture
docs ("typedef is the binary struct engine", "use typedef",
"typedef limitation", "replaced by typedef", etc.) to alktype.
Rename TypedefEngine in the ADR-007 code example to AlkTypeEngine.

Preserve as provenance per the prior prose-rebrand decision:
typedef.ts references (external TypeBox source file),
docs/research/alknet-typedef/findings.md research citations,
/workspace/alknet-typedef-poc/ POC path, and the
"alknet-typedef:" research section headers in findings.

Build, 295 tests, and clippy all pass clean.
This commit is contained in:
glm-5.2 committed 2026-08-02 07:05:53 +00:00
1 parent 1cfb3638d1
commit 5e268e8f47
31 files changed
+1851 -1851

No files matched your search

+63 -63
View File
@@ -9,16 +9,16 @@
use alktype::data_access;
use alktype::tunion;
use alktype::{Endian, TypedefError};
use alktype::{Endian, AlkTypeError};
use serde_json::json;
fn sftp_like_byte_union() -> serde_json::Value {
json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {
"kind": "byte",
"offset": 0,
"type": "TypeDef:Uint8"
"type": "AlkType:Uint8"
},
"mapping": {
"5": { "$ref": "#/$defs/Read" },
@@ -26,18 +26,18 @@ fn sftp_like_byte_union() -> serde_json::Value {
},
"$defs": {
"Read": {
"TypeDef:Struct": true,
"AlkType:Struct": true,
"properties": {
"handle": { "TypeDef:Uint32": true },
"length": { "TypeDef:Uint32": true }
"handle": { "AlkType:Uint32": true },
"length": { "AlkType:Uint32": true }
}
},
"Write": {
"TypeDef:Struct": true,
"AlkType:Struct": true,
"properties": {
"handle": { "TypeDef:Uint32": true },
"length": { "TypeDef:Uint32": true },
"data": { "TypeDef:Uint32": true }
"handle": { "AlkType:Uint32": true },
"length": { "AlkType:Uint32": true },
"data": { "AlkType:Uint32": true }
}
}
}
@@ -45,7 +45,7 @@ fn sftp_like_byte_union() -> serde_json::Value {
}
#[test]
fn read_byte_discriminator_uint8_dispatches_to_read() -> Result<(), TypedefError> {
fn read_byte_discriminator_uint8_dispatches_to_read() -> Result<(), AlkTypeError> {
let union_schema = sftp_like_byte_union();
let mut buffer = vec![0u8; 16];
buffer[0] = 5;
@@ -59,7 +59,7 @@ fn read_byte_discriminator_uint8_dispatches_to_read() -> Result<(), TypedefError
let variant = tunion::resolve_variant(&union_schema, &dispatch.key)?;
assert_eq!(
variant
.get("TypeDef:Struct")
.get("AlkType:Struct")
.and_then(serde_json::Value::as_bool),
Some(true)
);
@@ -67,7 +67,7 @@ fn read_byte_discriminator_uint8_dispatches_to_read() -> Result<(), TypedefError
}
#[test]
fn read_byte_discriminator_uint8_dispatches_to_write() -> Result<(), TypedefError> {
fn read_byte_discriminator_uint8_dispatches_to_write() -> Result<(), AlkTypeError> {
let union_schema = sftp_like_byte_union();
let mut buffer = vec![0u8; 16];
buffer[0] = 6;
@@ -88,16 +88,16 @@ fn read_byte_discriminator_uint8_dispatches_to_write() -> Result<(), TypedefErro
}
#[test]
fn read_byte_discriminator_uint16_little_endian() -> Result<(), TypedefError> {
fn read_byte_discriminator_uint16_little_endian() -> Result<(), AlkTypeError> {
let schema = json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {
"kind": "byte",
"offset": 2,
"type": "TypeDef:Uint16"
"type": "AlkType:Uint16"
},
"mapping": {
"5": {"TypeDef:Struct": true, "properties": {"id": {"TypeDef:Uint32": true}}}
"5": {"AlkType:Struct": true, "properties": {"id": {"AlkType:Uint32": true}}}
}
});
let mut buffer = vec![0u8; 16];
@@ -110,16 +110,16 @@ fn read_byte_discriminator_uint16_little_endian() -> Result<(), TypedefError> {
}
#[test]
fn read_byte_discriminator_uint32_big_endian() -> Result<(), TypedefError> {
fn read_byte_discriminator_uint32_big_endian() -> Result<(), AlkTypeError> {
let schema = json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {
"kind": "byte",
"offset": 0,
"type": "TypeDef:Uint32"
"type": "AlkType:Uint32"
},
"mapping": {
"101": {"TypeDef:Struct": true, "properties": {"id": {"TypeDef:Uint32": true}}}
"101": {"AlkType:Struct": true, "properties": {"id": {"AlkType:Uint32": true}}}
}
});
let mut buffer = vec![0u8; 16];
@@ -132,21 +132,21 @@ fn read_byte_discriminator_uint32_big_endian() -> Result<(), TypedefError> {
}
#[test]
fn read_byte_discriminator_unknown_value_returns_access_error() -> Result<(), TypedefError> {
fn read_byte_discriminator_unknown_value_returns_access_error() -> Result<(), AlkTypeError> {
let union_schema = sftp_like_byte_union();
let buffer = [99u8, 0x00, 0x00, 0x00];
let err = tunion::read_byte_discriminator(&buffer, &union_schema, Endian::Big).unwrap_err();
assert!(matches!(err, TypedefError::Access { .. }), "got {err:?}");
assert!(matches!(err, AlkTypeError::Access { .. }), "got {err:?}");
Ok(())
}
#[test]
fn read_field_discriminator_string_dispatches_to_read() -> Result<(), TypedefError> {
fn read_field_discriminator_string_dispatches_to_read() -> Result<(), AlkTypeError> {
let union_schema = json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {"kind": "field", "name": "type"},
"properties": {
"type": { "TypeDef:String": true }
"type": { "AlkType:String": true }
},
"mapping": {
"read": {"$ref": "#/$defs/Read"},
@@ -154,17 +154,17 @@ fn read_field_discriminator_string_dispatches_to_read() -> Result<(), TypedefErr
},
"$defs": {
"Read": {
"TypeDef:Struct": true,
"AlkType:Struct": true,
"properties": {
"handle": { "TypeDef:Uint32": true },
"length": { "TypeDef:Uint32": true }
"handle": { "AlkType:Uint32": true },
"length": { "AlkType:Uint32": true }
}
},
"Write": {
"TypeDef:Struct": true,
"AlkType:Struct": true,
"properties": {
"handle": { "TypeDef:Uint32": true },
"data": { "TypeDef:Bytes": true }
"handle": { "AlkType:Uint32": true },
"data": { "AlkType:Bytes": true }
}
}
}
@@ -180,7 +180,7 @@ fn read_field_discriminator_string_dispatches_to_read() -> Result<(), TypedefErr
let variant = tunion::resolve_variant(&union_schema, &dispatch.key)?;
assert_eq!(
variant
.get("TypeDef:Struct")
.get("AlkType:Struct")
.and_then(serde_json::Value::as_bool),
Some(true)
);
@@ -188,12 +188,12 @@ fn read_field_discriminator_string_dispatches_to_read() -> Result<(), TypedefErr
}
#[test]
fn read_field_discriminator_string_dispatches_to_write() -> Result<(), TypedefError> {
fn read_field_discriminator_string_dispatches_to_write() -> Result<(), AlkTypeError> {
let union_schema = json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {"kind": "field", "name": "type"},
"properties": {
"type": { "TypeDef:String": true }
"type": { "AlkType:String": true }
},
"mapping": {
"read": {"$ref": "#/$defs/Read"},
@@ -201,12 +201,12 @@ fn read_field_discriminator_string_dispatches_to_write() -> Result<(), TypedefEr
},
"$defs": {
"Read": {
"TypeDef:Struct": true,
"properties": {"x": {"TypeDef:Uint8": true}}
"AlkType:Struct": true,
"properties": {"x": {"AlkType:Uint8": true}}
},
"Write": {
"TypeDef:Struct": true,
"properties": {"y": {"TypeDef:Uint16": true}}
"AlkType:Struct": true,
"properties": {"y": {"AlkType:Uint16": true}}
}
}
});
@@ -228,16 +228,16 @@ fn read_field_discriminator_string_dispatches_to_write() -> Result<(), TypedefEr
}
#[test]
fn read_field_discriminator_uint8_field() -> Result<(), TypedefError> {
fn read_field_discriminator_uint8_field() -> Result<(), AlkTypeError> {
let union_schema = json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {"kind": "field", "name": "tag"},
"properties": {
"tag": { "TypeDef:Uint8": true }
"tag": { "AlkType:Uint8": true }
},
"mapping": {
"0": {"TypeDef:Struct": true, "properties": {"a": {"TypeDef:Uint32": true}}},
"1": {"TypeDef:Struct": true, "properties": {"b": {"TypeDef:Uint16": true}}}
"0": {"AlkType:Struct": true, "properties": {"a": {"AlkType:Uint32": true}}},
"1": {"AlkType:Struct": true, "properties": {"b": {"AlkType:Uint16": true}}}
}
});
let mut buffer = vec![0u8; 8];
@@ -254,40 +254,40 @@ fn read_field_discriminator_uint8_field() -> Result<(), TypedefError> {
}
#[test]
fn read_field_discriminator_unknown_value_returns_access_error() -> Result<(), TypedefError> {
fn read_field_discriminator_unknown_value_returns_access_error() -> Result<(), AlkTypeError> {
let union_schema = json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {"kind": "field", "name": "tag"},
"properties": {
"tag": { "TypeDef:Uint8": true }
"tag": { "AlkType:Uint8": true }
},
"mapping": {
"0": {"TypeDef:Struct": true, "properties": {"a": {"TypeDef:Uint32": true}}}
"0": {"AlkType:Struct": true, "properties": {"a": {"AlkType:Uint32": true}}}
}
});
let mut buffer = vec![0u8; 8];
buffer[0] = 99;
let err =
tunion::read_field_discriminator(&buffer, &union_schema, 0, Endian::Little).unwrap_err();
assert!(matches!(err, TypedefError::Access { .. }), "got {err:?}");
assert!(matches!(err, AlkTypeError::Access { .. }), "got {err:?}");
Ok(())
}
#[test]
fn discriminator_size_returns_correct_values() -> Result<(), TypedefError> {
fn discriminator_size_returns_correct_values() -> Result<(), AlkTypeError> {
let u8_schema = json!({
"TypeDef:Union": true,
"discriminator": {"kind": "byte", "type": "TypeDef:Uint8"},
"AlkType:Union": true,
"discriminator": {"kind": "byte", "type": "AlkType:Uint8"},
"mapping": {}
});
let u16_schema = json!({
"TypeDef:Union": true,
"discriminator": {"kind": "byte", "type": "TypeDef:Uint16"},
"AlkType:Union": true,
"discriminator": {"kind": "byte", "type": "AlkType:Uint16"},
"mapping": {}
});
let u32_schema = json!({
"TypeDef:Union": true,
"discriminator": {"kind": "byte", "type": "TypeDef:Uint32"},
"AlkType:Union": true,
"discriminator": {"kind": "byte", "type": "AlkType:Uint32"},
"mapping": {}
});
assert_eq!(tunion::discriminator_size(&u8_schema)?, 1);
@@ -299,25 +299,25 @@ fn discriminator_size_returns_correct_values() -> Result<(), TypedefError> {
#[test]
fn discriminator_size_field_kind_returns_schema_error() {
let schema = json!({
"TypeDef:Union": true,
"AlkType:Union": true,
"discriminator": {"kind": "field", "name": "type"},
"properties": {"type": {"TypeDef:Uint8": true}},
"properties": {"type": {"AlkType:Uint8": true}},
"mapping": {}
});
let err = tunion::discriminator_size(&schema).unwrap_err();
assert!(matches!(err, TypedefError::Schema(_)), "got {err:?}");
assert!(matches!(err, AlkTypeError::Schema(_)), "got {err:?}");
}
#[test]
fn resolve_variant_returns_schema_error_for_unknown_key() {
let union_schema = sftp_like_byte_union();
let err = tunion::resolve_variant(&union_schema, "999").unwrap_err();
assert!(matches!(err, TypedefError::Schema(_)), "got {err:?}");
assert!(matches!(err, AlkTypeError::Schema(_)), "got {err:?}");
}
#[test]
fn parse_discriminator_missing_returns_schema_error() {
let schema = json!({"TypeDef:Union": true});
let schema = json!({"AlkType:Union": true});
let err = alktype::parse_discriminator(&schema).unwrap_err();
assert!(matches!(err, TypedefError::Schema(_)), "got {err:?}");
assert!(matches!(err, AlkTypeError::Schema(_)), "got {err:?}");
}