@rawdash/server 0.1.0
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/LICENSE +202 -0
- package/README.md +112 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +828 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# @rawdash/server
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@rawdash/server)
|
|
4
|
+
[](https://github.com/rawdash/rawdash/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Standalone Hono HTTP server hosting the rawdash data API.
|
|
7
|
+
|
|
8
|
+
## What it is
|
|
9
|
+
|
|
10
|
+
`@rawdash/server` takes a rawdash config, runs the sync engine in-process, and exposes a REST API for widget data. Deploy it as a standalone service alongside your frontend, or use `createServer` to get the raw Hono app and deploy it to any JS runtime (Cloudflare Workers, Bun, Deno, etc.).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @rawdash/server
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick example
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { GitHubActionsConnector } from '@rawdash/connector-github';
|
|
22
|
+
import { defineConfig, defineDashboard, secret } from '@rawdash/core';
|
|
23
|
+
import { serve } from '@rawdash/server';
|
|
24
|
+
|
|
25
|
+
const github = new GitHubActionsConnector({
|
|
26
|
+
owner: 'my-org',
|
|
27
|
+
repo: 'my-repo',
|
|
28
|
+
token: secret('GITHUB_TOKEN'),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
serve(
|
|
32
|
+
defineConfig({
|
|
33
|
+
connectors: [{ connector: github }],
|
|
34
|
+
dashboards: {
|
|
35
|
+
engineering: defineDashboard({ widgets: {} }),
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
{ port: 8080 },
|
|
39
|
+
);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
### `serve(config, options?)`
|
|
45
|
+
|
|
46
|
+
Starts the HTTP server on Node.js (via `@hono/node-server`). Options:
|
|
47
|
+
|
|
48
|
+
| Option | Type | Default | Description |
|
|
49
|
+
| --------- | --------------- | --------- | ------------------------------------- |
|
|
50
|
+
| `port` | `number` | `8080` | Port to listen on |
|
|
51
|
+
| `storage` | `ServerStorage` | in-memory | Storage backend (e.g. `TursoStorage`) |
|
|
52
|
+
|
|
53
|
+
### `createServer(config, options?)`
|
|
54
|
+
|
|
55
|
+
Returns the Hono app without binding to a port. Use when you need the app object directly.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { createServer } from '@rawdash/server';
|
|
59
|
+
|
|
60
|
+
const app = createServer(config);
|
|
61
|
+
export default app; // deploy to Cloudflare Workers, Bun, Deno, etc.
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## HTTP endpoints
|
|
65
|
+
|
|
66
|
+
### `GET /dashboards/:dashboardId/widgets`
|
|
67
|
+
|
|
68
|
+
Returns all cached widget entries for a dashboard.
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
[
|
|
72
|
+
{
|
|
73
|
+
"id": "github:pull_requests",
|
|
74
|
+
"connectorId": "github",
|
|
75
|
+
"widgetId": "pull_requests",
|
|
76
|
+
"data": [],
|
|
77
|
+
"cachedAt": "2026-04-11T10:00:00.000Z"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### `GET /dashboards/:dashboardId/widgets/:widgetId`
|
|
83
|
+
|
|
84
|
+
Returns a single widget by ID. Returns `404` if not found.
|
|
85
|
+
|
|
86
|
+
### `POST /sync`
|
|
87
|
+
|
|
88
|
+
Triggers an immediate sync across all configured connectors. Returns `{ "triggered": false }` if a sync is already in progress.
|
|
89
|
+
|
|
90
|
+
### `GET /health`
|
|
91
|
+
|
|
92
|
+
Returns the current sync state.
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"status": "idle",
|
|
97
|
+
"lastSyncAt": "2026-04-11T10:00:00.000Z",
|
|
98
|
+
"lastError": null
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`status` is one of `"idle"`, `"syncing"`, or `"error"`.
|
|
103
|
+
|
|
104
|
+
## Links
|
|
105
|
+
|
|
106
|
+
- [rawdash docs](https://rawdash.dev)
|
|
107
|
+
- [GitHub](https://github.com/rawdash/rawdash)
|
|
108
|
+
- [Issues](https://github.com/rawdash/rawdash/issues)
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { StorageHandle, SyncState, DashboardConfig, WidgetEntry, ResolvedMetric } from '@rawdash/core';
|
|
2
|
+
export { DashboardConfig, SyncState, WidgetEntry } from '@rawdash/core';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
|
|
5
|
+
interface ServerStorage {
|
|
6
|
+
getStorageHandle(connectorId: string): StorageHandle;
|
|
7
|
+
getSyncState(): Promise<SyncState>;
|
|
8
|
+
setSyncing(): Promise<boolean>;
|
|
9
|
+
setSyncSuccess(): Promise<void>;
|
|
10
|
+
setSyncError(error: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
interface ServeOptions {
|
|
13
|
+
port?: number;
|
|
14
|
+
storage?: ServerStorage;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface RawdashRouter {
|
|
18
|
+
mount(app: Hono): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare function createServer(routers: RawdashRouter[]): Hono;
|
|
22
|
+
|
|
23
|
+
declare function createEngineRouters(config: DashboardConfig, storage?: ServerStorage): RawdashRouter[];
|
|
24
|
+
|
|
25
|
+
interface EngineOptions {
|
|
26
|
+
storage?: ServerStorage;
|
|
27
|
+
}
|
|
28
|
+
interface Engine {
|
|
29
|
+
getWidget(dashboardId: string, widgetId: string): Promise<WidgetEntry | undefined>;
|
|
30
|
+
getWidgets(dashboardId: string): Promise<WidgetEntry[]>;
|
|
31
|
+
getHealth(): Promise<{
|
|
32
|
+
status: 'idle' | 'syncing' | 'error';
|
|
33
|
+
lastSyncAt: string | null;
|
|
34
|
+
lastError: string | null;
|
|
35
|
+
}>;
|
|
36
|
+
triggerSync(): Promise<{
|
|
37
|
+
triggered: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
declare function createEngine(config: DashboardConfig, options?: EngineOptions): Engine;
|
|
41
|
+
|
|
42
|
+
declare function computeMetric(storage: StorageHandle, metric: ResolvedMetric): Promise<unknown>;
|
|
43
|
+
|
|
44
|
+
declare class InMemoryStorage implements ServerStorage {
|
|
45
|
+
private eventStore;
|
|
46
|
+
private entityStore;
|
|
47
|
+
private metricStore;
|
|
48
|
+
private edgeStore;
|
|
49
|
+
private distributionStore;
|
|
50
|
+
private syncState;
|
|
51
|
+
getStorageHandle(connectorId: string): StorageHandle;
|
|
52
|
+
getSyncState(): Promise<SyncState>;
|
|
53
|
+
setSyncing(): Promise<boolean>;
|
|
54
|
+
setSyncSuccess(): Promise<void>;
|
|
55
|
+
setSyncError(error: string): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare function serve(config: DashboardConfig, options?: ServeOptions): void;
|
|
59
|
+
|
|
60
|
+
export { type Engine, type EngineOptions, InMemoryStorage, type RawdashRouter, type ServeOptions, type ServerStorage, computeMetric, createEngine, createEngineRouters, createServer, serve };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { serve as honoServe } from "@hono/node-server";
|
|
3
|
+
|
|
4
|
+
// src/routers/health.ts
|
|
5
|
+
var HealthRouter = class {
|
|
6
|
+
constructor(storage) {
|
|
7
|
+
this.storage = storage;
|
|
8
|
+
}
|
|
9
|
+
storage;
|
|
10
|
+
mount(app) {
|
|
11
|
+
app.get("/health", async (c) => {
|
|
12
|
+
return c.json(await this.storage.getSyncState());
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/routers/retention.ts
|
|
18
|
+
import { selectForDeletion } from "@rawdash/core";
|
|
19
|
+
var DEFAULT_INTERVAL_MS = 60 * 60 * 1e3;
|
|
20
|
+
function hasPruningPolicy(config) {
|
|
21
|
+
return config.maxAge !== void 0 || config.maxSize !== void 0;
|
|
22
|
+
}
|
|
23
|
+
var RetentionRouter = class {
|
|
24
|
+
constructor(config, storage) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.storage = storage;
|
|
27
|
+
}
|
|
28
|
+
config;
|
|
29
|
+
storage;
|
|
30
|
+
interval = null;
|
|
31
|
+
inFlight = null;
|
|
32
|
+
async runRetention() {
|
|
33
|
+
if (this.inFlight) {
|
|
34
|
+
return this.inFlight;
|
|
35
|
+
}
|
|
36
|
+
this.inFlight = this.runRetentionOnce().finally(() => {
|
|
37
|
+
this.inFlight = null;
|
|
38
|
+
});
|
|
39
|
+
return this.inFlight;
|
|
40
|
+
}
|
|
41
|
+
async runRetentionOnce() {
|
|
42
|
+
const retentionConfig = this.config.retention;
|
|
43
|
+
if (!retentionConfig || !hasPruningPolicy(retentionConfig)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const nowMs = Date.now();
|
|
47
|
+
const results = await Promise.allSettled(
|
|
48
|
+
this.config.connectors.map(async ({ connector }) => {
|
|
49
|
+
const handle = this.storage.getStorageHandle(connector.id);
|
|
50
|
+
const [events, metrics, distributions] = await Promise.all([
|
|
51
|
+
handle.queryEvents({}),
|
|
52
|
+
handle.queryMetrics({}),
|
|
53
|
+
handle.queryDistributions({})
|
|
54
|
+
]);
|
|
55
|
+
await applyRetentionToShape(
|
|
56
|
+
events,
|
|
57
|
+
(e) => e.start_ts,
|
|
58
|
+
retentionConfig,
|
|
59
|
+
nowMs,
|
|
60
|
+
(survivors, names) => handle.events(survivors, { names })
|
|
61
|
+
);
|
|
62
|
+
await applyRetentionToShape(
|
|
63
|
+
metrics,
|
|
64
|
+
(m) => m.ts,
|
|
65
|
+
retentionConfig,
|
|
66
|
+
nowMs,
|
|
67
|
+
(survivors, names) => handle.metrics(survivors, { names })
|
|
68
|
+
);
|
|
69
|
+
await applyRetentionToShape(
|
|
70
|
+
distributions,
|
|
71
|
+
(d) => d.ts,
|
|
72
|
+
retentionConfig,
|
|
73
|
+
nowMs,
|
|
74
|
+
(survivors, names) => handle.distributions(survivors, { names })
|
|
75
|
+
);
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
const failures = results.filter(
|
|
79
|
+
(r) => r.status === "rejected"
|
|
80
|
+
);
|
|
81
|
+
if (failures.length > 0) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Retention failed for ${failures.length} connector(s): ${failures.map((f) => String(f.reason)).join("; ")}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
mount(app) {
|
|
88
|
+
app.post("/retain", async (c) => {
|
|
89
|
+
try {
|
|
90
|
+
await this.runRetention();
|
|
91
|
+
return c.json({ triggered: true });
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.error("retention run failed", err);
|
|
94
|
+
return c.json({ triggered: false }, 500);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const retentionConfig = this.config.retention;
|
|
98
|
+
if (retentionConfig && hasPruningPolicy(retentionConfig)) {
|
|
99
|
+
const intervalMs = retentionConfig.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
100
|
+
this.interval = setInterval(() => {
|
|
101
|
+
void this.runRetention().catch((err) => {
|
|
102
|
+
console.error("retention run failed", err);
|
|
103
|
+
});
|
|
104
|
+
}, intervalMs);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
stop() {
|
|
108
|
+
if (this.interval !== null) {
|
|
109
|
+
clearInterval(this.interval);
|
|
110
|
+
this.interval = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
async function applyRetentionToShape(rows, getTs, config, nowMs, writeSurvivors) {
|
|
115
|
+
if (rows.length === 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const sorted = [...rows].sort((a, b) => getTs(b) - getTs(a));
|
|
119
|
+
const toDeleteSet = new Set(selectForDeletion(sorted, getTs, config, nowMs));
|
|
120
|
+
if (toDeleteSet.size === 0) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const survivors = sorted.filter((r) => !toDeleteSet.has(r));
|
|
124
|
+
const allNames = [...new Set(rows.map((r) => r.name))];
|
|
125
|
+
await writeSurvivors(survivors, allNames);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/routers/sync.ts
|
|
129
|
+
var FULL_SYNC_TIMEOUT_MS = 3e5;
|
|
130
|
+
var SyncRouter = class {
|
|
131
|
+
constructor(config, storage) {
|
|
132
|
+
this.config = config;
|
|
133
|
+
this.storage = storage;
|
|
134
|
+
}
|
|
135
|
+
config;
|
|
136
|
+
storage;
|
|
137
|
+
async runSync() {
|
|
138
|
+
const acquired = await this.storage.setSyncing();
|
|
139
|
+
if (!acquired) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const errors = [];
|
|
143
|
+
await Promise.allSettled(
|
|
144
|
+
this.config.connectors.map(async ({ connector }) => {
|
|
145
|
+
const handle = this.storage.getStorageHandle(connector.id);
|
|
146
|
+
const controller = new AbortController();
|
|
147
|
+
const timer = setTimeout(
|
|
148
|
+
() => controller.abort(),
|
|
149
|
+
FULL_SYNC_TIMEOUT_MS
|
|
150
|
+
);
|
|
151
|
+
try {
|
|
152
|
+
await connector.sync({ mode: "full" }, handle, controller.signal);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
155
|
+
errors.push(
|
|
156
|
+
`${connector.id} timed out after ${FULL_SYNC_TIMEOUT_MS}ms`
|
|
157
|
+
);
|
|
158
|
+
} else {
|
|
159
|
+
errors.push(err instanceof Error ? err.message : String(err));
|
|
160
|
+
}
|
|
161
|
+
} finally {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
if (errors.length > 0) {
|
|
167
|
+
await this.storage.setSyncError(errors.join("; "));
|
|
168
|
+
} else {
|
|
169
|
+
await this.storage.setSyncSuccess();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
mount(app) {
|
|
173
|
+
app.post("/sync", async (c) => {
|
|
174
|
+
const state = await this.storage.getSyncState();
|
|
175
|
+
if (state.status === "syncing") {
|
|
176
|
+
return c.json({ triggered: false });
|
|
177
|
+
}
|
|
178
|
+
void this.runSync();
|
|
179
|
+
return c.json({ triggered: true });
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/compute.ts
|
|
185
|
+
function matchesCondition(record, cond) {
|
|
186
|
+
const val = record[cond.field];
|
|
187
|
+
switch (cond.op) {
|
|
188
|
+
case "eq":
|
|
189
|
+
return val === cond.value;
|
|
190
|
+
case "neq":
|
|
191
|
+
return val !== cond.value;
|
|
192
|
+
case "gt":
|
|
193
|
+
return val > cond.value;
|
|
194
|
+
case "gte":
|
|
195
|
+
return val >= cond.value;
|
|
196
|
+
case "lt":
|
|
197
|
+
return val < cond.value;
|
|
198
|
+
case "lte":
|
|
199
|
+
return val <= cond.value;
|
|
200
|
+
case "contains":
|
|
201
|
+
return String(val).includes(String(cond.value));
|
|
202
|
+
default:
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function applyFilter(record, filter) {
|
|
207
|
+
if (!filter) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
for (const clause of filter) {
|
|
211
|
+
if ("or" in clause) {
|
|
212
|
+
if (!clause.or.some((cond) => matchesCondition(record, cond))) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
if (!matchesCondition(record, clause)) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
var WINDOW_MS = {
|
|
224
|
+
h: 36e5,
|
|
225
|
+
d: 864e5,
|
|
226
|
+
w: 6048e5,
|
|
227
|
+
m: 2592e6
|
|
228
|
+
};
|
|
229
|
+
function parseWindowMs(window) {
|
|
230
|
+
const match = /^(\d+)(h|d|w|m)$/.exec(window);
|
|
231
|
+
if (!match) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
const unitMs = WINDOW_MS[match[2]];
|
|
235
|
+
if (unitMs === void 0) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
return parseInt(match[1]) * unitMs;
|
|
239
|
+
}
|
|
240
|
+
function truncateToGranularity(ts, granularity) {
|
|
241
|
+
const d = new Date(ts);
|
|
242
|
+
switch (granularity) {
|
|
243
|
+
case "hour":
|
|
244
|
+
d.setUTCMinutes(0, 0, 0);
|
|
245
|
+
return d.toISOString();
|
|
246
|
+
case "day":
|
|
247
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
248
|
+
return d.toISOString().slice(0, 10);
|
|
249
|
+
case "week": {
|
|
250
|
+
d.setUTCDate(d.getUTCDate() - d.getUTCDay());
|
|
251
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
252
|
+
return d.toISOString().slice(0, 10);
|
|
253
|
+
}
|
|
254
|
+
case "month":
|
|
255
|
+
d.setUTCDate(1);
|
|
256
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
257
|
+
return d.toISOString().slice(0, 7);
|
|
258
|
+
default:
|
|
259
|
+
return d.toISOString().slice(0, 10);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function computeAgg(records, field, fn) {
|
|
263
|
+
if (fn === "count") {
|
|
264
|
+
return records.length;
|
|
265
|
+
}
|
|
266
|
+
if (fn === "latest") {
|
|
267
|
+
return records.at(-1)?.[field] ?? null;
|
|
268
|
+
}
|
|
269
|
+
if (fn === "first") {
|
|
270
|
+
return records[0]?.[field] ?? null;
|
|
271
|
+
}
|
|
272
|
+
const values = records.map((r) => r[field]).filter((v) => v !== void 0 && v !== null);
|
|
273
|
+
const nonNumeric = values.find((v) => typeof v !== "number");
|
|
274
|
+
if (nonNumeric !== void 0) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`computeAgg: fn "${fn}" requires numeric values for field "${field}", got ${typeof nonNumeric} (${String(nonNumeric)})`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
const numbers = values;
|
|
280
|
+
if (fn === "sum") {
|
|
281
|
+
return numbers.reduce((a, b) => a + b, 0);
|
|
282
|
+
}
|
|
283
|
+
if (fn === "avg") {
|
|
284
|
+
return numbers.length > 0 ? numbers.reduce((a, b) => a + b, 0) / numbers.length : null;
|
|
285
|
+
}
|
|
286
|
+
if (fn === "min") {
|
|
287
|
+
return numbers.length > 0 ? Math.min(...numbers) : null;
|
|
288
|
+
}
|
|
289
|
+
if (fn === "max") {
|
|
290
|
+
return numbers.length > 0 ? Math.max(...numbers) : null;
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
function sortByTs(records, tsField) {
|
|
295
|
+
return [...records].sort((a, b) => {
|
|
296
|
+
return a[tsField] - b[tsField];
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
function computeGroupBy(records, metric, tsField) {
|
|
300
|
+
const { field, granularity } = metric.groupBy;
|
|
301
|
+
const groups = /* @__PURE__ */ new Map();
|
|
302
|
+
for (const record of records) {
|
|
303
|
+
const ts = record[field];
|
|
304
|
+
if (ts === void 0 || typeof ts !== "number") {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const key = truncateToGranularity(ts, granularity);
|
|
308
|
+
if (!groups.has(key)) {
|
|
309
|
+
groups.set(key, []);
|
|
310
|
+
}
|
|
311
|
+
groups.get(key).push(record);
|
|
312
|
+
}
|
|
313
|
+
return [...groups.entries()].map(([key, groupRecords]) => ({
|
|
314
|
+
date: key,
|
|
315
|
+
value: computeAgg(
|
|
316
|
+
sortByTs(groupRecords, tsField),
|
|
317
|
+
metric.field,
|
|
318
|
+
metric.fn
|
|
319
|
+
)
|
|
320
|
+
})).sort((a, b) => a.date < b.date ? -1 : 1);
|
|
321
|
+
}
|
|
322
|
+
function getTimestampField(shape) {
|
|
323
|
+
switch (shape) {
|
|
324
|
+
case "event":
|
|
325
|
+
return "start_ts";
|
|
326
|
+
case "metric":
|
|
327
|
+
case "distribution":
|
|
328
|
+
return "ts";
|
|
329
|
+
case "entity":
|
|
330
|
+
case "edge":
|
|
331
|
+
return "updated_at";
|
|
332
|
+
default:
|
|
333
|
+
return "start_ts";
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
async function computeMetric(storage, metric) {
|
|
337
|
+
const tsField = getTimestampField(metric.shape);
|
|
338
|
+
const windowMs = metric.window ? parseWindowMs(metric.window) : null;
|
|
339
|
+
const windowStart = windowMs !== null ? Date.now() - windowMs : void 0;
|
|
340
|
+
let records;
|
|
341
|
+
switch (metric.shape) {
|
|
342
|
+
case "event": {
|
|
343
|
+
const events = await storage.queryEvents({
|
|
344
|
+
name: metric.name,
|
|
345
|
+
start: windowStart
|
|
346
|
+
});
|
|
347
|
+
records = events.map((e) => ({
|
|
348
|
+
...e.attributes,
|
|
349
|
+
name: e.name,
|
|
350
|
+
start_ts: e.start_ts,
|
|
351
|
+
end_ts: e.end_ts
|
|
352
|
+
}));
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case "entity": {
|
|
356
|
+
const type = metric.entityType ?? metric.name ?? "";
|
|
357
|
+
const entities = await storage.queryEntities({ type });
|
|
358
|
+
records = entities.map((e) => ({
|
|
359
|
+
...e.attributes,
|
|
360
|
+
type: e.type,
|
|
361
|
+
id: e.id,
|
|
362
|
+
updated_at: e.updated_at
|
|
363
|
+
}));
|
|
364
|
+
if (windowStart !== void 0) {
|
|
365
|
+
records = records.filter((r) => r[tsField] >= windowStart);
|
|
366
|
+
}
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
case "metric": {
|
|
370
|
+
const metrics = await storage.queryMetrics({
|
|
371
|
+
name: metric.name,
|
|
372
|
+
start: windowStart
|
|
373
|
+
});
|
|
374
|
+
records = metrics.map((m) => ({
|
|
375
|
+
...m.attributes,
|
|
376
|
+
name: m.name,
|
|
377
|
+
ts: m.ts,
|
|
378
|
+
value: m.value
|
|
379
|
+
}));
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
case "edge": {
|
|
383
|
+
const edges = await storage.traverse({ kind: metric.name });
|
|
384
|
+
records = edges.map((e) => ({
|
|
385
|
+
...e.attributes,
|
|
386
|
+
from_type: e.from_type,
|
|
387
|
+
from_id: e.from_id,
|
|
388
|
+
kind: e.kind,
|
|
389
|
+
to_type: e.to_type,
|
|
390
|
+
to_id: e.to_id,
|
|
391
|
+
updated_at: e.updated_at
|
|
392
|
+
}));
|
|
393
|
+
if (windowStart !== void 0) {
|
|
394
|
+
records = records.filter((r) => r[tsField] >= windowStart);
|
|
395
|
+
}
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
case "distribution": {
|
|
399
|
+
const distributions = await storage.queryDistributions({
|
|
400
|
+
name: metric.name,
|
|
401
|
+
start: windowStart
|
|
402
|
+
});
|
|
403
|
+
records = distributions.map((d) => ({
|
|
404
|
+
...d.attributes,
|
|
405
|
+
name: d.name,
|
|
406
|
+
ts: d.ts,
|
|
407
|
+
kind: d.kind,
|
|
408
|
+
data: d.data
|
|
409
|
+
}));
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
default:
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
const filtered = records.filter((r) => applyFilter(r, metric.filter));
|
|
416
|
+
const sorted = sortByTs(filtered, tsField);
|
|
417
|
+
if (metric.groupBy) {
|
|
418
|
+
return computeGroupBy(sorted, metric, tsField);
|
|
419
|
+
}
|
|
420
|
+
return computeAgg(sorted, metric.field, metric.fn);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/routers/widgets.ts
|
|
424
|
+
var WidgetsRouter = class {
|
|
425
|
+
constructor(dashboardId, dashboard, connectors, storage) {
|
|
426
|
+
this.dashboardId = dashboardId;
|
|
427
|
+
this.dashboard = dashboard;
|
|
428
|
+
this.connectors = connectors;
|
|
429
|
+
this.storage = storage;
|
|
430
|
+
}
|
|
431
|
+
dashboardId;
|
|
432
|
+
dashboard;
|
|
433
|
+
connectors;
|
|
434
|
+
storage;
|
|
435
|
+
async resolveWidget(id, widget) {
|
|
436
|
+
if (widget.kind === "status") {
|
|
437
|
+
return {
|
|
438
|
+
id,
|
|
439
|
+
widgetId: id,
|
|
440
|
+
connectorId: widget.source,
|
|
441
|
+
data: null,
|
|
442
|
+
cachedAt: null
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
const { connectorId } = widget.metric;
|
|
446
|
+
const connectorEntry = this.connectors.find(
|
|
447
|
+
(e) => e.connector.id === connectorId
|
|
448
|
+
);
|
|
449
|
+
if (!connectorEntry) {
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
const handle = this.storage.getStorageHandle(connectorId);
|
|
453
|
+
const data = await computeMetric(handle, widget.metric);
|
|
454
|
+
return {
|
|
455
|
+
id,
|
|
456
|
+
widgetId: id,
|
|
457
|
+
connectorId,
|
|
458
|
+
data,
|
|
459
|
+
cachedAt: (await this.storage.getSyncState()).lastSyncAt
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
mount(app) {
|
|
463
|
+
const base = `/dashboards/${this.dashboardId}/widgets`;
|
|
464
|
+
app.get(base, async (c) => {
|
|
465
|
+
const entries = Object.entries(this.dashboard.widgets);
|
|
466
|
+
const resolved = await Promise.all(
|
|
467
|
+
entries.map(([key, widget]) => this.resolveWidget(key, widget))
|
|
468
|
+
);
|
|
469
|
+
const widgets = resolved.filter((w) => w !== void 0);
|
|
470
|
+
return c.json(widgets);
|
|
471
|
+
});
|
|
472
|
+
app.get(`${base}/:widgetId`, async (c) => {
|
|
473
|
+
const widgetId = c.req.param("widgetId");
|
|
474
|
+
const widget = this.dashboard.widgets[widgetId];
|
|
475
|
+
if (!widget) {
|
|
476
|
+
return c.json({ error: "Widget not found" }, 404);
|
|
477
|
+
}
|
|
478
|
+
const result = await this.resolveWidget(widgetId, widget);
|
|
479
|
+
if (!result) {
|
|
480
|
+
return c.json({ error: "Widget not found" }, 404);
|
|
481
|
+
}
|
|
482
|
+
return c.json(result);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// src/storage.ts
|
|
488
|
+
var InMemoryStorage = class {
|
|
489
|
+
eventStore = /* @__PURE__ */ new Map();
|
|
490
|
+
entityStore = /* @__PURE__ */ new Map();
|
|
491
|
+
metricStore = /* @__PURE__ */ new Map();
|
|
492
|
+
edgeStore = /* @__PURE__ */ new Map();
|
|
493
|
+
distributionStore = /* @__PURE__ */ new Map();
|
|
494
|
+
syncState = {
|
|
495
|
+
status: "idle",
|
|
496
|
+
lastSyncAt: null,
|
|
497
|
+
lastError: null
|
|
498
|
+
};
|
|
499
|
+
getStorageHandle(connectorId) {
|
|
500
|
+
const getEntityMap = () => {
|
|
501
|
+
if (!this.entityStore.has(connectorId)) {
|
|
502
|
+
this.entityStore.set(connectorId, /* @__PURE__ */ new Map());
|
|
503
|
+
}
|
|
504
|
+
return this.entityStore.get(connectorId);
|
|
505
|
+
};
|
|
506
|
+
const upsertEntities = (es) => {
|
|
507
|
+
const byType = getEntityMap();
|
|
508
|
+
for (const e of es) {
|
|
509
|
+
if (!byType.has(e.type)) {
|
|
510
|
+
byType.set(e.type, /* @__PURE__ */ new Map());
|
|
511
|
+
}
|
|
512
|
+
byType.get(e.type).set(e.id, e);
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
const upsertEdges = (es) => {
|
|
516
|
+
const existing = this.edgeStore.get(connectorId) ?? [];
|
|
517
|
+
const index = /* @__PURE__ */ new Map();
|
|
518
|
+
for (let i = 0; i < existing.length; i++) {
|
|
519
|
+
const e = existing[i];
|
|
520
|
+
index.set(
|
|
521
|
+
`${e.from_type}:${e.from_id}:${e.kind}:${e.to_type}:${e.to_id}`,
|
|
522
|
+
i
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
for (const e of es) {
|
|
526
|
+
const key = `${e.from_type}:${e.from_id}:${e.kind}:${e.to_type}:${e.to_id}`;
|
|
527
|
+
const idx = index.get(key);
|
|
528
|
+
if (idx !== void 0) {
|
|
529
|
+
existing[idx] = e;
|
|
530
|
+
} else {
|
|
531
|
+
index.set(key, existing.length);
|
|
532
|
+
existing.push(e);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
this.edgeStore.set(connectorId, existing);
|
|
536
|
+
};
|
|
537
|
+
return {
|
|
538
|
+
event: async (e) => {
|
|
539
|
+
if (!this.eventStore.has(connectorId)) {
|
|
540
|
+
this.eventStore.set(connectorId, []);
|
|
541
|
+
}
|
|
542
|
+
this.eventStore.get(connectorId).push(e);
|
|
543
|
+
},
|
|
544
|
+
entity: async (e) => {
|
|
545
|
+
upsertEntities([e]);
|
|
546
|
+
},
|
|
547
|
+
metric: async (m) => {
|
|
548
|
+
if (!this.metricStore.has(connectorId)) {
|
|
549
|
+
this.metricStore.set(connectorId, []);
|
|
550
|
+
}
|
|
551
|
+
this.metricStore.get(connectorId).push(m);
|
|
552
|
+
},
|
|
553
|
+
edge: async (e) => {
|
|
554
|
+
upsertEdges([e]);
|
|
555
|
+
},
|
|
556
|
+
distribution: async (d) => {
|
|
557
|
+
if (!this.distributionStore.has(connectorId)) {
|
|
558
|
+
this.distributionStore.set(connectorId, []);
|
|
559
|
+
}
|
|
560
|
+
this.distributionStore.get(connectorId).push(d);
|
|
561
|
+
},
|
|
562
|
+
events: async (es, scope) => {
|
|
563
|
+
const names = new Set(scope?.names ?? es.map((e) => e.name));
|
|
564
|
+
const kept = (this.eventStore.get(connectorId) ?? []).filter(
|
|
565
|
+
(e) => !names.has(e.name)
|
|
566
|
+
);
|
|
567
|
+
this.eventStore.set(connectorId, [...kept, ...es]);
|
|
568
|
+
},
|
|
569
|
+
entities: async (es, scope) => {
|
|
570
|
+
const byType = getEntityMap();
|
|
571
|
+
const types = new Set(scope?.types ?? es.map((e) => e.type));
|
|
572
|
+
for (const type of types) {
|
|
573
|
+
byType.set(type, /* @__PURE__ */ new Map());
|
|
574
|
+
}
|
|
575
|
+
upsertEntities(es);
|
|
576
|
+
},
|
|
577
|
+
metrics: async (ms, scope) => {
|
|
578
|
+
const names = new Set(scope?.names ?? ms.map((m) => m.name));
|
|
579
|
+
const kept = (this.metricStore.get(connectorId) ?? []).filter(
|
|
580
|
+
(m) => !names.has(m.name)
|
|
581
|
+
);
|
|
582
|
+
this.metricStore.set(connectorId, [...kept, ...ms]);
|
|
583
|
+
},
|
|
584
|
+
edges: async (es, scope) => {
|
|
585
|
+
const kinds = new Set(scope?.kinds ?? es.map((e) => e.kind));
|
|
586
|
+
const kept = (this.edgeStore.get(connectorId) ?? []).filter(
|
|
587
|
+
(e) => !kinds.has(e.kind)
|
|
588
|
+
);
|
|
589
|
+
this.edgeStore.set(connectorId, kept);
|
|
590
|
+
upsertEdges(es);
|
|
591
|
+
},
|
|
592
|
+
distributions: async (ds, scope) => {
|
|
593
|
+
const names = new Set(scope?.names ?? ds.map((d) => d.name));
|
|
594
|
+
const kept = (this.distributionStore.get(connectorId) ?? []).filter(
|
|
595
|
+
(d) => !names.has(d.name)
|
|
596
|
+
);
|
|
597
|
+
this.distributionStore.set(connectorId, [...kept, ...ds]);
|
|
598
|
+
},
|
|
599
|
+
queryEvents: async (q) => {
|
|
600
|
+
let results = this.eventStore.get(connectorId) ?? [];
|
|
601
|
+
if (q.name !== void 0) {
|
|
602
|
+
results = results.filter((e) => e.name === q.name);
|
|
603
|
+
}
|
|
604
|
+
if (q.start !== void 0) {
|
|
605
|
+
results = results.filter((e) => e.start_ts >= q.start);
|
|
606
|
+
}
|
|
607
|
+
if (q.end !== void 0) {
|
|
608
|
+
results = results.filter((e) => e.start_ts <= q.end);
|
|
609
|
+
}
|
|
610
|
+
return results;
|
|
611
|
+
},
|
|
612
|
+
getEntity: async (type, id) => {
|
|
613
|
+
return getEntityMap().get(type)?.get(id) ?? null;
|
|
614
|
+
},
|
|
615
|
+
queryEntities: async (q) => {
|
|
616
|
+
const byType = getEntityMap().get(q.type);
|
|
617
|
+
if (!byType) {
|
|
618
|
+
return [];
|
|
619
|
+
}
|
|
620
|
+
return Array.from(byType.values());
|
|
621
|
+
},
|
|
622
|
+
queryMetrics: async (q) => {
|
|
623
|
+
let results = this.metricStore.get(connectorId) ?? [];
|
|
624
|
+
if (q.name !== void 0) {
|
|
625
|
+
results = results.filter((m) => m.name === q.name);
|
|
626
|
+
}
|
|
627
|
+
if (q.start !== void 0) {
|
|
628
|
+
results = results.filter((m) => m.ts >= q.start);
|
|
629
|
+
}
|
|
630
|
+
if (q.end !== void 0) {
|
|
631
|
+
results = results.filter((m) => m.ts <= q.end);
|
|
632
|
+
}
|
|
633
|
+
return results;
|
|
634
|
+
},
|
|
635
|
+
traverse: async (q) => {
|
|
636
|
+
let results = this.edgeStore.get(connectorId) ?? [];
|
|
637
|
+
if (q.fromType !== void 0) {
|
|
638
|
+
results = results.filter((e) => e.from_type === q.fromType);
|
|
639
|
+
}
|
|
640
|
+
if (q.fromId !== void 0) {
|
|
641
|
+
results = results.filter((e) => e.from_id === q.fromId);
|
|
642
|
+
}
|
|
643
|
+
if (q.kind !== void 0) {
|
|
644
|
+
results = results.filter((e) => e.kind === q.kind);
|
|
645
|
+
}
|
|
646
|
+
if (q.toType !== void 0) {
|
|
647
|
+
results = results.filter((e) => e.to_type === q.toType);
|
|
648
|
+
}
|
|
649
|
+
if (q.toId !== void 0) {
|
|
650
|
+
results = results.filter((e) => e.to_id === q.toId);
|
|
651
|
+
}
|
|
652
|
+
return results;
|
|
653
|
+
},
|
|
654
|
+
queryDistributions: async (q) => {
|
|
655
|
+
let results = this.distributionStore.get(connectorId) ?? [];
|
|
656
|
+
if (q.name !== void 0) {
|
|
657
|
+
results = results.filter((d) => d.name === q.name);
|
|
658
|
+
}
|
|
659
|
+
if (q.start !== void 0) {
|
|
660
|
+
results = results.filter((d) => d.ts >= q.start);
|
|
661
|
+
}
|
|
662
|
+
if (q.end !== void 0) {
|
|
663
|
+
results = results.filter((d) => d.ts <= q.end);
|
|
664
|
+
}
|
|
665
|
+
return results;
|
|
666
|
+
},
|
|
667
|
+
// Entities and edges are excluded — they hold the latest known state per
|
|
668
|
+
// primary key; deleting by age would lose live data.
|
|
669
|
+
deleteOlderThan: async (shape, tsUnixMs) => {
|
|
670
|
+
if (shape === "events") {
|
|
671
|
+
const before = this.eventStore.get(connectorId) ?? [];
|
|
672
|
+
const after = before.filter((e) => e.start_ts >= tsUnixMs);
|
|
673
|
+
this.eventStore.set(connectorId, after);
|
|
674
|
+
return { rowsDeleted: before.length - after.length };
|
|
675
|
+
} else if (shape === "metrics") {
|
|
676
|
+
const before = this.metricStore.get(connectorId) ?? [];
|
|
677
|
+
const after = before.filter((m) => m.ts >= tsUnixMs);
|
|
678
|
+
this.metricStore.set(connectorId, after);
|
|
679
|
+
return { rowsDeleted: before.length - after.length };
|
|
680
|
+
} else if (shape === "distributions") {
|
|
681
|
+
const before = this.distributionStore.get(connectorId) ?? [];
|
|
682
|
+
const after = before.filter((d) => d.ts >= tsUnixMs);
|
|
683
|
+
this.distributionStore.set(connectorId, after);
|
|
684
|
+
return { rowsDeleted: before.length - after.length };
|
|
685
|
+
} else {
|
|
686
|
+
throw new Error(
|
|
687
|
+
`Unsupported shape for deleteOlderThan: ${String(shape)}`
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
async getSyncState() {
|
|
694
|
+
return { ...this.syncState };
|
|
695
|
+
}
|
|
696
|
+
async setSyncing() {
|
|
697
|
+
if (this.syncState.status === "syncing") {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
this.syncState = { ...this.syncState, status: "syncing" };
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
async setSyncSuccess() {
|
|
704
|
+
this.syncState = {
|
|
705
|
+
status: "idle",
|
|
706
|
+
lastSyncAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
707
|
+
lastError: null
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
async setSyncError(error) {
|
|
711
|
+
this.syncState = {
|
|
712
|
+
status: "error",
|
|
713
|
+
lastSyncAt: this.syncState.lastSyncAt,
|
|
714
|
+
lastError: error
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// src/engine-router.ts
|
|
720
|
+
function createEngineRouters(config, storage = new InMemoryStorage()) {
|
|
721
|
+
const widgetRouters = Object.entries(config.dashboards).map(
|
|
722
|
+
([dashboardId, dashboard]) => new WidgetsRouter(dashboardId, dashboard, config.connectors, storage)
|
|
723
|
+
);
|
|
724
|
+
return [
|
|
725
|
+
...widgetRouters,
|
|
726
|
+
new SyncRouter(config, storage),
|
|
727
|
+
new RetentionRouter(config, storage),
|
|
728
|
+
new HealthRouter(storage)
|
|
729
|
+
];
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// src/server.ts
|
|
733
|
+
import { Hono } from "hono";
|
|
734
|
+
function createServer(routers) {
|
|
735
|
+
const app = new Hono();
|
|
736
|
+
for (const router of routers) {
|
|
737
|
+
router.mount(app);
|
|
738
|
+
}
|
|
739
|
+
return app;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// src/engine.ts
|
|
743
|
+
function createEngine(config, options = {}) {
|
|
744
|
+
const storage = options.storage ?? new InMemoryStorage();
|
|
745
|
+
const syncRouter = new SyncRouter(config, storage);
|
|
746
|
+
async function resolveWidget(connectors, id, widget) {
|
|
747
|
+
if (widget.kind === "status") {
|
|
748
|
+
return {
|
|
749
|
+
id,
|
|
750
|
+
widgetId: id,
|
|
751
|
+
connectorId: widget.source,
|
|
752
|
+
data: null,
|
|
753
|
+
cachedAt: null
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
const { connectorId } = widget.metric;
|
|
757
|
+
const connectorEntry = connectors.find(
|
|
758
|
+
(e) => e.connector.id === connectorId
|
|
759
|
+
);
|
|
760
|
+
if (!connectorEntry) {
|
|
761
|
+
return void 0;
|
|
762
|
+
}
|
|
763
|
+
const handle = storage.getStorageHandle(connectorId);
|
|
764
|
+
const data = await computeMetric(handle, widget.metric);
|
|
765
|
+
return {
|
|
766
|
+
id,
|
|
767
|
+
widgetId: id,
|
|
768
|
+
connectorId,
|
|
769
|
+
data,
|
|
770
|
+
cachedAt: (await storage.getSyncState()).lastSyncAt
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
return {
|
|
774
|
+
async getWidget(dashboardId, widgetId) {
|
|
775
|
+
const dashboard = config.dashboards[dashboardId];
|
|
776
|
+
if (!dashboard) {
|
|
777
|
+
return void 0;
|
|
778
|
+
}
|
|
779
|
+
const widget = dashboard.widgets[widgetId];
|
|
780
|
+
if (!widget) {
|
|
781
|
+
return void 0;
|
|
782
|
+
}
|
|
783
|
+
return resolveWidget(config.connectors, widgetId, widget);
|
|
784
|
+
},
|
|
785
|
+
async getWidgets(dashboardId) {
|
|
786
|
+
const dashboard = config.dashboards[dashboardId];
|
|
787
|
+
if (!dashboard) {
|
|
788
|
+
return [];
|
|
789
|
+
}
|
|
790
|
+
const entries = Object.entries(dashboard.widgets);
|
|
791
|
+
const resolved = await Promise.all(
|
|
792
|
+
entries.map(
|
|
793
|
+
([key, widget]) => resolveWidget(config.connectors, key, widget)
|
|
794
|
+
)
|
|
795
|
+
);
|
|
796
|
+
return resolved.filter((w) => w !== void 0);
|
|
797
|
+
},
|
|
798
|
+
async getHealth() {
|
|
799
|
+
return storage.getSyncState();
|
|
800
|
+
},
|
|
801
|
+
async triggerSync() {
|
|
802
|
+
const state = await storage.getSyncState();
|
|
803
|
+
if (state.status === "syncing") {
|
|
804
|
+
return { triggered: false };
|
|
805
|
+
}
|
|
806
|
+
void syncRouter.runSync().catch((error) => {
|
|
807
|
+
console.error("Rawdash sync failed", error);
|
|
808
|
+
});
|
|
809
|
+
return { triggered: true };
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// src/index.ts
|
|
815
|
+
function serve(config, options = {}) {
|
|
816
|
+
const { port = 8080, storage } = options;
|
|
817
|
+
const app = createServer(createEngineRouters(config, storage));
|
|
818
|
+
honoServe({ fetch: app.fetch, port });
|
|
819
|
+
}
|
|
820
|
+
export {
|
|
821
|
+
InMemoryStorage,
|
|
822
|
+
computeMetric,
|
|
823
|
+
createEngine,
|
|
824
|
+
createEngineRouters,
|
|
825
|
+
createServer,
|
|
826
|
+
serve
|
|
827
|
+
};
|
|
828
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/routers/health.ts","../src/routers/retention.ts","../src/routers/sync.ts","../src/compute.ts","../src/routers/widgets.ts","../src/storage.ts","../src/engine-router.ts","../src/server.ts","../src/engine.ts"],"sourcesContent":["import { serve as honoServe } from '@hono/node-server';\n\nimport { createEngineRouters } from './engine-router';\nimport { createServer } from './server';\nimport type { DashboardConfig, ServeOptions } from './types';\n\nexport { createServer } from './server';\nexport { createEngineRouters } from './engine-router';\nexport { createEngine } from './engine';\nexport { computeMetric } from './compute';\nexport { InMemoryStorage } from './storage';\nexport type { RawdashRouter } from './router';\nexport type { SyncState, WidgetEntry } from '@rawdash/core';\nexport type { DashboardConfig, ServeOptions, ServerStorage } from './types';\nexport type { Engine, EngineOptions } from './engine';\n\nexport function serve(\n config: DashboardConfig,\n options: ServeOptions = {},\n): void {\n const { port = 8080, storage } = options;\n const app = createServer(createEngineRouters(config, storage));\n honoServe({ fetch: app.fetch, port });\n}\n","import type { Hono } from 'hono';\n\nimport type { RawdashRouter } from '../router';\nimport type { ServerStorage } from '../types';\n\nexport class HealthRouter implements RawdashRouter {\n constructor(private storage: ServerStorage) {}\n\n mount(app: Hono): void {\n app.get('/health', async (c) => {\n return c.json(await this.storage.getSyncState());\n });\n }\n}\n","import type { DashboardConfig, RetentionConfig } from '@rawdash/core';\nimport { selectForDeletion } from '@rawdash/core';\nimport type { Hono } from 'hono';\n\nimport type { RawdashRouter } from '../router';\nimport type { ServerStorage } from '../types';\n\nconst DEFAULT_INTERVAL_MS = 60 * 60 * 1000; // 1 hour\n\nfunction hasPruningPolicy(config: RetentionConfig): boolean {\n return config.maxAge !== undefined || config.maxSize !== undefined;\n}\n\nexport class RetentionRouter implements RawdashRouter {\n private interval: ReturnType<typeof setInterval> | null = null;\n private inFlight: Promise<void> | null = null;\n\n constructor(\n private config: DashboardConfig,\n private storage: ServerStorage,\n ) {}\n\n async runRetention(): Promise<void> {\n if (this.inFlight) {\n return this.inFlight;\n }\n\n this.inFlight = this.runRetentionOnce().finally(() => {\n this.inFlight = null;\n });\n\n return this.inFlight;\n }\n\n private async runRetentionOnce(): Promise<void> {\n const retentionConfig = this.config.retention;\n if (!retentionConfig || !hasPruningPolicy(retentionConfig)) {\n return;\n }\n\n const nowMs = Date.now();\n\n const results = await Promise.allSettled(\n this.config.connectors.map(async ({ connector }) => {\n const handle = this.storage.getStorageHandle(connector.id);\n\n const [events, metrics, distributions] = await Promise.all([\n handle.queryEvents({}),\n handle.queryMetrics({}),\n handle.queryDistributions({}),\n ]);\n\n await applyRetentionToShape(\n events,\n (e) => e.start_ts,\n retentionConfig,\n nowMs,\n (survivors, names) => handle.events(survivors, { names }),\n );\n\n await applyRetentionToShape(\n metrics,\n (m) => m.ts,\n retentionConfig,\n nowMs,\n (survivors, names) => handle.metrics(survivors, { names }),\n );\n\n await applyRetentionToShape(\n distributions,\n (d) => d.ts,\n retentionConfig,\n nowMs,\n (survivors, names) => handle.distributions(survivors, { names }),\n );\n }),\n );\n\n const failures = results.filter(\n (r): r is PromiseRejectedResult => r.status === 'rejected',\n );\n if (failures.length > 0) {\n throw new Error(\n `Retention failed for ${failures.length} connector(s): ${failures.map((f) => String(f.reason)).join('; ')}`,\n );\n }\n }\n\n mount(app: Hono): void {\n app.post('/retain', async (c) => {\n try {\n await this.runRetention();\n return c.json({ triggered: true });\n } catch (err) {\n console.error('retention run failed', err);\n return c.json({ triggered: false }, 500);\n }\n });\n\n const retentionConfig = this.config.retention;\n if (retentionConfig && hasPruningPolicy(retentionConfig)) {\n const intervalMs = retentionConfig.intervalMs ?? DEFAULT_INTERVAL_MS;\n this.interval = setInterval(() => {\n void this.runRetention().catch((err) => {\n console.error('retention run failed', err);\n });\n }, intervalMs);\n }\n }\n\n stop(): void {\n if (this.interval !== null) {\n clearInterval(this.interval);\n this.interval = null;\n }\n }\n}\n\nasync function applyRetentionToShape<T extends { name: string }>(\n rows: T[],\n getTs: (row: T) => number,\n config: RetentionConfig,\n nowMs: number,\n writeSurvivors: (survivors: T[], names: string[]) => Promise<void>,\n): Promise<void> {\n if (rows.length === 0) {\n return;\n }\n\n const sorted = [...rows].sort((a, b) => getTs(b) - getTs(a));\n const toDeleteSet = new Set(selectForDeletion(sorted, getTs, config, nowMs));\n\n if (toDeleteSet.size === 0) {\n return;\n }\n\n const survivors = sorted.filter((r) => !toDeleteSet.has(r));\n const allNames = [...new Set(rows.map((r) => r.name))];\n\n await writeSurvivors(survivors, allNames);\n}\n","import type { DashboardConfig } from '@rawdash/core';\nimport type { Hono } from 'hono';\n\nimport type { RawdashRouter } from '../router';\nimport type { ServerStorage } from '../types';\n\nconst FULL_SYNC_TIMEOUT_MS = 300_000;\n\nexport class SyncRouter implements RawdashRouter {\n constructor(\n private config: DashboardConfig,\n private storage: ServerStorage,\n ) {}\n\n async runSync(): Promise<void> {\n const acquired = await this.storage.setSyncing();\n if (!acquired) {\n return;\n }\n const errors: string[] = [];\n await Promise.allSettled(\n this.config.connectors.map(async ({ connector }) => {\n const handle = this.storage.getStorageHandle(connector.id);\n const controller = new AbortController();\n const timer = setTimeout(\n () => controller.abort(),\n FULL_SYNC_TIMEOUT_MS,\n );\n try {\n await connector.sync({ mode: 'full' }, handle, controller.signal);\n } catch (err) {\n if (err instanceof Error && err.name === 'AbortError') {\n errors.push(\n `${connector.id} timed out after ${FULL_SYNC_TIMEOUT_MS}ms`,\n );\n } else {\n errors.push(err instanceof Error ? err.message : String(err));\n }\n } finally {\n clearTimeout(timer);\n }\n }),\n );\n if (errors.length > 0) {\n await this.storage.setSyncError(errors.join('; '));\n } else {\n await this.storage.setSyncSuccess();\n }\n }\n\n mount(app: Hono): void {\n app.post('/sync', async (c) => {\n const state = await this.storage.getSyncState();\n if (state.status === 'syncing') {\n return c.json({ triggered: false });\n }\n void this.runSync();\n return c.json({ triggered: true });\n });\n }\n}\n","import type { ResolvedMetric, StorageHandle } from '@rawdash/core';\n\ntype FilterClause = NonNullable<ResolvedMetric['filter']>[number];\ntype FilterCondition = Exclude<FilterClause, { or: unknown[] }>;\n\nfunction matchesCondition(\n record: Record<string, unknown>,\n cond: FilterCondition,\n): boolean {\n const val = record[cond.field];\n switch (cond.op) {\n case 'eq':\n return val === cond.value;\n case 'neq':\n return val !== cond.value;\n case 'gt':\n return (val as number) > (cond.value as number);\n case 'gte':\n return (val as number) >= (cond.value as number);\n case 'lt':\n return (val as number) < (cond.value as number);\n case 'lte':\n return (val as number) <= (cond.value as number);\n case 'contains':\n return String(val).includes(String(cond.value));\n default:\n return false;\n }\n}\n\nfunction applyFilter(\n record: Record<string, unknown>,\n filter: ResolvedMetric['filter'],\n): boolean {\n if (!filter) {\n return true;\n }\n for (const clause of filter) {\n if ('or' in clause) {\n if (!clause.or.some((cond) => matchesCondition(record, cond))) {\n return false;\n }\n } else {\n if (!matchesCondition(record, clause)) {\n return false;\n }\n }\n }\n return true;\n}\n\nconst WINDOW_MS: Record<string, number> = {\n h: 3_600_000,\n d: 86_400_000,\n w: 604_800_000,\n m: 2_592_000_000,\n};\n\nfunction parseWindowMs(window: string): number | null {\n const match = /^(\\d+)(h|d|w|m)$/.exec(window);\n if (!match) {\n return null;\n }\n const unitMs = WINDOW_MS[match[2]!];\n if (unitMs === undefined) {\n return null;\n }\n return parseInt(match[1]!) * unitMs;\n}\n\nfunction truncateToGranularity(ts: number, granularity: string): string {\n const d = new Date(ts);\n switch (granularity) {\n case 'hour':\n d.setUTCMinutes(0, 0, 0);\n return d.toISOString();\n case 'day':\n d.setUTCHours(0, 0, 0, 0);\n return d.toISOString().slice(0, 10);\n case 'week': {\n d.setUTCDate(d.getUTCDate() - d.getUTCDay());\n d.setUTCHours(0, 0, 0, 0);\n return d.toISOString().slice(0, 10);\n }\n case 'month':\n d.setUTCDate(1);\n d.setUTCHours(0, 0, 0, 0);\n return d.toISOString().slice(0, 7);\n default:\n return d.toISOString().slice(0, 10);\n }\n}\n\nfunction computeAgg(\n records: Record<string, unknown>[],\n field: string,\n fn: string,\n): unknown {\n if (fn === 'count') {\n return records.length;\n }\n if (fn === 'latest') {\n return records.at(-1)?.[field] ?? null;\n }\n if (fn === 'first') {\n return records[0]?.[field] ?? null;\n }\n const values = records\n .map((r) => r[field])\n .filter((v) => v !== undefined && v !== null);\n const nonNumeric = values.find((v) => typeof v !== 'number');\n if (nonNumeric !== undefined) {\n throw new Error(\n `computeAgg: fn \"${fn}\" requires numeric values for field \"${field}\", got ${typeof nonNumeric} (${String(nonNumeric)})`,\n );\n }\n const numbers = values as number[];\n if (fn === 'sum') {\n return numbers.reduce((a, b) => a + b, 0);\n }\n if (fn === 'avg') {\n return numbers.length > 0\n ? numbers.reduce((a, b) => a + b, 0) / numbers.length\n : null;\n }\n if (fn === 'min') {\n return numbers.length > 0 ? Math.min(...numbers) : null;\n }\n if (fn === 'max') {\n return numbers.length > 0 ? Math.max(...numbers) : null;\n }\n return null;\n}\n\nfunction sortByTs(\n records: Record<string, unknown>[],\n tsField: string,\n): Record<string, unknown>[] {\n return [...records].sort((a, b) => {\n return (a[tsField] as number) - (b[tsField] as number);\n });\n}\n\nfunction computeGroupBy(\n records: Record<string, unknown>[],\n metric: ResolvedMetric,\n tsField: string,\n): unknown {\n const { field, granularity } = metric.groupBy!;\n const groups = new Map<string, Record<string, unknown>[]>();\n\n for (const record of records) {\n const ts = record[field] as number | undefined;\n if (ts === undefined || typeof ts !== 'number') {\n continue;\n }\n const key = truncateToGranularity(ts, granularity);\n if (!groups.has(key)) {\n groups.set(key, []);\n }\n groups.get(key)!.push(record);\n }\n\n return [...groups.entries()]\n .map(([key, groupRecords]) => ({\n date: key,\n value: computeAgg(\n sortByTs(groupRecords, tsField),\n metric.field,\n metric.fn,\n ),\n }))\n .sort((a, b) => (a.date < b.date ? -1 : 1));\n}\n\nfunction getTimestampField(shape: string): string {\n switch (shape) {\n case 'event':\n return 'start_ts';\n case 'metric':\n case 'distribution':\n return 'ts';\n case 'entity':\n case 'edge':\n return 'updated_at';\n default:\n return 'start_ts';\n }\n}\n\nexport async function computeMetric(\n storage: StorageHandle,\n metric: ResolvedMetric,\n): Promise<unknown> {\n const tsField = getTimestampField(metric.shape);\n\n const windowMs = metric.window ? parseWindowMs(metric.window) : null;\n const windowStart = windowMs !== null ? Date.now() - windowMs : undefined;\n\n let records: Record<string, unknown>[];\n\n switch (metric.shape) {\n case 'event': {\n const events = await storage.queryEvents({\n name: metric.name,\n start: windowStart,\n });\n records = events.map((e) => ({\n ...e.attributes,\n name: e.name,\n start_ts: e.start_ts,\n end_ts: e.end_ts,\n }));\n break;\n }\n\n case 'entity': {\n const type = metric.entityType ?? metric.name ?? '';\n const entities = await storage.queryEntities({ type });\n records = entities.map((e) => ({\n ...e.attributes,\n type: e.type,\n id: e.id,\n updated_at: e.updated_at,\n }));\n if (windowStart !== undefined) {\n records = records.filter((r) => (r[tsField] as number) >= windowStart);\n }\n break;\n }\n\n case 'metric': {\n const metrics = await storage.queryMetrics({\n name: metric.name,\n start: windowStart,\n });\n records = metrics.map((m) => ({\n ...m.attributes,\n name: m.name,\n ts: m.ts,\n value: m.value,\n }));\n break;\n }\n\n case 'edge': {\n const edges = await storage.traverse({ kind: metric.name });\n records = edges.map((e) => ({\n ...e.attributes,\n from_type: e.from_type,\n from_id: e.from_id,\n kind: e.kind,\n to_type: e.to_type,\n to_id: e.to_id,\n updated_at: e.updated_at,\n }));\n if (windowStart !== undefined) {\n records = records.filter((r) => (r[tsField] as number) >= windowStart);\n }\n break;\n }\n\n case 'distribution': {\n const distributions = await storage.queryDistributions({\n name: metric.name,\n start: windowStart,\n });\n records = distributions.map((d) => ({\n ...d.attributes,\n name: d.name,\n ts: d.ts,\n kind: d.kind,\n data: d.data,\n }));\n break;\n }\n\n default:\n return null;\n }\n\n const filtered = records.filter((r) => applyFilter(r, metric.filter));\n const sorted = sortByTs(filtered, tsField);\n\n if (metric.groupBy) {\n return computeGroupBy(sorted, metric, tsField);\n }\n\n return computeAgg(sorted, metric.field, metric.fn);\n}\n","import type {\n ConnectorEntry,\n Dashboard,\n Widget,\n WidgetEntry,\n} from '@rawdash/core';\nimport type { Hono } from 'hono';\n\nimport { computeMetric } from '../compute';\nimport type { RawdashRouter } from '../router';\nimport type { ServerStorage } from '../types';\n\nexport class WidgetsRouter implements RawdashRouter {\n constructor(\n private dashboardId: string,\n private dashboard: Dashboard,\n private connectors: ConnectorEntry[],\n private storage: ServerStorage,\n ) {}\n\n private async resolveWidget(\n id: string,\n widget: Widget,\n ): Promise<WidgetEntry | undefined> {\n if (widget.kind === 'status') {\n return {\n id,\n widgetId: id,\n connectorId: widget.source,\n data: null,\n cachedAt: null,\n };\n }\n const { connectorId } = widget.metric;\n const connectorEntry = this.connectors.find(\n (e) => e.connector.id === connectorId,\n );\n if (!connectorEntry) {\n return undefined;\n }\n const handle = this.storage.getStorageHandle(connectorId);\n const data = await computeMetric(handle, widget.metric);\n return {\n id,\n widgetId: id,\n connectorId,\n data,\n cachedAt: (await this.storage.getSyncState()).lastSyncAt,\n };\n }\n\n mount(app: Hono): void {\n const base = `/dashboards/${this.dashboardId}/widgets`;\n\n app.get(base, async (c) => {\n const entries = Object.entries(this.dashboard.widgets);\n const resolved = await Promise.all(\n entries.map(([key, widget]) => this.resolveWidget(key, widget)),\n );\n const widgets = resolved.filter((w): w is WidgetEntry => w !== undefined);\n return c.json(widgets);\n });\n\n app.get(`${base}/:widgetId`, async (c) => {\n const widgetId = c.req.param('widgetId');\n const widget = this.dashboard.widgets[widgetId];\n if (!widget) {\n return c.json({ error: 'Widget not found' }, 404);\n }\n const result = await this.resolveWidget(widgetId, widget);\n if (!result) {\n return c.json({ error: 'Widget not found' }, 404);\n }\n return c.json(result);\n });\n }\n}\n","import type {\n Distribution,\n DistributionQuery,\n Edge,\n EdgeQuery,\n Entity,\n EntityQuery,\n Event,\n EventQuery,\n Metric,\n MetricQuery,\n StorageHandle,\n SyncState,\n} from '@rawdash/core';\n\nimport type { ServerStorage } from './types';\n\nexport class InMemoryStorage implements ServerStorage {\n private eventStore = new Map<string, Event[]>();\n private entityStore = new Map<string, Map<string, Map<string, Entity>>>();\n private metricStore = new Map<string, Metric[]>();\n private edgeStore = new Map<string, Edge[]>();\n private distributionStore = new Map<string, Distribution[]>();\n private syncState: SyncState = {\n status: 'idle',\n lastSyncAt: null,\n lastError: null,\n };\n\n getStorageHandle(connectorId: string): StorageHandle {\n const getEntityMap = (): Map<string, Map<string, Entity>> => {\n if (!this.entityStore.has(connectorId)) {\n this.entityStore.set(connectorId, new Map());\n }\n return this.entityStore.get(connectorId)!;\n };\n\n const upsertEntities = (es: Entity[]): void => {\n const byType = getEntityMap();\n for (const e of es) {\n if (!byType.has(e.type)) {\n byType.set(e.type, new Map());\n }\n byType.get(e.type)!.set(e.id, e);\n }\n };\n\n const upsertEdges = (es: Edge[]): void => {\n const existing = this.edgeStore.get(connectorId) ?? [];\n const index = new Map<string, number>();\n for (let i = 0; i < existing.length; i++) {\n const e = existing[i]!;\n index.set(\n `${e.from_type}:${e.from_id}:${e.kind}:${e.to_type}:${e.to_id}`,\n i,\n );\n }\n for (const e of es) {\n const key = `${e.from_type}:${e.from_id}:${e.kind}:${e.to_type}:${e.to_id}`;\n const idx = index.get(key);\n if (idx !== undefined) {\n existing[idx] = e;\n } else {\n index.set(key, existing.length);\n existing.push(e);\n }\n }\n this.edgeStore.set(connectorId, existing);\n };\n\n return {\n event: async (e) => {\n if (!this.eventStore.has(connectorId)) {\n this.eventStore.set(connectorId, []);\n }\n this.eventStore.get(connectorId)!.push(e);\n },\n\n entity: async (e) => {\n upsertEntities([e]);\n },\n\n metric: async (m) => {\n if (!this.metricStore.has(connectorId)) {\n this.metricStore.set(connectorId, []);\n }\n this.metricStore.get(connectorId)!.push(m);\n },\n\n edge: async (e) => {\n upsertEdges([e]);\n },\n\n distribution: async (d) => {\n if (!this.distributionStore.has(connectorId)) {\n this.distributionStore.set(connectorId, []);\n }\n this.distributionStore.get(connectorId)!.push(d);\n },\n\n events: async (es, scope) => {\n const names = new Set(scope?.names ?? es.map((e) => e.name));\n const kept = (this.eventStore.get(connectorId) ?? []).filter(\n (e) => !names.has(e.name),\n );\n this.eventStore.set(connectorId, [...kept, ...es]);\n },\n\n entities: async (es, scope) => {\n const byType = getEntityMap();\n const types = new Set(scope?.types ?? es.map((e) => e.type));\n for (const type of types) {\n byType.set(type, new Map());\n }\n upsertEntities(es);\n },\n\n metrics: async (ms, scope) => {\n const names = new Set(scope?.names ?? ms.map((m) => m.name));\n const kept = (this.metricStore.get(connectorId) ?? []).filter(\n (m) => !names.has(m.name),\n );\n this.metricStore.set(connectorId, [...kept, ...ms]);\n },\n\n edges: async (es, scope) => {\n const kinds = new Set(scope?.kinds ?? es.map((e) => e.kind));\n const kept = (this.edgeStore.get(connectorId) ?? []).filter(\n (e) => !kinds.has(e.kind),\n );\n this.edgeStore.set(connectorId, kept);\n upsertEdges(es);\n },\n\n distributions: async (ds, scope) => {\n const names = new Set(scope?.names ?? ds.map((d) => d.name));\n const kept = (this.distributionStore.get(connectorId) ?? []).filter(\n (d) => !names.has(d.name),\n );\n this.distributionStore.set(connectorId, [...kept, ...ds]);\n },\n\n queryEvents: async (q: EventQuery) => {\n let results = this.eventStore.get(connectorId) ?? [];\n if (q.name !== undefined) {\n results = results.filter((e) => e.name === q.name);\n }\n if (q.start !== undefined) {\n results = results.filter((e) => e.start_ts >= q.start!);\n }\n if (q.end !== undefined) {\n results = results.filter((e) => e.start_ts <= q.end!);\n }\n return results;\n },\n\n getEntity: async (type: string, id: string) => {\n return getEntityMap().get(type)?.get(id) ?? null;\n },\n\n queryEntities: async (q: EntityQuery) => {\n const byType = getEntityMap().get(q.type);\n if (!byType) {\n return [];\n }\n return Array.from(byType.values());\n },\n\n queryMetrics: async (q: MetricQuery) => {\n let results = this.metricStore.get(connectorId) ?? [];\n if (q.name !== undefined) {\n results = results.filter((m) => m.name === q.name);\n }\n if (q.start !== undefined) {\n results = results.filter((m) => m.ts >= q.start!);\n }\n if (q.end !== undefined) {\n results = results.filter((m) => m.ts <= q.end!);\n }\n return results;\n },\n\n traverse: async (q: EdgeQuery) => {\n let results = this.edgeStore.get(connectorId) ?? [];\n if (q.fromType !== undefined) {\n results = results.filter((e) => e.from_type === q.fromType);\n }\n if (q.fromId !== undefined) {\n results = results.filter((e) => e.from_id === q.fromId);\n }\n if (q.kind !== undefined) {\n results = results.filter((e) => e.kind === q.kind);\n }\n if (q.toType !== undefined) {\n results = results.filter((e) => e.to_type === q.toType);\n }\n if (q.toId !== undefined) {\n results = results.filter((e) => e.to_id === q.toId);\n }\n return results;\n },\n\n queryDistributions: async (q: DistributionQuery) => {\n let results = this.distributionStore.get(connectorId) ?? [];\n if (q.name !== undefined) {\n results = results.filter((d) => d.name === q.name);\n }\n if (q.start !== undefined) {\n results = results.filter((d) => d.ts >= q.start!);\n }\n if (q.end !== undefined) {\n results = results.filter((d) => d.ts <= q.end!);\n }\n return results;\n },\n\n // Entities and edges are excluded — they hold the latest known state per\n // primary key; deleting by age would lose live data.\n deleteOlderThan: async (shape, tsUnixMs) => {\n if (shape === 'events') {\n const before = this.eventStore.get(connectorId) ?? [];\n const after = before.filter((e) => e.start_ts >= tsUnixMs);\n this.eventStore.set(connectorId, after);\n return { rowsDeleted: before.length - after.length };\n } else if (shape === 'metrics') {\n const before = this.metricStore.get(connectorId) ?? [];\n const after = before.filter((m) => m.ts >= tsUnixMs);\n this.metricStore.set(connectorId, after);\n return { rowsDeleted: before.length - after.length };\n } else if (shape === 'distributions') {\n const before = this.distributionStore.get(connectorId) ?? [];\n const after = before.filter((d) => d.ts >= tsUnixMs);\n this.distributionStore.set(connectorId, after);\n return { rowsDeleted: before.length - after.length };\n } else {\n throw new Error(\n `Unsupported shape for deleteOlderThan: ${String(shape)}`,\n );\n }\n },\n };\n }\n\n async getSyncState(): Promise<SyncState> {\n return { ...this.syncState };\n }\n\n async setSyncing(): Promise<boolean> {\n if (this.syncState.status === 'syncing') {\n return false;\n }\n this.syncState = { ...this.syncState, status: 'syncing' };\n return true;\n }\n\n async setSyncSuccess(): Promise<void> {\n this.syncState = {\n status: 'idle',\n lastSyncAt: new Date().toISOString(),\n lastError: null,\n };\n }\n\n async setSyncError(error: string): Promise<void> {\n this.syncState = {\n status: 'error',\n lastSyncAt: this.syncState.lastSyncAt,\n lastError: error,\n };\n }\n}\n","import type { DashboardConfig } from '@rawdash/core';\n\nimport type { RawdashRouter } from './router';\nimport { HealthRouter } from './routers/health';\nimport { RetentionRouter } from './routers/retention';\nimport { SyncRouter } from './routers/sync';\nimport { WidgetsRouter } from './routers/widgets';\nimport { InMemoryStorage } from './storage';\nimport type { ServerStorage } from './types';\n\nexport function createEngineRouters(\n config: DashboardConfig,\n storage: ServerStorage = new InMemoryStorage(),\n): RawdashRouter[] {\n const widgetRouters = Object.entries(config.dashboards).map(\n ([dashboardId, dashboard]) =>\n new WidgetsRouter(dashboardId, dashboard, config.connectors, storage),\n );\n\n return [\n ...widgetRouters,\n new SyncRouter(config, storage),\n new RetentionRouter(config, storage),\n new HealthRouter(storage),\n ];\n}\n","import { Hono } from 'hono';\n\nimport type { RawdashRouter } from './router';\n\nexport function createServer(routers: RawdashRouter[]): Hono {\n const app = new Hono();\n for (const router of routers) {\n router.mount(app);\n }\n return app;\n}\n","import type { DashboardConfig, Widget, WidgetEntry } from '@rawdash/core';\n\nimport { computeMetric } from './compute';\nimport { SyncRouter } from './routers/sync';\nimport { InMemoryStorage } from './storage';\nimport type { ServerStorage } from './types';\n\nexport interface EngineOptions {\n storage?: ServerStorage;\n}\n\nexport interface Engine {\n getWidget(\n dashboardId: string,\n widgetId: string,\n ): Promise<WidgetEntry | undefined>;\n getWidgets(dashboardId: string): Promise<WidgetEntry[]>;\n getHealth(): Promise<{\n status: 'idle' | 'syncing' | 'error';\n lastSyncAt: string | null;\n lastError: string | null;\n }>;\n triggerSync(): Promise<{ triggered: boolean }>;\n}\n\nexport function createEngine(\n config: DashboardConfig,\n options: EngineOptions = {},\n): Engine {\n const storage: ServerStorage = options.storage ?? new InMemoryStorage();\n const syncRouter = new SyncRouter(config, storage);\n\n async function resolveWidget(\n connectors: DashboardConfig['connectors'],\n id: string,\n widget: Widget,\n ): Promise<WidgetEntry | undefined> {\n if (widget.kind === 'status') {\n return {\n id,\n widgetId: id,\n connectorId: widget.source,\n data: null,\n cachedAt: null,\n };\n }\n const { connectorId } = widget.metric;\n const connectorEntry = connectors.find(\n (e) => e.connector.id === connectorId,\n );\n if (!connectorEntry) {\n return undefined;\n }\n const handle = storage.getStorageHandle(connectorId);\n const data = await computeMetric(handle, widget.metric);\n return {\n id,\n widgetId: id,\n connectorId,\n data,\n cachedAt: (await storage.getSyncState()).lastSyncAt,\n };\n }\n\n return {\n async getWidget(dashboardId, widgetId) {\n const dashboard = config.dashboards[dashboardId];\n if (!dashboard) {\n return undefined;\n }\n const widget = dashboard.widgets[widgetId];\n if (!widget) {\n return undefined;\n }\n return resolveWidget(config.connectors, widgetId, widget);\n },\n\n async getWidgets(dashboardId) {\n const dashboard = config.dashboards[dashboardId];\n if (!dashboard) {\n return [];\n }\n const entries = Object.entries(dashboard.widgets);\n const resolved = await Promise.all(\n entries.map(([key, widget]) =>\n resolveWidget(config.connectors, key, widget),\n ),\n );\n return resolved.filter((w): w is WidgetEntry => w !== undefined);\n },\n\n async getHealth() {\n return storage.getSyncState();\n },\n\n async triggerSync() {\n const state = await storage.getSyncState();\n if (state.status === 'syncing') {\n return { triggered: false };\n }\n void syncRouter.runSync().catch((error) => {\n console.error('Rawdash sync failed', error);\n });\n return { triggered: true };\n },\n };\n}\n"],"mappings":";AAAA,SAAS,SAAS,iBAAiB;;;ACK5B,IAAM,eAAN,MAA4C;AAAA,EACjD,YAAoB,SAAwB;AAAxB;AAAA,EAAyB;AAAA,EAAzB;AAAA,EAEpB,MAAM,KAAiB;AACrB,QAAI,IAAI,WAAW,OAAO,MAAM;AAC9B,aAAO,EAAE,KAAK,MAAM,KAAK,QAAQ,aAAa,CAAC;AAAA,IACjD,CAAC;AAAA,EACH;AACF;;;ACZA,SAAS,yBAAyB;AAMlC,IAAM,sBAAsB,KAAK,KAAK;AAEtC,SAAS,iBAAiB,QAAkC;AAC1D,SAAO,OAAO,WAAW,UAAa,OAAO,YAAY;AAC3D;AAEO,IAAM,kBAAN,MAA+C;AAAA,EAIpD,YACU,QACA,SACR;AAFQ;AACA;AAAA,EACP;AAAA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,IAEA,MAAM,YAAY;AAChB,aAAO,QAAQ,aAAa;AAAA,IAC9B;AAAA,IAEA,MAAM,cAAc;AAClB,YAAM,QAAQ,MAAM,QAAQ,aAAa;AACzC,UAAI,MAAM,WAAW,WAAW;AAC9B,eAAO,EAAE,WAAW,MAAM;AAAA,MAC5B;AACA,WAAK,WAAW,QAAQ,EAAE,MAAM,CAAC,UAAU;AACzC,gBAAQ,MAAM,uBAAuB,KAAK;AAAA,MAC5C,CAAC;AACD,aAAO,EAAE,WAAW,KAAK;AAAA,IAC3B;AAAA,EACF;AACF;;;AT1FO,SAAS,MACd,QACA,UAAwB,CAAC,GACnB;AACN,QAAM,EAAE,OAAO,MAAM,QAAQ,IAAI;AACjC,QAAM,MAAM,aAAa,oBAAoB,QAAQ,OAAO,CAAC;AAC7D,YAAU,EAAE,OAAO,IAAI,OAAO,KAAK,CAAC;AACtC;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rawdash/server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Rawdash standalone Hono server",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/rawdash/rawdash.git",
|
|
10
|
+
"directory": "packages/server"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"@rawdash/source": "./src/index.ts",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@hono/node-server": "^1.13.7",
|
|
26
|
+
"hono": "^4.7.7",
|
|
27
|
+
"@rawdash/core": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsup": "^8.0.0",
|
|
31
|
+
"tsx": "^4.19.2",
|
|
32
|
+
"typescript": "^5.7.2"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsx src/dev.ts",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"lint": "eslint src",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
}
|
|
41
|
+
}
|