From abb4990b3e8342606566dc4f5b9f60a80a6a4360 Mon Sep 17 00:00:00 2001 From: Skoow <89569841+Skoowshot@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:11:16 +0500 Subject: [PATCH 1/4] feat: add workspace.Workspace --- internal/workspace/workspace.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 internal/workspace/workspace.go diff --git a/internal/workspace/workspace.go b/internal/workspace/workspace.go new file mode 100644 index 0000000..c9596bf --- /dev/null +++ b/internal/workspace/workspace.go @@ -0,0 +1,7 @@ +package workspace + +import "github.com/Skoowshot/qrix-runtime/internal/store" + +type Workspace struct { + Stores *store.Registry +} From b16f485ef2b7f13cc3a31654a223fa0e4d94b3d3 Mon Sep 17 00:00:00 2001 From: Skoow <89569841+Skoowshot@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:13:11 +0500 Subject: [PATCH 2/4] feat: add workspace.Registry, workspace.ID --- internal/workspace/errors.go | 7 +++++ internal/workspace/registry.go | 56 +++++++++++++++++++++++++++++++++ internal/workspace/workspace.go | 7 +++++ 3 files changed, 70 insertions(+) create mode 100644 internal/workspace/errors.go create mode 100644 internal/workspace/registry.go diff --git a/internal/workspace/errors.go b/internal/workspace/errors.go new file mode 100644 index 0000000..a21eedc --- /dev/null +++ b/internal/workspace/errors.go @@ -0,0 +1,7 @@ +package workspace + +import "errors" + +var ( + ErrNameAlreadyExists = errors.New("name already exists") +) diff --git a/internal/workspace/registry.go b/internal/workspace/registry.go new file mode 100644 index 0000000..c8f4bc2 --- /dev/null +++ b/internal/workspace/registry.go @@ -0,0 +1,56 @@ +package workspace + +import ( + "fmt" + "sync" +) + +// Registry maps ID to Workspace and Name to ID. +type Registry struct { + nextID uint64 + byID map[ID]Workspace + nameToID map[Name]ID + mu sync.RWMutex +} + +// NewRegistry creates a Registry. +func NewRegistry() *Registry { + return &Registry{ + byID: make(map[ID]Workspace), + nameToID: make(map[Name]ID), + } +} + +// Put maps the given Workspace by a generated ID, and maps the given Name to generated ID. +func (r *Registry) Put(name Name, workspace Workspace) (ID, error) { + r.mu.Lock() + defer r.mu.Unlock() + + if _, ok := r.nameToID[name]; ok { + return 0, fmt.Errorf("%w: %v", ErrNameAlreadyExists, name) + } + + r.nextID++ + id := ID(r.nextID) + r.byID[id] = workspace + r.nameToID[name] = id + return id, nil +} + +// Get returns the Workspace by ID. +func (r *Registry) Get(id ID) (Workspace, bool) { + r.mu.RLock() + defer r.mu.RUnlock() + + workspace, ok := r.byID[id] + return workspace, ok +} + +// GetID returns the ID by Name. +func (r *Registry) GetID(name Name) (ID, bool) { + r.mu.RLock() + defer r.mu.RUnlock() + + workspace, ok := r.nameToID[name] + return workspace, ok +} diff --git a/internal/workspace/workspace.go b/internal/workspace/workspace.go index c9596bf..2cf21e8 100644 --- a/internal/workspace/workspace.go +++ b/internal/workspace/workspace.go @@ -2,6 +2,13 @@ package workspace import "github.com/Skoowshot/qrix-runtime/internal/store" +// ID is a unique runtime hot-path identifier of Workspace. +type ID uint64 + +// Name is a unique cold-path name of Workspace. +type Name string + +// Workspace is an isolated self-contained unit holding application state. type Workspace struct { Stores *store.Registry } From 6b62016cefc951d122f860fd4a8b809397be7f8c Mon Sep 17 00:00:00 2001 From: Skoow <89569841+Skoowshot@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:23:17 +0500 Subject: [PATCH 3/4] feat: add network.Network to workspace.Workspace --- internal/workspace/workspace.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/workspace/workspace.go b/internal/workspace/workspace.go index 2cf21e8..f32c881 100644 --- a/internal/workspace/workspace.go +++ b/internal/workspace/workspace.go @@ -1,6 +1,9 @@ package workspace -import "github.com/Skoowshot/qrix-runtime/internal/store" +import ( + "github.com/Skoowshot/qrix-runtime/internal/network" + "github.com/Skoowshot/qrix-runtime/internal/store" +) // ID is a unique runtime hot-path identifier of Workspace. type ID uint64 @@ -10,5 +13,6 @@ type Name string // Workspace is an isolated self-contained unit holding application state. type Workspace struct { - Stores *store.Registry + Stores *store.Registry + Network *network.Network } From e6310af26638806c8681d6df4df087586dde0b26 Mon Sep 17 00:00:00 2001 From: Skoow <89569841+Skoowshot@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:23:26 +0500 Subject: [PATCH 4/4] refactor: change Workspace to *Workspace in workspace.Registry --- internal/workspace/registry.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/workspace/registry.go b/internal/workspace/registry.go index c8f4bc2..c496175 100644 --- a/internal/workspace/registry.go +++ b/internal/workspace/registry.go @@ -8,7 +8,7 @@ import ( // Registry maps ID to Workspace and Name to ID. type Registry struct { nextID uint64 - byID map[ID]Workspace + byID map[ID]*Workspace nameToID map[Name]ID mu sync.RWMutex } @@ -16,13 +16,13 @@ type Registry struct { // NewRegistry creates a Registry. func NewRegistry() *Registry { return &Registry{ - byID: make(map[ID]Workspace), + byID: make(map[ID]*Workspace), nameToID: make(map[Name]ID), } } // Put maps the given Workspace by a generated ID, and maps the given Name to generated ID. -func (r *Registry) Put(name Name, workspace Workspace) (ID, error) { +func (r *Registry) Put(name Name, workspace *Workspace) (ID, error) { r.mu.Lock() defer r.mu.Unlock() @@ -38,7 +38,7 @@ func (r *Registry) Put(name Name, workspace Workspace) (ID, error) { } // Get returns the Workspace by ID. -func (r *Registry) Get(id ID) (Workspace, bool) { +func (r *Registry) Get(id ID) (*Workspace, bool) { r.mu.RLock() defer r.mu.RUnlock()