-
-
Notifications
You must be signed in to change notification settings - Fork 807
implement /api/schemas (json schemas from tsunami atoms /api/config /api/data) #2335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78e82ee
b655e3e
37a29cb
3fcf2c7
4259018
4fba48f
6aa0540
36c613e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,20 +6,33 @@ package engine | |
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "reflect" | ||
| "sync" | ||
| ) | ||
|
|
||
| // AtomMeta provides metadata about an atom for validation and documentation | ||
| type AtomMeta struct { | ||
| Description string // short, user-facing | ||
| Units string // "ms", "GiB", etc. | ||
| Min *float64 // optional minimum (numeric types) | ||
| Max *float64 // optional maximum (numeric types) | ||
| Enum []string // allowed values if finite set | ||
| Pattern string // regex constraint for strings | ||
| } | ||
|
|
||
| type AtomImpl[T any] struct { | ||
| lock *sync.Mutex | ||
| val T | ||
| usedBy map[string]bool // component waveid -> true | ||
| meta *AtomMeta // optional metadata | ||
| } | ||
|
|
||
| func MakeAtomImpl[T any](initialVal T) *AtomImpl[T] { | ||
| func MakeAtomImpl[T any](initialVal T, meta *AtomMeta) *AtomImpl[T] { | ||
| return &AtomImpl[T]{ | ||
| lock: &sync.Mutex{}, | ||
| val: initialVal, | ||
| usedBy: make(map[string]bool), | ||
| meta: meta, | ||
| } | ||
| } | ||
|
Comment on lines
+30
to
37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meta escape hatch: copy metadata at construction to prevent external mutation Storing the caller-provided *AtomMeta directly allows later unsynchronized mutations by the caller, leading to data races and inconsistent schemas. Clone it on input. Apply: func MakeAtomImpl[T any](initialVal T, meta *AtomMeta) *AtomImpl[T] {
return &AtomImpl[T]{
lock: &sync.Mutex{},
val: initialVal,
usedBy: make(map[string]bool),
- meta: meta,
+ meta: cloneAtomMeta(meta),
}
}Add once in this file: // cloneAtomMeta makes a deep copy to keep AtomMeta immutable/owned by the atom.
func cloneAtomMeta(in *AtomMeta) *AtomMeta {
if in == nil {
return nil
}
out := *in // shallow copy first
if in.Enum != nil {
out.Enum = append([]string(nil), in.Enum...)
}
if in.Min != nil {
v := *in.Min
out.Min = &v
}
if in.Max != nil {
v := *in.Max
out.Max = &v
}
return &out
}🤖 Prompt for AI Agents |
||
|
|
||
|
|
@@ -84,3 +97,13 @@ func (a *AtomImpl[T]) GetUsedBy() []string { | |
| } | ||
| return keys | ||
| } | ||
|
|
||
| func (a *AtomImpl[T]) GetMeta() *AtomMeta { | ||
| a.lock.Lock() | ||
| defer a.lock.Unlock() | ||
| return a.meta | ||
| } | ||
|
Comment on lines
+101
to
+105
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not return internal pointer; return a clone to avoid data races Returning a.meta exposes internal state for mutation without locks. Return a cloned copy. Apply: func (a *AtomImpl[T]) GetMeta() *AtomMeta {
a.lock.Lock()
defer a.lock.Unlock()
- return a.meta
+ return cloneAtomMeta(a.meta)
}
🤖 Prompt for AI Agents |
||
|
|
||
| func (a *AtomImpl[T]) GetAtomType() reflect.Type { | ||
| return reflect.TypeOf((*T)(nil)).Elem() | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Backwards-incompatible API change: ensure all call sites add the meta arg.
ConfigAtom/DataAtom now require a third parameter. Verify no two-arg calls remain.
Run:
Also applies to: 51-58
🏁 Script executed:
Length of output: 370
Backwards-incompatible API change — add missing meta argument to ConfigAtom/DataAtom call sites
Found a legacy two-arg call; update to pass the new third meta parameter.
🤖 Prompt for AI Agents