Skip to content
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

Fix: server api types #1783

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/server-api/src/deltas.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Delta, Path } from './deltas'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const metaDelta: Delta = {
updates: [
{
meta: [
{
path: 'foo.bar' as Path,
value: {
displayName: 'Foo Bar'
}
}
]
}
]
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const valuesDelta: Delta = {
updates: [
{
values: [
{
path: 'foo.bar' as Path,
value: {
displayName: 'Foo Bar'
}
}
]
}
]
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const combinedDelta: Delta = {
updates: [
{
meta: [
{
path: 'foo.bar' as Path,
value: {
displayName: 'Foo Bar'
}
}
]
},
{
values: [
{
path: 'foo.bar' as Path,
value: {
displayName: 'Foo Bar'
}
}
]
}
]
}
37 changes: 24 additions & 13 deletions packages/server-api/src/deltas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ export interface DeltaSubscription {
}>
}

// "Classic" Delta with values
export interface ValuesDelta {
export interface Delta {
context?: Context
updates: Update[]
}

export interface MetaDelta {
metas: Array<{ values: Meta[] }>
}

// Delta Message
export type Delta = ValuesDelta | MetaDelta
/**
* @deprecated earlier mistake assumed ValuesDelta and MetaDelta were separate
*/
export type ValuesDelta = Delta
/**
* @deprecated earlier mistake assumed ValuesDelta and MetaDelta were separate
*/
export type MetaDelta = Delta

export interface Update {
export type Update = {
timestamp?: Timestamp
source?: Source
$source?: SourceRef
values: PathValue[]
}
} & ({ values: PathValue[] } | { meta: Meta[] }) // require either values or meta or both

// Update delta
export interface PathValue {
Expand All @@ -67,15 +67,26 @@ export interface Notification {

// MetaMessage
export interface Meta {
path: string
path: Path
value: MetaValue
}

// Meta payload
export interface MetaValue {
description: string
description?: string
units?: string
example?: string
timeout?: number
displayName?: string
displayScale?: {
lower: number
upper: number
}
zones?: {
upper: number
lower: number
state: string
}[]
}

// Notification attribute types
Expand Down
3 changes: 2 additions & 1 deletion packages/server-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
},
"ts-node": {
"files": true
}
},
"exclude": ["src/**/*.test.ts"]
}