@alteriom/mqtt-schema 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,174 +1,228 @@
1
- # @alteriom/mqtt-schema
2
-
3
- Alteriom MQTT v1 JSON Schemas, TypeScript types, and production‑ready validation helpers for integrating firmware MQTT payloads into web or backend services.
4
-
5
- ## Why this exists
6
- Firmware emits structured MQTT payloads that must remain tightly aligned with web, analytics, and gateway logic. This package is the single source of truth for:
7
-
8
- - Canonical, versioned JSON Schemas (`schema_version: 1` series)
9
- - Embedded (tree‑shakeable) schema objects — no runtime file I/O
10
- - Precompiled Ajv validators (fast + consistent across CJS / ESM)
11
- - TypeScript interfaces & type guards generated from the same source schema set
12
- - Message classification helper that infers the schema kind heuristically
13
- - Forward‑compatible design: unknown extra properties are ignored unless explicitly constrained
14
-
15
- ## Features
16
-
17
- - Dual build: CommonJS + ESM (Node 16+ / bundlers)
18
- - Zero configuration: just import and validate
19
- - Helpful error paths (JSON Pointer style)
20
- - Lightweight (Ajv peer dependency, schemas embedded)
21
- - Ships original schema JSON files (optional consumption)
22
-
23
- ## Installation
24
-
25
- ```bash
26
- npm install @alteriom/mqtt-schema ajv ajv-formats
27
- ```
28
-
29
- ## Quick Start
30
-
31
- Validate a JSON payload (object already parsed):
32
-
33
- ```ts
34
- import { validators } from '@alteriom/mqtt-schema';
35
-
36
- const payload = JSON.parse(rawMqttString);
37
- const result = validators.sensorData(payload);
38
- if (!result.valid) {
39
- console.error('Invalid sensor data', result.errors);
40
- }
41
- ```
42
-
43
- Classify and validate automatically:
44
-
45
- ```ts
46
- import { classifyAndValidate } from '@alteriom/mqtt-schema';
47
-
48
- const { kind, result } = classifyAndValidate(payload);
49
- if (result.valid) {
50
- console.log('Message kind:', kind);
51
- } else {
52
- console.warn('Validation errors', result.errors);
53
- }
54
- ```
55
-
56
- Use strong TypeScript types after classification:
57
-
58
- ```ts
59
- import { classifyAndValidate, isSensorDataMessage, SensorDataMessage } from '@alteriom/mqtt-schema';
60
-
61
- const { result } = classifyAndValidate(payload);
62
- if (result.valid && isSensorDataMessage(payload)) {
63
- const data: SensorDataMessage = payload;
64
- Object.entries(data.sensors).forEach(([name, s]) => {
65
- console.log(name, s.value, s.unit);
66
- });
67
- }
68
- ```
69
-
70
- Access raw schema JSON (if you need to introspect or power form generation):
71
-
72
- ```ts
73
- import envelopeSchema from '@alteriom/mqtt-schema/schemas/envelope.schema.json';
74
- ```
75
-
76
- ## API Surface
77
-
78
- ```ts
79
- import { validators, validateMessage, classifyAndValidate } from '@alteriom/mqtt-schema';
80
-
81
- // 1. Direct validator by message kind
82
- validators.sensorData(payload); // => { valid: boolean; errors?: string[] }
83
-
84
- // 2. Generic function
85
- validateMessage('sensorData', payload);
86
-
87
- // 3. Classify unknown payload then validate
88
- const { kind, result } = classifyAndValidate(payload);
89
-
90
- // 4. Type guards (when available)
91
- // if (isSensorDataMessage(payload)) { ... }
92
- ```
93
-
94
- Validation result format:
95
-
96
- ```ts
97
- interface ValidationResult {
98
- valid: boolean;
99
- errors?: string[]; // Each item contains instancePath + message
100
- }
101
- ```
102
-
103
- ### Performance Notes
104
- All Ajv validator functions are compiled once at module load. For typical web usage (tens to hundreds of validations per page/session) this is faster and simpler than on‑demand compilation. If you need custom Ajv options (e.g., different formats), open an issue—an override hook can be added without breaking changes.
105
-
106
- ### Embedded Schemas
107
- `schema_data.ts` is auto‑generated during build. This avoids dynamic `require()` / `import` of JSON and works cleanly in both Node ESM and bundlers without JSON import assertions. The original JSON files are still published under `schemas/` for tooling or documentation pipelines.
108
-
109
- ## Provided Schemas (v1)
110
-
111
- | File | Purpose |
112
- |------|---------|
113
- | envelope.schema.json | Base required envelope fields |
114
- | sensor_data.schema.json | Telemetry payload with sensors map |
115
- | sensor_heartbeat.schema.json | Lightweight heartbeat (firmware_version may be omitted) |
116
- | sensor_status.schema.json | Sensor status / presence updates |
117
- | gateway_info.schema.json | Gateway identity & capabilities |
118
- | gateway_metrics.schema.json | Gateway performance metrics |
119
- | firmware_status.schema.json | Firmware update lifecycle events |
120
- | control_response.schema.json | Command/control response messages |
121
-
122
- ## Exports
123
-
124
- | Export | Type | Description |
125
- |--------|------|-------------|
126
- | `validators` | object | Precompiled validators per message type |
127
- | `validateMessage(kind,data)` | fn | Run a specific validator by key |
128
- | `classifyAndValidate(data)` | fn | Heuristic classification + validation |
129
- | `SensorDataMessage` etc. | TS interfaces | Strongly typed shapes |
130
- | `isSensorDataMessage` etc. | type guards | Runtime narrowing helpers |
131
- | `schemas/*.json` | JSON | Original schema assets (optional) |
132
-
133
- ### Validator Keys
134
- `sensorData`, `sensorHeartbeat`, `sensorStatus`, `gatewayInfo`, `gatewayMetrics`, `firmwareStatus`, `controlResponse`
135
-
136
- ### Classification Heuristics (Simplified)
137
- - `metrics` → `gatewayMetrics`
138
- - `sensors` → `sensorData`
139
- - `progress_pct` or OTA status keywords → `firmwareStatus`
140
- - `status` + `device_type: sensor` → `sensorStatus`
141
- - `status: ok|error` (no other match) → `controlResponse`
142
- - `device_type: gateway` → `gatewayInfo`
143
- - fallback → `sensorHeartbeat`
144
-
145
- ## Versioning Policy
146
-
147
- Schema stability is paramount. We track two related versions:
148
-
149
- | Concept | Meaning |
150
- |---------|---------|
151
- | `schema_version` (in payload) | Wire format major. Only increments for breaking changes. |
152
- | npm package version | Follows semver; patch/minor may add optional properties or tooling, major aligns with `schema_version` bump. |
153
-
154
- Backward‑compatible additions: new optional properties or enums, documented in CHANGELOG. Breaking: new required fields, structural changes, or removed properties (triggers parallel `v2` schema path & coordinated firmware rollout).
155
-
156
- ## TypeScript / Bundler Notes
157
- - Works in TS >= 5, Node >= 16, Vite / Webpack / ESBuild.
158
- - Tree shaking: unused validators pruned when using ESM builds.
159
- - No side effects besides Ajv instance creation.
160
-
161
- ## Roadmap
162
- - Optional custom Ajv injection hook
163
- - JSON Schema → Zod conversion example
164
- - Runtime metrics helper (count validation categories)
165
-
166
- ## Contributing
167
- Issues & PRs welcome. Ensure firmware repo schemas remain the authoritative source—do not manually edit generated `schema_data.ts`.
168
-
169
- ## Security
170
- Schemas are static. No network access. Supply-chain risk minimized by keeping dependencies minimal (Ajv + formats only).
171
-
172
- ## License
173
-
174
- MIT
1
+ # @alteriom/mqtt-schema
2
+
3
+ Alteriom MQTT v1 JSON Schemas, TypeScript types, and production‑ready validation helpers for integrating firmware MQTT payloads into web or backend services.
4
+
5
+ ## Why this exists
6
+ Firmware emits structured MQTT payloads that must remain tightly aligned with web, analytics, and gateway logic. This package is the single source of truth for:
7
+
8
+ - Canonical, versioned JSON Schemas (`schema_version: 1` series)
9
+ - Embedded (tree‑shakeable) schema objects — no runtime file I/O
10
+ - Precompiled Ajv validators (fast + consistent across CJS / ESM)
11
+ - TypeScript interfaces & type guards generated from the same source schema set
12
+ - Message classification helper that infers the schema kind heuristically
13
+ - Forward‑compatible design: unknown extra properties are ignored unless explicitly constrained
14
+
15
+ ## Features
16
+
17
+ - Dual build: CommonJS + ESM (Node 16+ / bundlers)
18
+ - Zero configuration: just import and validate
19
+ - Helpful error paths (JSON Pointer style)
20
+ - Lightweight (Ajv peer dependency, schemas embedded)
21
+ - Ships original schema JSON files (optional consumption)
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @alteriom/mqtt-schema ajv ajv-formats
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ Validate a JSON payload (object already parsed):
32
+
33
+ ```ts
34
+ import { validators } from '@alteriom/mqtt-schema';
35
+
36
+ const payload = JSON.parse(rawMqttString);
37
+ const result = validators.sensorData(payload);
38
+ if (!result.valid) {
39
+ console.error('Invalid sensor data', result.errors);
40
+ }
41
+ ```
42
+
43
+ Classify and validate automatically:
44
+
45
+ ```ts
46
+ import { classifyAndValidate } from '@alteriom/mqtt-schema';
47
+
48
+ const { kind, result } = classifyAndValidate(payload);
49
+ if (result.valid) {
50
+ console.log('Message kind:', kind);
51
+ } else {
52
+ console.warn('Validation errors', result.errors);
53
+ }
54
+ ```
55
+
56
+ Use strong TypeScript types after classification:
57
+
58
+ ```ts
59
+ import { classifyAndValidate, isSensorDataMessage, SensorDataMessage } from '@alteriom/mqtt-schema';
60
+
61
+ const { result } = classifyAndValidate(payload);
62
+ if (result.valid && isSensorDataMessage(payload)) {
63
+ const data: SensorDataMessage = payload;
64
+ Object.entries(data.sensors).forEach(([name, s]) => {
65
+ console.log(name, s.value, s.unit);
66
+ });
67
+ }
68
+ ```
69
+
70
+ Access raw schema JSON (if you need to introspect or power form generation):
71
+
72
+ ```ts
73
+ import envelopeSchema from '@alteriom/mqtt-schema/schemas/envelope.schema.json';
74
+ ```
75
+
76
+ ## API Surface
77
+
78
+ ```ts
79
+ import { validators, validateMessage, classifyAndValidate } from '@alteriom/mqtt-schema';
80
+
81
+ // 1. Direct validator by message kind
82
+ validators.sensorData(payload); // => { valid: boolean; errors?: string[] }
83
+
84
+ // 2. Generic function
85
+ validateMessage('sensorData', payload);
86
+
87
+ // 3. Classify unknown payload then validate
88
+ const { kind, result } = classifyAndValidate(payload);
89
+
90
+ // 4. Type guards (when available)
91
+ // if (isSensorDataMessage(payload)) { ... }
92
+ ```
93
+
94
+ Validation result format:
95
+
96
+ ```ts
97
+ interface ValidationResult {
98
+ valid: boolean;
99
+ errors?: string[]; // Each item contains instancePath + message
100
+ }
101
+ ```
102
+
103
+ ### Performance Notes
104
+ All Ajv validator functions are compiled once at module load. For typical web usage (tens to hundreds of validations per page/session) this is faster and simpler than on‑demand compilation. If you need custom Ajv options (e.g., different formats), open an issue—an override hook can be added without breaking changes.
105
+
106
+ ### Embedded Schemas
107
+ `schema_data.ts` is auto‑generated during build. This avoids dynamic `require()` / `import` of JSON and works cleanly in both Node ESM and bundlers without JSON import assertions. The original JSON files are still published under `schemas/` for tooling or documentation pipelines.
108
+
109
+ ## Provided Schemas (v1)
110
+
111
+ | File | Purpose |
112
+ |------|---------|
113
+ | envelope.schema.json | Base required envelope fields |
114
+ | sensor_data.schema.json | Telemetry payload with sensors map |
115
+ | sensor_heartbeat.schema.json | Lightweight heartbeat (firmware_version may be omitted) |
116
+ | sensor_status.schema.json | Sensor status / presence updates |
117
+ | gateway_info.schema.json | Gateway identity & capabilities |
118
+ | gateway_metrics.schema.json | Gateway performance metrics |
119
+ | firmware_status.schema.json | Firmware update lifecycle events |
120
+ | control_response.schema.json | Command/control response messages |
121
+
122
+ ## Exports
123
+
124
+ | Export | Type | Description |
125
+ |--------|------|-------------|
126
+ | `validators` | object | Precompiled validators per message type |
127
+ | `validateMessage(kind,data)` | fn | Run a specific validator by key |
128
+ | `classifyAndValidate(data)` | fn | Heuristic classification + validation |
129
+ | `SensorDataMessage` etc. | TS interfaces | Strongly typed shapes |
130
+ | `isSensorDataMessage` etc. | type guards | Runtime narrowing helpers |
131
+ | `schemas/*.json` | JSON | Original schema assets (optional) |
132
+
133
+ ### Validator Keys
134
+ `sensorData`, `sensorHeartbeat`, `sensorStatus`, `gatewayInfo`, `gatewayMetrics`, `firmwareStatus`, `controlResponse`
135
+
136
+ ### Classification Heuristics (Simplified)
137
+
138
+ - `metrics` → `gatewayMetrics`
139
+ - `sensors` → `sensorData`
140
+ - `progress_pct` or OTA status keywords → `firmwareStatus`
141
+ - `status` + `device_type: sensor` → `sensorStatus`
142
+ - `status: ok|error` (no other match) → `controlResponse`
143
+ - `device_type: gateway` → `gatewayInfo`
144
+ - fallback → `sensorHeartbeat`
145
+
146
+ ## Versioning Policy
147
+
148
+ Schema stability is paramount. We track two related versions:
149
+
150
+ | Concept | Meaning |
151
+ |---------|---------|
152
+ | `schema_version` (in payload) | Wire format major. Only increments for breaking changes. |
153
+ | npm package version | Follows semver; patch/minor may add optional properties or tooling, major aligns with `schema_version` bump. |
154
+
155
+ Backward‑compatible additions: new optional properties or enums, documented in CHANGELOG. Breaking: new required fields, structural changes, or removed properties (triggers parallel `v2` schema path & coordinated firmware rollout).
156
+
157
+ ## TypeScript / Bundler Notes
158
+
159
+ - Works in TS >= 5, Node >= 16, Vite / Webpack / ESBuild.
160
+ - Tree shaking: unused validators pruned when using ESM builds.
161
+ - No side effects besides Ajv instance creation.
162
+
163
+ ## Roadmap
164
+
165
+ - Optional custom Ajv injection hook
166
+ - JSON Schema → Zod conversion example
167
+ - Runtime metrics helper (count validation categories)
168
+
169
+ ## Contributing
170
+
171
+ Issues & PRs welcome. Ensure firmware repo schemas remain the authoritative source—do not manually edit generated `schema_data.ts`.
172
+
173
+ ## Security
174
+
175
+ Schemas are static. No network access. Supply-chain risk minimized by keeping dependencies minimal (Ajv + formats only).
176
+
177
+ ## License
178
+
179
+ MIT
180
+
181
+ ## Registry Mirrors
182
+
183
+ This package is published to BOTH:
184
+
185
+ - Public npm registry: `https://registry.npmjs.org` (primary)
186
+ - GitHub Packages registry: `https://npm.pkg.github.com` (mirror for visibility in repo Packages tab)
187
+
188
+ ### Installing from GitHub Packages (optional)
189
+
190
+ Create or update an `.npmrc` with a scoped registry override (auth token with `read:packages` required):
191
+
192
+ ```
193
+ @alteriom:registry=https://npm.pkg.github.com
194
+ //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
195
+ ```
196
+
197
+ Then install normally:
198
+
199
+ ```
200
+ npm install @alteriom/mqtt-schema ajv ajv-formats
201
+ ```
202
+
203
+ If you omit the override, npmjs.org is used (recommended for most consumers).
204
+
205
+ ### Why dual publish?
206
+
207
+ - GitHub Packages listing provides provenance + quick visibility in the repo UI.
208
+ - npm remains the canonical public distribution source (faster, anonymous installs allowed).
209
+
210
+ ### Operational Notes
211
+
212
+ | Aspect | Behavior |
213
+ |--------|----------|
214
+ | Build artifact | Built once, same tarball published to both registries. |
215
+ | Version uniqueness | Same version must not be republished; bump if any change needed. |
216
+ | Auth (GitHub) | Always required for install from GitHub Packages, even for public repos. |
217
+ | Tarball parity | Do not rebuild between publishes; workflows ensure single build. |
218
+ | Fallback strategy | If mirror publish fails (e.g., transient), primary npm publish still stands. |
219
+ | Provenance flag | Applied for npm (GitHub ignores currently). |
220
+
221
+ ### Verifying a Release
222
+
223
+ ```bash
224
+ npm view @alteriom/mqtt-schema version
225
+ npm view @alteriom/mqtt-schema version --registry=https://npm.pkg.github.com
226
+ ```
227
+
228
+ Both should return the same version.
@@ -1,15 +1,15 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://schemas.alteriom.io/mqtt/v1/control_response.schema.json",
4
- "title": "Control / Command Response v1",
5
- "allOf": [{"$ref": "envelope.schema.json"}],
6
- "type": "object",
7
- "required": ["status"],
8
- "properties": {
9
- "command": {"type": "string"},
10
- "status": {"type": "string", "enum": ["ok", "error"]},
11
- "message": {"type": "string"},
12
- "result": {"type": ["object", "array", "string", "number", "boolean", "null"]}
13
- },
14
- "additionalProperties": true
15
- }
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.alteriom.io/mqtt/v1/control_response.schema.json",
4
+ "title": "Control / Command Response v1",
5
+ "allOf": [{"$ref": "envelope.schema.json"}],
6
+ "type": "object",
7
+ "required": ["status"],
8
+ "properties": {
9
+ "command": {"type": "string"},
10
+ "status": {"type": "string", "enum": ["ok", "error"]},
11
+ "message": {"type": "string"},
12
+ "result": {"type": ["object", "array", "string", "number", "boolean", "null"]}
13
+ },
14
+ "additionalProperties": true
15
+ }
@@ -1,16 +1,16 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://schemas.alteriom.io/mqtt/v1/envelope.schema.json",
4
- "title": "Alteriom MQTT Base Envelope v1",
5
- "type": "object",
6
- "required": ["schema_version", "device_id", "device_type", "timestamp", "firmware_version"],
7
- "properties": {
8
- "schema_version": {"type": "integer", "const": 1},
9
- "device_id": {"type": "string", "minLength": 1, "maxLength": 64, "pattern": "^[A-Za-z0-9_-]+$"},
10
- "device_type": {"type": "string", "enum": ["sensor", "gateway"]},
11
- "timestamp": {"type": "string", "format": "date-time"},
12
- "firmware_version": {"type": "string", "minLength": 1, "maxLength": 40},
13
- "hardware_version": {"type": "string", "maxLength": 80}
14
- },
15
- "additionalProperties": true
16
- }
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.alteriom.io/mqtt/v1/envelope.schema.json",
4
+ "title": "Alteriom MQTT Base Envelope v1",
5
+ "type": "object",
6
+ "required": ["schema_version", "device_id", "device_type", "timestamp", "firmware_version"],
7
+ "properties": {
8
+ "schema_version": {"type": "integer", "const": 1},
9
+ "device_id": {"type": "string", "minLength": 1, "maxLength": 64, "pattern": "^[A-Za-z0-9_-]+$"},
10
+ "device_type": {"type": "string", "enum": ["sensor", "gateway"]},
11
+ "timestamp": {"type": "string", "format": "date-time"},
12
+ "firmware_version": {"type": "string", "minLength": 1, "maxLength": 40},
13
+ "hardware_version": {"type": "string", "maxLength": 80}
14
+ },
15
+ "additionalProperties": true
16
+ }
@@ -1,17 +1,17 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://schemas.alteriom.io/mqtt/v1/firmware_status.schema.json",
4
- "title": "Firmware Update Status v1",
5
- "allOf": [{"$ref": "envelope.schema.json"}],
6
- "type": "object",
7
- "required": ["status"],
8
- "properties": {
9
- "event": {"type": "string"},
10
- "from_version": {"type": "string"},
11
- "to_version": {"type": "string"},
12
- "status": {"type": "string", "enum": ["pending", "downloading", "flashing", "verifying", "rebooting", "completed", "failed"]},
13
- "progress_pct": {"type": "number", "minimum": 0, "maximum": 100},
14
- "error": {"type": ["string", "null"]}
15
- },
16
- "additionalProperties": true
17
- }
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.alteriom.io/mqtt/v1/firmware_status.schema.json",
4
+ "title": "Firmware Update Status v1",
5
+ "allOf": [{"$ref": "envelope.schema.json"}],
6
+ "type": "object",
7
+ "required": ["status"],
8
+ "properties": {
9
+ "event": {"type": "string"},
10
+ "from_version": {"type": "string"},
11
+ "to_version": {"type": "string"},
12
+ "status": {"type": "string", "enum": ["pending", "downloading", "flashing", "verifying", "rebooting", "completed", "failed"]},
13
+ "progress_pct": {"type": "number", "minimum": 0, "maximum": 100},
14
+ "error": {"type": ["string", "null"]}
15
+ },
16
+ "additionalProperties": true
17
+ }
@@ -1,21 +1,21 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://schemas.alteriom.io/mqtt/v1/gateway_info.schema.json",
4
- "title": "Gateway Info v1",
5
- "allOf": [{"$ref": "envelope.schema.json"}],
6
- "type": "object",
7
- "properties": {
8
- "mac_address": {"type": "string", "pattern": "^[0-9A-Fa-f:]{17}$"},
9
- "ip_address": {"type": "string", "format": "ipv4"},
10
- "capabilities": {
11
- "type": "object",
12
- "properties": {
13
- "max_nodes": {"type": "integer", "minimum": 0},
14
- "supports_mesh": {"type": "boolean"},
15
- "firmware_update": {"type": "boolean"}
16
- },
17
- "additionalProperties": true
18
- }
19
- },
20
- "additionalProperties": true
21
- }
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.alteriom.io/mqtt/v1/gateway_info.schema.json",
4
+ "title": "Gateway Info v1",
5
+ "allOf": [{"$ref": "envelope.schema.json"}],
6
+ "type": "object",
7
+ "properties": {
8
+ "mac_address": {"type": "string", "pattern": "^[0-9A-Fa-f:]{17}$"},
9
+ "ip_address": {"type": "string", "format": "ipv4"},
10
+ "capabilities": {
11
+ "type": "object",
12
+ "properties": {
13
+ "max_nodes": {"type": "integer", "minimum": 0},
14
+ "supports_mesh": {"type": "boolean"},
15
+ "firmware_update": {"type": "boolean"}
16
+ },
17
+ "additionalProperties": true
18
+ }
19
+ },
20
+ "additionalProperties": true
21
+ }
@@ -1,26 +1,26 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://schemas.alteriom.io/mqtt/v1/gateway_metrics.schema.json",
4
- "title": "Gateway Metrics v1",
5
- "allOf": [{"$ref": "envelope.schema.json"}],
6
- "type": "object",
7
- "required": ["metrics"],
8
- "properties": {
9
- "metrics": {
10
- "type": "object",
11
- "required": ["uptime_s"],
12
- "properties": {
13
- "uptime_s": {"type": "integer", "minimum": 0},
14
- "cpu_usage_pct": {"type": "number", "minimum": 0, "maximum": 100},
15
- "memory_usage_pct": {"type": "number", "minimum": 0, "maximum": 100},
16
- "temperature_c": {"type": "number"},
17
- "connected_devices": {"type": "integer", "minimum": 0},
18
- "mesh_nodes": {"type": "integer", "minimum": 0},
19
- "packet_loss_pct": {"type": "number", "minimum": 0, "maximum": 100},
20
- "data_throughput_kbps": {"type": "number", "minimum": 0}
21
- },
22
- "additionalProperties": true
23
- }
24
- },
25
- "additionalProperties": true
26
- }
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.alteriom.io/mqtt/v1/gateway_metrics.schema.json",
4
+ "title": "Gateway Metrics v1",
5
+ "allOf": [{"$ref": "envelope.schema.json"}],
6
+ "type": "object",
7
+ "required": ["metrics"],
8
+ "properties": {
9
+ "metrics": {
10
+ "type": "object",
11
+ "required": ["uptime_s"],
12
+ "properties": {
13
+ "uptime_s": {"type": "integer", "minimum": 0},
14
+ "cpu_usage_pct": {"type": "number", "minimum": 0, "maximum": 100},
15
+ "memory_usage_pct": {"type": "number", "minimum": 0, "maximum": 100},
16
+ "temperature_c": {"type": "number"},
17
+ "connected_devices": {"type": "integer", "minimum": 0},
18
+ "mesh_nodes": {"type": "integer", "minimum": 0},
19
+ "packet_loss_pct": {"type": "number", "minimum": 0, "maximum": 100},
20
+ "data_throughput_kbps": {"type": "number", "minimum": 0}
21
+ },
22
+ "additionalProperties": true
23
+ }
24
+ },
25
+ "additionalProperties": true
26
+ }
@@ -1,14 +1,14 @@
1
- {
2
- "$comment": "Convenience bundle referencing all v1 schema artifact filenames for tooling discovery.",
3
- "version": 1,
4
- "schemas": {
5
- "envelope": "envelope.schema.json",
6
- "sensor_data": "sensor_data.schema.json",
7
- "sensor_heartbeat": "sensor_heartbeat.schema.json",
8
- "sensor_status": "sensor_status.schema.json",
9
- "gateway_info": "gateway_info.schema.json",
10
- "gateway_metrics": "gateway_metrics.schema.json",
11
- "firmware_status": "firmware_status.schema.json",
12
- "control_response": "control_response.schema.json"
13
- }
14
- }
1
+ {
2
+ "$comment": "Convenience bundle referencing all v1 schema artifact filenames for tooling discovery.",
3
+ "version": 1,
4
+ "schemas": {
5
+ "envelope": "envelope.schema.json",
6
+ "sensor_data": "sensor_data.schema.json",
7
+ "sensor_heartbeat": "sensor_heartbeat.schema.json",
8
+ "sensor_status": "sensor_status.schema.json",
9
+ "gateway_info": "gateway_info.schema.json",
10
+ "gateway_metrics": "gateway_metrics.schema.json",
11
+ "firmware_status": "firmware_status.schema.json",
12
+ "control_response": "control_response.schema.json"
13
+ }
14
+ }