Files
storage/tasks/drift/bridge-functions.md

2.6 KiB

id, name, status, depends_on, scope, risk, impact, level
id name status depends_on scope risk impact level
drift/bridge-functions Create bridge.ts with moduleToDbSchema, validateNode, validateEdge pending
drift/metagraph-module
moderate medium component implementation

Description

Create the bridge between TypeBox Modules and database row values. The moduleToDbSchema() function projects a graph type Module to DB row values for the metagraph tables. The validateNode() and validateEdge() functions validate data against Module entries.

This is Phase 2 of the metagraph-module.md implementation path.

Per the spec, moduleToDbSchema() takes a TModule and returns a DbSchema with:

  • graphType: DbGraphTypeRow — name from Module name, config from Config entry
  • nodeTypes: DbNodeTypeRow[] — one per *Node entry, name = entry name minus suffix
  • edgeTypes: DbEdgeTypeRow[] — one per *Edge entry, with constraint data from *EdgeConstraints entries

The function must enforce the entry naming convention (*Node, *Edge, Config, *EdgeConstraints, *Enum, BaseNode, BaseEdge) and throw on:

  • Entries with unrecognized suffixes (bare names are treated as shared types, not DB rows)
  • *EdgeConstraints entries referencing edge types not in the Module
  • *EdgeConstraints with empty allowedSourceTypes AND allowedTargetTypes
  • Module without a Config entry

Acceptance Criteria

  • src/graphs/bridge.ts exists with moduleToDbSchema(), validateNode(), validateEdge() exports
  • moduleToDbSchema() accepts a TModule and returns DbSchema with graphType, nodeTypes, edgeTypes
  • moduleToDbSchema() enforces naming convention: entries ending in Node become node type rows, entries ending in Edge become edge type rows, Config becomes the graph type config
  • moduleToDbSchema() throws on missing Config, unrecognized bare entry suffixes, empty EdgeConstraints, EdgeConstraints referencing nonexistent edge types
  • validateNode(module, entryName, data) returns booleantrue if data passes Value.Check against the resolved Module entry, false if invalid, throws if entryName doesn't match an *Node entry
  • validateEdge(module, entryName, data) same pattern for *Edge entries
  • src/graphs/mod.ts re-exports from bridge.ts
  • deno check mod.ts passes

References

  • docs/architecture/metagraph-module.md — "Bridge Functions" and "DB Persistence Bridge" sections
  • docs/architecture/decisions/014-dereferenced-entry-schemas.md
  • docs/architecture/decisions/016-naming-convention-for-module-entries.md

Notes

To be filled by implementation agent

Summary

To be filled on completion