diff --git a/packages/server-api/src/deltas.test.ts b/packages/server-api/src/deltas.test.ts new file mode 100644 index 000000000..535231765 --- /dev/null +++ b/packages/server-api/src/deltas.test.ts @@ -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' + } + } + ] + } + ] +} diff --git a/packages/server-api/src/deltas.ts b/packages/server-api/src/deltas.ts index 2e60078bd..e8e5320ff 100644 --- a/packages/server-api/src/deltas.ts +++ b/packages/server-api/src/deltas.ts @@ -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 { @@ -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 diff --git a/packages/server-api/tsconfig.json b/packages/server-api/tsconfig.json index 5023d43d6..0bad7084f 100644 --- a/packages/server-api/tsconfig.json +++ b/packages/server-api/tsconfig.json @@ -69,5 +69,6 @@ }, "ts-node": { "files": true - } + }, + "exclude": ["src/**/*.test.ts"] }