summaryrefslogtreecommitdiff
path: root/internal/tree/core.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tree/core.go')
-rw-r--r--internal/tree/core.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/tree/core.go b/internal/tree/core.go
new file mode 100644
index 0000000..aa47fb6
--- /dev/null
+++ b/internal/tree/core.go
@@ -0,0 +1,47 @@
+package tree
+
+import (
+ "sync"
+
+ "go.neonxp.dev/djson/internal/storage"
+ "go.neonxp.dev/json/model"
+)
+
+type stdCore struct {
+ Root model.ObjectNode
+ state CoreState
+ mu sync.RWMutex
+ storage storage.Storage
+}
+
+func New(storage storage.Storage) Core {
+ return &stdCore{
+ Root: model.ObjectNode{},
+ state: Running,
+ mu: sync.RWMutex{},
+ storage: storage,
+ }
+}
+
+func (t *stdCore) Init() error {
+ // Load initial mutations
+ for m := range t.storage.Load() {
+ if err := t.execute(&m); err != nil {
+ t.state = Failed
+ return err
+ }
+ }
+ t.state = Ready
+ return nil
+}
+
+func (t *stdCore) Get(nodes []string) (model.Node, error) {
+ if len(nodes) == 0 {
+ return &t.Root, nil
+ }
+ return model.Query(&t.Root, nodes)
+}
+
+func (t *stdCore) State() CoreState {
+ return t.state
+}