@@ -10,11 +10,10 @@ import (
1010 "sync"
1111 "time"
1212
13- "memex/internal/memex/core"
1413 "memex/internal/memex/storage/rabin"
1514 "memex/internal/memex/storage/store"
1615 "memex/internal/memex/transaction"
17- "memex/pkg/types "
16+ "memex/pkg/module "
1817)
1918
2019// Magic number for .mx files
@@ -41,20 +40,15 @@ type Repository struct {
4140 store * store.ChunkStore
4241 txStore * transaction.ActionStore
4342 lockMgr sync.Mutex
44- modules map [string ]core .Module
43+ modules map [string ]module .Module
4544}
4645
4746// Ensure Repository implements required interfaces
4847var (
4948 _ transaction.Storage = (* Repository )(nil )
50- _ core .Repository = (* Repository )(nil )
49+ _ module .Repository = (* Repository )(nil )
5150)
5251
53- // AsModuleRepository returns the repository as a types.ModuleRepository
54- func (r * Repository ) AsModuleRepository () types.ModuleRepository {
55- return NewRepositoryAdapter (r )
56- }
57-
5852// Create creates a new repository at the given path
5953func Create (path string ) (* Repository , error ) {
6054 // Create file
@@ -85,7 +79,7 @@ func Create(path string) (*Repository, error) {
8579 path : path ,
8680 file : file ,
8781 header : header ,
88- modules : make (map [string ]core .Module ),
82+ modules : make (map [string ]module .Module ),
8983 }
9084
9185 // Create transaction store
@@ -136,7 +130,7 @@ func Open(path string) (*Repository, error) {
136130 path : path ,
137131 file : file ,
138132 header : header ,
139- modules : make (map [string ]core .Module ),
133+ modules : make (map [string ]module .Module ),
140134 }
141135
142136 // Create transaction store
@@ -178,29 +172,32 @@ func (r *Repository) GetLockManager() interface{} {
178172
179173// Module operations
180174
181- func (r * Repository ) GetModule (id string ) (core .Module , bool ) {
175+ func (r * Repository ) GetModule (id string ) (module .Module , bool ) {
182176 module , exists := r .modules [id ]
183177 return module , exists
184178}
185179
186- func (r * Repository ) RegisterModule (module core.Module ) error {
187- if _ , exists := r .modules [module .ID ()]; exists {
188- return fmt .Errorf ("module already registered: %s" , module .ID ())
180+ func (r * Repository ) RegisterModule (m module.Module ) error {
181+ if _ , exists := r .modules [m .ID ()]; exists {
182+ return fmt .Errorf ("module already registered: %s" , m .ID ())
183+ }
184+ if err := m .Init (r ); err != nil {
185+ return fmt .Errorf ("initializing module: %w" , err )
189186 }
190- r .modules [module .ID ()] = module
187+ r .modules [m .ID ()] = m
191188 return nil
192189}
193190
194- func (r * Repository ) ListModules () []core .Module {
195- modules := make ([]core .Module , 0 , len (r .modules ))
196- for _ , module := range r .modules {
197- modules = append (modules , module )
191+ func (r * Repository ) ListModules () []module .Module {
192+ modules := make ([]module .Module , 0 , len (r .modules ))
193+ for _ , m := range r .modules {
194+ modules = append (modules , m )
198195 }
199196 return modules
200197}
201198
202- func (r * Repository ) QueryNodesByModule (moduleID string ) ([]* core .Node , error ) {
203- nodes := []* core .Node {}
199+ func (r * Repository ) QueryNodesByModule (moduleID string ) ([]* module .Node , error ) {
200+ nodes := []* module .Node {}
204201 ids , err := r .ListNodes ()
205202 if err != nil {
206203 return nil , err
@@ -218,8 +215,8 @@ func (r *Repository) QueryNodesByModule(moduleID string) ([]*core.Node, error) {
218215 return nodes , nil
219216}
220217
221- func (r * Repository ) QueryLinksByModule (moduleID string ) ([]* core .Link , error ) {
222- links := []* core .Link {}
218+ func (r * Repository ) QueryLinksByModule (moduleID string ) ([]* module .Link , error ) {
219+ links := []* module .Link {}
223220 chunks , err := r .store .ListChunks ()
224221 if err != nil {
225222 return nil , err
@@ -231,7 +228,7 @@ func (r *Repository) QueryLinksByModule(moduleID string) ([]*core.Link, error) {
231228 continue
232229 }
233230
234- var link core .Link
231+ var link module .Link
235232 if err := json .Unmarshal (data , & link ); err != nil {
236233 continue
237234 }
@@ -253,7 +250,7 @@ func (r *Repository) GetContent(id string) ([]byte, error) {
253250}
254251
255252// GetNode retrieves a node from the repository
256- func (r * Repository ) GetNode (id string ) (* core .Node , error ) {
253+ func (r * Repository ) GetNode (id string ) (* module .Node , error ) {
257254 var data []byte
258255 var err error
259256
@@ -274,10 +271,10 @@ func (r *Repository) GetNode(id string) (*core.Node, error) {
274271 }
275272
276273 // Parse node
277- var node core .Node
274+ var node module .Node
278275 if err := json .Unmarshal (data , & node ); err != nil {
279276 // If parsing fails, try wrapping the data in a basic node structure
280- node = core .Node {
277+ node = module .Node {
281278 Content : data ,
282279 Meta : make (map [string ]interface {}),
283280 }
@@ -302,7 +299,7 @@ func (r *Repository) AddNode(content []byte, nodeType string, meta map[string]in
302299
303300 // Create node
304301 now := time .Now ().UTC ()
305- node := & core .Node {
302+ node := & module .Node {
306303 Type : nodeType ,
307304 Content : content ,
308305 Meta : meta ,
@@ -380,7 +377,7 @@ func (r *Repository) AddNodeWithID(id string, content []byte, nodeType string, m
380377
381378 // Create node
382379 now := time .Now ().UTC ()
383- node := & core .Node {
380+ node := & module .Node {
384381 ID : id ,
385382 Type : nodeType ,
386383 Content : content ,
@@ -528,7 +525,7 @@ func (r *Repository) AddLink(source, target, linkType string, meta map[string]in
528525
529526 // Create link
530527 now := time .Now ().UTC ()
531- link := & core .Link {
528+ link := & module .Link {
532529 Source : source ,
533530 Target : target ,
534531 Type : linkType ,
@@ -583,15 +580,15 @@ func (r *Repository) AddLink(source, target, linkType string, meta map[string]in
583580}
584581
585582// GetLinks returns all links for a node
586- func (r * Repository ) GetLinks (nodeID string ) ([]* core .Link , error ) {
583+ func (r * Repository ) GetLinks (nodeID string ) ([]* module .Link , error ) {
587584 // List all chunks
588585 chunks , err := r .store .ListChunks ()
589586 if err != nil {
590587 return nil , fmt .Errorf ("listing chunks: %w" , err )
591588 }
592589
593590 // Filter and parse links
594- var links []* core .Link
591+ var links []* module .Link
595592 for _ , chunk := range chunks {
596593 // Get chunk data
597594 data , err := r .store .Get ([][]byte {chunk })
@@ -600,7 +597,7 @@ func (r *Repository) GetLinks(nodeID string) ([]*core.Link, error) {
600597 }
601598
602599 // Try to parse as link
603- var link core .Link
600+ var link module .Link
604601 if err := json .Unmarshal (data , & link ); err != nil {
605602 continue
606603 }
@@ -643,7 +640,7 @@ func (r *Repository) DeleteLink(source, target, linkType string) error {
643640 }
644641
645642 // Try to parse as link
646- var link core .Link
643+ var link module .Link
647644 if err := json .Unmarshal (data , & link ); err != nil {
648645 continue
649646 }
0 commit comments