@happyvertical/smrt-reports 0.40.14 → 0.40.15

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 ADDED
@@ -0,0 +1,110 @@
1
+ # @happyvertical/smrt-reports
2
+
3
+ Materialized aggregate reports for s-m-r-t. Define a report as a decorated class,
4
+ compile it to a portable aggregate query, and refresh its normal s-m-r-t table
5
+ manually, on a schedule, after source changes, or when a TTL expires.
6
+
7
+ Runtime refresh verifies schema but does not create report or system tables.
8
+ Include report models in normal manifest-driven migrations before refreshing.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pnpm add @happyvertical/smrt-reports
14
+ ```
15
+
16
+ ## Define a report
17
+
18
+ ```ts
19
+ import { SmrtObject, smrt } from '@happyvertical/smrt-core';
20
+ import {
21
+ groupBy,
22
+ month,
23
+ report,
24
+ SmrtReport,
25
+ SmrtReportCollection,
26
+ sum,
27
+ } from '@happyvertical/smrt-reports';
28
+
29
+ @smrt()
30
+ class Invoice extends SmrtObject {
31
+ customerId = '';
32
+ issuedAt = new Date();
33
+ totalAmount = 0.0;
34
+ status = '';
35
+ }
36
+
37
+ @report({
38
+ source: Invoice,
39
+ where: { status: 'paid' },
40
+ refresh: { manual: true },
41
+ })
42
+ @smrt()
43
+ class MonthlyRevenue extends SmrtReport {
44
+ @groupBy('customerId') customerId = '';
45
+ @month('issuedAt') issuedMonth = new Date();
46
+ @sum('totalAmount') revenue = 0.0;
47
+ }
48
+
49
+ class MonthlyRevenueCollection extends SmrtReportCollection<MonthlyRevenue> {
50
+ static readonly _itemClass = MonthlyRevenue;
51
+ }
52
+
53
+ const reports = await MonthlyRevenueCollection.create({ db: 'app.db' });
54
+ await reports.refresh();
55
+ const rows = await reports.list({ orderBy: 'issued_month DESC' });
56
+ ```
57
+
58
+ ## Decorators
59
+
60
+ | Decorator | Meaning |
61
+ | --- | --- |
62
+ | `@report({ source, ... })` | Declare the source and refresh policy |
63
+ | `@groupBy(column?)` | Group by a source column |
64
+ | `@minute()` through `@year()` | Bucket a source timestamp |
65
+ | `@sum()`, `@avg()`, `@min()`, `@max()` | Aggregate a source column |
66
+ | `@count()` | Count rows or distinct values |
67
+ | `@aggregate()` | Define a custom supported aggregate shape |
68
+
69
+ Every non-system report field must be a grouping key, time bucket, or aggregate.
70
+ Metadata is stored under the field's `_meta.__report` contract so scanner and
71
+ runtime compilation stay aligned.
72
+
73
+ ## Refresh modes
74
+
75
+ - `rebuild` replaces the materialized result.
76
+ - `incremental` recomputes groups affected after a source watermark and removes
77
+ groups that become empty.
78
+ - TTL-backed collections refresh before reads when the report is stale.
79
+ - `ReportScheduleRunner` and `registerReportRefreshInterceptor()` enqueue
80
+ durable refresh jobs through [`smrt-jobs`](../jobs/README.md).
81
+
82
+ Incremental sources need watermark and soft-delete columns, normally
83
+ `updatedAt` and `deletedAt`. Tenant-scoped aggregate SQL explicitly filters
84
+ `tenant_id`; normal collection interceptors cannot secure a raw aggregate.
85
+
86
+ ## Public entry points
87
+
88
+ The package exposes focused subpaths for consumers that want only the compiler,
89
+ decorators, refresh engine, scheduler, state models, or aggregate compatibility
90
+ helpers:
91
+
92
+ ```text
93
+ @happyvertical/smrt-reports
94
+ @happyvertical/smrt-reports/compiler
95
+ @happyvertical/smrt-reports/decorators
96
+ @happyvertical/smrt-reports/refresh
97
+ @happyvertical/smrt-reports/scheduler
98
+ @happyvertical/smrt-reports/state
99
+ @happyvertical/smrt-reports/aggregate
100
+ ```
101
+
102
+ ## Development
103
+
104
+ ```bash
105
+ pnpm --filter @happyvertical/smrt-reports test
106
+ pnpm --filter @happyvertical/smrt-reports typecheck
107
+ pnpm --filter @happyvertical/smrt-reports build
108
+ ```
109
+
110
+ See [`AGENTS.md`](./AGENTS.md) for refresh, schema, and tenancy invariants.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": "1.0.0",
3
- "timestamp": 1784377940326,
3
+ "timestamp": 1784492242116,
4
4
  "packageName": "@happyvertical/smrt-reports",
5
- "packageVersion": "0.40.14",
5
+ "packageVersion": "0.40.15",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-reports:SmrtReport": {
8
8
  "name": "smrtreport",
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-07-18T12:32:29.039Z",
3
+ "generatedAt": "2026-07-19T20:17:31.040Z",
4
4
  "packageName": "@happyvertical/smrt-reports",
5
- "packageVersion": "0.40.14",
5
+ "packageVersion": "0.40.15",
6
6
  "sourceManifestPath": "dist/manifest.json",
7
7
  "agentDocPath": "AGENTS.md",
8
8
  "sourceHashes": {
9
- "manifest": "c81c4fd4fff63c5b7f8cdb49c493b87605d1391a947b74a6838e2bebb8b3462e",
10
- "packageJson": "f8aabe8d4360601901d4fe5add2ff8539a85c39066d6245ba68ac675d4cdb80c",
9
+ "manifest": "e11e5d6b5cee5a404d31f2cb2385a04ce86b9485bdc38f899bed958efffcb204",
10
+ "packageJson": "8d5de5bb1d6294c678f520f07a47a73cdca2b59fe3c5b75be44098e6da922ab6",
11
11
  "agents": "bf851be60baab2fd98149165885f70c4f4979123ff72bf8f4b43edfae4478e87"
12
12
  },
13
13
  "exports": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-reports",
3
- "version": "0.40.14",
3
+ "version": "0.40.15",
4
4
  "description": "Materialized aggregate report models for SMRT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,16 +44,16 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@happyvertical/sql": "^0.80.2",
47
- "@happyvertical/smrt-jobs": "0.40.14",
48
- "@happyvertical/smrt-core": "0.40.14",
49
- "@happyvertical/smrt-tenancy": "0.40.14"
47
+ "@happyvertical/smrt-core": "0.40.15",
48
+ "@happyvertical/smrt-jobs": "0.40.15",
49
+ "@happyvertical/smrt-tenancy": "0.40.15"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/node": "24.13.2",
53
53
  "typescript": "5.9.3",
54
54
  "vite": "8.1.4",
55
55
  "vitest": "4.1.10",
56
- "@happyvertical/smrt-vitest": "0.40.14"
56
+ "@happyvertical/smrt-vitest": "0.40.15"
57
57
  },
58
58
  "keywords": [
59
59
  "ai",