# API Reference {.appendix}
An annotated summary of the public API surface. For full documentation, see the generated API docs shipped with each package.
## TypeScript SDK (`@panproto/core`)
### Initialization
| Signature | Description |
|-----------|-------------|
| `Panproto.init()` → `Panproto` | Initialize the panproto runtime (loads the WASM engine). |
| `panproto.protocol(name)` → `Protocol` | Retrieve a built-in or registered protocol by name. |
### Schema construction
| Signature | Description |
|-----------|-------------|
| `protocol.schema()` → `SchemaBuilder` | Begin building a schema within a protocol. |
| `builder.addVertex(name, props?)` → `SchemaBuilder` | Add a vertex (sort instance) to the schema. |
| `builder.addEdge(name, src, tgt, props?)` → `SchemaBuilder` | Add an edge (operation instance) between vertices. |
| `builder.build()` → `BuiltSchema` | Finalize and validate the schema. |
### Migration
| Signature | Description |
|-----------|-------------|
| `panproto.migration(old, new)` → `MigrationBuilder` | Begin constructing a migration between two schemas. |
| `builder.renameVertex(from, to)` → `MigrationBuilder` | Map a vertex in the old schema to a renamed vertex in the new. |
| `builder.mapEdge(from, to)` → `MigrationBuilder` | Map an edge in the old schema to an edge in the new. |
| `builder.compile()` → `CompiledMigration` | Compile the migration into an executable form. |
| `migration.lift(record)` → `Record` | Migrate a data record forward through the schema change. |
| `migration.get(record)` → `View` | Extract the forward view (lens get). |
| `migration.put(view, complement)` → `Record` | Reconstruct a source record from a view and complement (lens put). |
### Diff and existence
| Signature | Description |
|-----------|-------------|
| `panproto.diff(old, new)` → `DiffReport` | Compute structural differences between two schemas. |
| `panproto.checkExistence(old, new, builder)` → `ExistenceReport` | Check whether a valid migration exists for the given schema change. |
### Lens combinators
| Combinator | Description |
|------------|-------------|
| `renameField(from, to)` | Rename a field. |
| `addField(name, defaultValue)` | Add a field with a default value. |
| `removeField(name)` | Remove a field (captured in complement). |
| `wrapInObject(field, wrapper)` | Nest a field inside a new wrapper object. |
| `hoistField(path)` | Pull a nested field up to the current level. |
| `coerceType(field, fromType, toType)` | Convert a field's type. |
| `compose(l1, l2)` | Compose two lenses sequentially. |
| `pipeline(...lenses)` | Compose a chain of lenses left to right. |
### Built-in protocol specs
All 76 built-in protocols are accessible via named constants. Each protocol supports bidirectional conversion: `parse_*` functions read source documents into a panproto schema, and matching `emit_*` functions write a panproto schema back out. All protocols have full parse + emit support.
**Serialization**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `PROTOBUF_SPEC` | Protocol Buffers | `parse_proto` / `emit_proto` |
| `AVRO_SPEC` | Apache Avro | `parse_avsc` / `emit_avsc` |
| `THRIFT_SPEC` | Apache Thrift | `parse_thrift` / `emit_thrift` |
| `CAPNPROTO_SPEC` | Cap'n Proto | `parse_capnp` / `emit_capnp` |
| `FLATBUFFERS_SPEC` | FlatBuffers | `parse_fbs` / `emit_fbs` |
| `ASN1_SPEC` | ASN.1 | `parse_asn1` / `emit_asn1` |
| `BOND_SPEC` | Microsoft Bond | `parse_bond` / `emit_bond` |
| `MSGPACK_SPEC` | MsgPack Schema | `parse_msgpack_schema` / `emit_msgpack_schema` |
**Data Schema**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `JSON_SCHEMA_SPEC` | JSON Schema | `parse_json_schema` / `emit_json_schema` |
| `XML_SCHEMA_SPEC` | XML / XSD | `parse_xsd` / `emit_xsd` |
| `CSV_SCHEMA_SPEC` | CSV / Table Schema | `parse_tableschema` / `emit_tableschema` |
| `YAML_SCHEMA_SPEC` | YAML Schema | `parse_yaml_schema` / `emit_yaml_schema` |
| `TOML_SCHEMA_SPEC` | TOML Schema | `parse_toml_schema` / `emit_toml_schema` |
| `CDDL_SPEC` | CDDL | `parse_cddl` / `emit_cddl` |
| `INI_SCHEMA_SPEC` | INI Schema | `parse_ini_schema` / `emit_ini_schema` |
| `BSON_SCHEMA_SPEC` | BSON Schema | `parse_bson_schema` / `emit_bson_schema` |
**API**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `GRAPHQL_SPEC` | GraphQL SDL | `parse_graphql` / `emit_graphql` |
| `OPENAPI_SPEC` | OpenAPI | `parse_openapi` / `emit_openapi` |
| `ASYNCAPI_SPEC` | AsyncAPI | `parse_asyncapi` / `emit_asyncapi` |
| `RAML_SPEC` | RAML | `parse_raml` / `emit_raml` |
| `JSONAPI_SPEC` | JSON:API | `parse_jsonapi` / `emit_jsonapi` |
**Database**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `SQL_SPEC` | SQL DDL | `parse_sql` / `emit_sql` |
| `MONGODB_SPEC` | MongoDB | `parse_mongo` / `emit_mongo` |
| `CASSANDRA_SPEC` | Cassandra | `parse_cassandra` / `emit_cassandra` |
| `DYNAMODB_SPEC` | DynamoDB | `parse_dynamo` / `emit_dynamo` |
| `NEO4J_SPEC` | Neo4j | `parse_neo4j` / `emit_neo4j` |
| `REDIS_SPEC` | Redis | `parse_redis` / `emit_redis` |
**Type Systems**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `TYPESCRIPT_SPEC` | TypeScript | `parse_typescript` / `emit_typescript` |
| `PYTHON_SPEC` | Python | `parse_python` / `emit_python` |
| `RUST_SERDE_SPEC` | Rust Serde | `parse_rust_serde` / `emit_rust_serde` |
| `JAVA_SPEC` | Java | `parse_java` / `emit_java` |
| `GO_SPEC` | Go | `parse_go` / `emit_go` |
| `SWIFT_SPEC` | Swift | `parse_swift` / `emit_swift` |
| `KOTLIN_SPEC` | Kotlin | `parse_kotlin` / `emit_kotlin` |
| `CSHARP_SPEC` | C# | `parse_csharp` / `emit_csharp` |
**Web / Document**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `ATPROTO_SPEC` | AT Protocol (Bluesky Lexicon) | `parse_atproto` / `emit_atproto` |
| `HTML_SPEC` | HTML | `parse_html` / `emit_html` |
| `CSS_SPEC` | CSS | `parse_css` / `emit_css` |
| `DOCX_SPEC` | DOCX | `parse_docx` / `emit_docx` |
| `ODF_SPEC` | ODF | `parse_odf` / `emit_odf` |
| `MARKDOWN_SPEC` | Markdown | `parse_markdown` / `emit_markdown` |
| `JSX_SPEC` | JSX / React | `parse_jsx` / `emit_jsx` |
| `VUE_SPEC` | Vue | `parse_vue` / `emit_vue` |
| `SVELTE_SPEC` | Svelte | `parse_svelte` / `emit_svelte` |
| `XML_SPEC` | XML / XSD | `parse_xml` / `emit_xml` |
**Data Science**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `PARQUET_SPEC` | Parquet | `parse_parquet` / `emit_parquet` |
| `ARROW_SPEC` | Arrow | `parse_arrow` / `emit_arrow` |
| `DATAFRAME_SPEC` | DataFrame | `parse_dataframe` / `emit_dataframe` |
**Domain**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `GEOJSON_SPEC` | GeoJSON | `parse_geojson` / `emit_geojson` |
| `FHIR_SPEC` | FHIR | `parse_fhir` / `emit_fhir` |
| `RSS_SPEC` | RSS / Atom | `parse_rss` / `emit_rss` |
| `VCARD_SPEC` | vCard / iCal | `parse_vcard` / `emit_vcard` |
| `EDI_X12_SPEC` | EDI X12 | `parse_edi_x12` / `emit_edi_x12` |
| `SWIFT_MT_SPEC` | SWIFT MT | `parse_swift_mt` / `emit_swift_mt` |
**Config**
| Constant | Protocol | Parse / Emit |
|----------|----------|--------------|
| `HCL_SPEC` | HCL | `parse_hcl` / `emit_hcl` |
| `K8S_CRD_SPEC` | Kubernetes CRD | `parse_k8s_crd` / `emit_k8s_crd` |
| `CLOUDFORMATION_SPEC` | CloudFormation | `parse_cloudformation` / `emit_cloudformation` |
| `ANSIBLE_SPEC` | Ansible | `parse_ansible` / `emit_ansible` |
## Rust (`panproto-core`)
### `panproto_gat` — Theory engine
| Item | Description |
|------|-------------|
| `Theory` | A generalized algebraic theory: sorts, operations, equations. |
| `Sort` | A sort declaration within a theory. |
| `Operation` | An operation declaration with input sorts and output sort. |
| `Equation` | An equational axiom between terms. |
| `TheoryMorphism` | A structure-preserving map between theories. |
| `colimit(t1, t2, shared)` → `Result<Theory, GatError>` | Compute the pushout of two theories over a shared base. |
### `panproto_schema` — Schema layer
| Item | Description |
|------|-------------|
| `Schema` | A model of a protocol theory: vertices, edges, and their relationships. |
| `SchemaBuilder` | Builder for constructing schemas incrementally. |
| `Protocol` | A named theory that defines a schema language. |
| `Vertex` | A vertex in a schema (instance of a sort). |
| `Edge` | An edge in a schema (instance of an operation). |
### `panproto_inst` — Instance layer
| Item | Description |
|------|-------------|
| `WInstance` | An instance encoded as a W-type (tree-structured data). |
| `FInstance` | An instance encoded as a functor (relational data). |
| `wtype_restrict(inst, morph)` → `WInstance` | Migrate a W-type instance along a schema morphism. |
| `functor_restrict(inst, morph)` → `FInstance` | Migrate a functor instance along a schema morphism. |
| `parse_json(json, schema)` → `Result<WInstance, ParseError>` | Parse JSON into a typed instance. |
| `to_json(inst)` → `Value` | Serialize an instance back to JSON. |
### `panproto_mig` — Migration engine
| Item | Description |
|------|-------------|
| `Migration` | A compiled migration between two schemas. |
| `compile(builder)` → `Result<Migration, MigError>` | Compile a migration specification. |
| `lift_wtype(migration, inst)` → `WInstance` | Lift a W-type instance through a migration. |
| `lift_functor(migration, inst)` → `FInstance` | Lift a functor instance through a migration. |
| `check_existence(old, new)` → `ExistenceReport` | Check whether a migration between two schemas exists. |
| `compose(m1, m2)` → `Result<Migration, MigError>` | Compose two migrations sequentially. |
| `invert(m)` → `Result<Migration, MigError>` | Invert a migration (when the underlying lens is an isomorphism). |
### `panproto_lens` — Lens layer
| Item | Description |
|------|-------------|
| `Lens` | A bidirectional transformation between two schemas. |
| `Complement` | The data discarded by the forward direction (needed for `put`). |
| `Combinator` | A single lens-building step (rename, add, remove, etc.). |
| `get(lens, source)` → `View` | Apply the forward direction of a lens. |
| `put(lens, view, complement)` → `Source` | Apply the backward direction, restoring the source. |
| `from_combinators(steps)` → `Result<Lens, LensError>` | Build a lens from a sequence of combinators. |
| `check_laws(lens)` → `LawReport` | Verify that a lens satisfies the get-put and put-get laws. |
| `EditLens` | Incremental lens: translates individual `TreeEdit` values between schemas. |
| `EditLens::get_edit(edit)` → `TreeEdit` | Translate a source edit to a view edit, updating the complement. |
| `EditLens::put_edit(edit)` → `TreeEdit` | Translate a view edit back to a source edit. |
| `EditProvenance` | Translation lineage: source edit, rules applied, policy consulted, totality. |
| `check_edit_consistency` | Verify the Consistency law (incremental path agrees with batch path). |
| `check_complement_coherence` | Verify the Complement coherence law. |
### `panproto_inst` — Instance layer (edit support)
| Item | Description |
|------|-------------|
| `TreeEdit` | Edit monoid for W-type instances: identity, compose, apply. |
| `TableEdit` | Edit monoid for functor instances: InsertRow, DeleteRow, UpdateCell. |
| `ReachabilityIndex` | Incremental reachability tracking for the edit lens pipeline. |
| `ContractionTracker` | Incremental ancestor contraction tracking for the edit lens pipeline. |
### `panproto_emit` — Emit helpers
The shared `emit` module provides utilities used by all `emit_*` functions. Protocol authors implementing a custom emitter should build on these primitives.
| Item | Description |
|------|-------------|
| `find_roots(schema)` → `Vec<VertexId>` | Return all vertices with no incoming edges—the natural entry points for top-down emission. |
| `children_by_edge(schema, vertex)` → `Vec<(EdgeId, VertexId)>` | List the outgoing edges and their target vertices for a given vertex, in declaration order. |
| `constraint_value(schema, edge, key)` → `Option<Value>` | Look up a named constraint on an edge (e.g. a field's default value or cardinality bound). |
| `IndentWriter` | A write adapter that tracks indentation depth and inserts consistent leading whitespace, suitable for text-based emitters. |