@molecule/api-resource-readings 1.0.3 → 1.0.5
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 +68 -69
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -3,15 +3,11 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-10-16T23:31:31.618Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-readings
|
|
10
10
|
|
|
11
|
-
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
-
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
-
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
-
|
|
15
11
|
`@molecule/api-resource-readings` — generic time-series sensor data.
|
|
16
12
|
|
|
17
13
|
Ingest readings via `POST /` or `POST /bulk`, then query raw or
|
|
@@ -21,6 +17,10 @@ Extracted from the energy-monitoring flagship — the pattern works
|
|
|
21
17
|
for any time-series surface (IoT sensors, app metrics, financial
|
|
22
18
|
tick data, etc.).
|
|
23
19
|
|
|
20
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
21
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
22
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
23
|
+
|
|
24
24
|
## Quick Start
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
@@ -55,20 +55,20 @@ npm install -D @types/express
|
|
|
55
55
|
|
|
56
56
|
### Interfaces
|
|
57
57
|
|
|
58
|
-
#### `
|
|
58
|
+
#### `ReadingRow`
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
Raw database row shape for a single sensor reading record.
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
|
-
interface
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
interface ReadingRow {
|
|
64
|
+
id: string
|
|
65
|
+
owner_id: string
|
|
66
66
|
sensor_id: string
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
metric: string
|
|
68
|
+
value: number
|
|
69
|
+
unit: string | null
|
|
70
|
+
recorded_at: string | Date
|
|
71
|
+
metadata: Record<string, unknown> | null
|
|
72
72
|
}
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -86,20 +86,20 @@ interface ReadingPoint {
|
|
|
86
86
|
}
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
#### `
|
|
89
|
+
#### `AggregatedPoint`
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
A time-bucketed aggregate of sensor readings (min/max/avg/sum/count per bucket).
|
|
92
92
|
|
|
93
93
|
```typescript
|
|
94
|
-
interface
|
|
95
|
-
|
|
96
|
-
owner_id: string
|
|
97
|
-
sensor_id: string
|
|
94
|
+
interface AggregatedPoint {
|
|
95
|
+
bucket_at: string
|
|
98
96
|
metric: string
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
sensor_id: string
|
|
98
|
+
min: number
|
|
99
|
+
max: number
|
|
100
|
+
avg: number
|
|
101
|
+
sum: number
|
|
102
|
+
count: number
|
|
103
103
|
}
|
|
104
104
|
```
|
|
105
105
|
|
|
@@ -115,20 +115,30 @@ type Granularity = 'raw' | '5min' | 'hour' | 'day'
|
|
|
115
115
|
|
|
116
116
|
### Functions
|
|
117
117
|
|
|
118
|
-
#### `
|
|
118
|
+
#### `createReadingsRouter()`
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
Creates and returns the Express router for the readings resource endpoints.
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
|
-
function
|
|
123
|
+
function createReadingsRouter(): Router
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
#### `
|
|
126
|
+
#### `ingestReading(ownerId, data)`
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
Persist a single sensor reading row for the given owner.
|
|
129
129
|
|
|
130
130
|
```typescript
|
|
131
|
-
function
|
|
131
|
+
function ingestReading(
|
|
132
|
+
ownerId: string,
|
|
133
|
+
data: {
|
|
134
|
+
sensor_id: string
|
|
135
|
+
metric: string
|
|
136
|
+
value: number
|
|
137
|
+
unit?: string | null
|
|
138
|
+
recorded_at?: string
|
|
139
|
+
metadata?: Record<string, unknown>
|
|
140
|
+
},
|
|
141
|
+
): Promise<ReadingRow>
|
|
132
142
|
```
|
|
133
143
|
|
|
134
144
|
#### `ingestBulk(ownerId, readings)`
|
|
@@ -149,22 +159,15 @@ function ingestBulk(
|
|
|
149
159
|
): Promise<number>
|
|
150
160
|
```
|
|
151
161
|
|
|
152
|
-
#### `
|
|
162
|
+
#### `listRawReadings(ownerId, opts?)`
|
|
153
163
|
|
|
154
|
-
|
|
164
|
+
Fetch raw, unaggregated reading points for an owner, optionally filtered by sensor, metric, and time range.
|
|
155
165
|
|
|
156
166
|
```typescript
|
|
157
|
-
function
|
|
167
|
+
function listRawReadings(
|
|
158
168
|
ownerId: string,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
metric: string
|
|
162
|
-
value: number
|
|
163
|
-
unit?: string | null
|
|
164
|
-
recorded_at?: string
|
|
165
|
-
metadata?: Record<string, unknown>
|
|
166
|
-
},
|
|
167
|
-
): Promise<ReadingRow>
|
|
169
|
+
opts?: { sensor_id?: string; metric?: string; from?: string; to?: string; limit?: number },
|
|
170
|
+
): Promise<ReadingPoint[]>
|
|
168
171
|
```
|
|
169
172
|
|
|
170
173
|
#### `listAggregatedReadings(ownerId, opts)`
|
|
@@ -186,15 +189,12 @@ function listAggregatedReadings(
|
|
|
186
189
|
): Promise<AggregatedPoint[]>
|
|
187
190
|
```
|
|
188
191
|
|
|
189
|
-
#### `
|
|
192
|
+
#### `countReadings(ownerId)`
|
|
190
193
|
|
|
191
|
-
|
|
194
|
+
Return the total number of readings stored for the given owner.
|
|
192
195
|
|
|
193
196
|
```typescript
|
|
194
|
-
function
|
|
195
|
-
ownerId: string,
|
|
196
|
-
opts?: { sensor_id?: string; metric?: string; from?: string; to?: string; limit?: number },
|
|
197
|
-
): Promise<ReadingPoint[]>
|
|
197
|
+
function countReadings(ownerId: string): Promise<number>
|
|
198
198
|
```
|
|
199
199
|
|
|
200
200
|
### Constants
|
|
@@ -207,6 +207,24 @@ Supported time-bucket granularities for reading aggregation queries.
|
|
|
207
207
|
const GRANULARITIES: readonly ['raw', '5min', 'hour', 'day']
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
+
#### `readingCreateSchema`
|
|
211
|
+
|
|
212
|
+
Zod schema for validating a single reading creation payload.
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
const readingCreateSchema: z.ZodObject<
|
|
216
|
+
{
|
|
217
|
+
sensor_id: z.ZodString
|
|
218
|
+
metric: z.ZodString
|
|
219
|
+
value: z.ZodNumber
|
|
220
|
+
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>
|
|
221
|
+
recorded_at: z.ZodOptional<z.ZodString>
|
|
222
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>
|
|
223
|
+
},
|
|
224
|
+
z.core.$strip
|
|
225
|
+
>
|
|
226
|
+
```
|
|
227
|
+
|
|
210
228
|
#### `readingBulkSchema`
|
|
211
229
|
|
|
212
230
|
Zod schema for validating a bulk readings creation payload (1–10 000 entries).
|
|
@@ -232,24 +250,6 @@ const readingBulkSchema: z.ZodObject<
|
|
|
232
250
|
>
|
|
233
251
|
```
|
|
234
252
|
|
|
235
|
-
#### `readingCreateSchema`
|
|
236
|
-
|
|
237
|
-
Zod schema for validating a single reading creation payload.
|
|
238
|
-
|
|
239
|
-
```typescript
|
|
240
|
-
const readingCreateSchema: z.ZodObject<
|
|
241
|
-
{
|
|
242
|
-
sensor_id: z.ZodString
|
|
243
|
-
metric: z.ZodString
|
|
244
|
-
value: z.ZodNumber
|
|
245
|
-
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>
|
|
246
|
-
recorded_at: z.ZodOptional<z.ZodString>
|
|
247
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>
|
|
248
|
-
},
|
|
249
|
-
z.core.$strip
|
|
250
|
-
>
|
|
251
|
-
```
|
|
252
|
-
|
|
253
253
|
#### `readingQuerySchema`
|
|
254
254
|
|
|
255
255
|
Zod schema for validating reading list/query filter parameters.
|
|
@@ -306,8 +306,7 @@ bucket in application code, or supply your own dialect's aggregation.
|
|
|
306
306
|
request).
|
|
307
307
|
|
|
308
308
|
Tables: `src/__setup__/readings.sql` creates `readings` (owner-scoped via
|
|
309
|
-
`owner_id`). An mlcl-scaffolded API replays `__setup__/*.sql`
|
|
310
|
-
on migrate; anywhere else run it once — nothing at runtime creates them.
|
|
309
|
+
`owner_id`). An mlcl-scaffolded API replays `__setup__/*.sql` on migrate (a `CREATE TABLE IF NOT EXISTS`, so a table the app's own migrations already create keeps only its own columns: ALTER in the ones it lacks); anywhere else run it once — nothing at runtime creates them.
|
|
311
310
|
|
|
312
311
|
## E2E Tests
|
|
313
312
|
|
package/dist/index.d.ts
CHANGED
|
@@ -44,8 +44,7 @@
|
|
|
44
44
|
* request).
|
|
45
45
|
*
|
|
46
46
|
* Tables: `src/__setup__/readings.sql` creates `readings` (owner-scoped via
|
|
47
|
-
* `owner_id`). An mlcl-scaffolded API replays `__setup__/*.sql`
|
|
48
|
-
* on migrate; anywhere else run it once — nothing at runtime creates them.
|
|
47
|
+
* `owner_id`). An mlcl-scaffolded API replays `__setup__/*.sql` on migrate (a `CREATE TABLE IF NOT EXISTS`, so a table the app's own migrations already create keeps only its own columns: ALTER in the ones it lacks); anywhere else run it once — nothing at runtime creates them.
|
|
49
48
|
*
|
|
50
49
|
* @e2e
|
|
51
50
|
* Integration checklist — drive the real UI (live preview, no mocks), adapt
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -44,8 +44,7 @@
|
|
|
44
44
|
* request).
|
|
45
45
|
*
|
|
46
46
|
* Tables: `src/__setup__/readings.sql` creates `readings` (owner-scoped via
|
|
47
|
-
* `owner_id`). An mlcl-scaffolded API replays `__setup__/*.sql`
|
|
48
|
-
* on migrate; anywhere else run it once — nothing at runtime creates them.
|
|
47
|
+
* `owner_id`). An mlcl-scaffolded API replays `__setup__/*.sql` on migrate (a `CREATE TABLE IF NOT EXISTS`, so a table the app's own migrations already create keeps only its own columns: ALTER in the ones it lacks); anywhere else run it once — nothing at runtime creates them.
|
|
49
48
|
*
|
|
50
49
|
* @e2e
|
|
51
50
|
* Integration checklist — drive the real UI (live preview, no mocks), adapt
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-readings",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Generic time-series sensor readings with on-the-fly aggregation (raw/5min/hour/day rollups)",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/api-resource-readings",
|
|
6
6
|
"type": "module",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/express": "5.0.6",
|
|
41
|
-
"@types/node": "26.
|
|
42
|
-
"express": "5.
|
|
41
|
+
"@types/node": "26.6.5",
|
|
42
|
+
"express": "5.3.0",
|
|
43
43
|
"typescript": "6.0.3",
|
|
44
|
-
"vitest": "4.1.
|
|
45
|
-
"zod": "4.
|
|
44
|
+
"vitest": "4.1.12",
|
|
45
|
+
"zod": "4.6.7"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@molecule/api-bonds-default-express": "^1.0.1",
|