@rawdash/core 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 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,89 @@
1
+ # @rawdash/core
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@rawdash/core)](https://www.npmjs.com/package/@rawdash/core)
4
+ [![license](https://img.shields.io/npm/l/@rawdash/core)](https://github.com/rawdash/rawdash/blob/main/LICENSE)
5
+
6
+ Headless dashboard backend primitives for rawdash. Define connectors, dashboards, widgets, and metrics — no UI assumptions, works anywhere.
7
+
8
+ ## What it is
9
+
10
+ `@rawdash/core` is the foundation of the rawdash ecosystem. It provides the types and functions (`defineConfig`, `defineDashboard`, `defineMetric`, `defineConnector`, `secret`) that every rawdash setup is built on. It has no framework dependencies and no I/O — it only models your dashboard configuration and the connector interface.
11
+
12
+ Other packages (`@rawdash/server`, `@rawdash/nextjs`, `@rawdash/mcp`) take a config produced by this package and add runtime behavior.
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ npm install @rawdash/core @rawdash/connector-github
18
+ ```
19
+
20
+ ## Quick example
21
+
22
+ ```ts
23
+ import { GitHubActionsConnector } from '@rawdash/connector-github';
24
+ import {
25
+ defineConfig,
26
+ defineDashboard,
27
+ defineMetric,
28
+ secret,
29
+ } from '@rawdash/core';
30
+
31
+ const github = new GitHubActionsConnector({
32
+ owner: 'my-org',
33
+ repo: 'my-repo',
34
+ token: secret('GITHUB_TOKEN'),
35
+ });
36
+
37
+ export default defineConfig({
38
+ connectors: [{ connector: github }],
39
+ dashboards: {
40
+ engineering: defineDashboard({
41
+ widgets: {
42
+ open_prs: {
43
+ kind: 'stat',
44
+ title: 'Open PRs',
45
+ metric: defineMetric({
46
+ connector: github,
47
+ shape: 'entity',
48
+ field: 'id',
49
+ fn: 'count',
50
+ filter: [{ field: 'state', op: 'eq', value: 'open' }],
51
+ }),
52
+ },
53
+ },
54
+ }),
55
+ },
56
+ });
57
+ ```
58
+
59
+ ## API
60
+
61
+ ### `defineConfig(config)`
62
+
63
+ Validates and returns a `DashboardConfig`. Throws if a widget references an unknown connector or uses invalid shape/fn values.
64
+
65
+ ### `defineDashboard({ widgets })`
66
+
67
+ Validates and returns a `Dashboard`. Widget keys must be URL-safe (`[a-zA-Z0-9_-]`).
68
+
69
+ ### `defineMetric(options)`
70
+
71
+ Returns a `ResolvedMetric` that can be used in stat, timeseries, and distribution widgets.
72
+
73
+ ### `secret(name)`
74
+
75
+ Returns a `SecretRef` that resolves the named environment variable at runtime. Connectors that accept a `token` or API key should use this to avoid hardcoding credentials.
76
+
77
+ ### `defineConnector(options)`
78
+
79
+ Low-level factory for authoring new connectors. Used by packages like `@rawdash/connector-github`.
80
+
81
+ ## Links
82
+
83
+ - [rawdash docs](https://rawdash.dev)
84
+ - [GitHub](https://github.com/rawdash/rawdash)
85
+ - [Issues](https://github.com/rawdash/rawdash/issues)
86
+
87
+ ## License
88
+
89
+ Apache-2.0
@@ -0,0 +1,344 @@
1
+ import { z } from 'zod';
2
+
3
+ type SecretRef = {
4
+ $secret: string;
5
+ };
6
+ declare function secret(name: string): SecretRef;
7
+ declare function isSecretRef(value: unknown): value is SecretRef;
8
+ interface SecretsResolver {
9
+ resolve(name: string): string | undefined;
10
+ }
11
+ declare class EnvSecretsResolver implements SecretsResolver {
12
+ resolve(name: string): string | undefined;
13
+ }
14
+ declare function resolveSecretRefs<T>(obj: T, resolver: SecretsResolver): T;
15
+
16
+ type JSONValue = string | number | boolean | null | JSONValue[] | {
17
+ [key: string]: JSONValue;
18
+ };
19
+ interface Event {
20
+ name: string;
21
+ start_ts: number;
22
+ end_ts: number | null;
23
+ attributes: Record<string, JSONValue>;
24
+ }
25
+ interface Entity {
26
+ type: string;
27
+ id: string;
28
+ attributes: Record<string, JSONValue>;
29
+ updated_at: number;
30
+ }
31
+ interface Metric {
32
+ name: string;
33
+ ts: number;
34
+ value: number;
35
+ attributes: Record<string, JSONValue>;
36
+ }
37
+ interface Edge {
38
+ from_type: string;
39
+ from_id: string;
40
+ kind: string;
41
+ to_type: string;
42
+ to_id: string;
43
+ attributes: Record<string, JSONValue>;
44
+ updated_at: number;
45
+ }
46
+ type Distribution = {
47
+ name: string;
48
+ ts: number;
49
+ kind: 'histogram';
50
+ data: {
51
+ buckets: Array<{
52
+ le: number;
53
+ count: number;
54
+ }>;
55
+ count: number;
56
+ sum: number;
57
+ };
58
+ attributes: Record<string, JSONValue>;
59
+ } | {
60
+ name: string;
61
+ ts: number;
62
+ kind: 'summary';
63
+ data: {
64
+ quantiles: Array<{
65
+ q: number;
66
+ value: number;
67
+ }>;
68
+ count: number;
69
+ sum: number;
70
+ };
71
+ attributes: Record<string, JSONValue>;
72
+ };
73
+ interface EventQuery {
74
+ name?: string;
75
+ start?: number;
76
+ end?: number;
77
+ }
78
+ interface EntityQuery {
79
+ type: string;
80
+ }
81
+ interface MetricQuery {
82
+ name?: string;
83
+ start?: number;
84
+ end?: number;
85
+ }
86
+ interface EdgeQuery {
87
+ fromType?: string;
88
+ fromId?: string;
89
+ kind?: string;
90
+ toType?: string;
91
+ toId?: string;
92
+ }
93
+ interface DistributionQuery {
94
+ name?: string;
95
+ start?: number;
96
+ end?: number;
97
+ }
98
+ interface StorageHandle {
99
+ event(e: Event): Promise<void>;
100
+ entity(e: Entity): Promise<void>;
101
+ metric(m: Metric): Promise<void>;
102
+ edge(e: Edge): Promise<void>;
103
+ distribution(d: Distribution): Promise<void>;
104
+ events(es: Event[], scope?: {
105
+ names?: string[];
106
+ }): Promise<void>;
107
+ entities(es: Entity[], scope?: {
108
+ types?: string[];
109
+ }): Promise<void>;
110
+ metrics(ms: Metric[], scope?: {
111
+ names?: string[];
112
+ }): Promise<void>;
113
+ edges(es: Edge[], scope?: {
114
+ kinds?: string[];
115
+ }): Promise<void>;
116
+ distributions(ds: Distribution[], scope?: {
117
+ names?: string[];
118
+ }): Promise<void>;
119
+ queryEvents(q: EventQuery): Promise<Event[]>;
120
+ getEntity(type: string, id: string): Promise<Entity | null>;
121
+ queryEntities(q: EntityQuery): Promise<Entity[]>;
122
+ queryMetrics(q: MetricQuery): Promise<Metric[]>;
123
+ traverse(q: EdgeQuery): Promise<Edge[]>;
124
+ queryDistributions(q: DistributionQuery): Promise<Distribution[]>;
125
+ deleteOlderThan(shape: 'events' | 'metrics' | 'distributions', tsUnixMs: number): Promise<{
126
+ rowsDeleted: number;
127
+ }>;
128
+ }
129
+ interface CredentialEntry {
130
+ description: string;
131
+ auth?: 'none' | 'optional' | 'required';
132
+ }
133
+ type CredentialSchema = Record<string, CredentialEntry>;
134
+ type InferCredentials<TCreds extends CredentialSchema> = {
135
+ [K in keyof TCreds]: TCreds[K] extends {
136
+ auth: 'required';
137
+ } ? string : string | undefined;
138
+ };
139
+ type InferCredentialInput<TCreds extends CredentialSchema> = {
140
+ [K in keyof TCreds]: TCreds[K] extends {
141
+ auth: 'required';
142
+ } ? string | SecretRef : string | SecretRef | undefined;
143
+ };
144
+ interface SyncRequest {
145
+ mode: 'full' | 'latest';
146
+ since?: string;
147
+ }
148
+ interface Connector {
149
+ readonly id: string;
150
+ readonly credentials?: CredentialSchema;
151
+ sync(request: SyncRequest, storage: StorageHandle, signal?: AbortSignal): Promise<void>;
152
+ }
153
+ declare abstract class BaseConnector<TSettings = unknown, TCreds extends CredentialSchema = CredentialSchema> implements Connector {
154
+ abstract readonly id: string;
155
+ readonly credentials?: TCreds;
156
+ protected settings: TSettings;
157
+ protected creds: InferCredentials<TCreds>;
158
+ constructor(settings: TSettings, creds?: InferCredentialInput<TCreds>);
159
+ abstract sync(request: SyncRequest, storage: StorageHandle, signal?: AbortSignal): Promise<void>;
160
+ }
161
+ declare function defineConnector<TSettings>(): <TCreds extends CredentialSchema = Record<string, never>>(def: {
162
+ id: string;
163
+ credentials?: TCreds;
164
+ sync: (this: {
165
+ settings: TSettings;
166
+ creds: InferCredentials<TCreds>;
167
+ }, request: SyncRequest, storage: StorageHandle, signal?: AbortSignal) => Promise<void>;
168
+ }) => {
169
+ new (settings: TSettings, creds?: InferCredentialInput<TCreds>): Connector;
170
+ readonly id: string;
171
+ readonly credentials: TCreds | undefined;
172
+ };
173
+
174
+ interface RetentionConfig {
175
+ maxAge?: number;
176
+ maxSize?: number;
177
+ floor?: number;
178
+ intervalMs?: number;
179
+ }
180
+ interface RetentionCandidates {
181
+ events: Event[];
182
+ metrics: Metric[];
183
+ distributions: Distribution[];
184
+ }
185
+ declare function selectForDeletion<T>(rows: T[], getTs: (row: T) => number, config: RetentionConfig, nowMs?: number): T[];
186
+ declare function computeRetention(handle: StorageHandle, config: RetentionConfig, nowMs?: number): Promise<RetentionCandidates>;
187
+
188
+ declare const widgetSchemas: {
189
+ readonly stat: z.ZodObject<{
190
+ title: z.ZodString;
191
+ metric: z.ZodString;
192
+ window: z.ZodOptional<z.ZodString>;
193
+ compare: z.ZodDefault<z.ZodEnum<{
194
+ none: "none";
195
+ "previous-period": "previous-period";
196
+ }>>;
197
+ }, z.core.$strip>;
198
+ readonly status: z.ZodObject<{
199
+ title: z.ZodString;
200
+ source: z.ZodString;
201
+ }, z.core.$strip>;
202
+ readonly timeseries: z.ZodObject<{
203
+ title: z.ZodString;
204
+ metric: z.ZodString;
205
+ window: z.ZodString;
206
+ granularity: z.ZodDefault<z.ZodEnum<{
207
+ hour: "hour";
208
+ day: "day";
209
+ week: "week";
210
+ }>>;
211
+ }, z.core.$strip>;
212
+ readonly distribution: z.ZodObject<{
213
+ title: z.ZodString;
214
+ metric: z.ZodString;
215
+ window: z.ZodString;
216
+ }, z.core.$strip>;
217
+ };
218
+ type WidgetKind = keyof typeof widgetSchemas;
219
+ declare function getWidgetSchema(kind: WidgetKind): z.ZodObject<{
220
+ title: z.ZodString;
221
+ metric: z.ZodString;
222
+ window: z.ZodOptional<z.ZodString>;
223
+ compare: z.ZodDefault<z.ZodEnum<{
224
+ none: "none";
225
+ "previous-period": "previous-period";
226
+ }>>;
227
+ }, z.core.$strip> | z.ZodObject<{
228
+ title: z.ZodString;
229
+ source: z.ZodString;
230
+ }, z.core.$strip> | z.ZodObject<{
231
+ title: z.ZodString;
232
+ metric: z.ZodString;
233
+ window: z.ZodString;
234
+ granularity: z.ZodDefault<z.ZodEnum<{
235
+ hour: "hour";
236
+ day: "day";
237
+ week: "week";
238
+ }>>;
239
+ }, z.core.$strip> | z.ZodObject<{
240
+ title: z.ZodString;
241
+ metric: z.ZodString;
242
+ window: z.ZodString;
243
+ }, z.core.$strip>;
244
+
245
+ type AggFn = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'latest' | 'first';
246
+ type Shape = 'event' | 'entity' | 'metric' | 'edge' | 'distribution';
247
+ type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains';
248
+ interface FilterCondition {
249
+ field: string;
250
+ op: FilterOperator;
251
+ value: string | number | boolean;
252
+ }
253
+ type FilterClause = FilterCondition | {
254
+ or: FilterCondition[];
255
+ };
256
+ interface GroupBy {
257
+ field: string;
258
+ granularity: 'hour' | 'day' | 'week' | 'month';
259
+ }
260
+ interface MetricDef {
261
+ connector: {
262
+ id: string;
263
+ };
264
+ shape: Shape;
265
+ name?: string;
266
+ entityType?: string;
267
+ field: string;
268
+ fn: AggFn;
269
+ window?: string;
270
+ filter?: FilterClause[];
271
+ groupBy?: GroupBy;
272
+ }
273
+ interface ResolvedMetric {
274
+ readonly connectorId: string;
275
+ readonly shape: Shape;
276
+ readonly name?: string;
277
+ readonly entityType?: string;
278
+ readonly field: string;
279
+ readonly fn: string;
280
+ readonly window?: string;
281
+ readonly filter?: FilterClause[];
282
+ readonly groupBy?: GroupBy;
283
+ }
284
+ interface StatWidget {
285
+ kind: 'stat';
286
+ title: string;
287
+ metric: ResolvedMetric;
288
+ window?: string;
289
+ compare?: 'none' | 'previous-period';
290
+ }
291
+ interface StatusWidget {
292
+ kind: 'status';
293
+ title: string;
294
+ source: string;
295
+ }
296
+ interface TimeseriesWidget {
297
+ kind: 'timeseries';
298
+ title: string;
299
+ metric: ResolvedMetric;
300
+ window: string;
301
+ granularity?: 'hour' | 'day' | 'week';
302
+ }
303
+ interface DistributionWidget {
304
+ kind: 'distribution';
305
+ title: string;
306
+ metric: ResolvedMetric;
307
+ window: string;
308
+ }
309
+ type Widget = StatWidget | StatusWidget | TimeseriesWidget | DistributionWidget;
310
+
311
+ interface ConnectorEntry {
312
+ connector: Connector;
313
+ }
314
+ interface Dashboard {
315
+ widgets: Record<string, Widget>;
316
+ }
317
+ interface DashboardConfig {
318
+ connectors: ConnectorEntry[];
319
+ dashboards: Record<string, Dashboard>;
320
+ retention?: RetentionConfig;
321
+ }
322
+ declare function defineDashboard(options: {
323
+ widgets: Record<string, Widget>;
324
+ }): Dashboard;
325
+ declare function defineMetric(options: MetricDef): ResolvedMetric;
326
+ declare function defineConfig(config: DashboardConfig): DashboardConfig;
327
+
328
+ interface WidgetEntry {
329
+ id: string;
330
+ widgetId: string;
331
+ connectorId: string;
332
+ data: unknown;
333
+ cachedAt: string | null;
334
+ }
335
+ interface SyncState {
336
+ status: 'idle' | 'syncing' | 'error';
337
+ lastSyncAt: string | null;
338
+ lastError: string | null;
339
+ }
340
+
341
+ type ConfigFieldsSchema = z.ZodObject<z.ZodRawShape>;
342
+ declare function defineConfigFields<T extends z.ZodRawShape>(schema: z.ZodObject<T>): z.ZodObject<T>;
343
+
344
+ export { type AggFn, BaseConnector, type ConfigFieldsSchema, type Connector, type ConnectorEntry, type CredentialEntry, type CredentialSchema, type Dashboard, type DashboardConfig, type Distribution, type DistributionQuery, type DistributionWidget, type Edge, type EdgeQuery, type Entity, type EntityQuery, EnvSecretsResolver, type Event, type EventQuery, type FilterClause, type FilterCondition, type FilterOperator, type GroupBy, type InferCredentialInput, type InferCredentials, type JSONValue, type Metric, type MetricDef, type MetricQuery, type ResolvedMetric, type RetentionCandidates, type RetentionConfig, type SecretRef, type SecretsResolver, type Shape, type StatWidget, type StatusWidget, type StorageHandle, type SyncRequest, type SyncState, type TimeseriesWidget, type Widget, type WidgetEntry, type WidgetKind, computeRetention, defineConfig, defineConfigFields, defineConnector, defineDashboard, defineMetric, getWidgetSchema, isSecretRef, resolveSecretRefs, secret, selectForDeletion, widgetSchemas };
package/dist/index.js ADDED
@@ -0,0 +1,302 @@
1
+ // src/secrets.ts
2
+ function secret(name) {
3
+ if (!/^[A-Z][A-Z0-9_]*$/.test(name)) {
4
+ throw new Error(
5
+ `Invalid secret name "${name}". Must match /^[A-Z][A-Z0-9_]*$/ (uppercase letters, digits, underscores; must start with a letter).`
6
+ );
7
+ }
8
+ return { $secret: name };
9
+ }
10
+ function isSecretRef(value) {
11
+ return typeof value === "object" && value !== null && "$secret" in value && typeof value.$secret === "string";
12
+ }
13
+ var EnvSecretsResolver = class {
14
+ resolve(name) {
15
+ const env = globalThis.process?.env;
16
+ return env?.[name];
17
+ }
18
+ };
19
+ function resolveSecretRefs(obj, resolver) {
20
+ if (isSecretRef(obj)) {
21
+ const name = obj.$secret;
22
+ const value = resolver.resolve(name);
23
+ if (value === void 0) {
24
+ throw new Error(
25
+ `Missing secret "${name}". Set it via process.env.${name} or the CLI: rawdash secrets set ${name} ...`
26
+ );
27
+ }
28
+ return value;
29
+ }
30
+ if (Array.isArray(obj)) {
31
+ return obj.map((item) => resolveSecretRefs(item, resolver));
32
+ }
33
+ if (typeof obj === "object" && obj !== null) {
34
+ const result = {};
35
+ for (const [key, val] of Object.entries(obj)) {
36
+ Object.defineProperty(result, key, {
37
+ value: resolveSecretRefs(val, resolver),
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true
41
+ });
42
+ }
43
+ return result;
44
+ }
45
+ return obj;
46
+ }
47
+
48
+ // src/connector.ts
49
+ var BaseConnector = class {
50
+ credentials;
51
+ settings;
52
+ creds;
53
+ constructor(settings, creds) {
54
+ this.settings = settings;
55
+ this.creds = creds ? resolveSecretRefs(
56
+ creds,
57
+ new EnvSecretsResolver()
58
+ ) : {};
59
+ }
60
+ };
61
+ function defineConnector() {
62
+ return function(def) {
63
+ class DynamicConnector extends BaseConnector {
64
+ static id = def.id;
65
+ static credentials = def.credentials;
66
+ id = def.id;
67
+ credentials = def.credentials;
68
+ async sync(request, storage, signal) {
69
+ return def.sync.call(
70
+ { settings: this.settings, creds: this.creds },
71
+ request,
72
+ storage,
73
+ signal
74
+ );
75
+ }
76
+ }
77
+ return DynamicConnector;
78
+ };
79
+ }
80
+
81
+ // src/widget-schemas.ts
82
+ import { z } from "zod";
83
+ var widgetSchemas = {
84
+ stat: z.object({
85
+ title: z.string().meta({ label: "Title", description: "Widget title." }),
86
+ metric: z.string().meta({ label: "Metric", description: "Metric reference." }),
87
+ window: z.string().optional().meta({ label: "Window", description: "Time window, e.g. '7d'." }),
88
+ compare: z.enum(["none", "previous-period"]).default("none").meta({ label: "Compare", description: "Comparison mode." })
89
+ }),
90
+ status: z.object({
91
+ title: z.string().meta({ label: "Title", description: "Widget title." }),
92
+ source: z.string().meta({
93
+ label: "Source",
94
+ description: "Connector or data source reference."
95
+ })
96
+ }),
97
+ timeseries: z.object({
98
+ title: z.string().meta({ label: "Title", description: "Widget title." }),
99
+ metric: z.string().meta({ label: "Metric", description: "Metric reference." }),
100
+ window: z.string().meta({ label: "Window", description: "Time window, e.g. '30d'." }),
101
+ granularity: z.enum(["hour", "day", "week"]).default("day").meta({ label: "Granularity", description: "Time bucket size." })
102
+ }),
103
+ distribution: z.object({
104
+ title: z.string().meta({ label: "Title", description: "Widget title." }),
105
+ metric: z.string().meta({ label: "Metric", description: "Metric reference." }),
106
+ window: z.string().meta({ label: "Window", description: "Time window, e.g. '7d'." })
107
+ })
108
+ };
109
+ function getWidgetSchema(kind) {
110
+ return widgetSchemas[kind];
111
+ }
112
+
113
+ // src/config.ts
114
+ var VALID_WIDGET_KINDS = new Set(Object.keys(widgetSchemas));
115
+ function defineDashboard(options) {
116
+ for (const [key, widget] of Object.entries(options.widgets)) {
117
+ if (!VALID_WIDGET_KINDS.has(widget.kind)) {
118
+ throw new Error(
119
+ `Widget "${key}": unknown kind "${widget.kind}". Must be one of: ${[...VALID_WIDGET_KINDS].join(", ")}`
120
+ );
121
+ }
122
+ const schema = getWidgetSchema(widget.kind);
123
+ const parseInput = { ...widget };
124
+ if (widget.kind !== "status") {
125
+ const m = widget.metric;
126
+ if (typeof m !== "object" || m === null) {
127
+ throw new Error(
128
+ `Widget "${key}" (kind "${widget.kind}"): metric is required`
129
+ );
130
+ }
131
+ parseInput.metric = "placeholder";
132
+ }
133
+ const result = schema.safeParse(parseInput);
134
+ if (!result.success) {
135
+ throw new Error(
136
+ `Widget "${key}" (kind "${widget.kind}"): ${result.error.issues.map((i) => i.message).join("; ")}`
137
+ );
138
+ }
139
+ }
140
+ return { widgets: options.widgets };
141
+ }
142
+ function defineMetric(options) {
143
+ return {
144
+ connectorId: options.connector.id,
145
+ shape: options.shape,
146
+ name: options.name,
147
+ entityType: options.entityType,
148
+ field: options.field,
149
+ fn: options.fn,
150
+ window: options.window,
151
+ filter: options.filter,
152
+ groupBy: options.groupBy
153
+ };
154
+ }
155
+ var VALID_SHAPES = /* @__PURE__ */ new Set([
156
+ "event",
157
+ "entity",
158
+ "metric",
159
+ "edge",
160
+ "distribution"
161
+ ]);
162
+ var VALID_FNS = /* @__PURE__ */ new Set([
163
+ "count",
164
+ "sum",
165
+ "avg",
166
+ "min",
167
+ "max",
168
+ "latest",
169
+ "first"
170
+ ]);
171
+ var SAFE_KEY_RE = /^[a-zA-Z0-9_-]+$/;
172
+ function validateConfig(config) {
173
+ if (config.retention) {
174
+ const { maxAge, maxSize, floor, intervalMs } = config.retention;
175
+ if (maxAge !== void 0 && (!Number.isFinite(maxAge) || maxAge < 0)) {
176
+ throw new Error("retention.maxAge must be a finite number >= 0");
177
+ }
178
+ if (maxSize !== void 0 && (!Number.isInteger(maxSize) || maxSize < 0)) {
179
+ throw new Error("retention.maxSize must be an integer >= 0");
180
+ }
181
+ if (floor !== void 0 && (!Number.isInteger(floor) || floor < 0)) {
182
+ throw new Error("retention.floor must be an integer >= 0");
183
+ }
184
+ if (intervalMs !== void 0 && (!Number.isFinite(intervalMs) || intervalMs <= 0)) {
185
+ throw new Error("retention.intervalMs must be a finite number > 0");
186
+ }
187
+ }
188
+ if (!config.dashboards || typeof config.dashboards !== "object" || Array.isArray(config.dashboards)) {
189
+ throw new Error(
190
+ 'defineConfig: config must include a "dashboards" record \u2014 did you mean to migrate from the old flat "widgets" shape?'
191
+ );
192
+ }
193
+ const connectorIds = new Set(config.connectors.map((e) => e.connector.id));
194
+ for (const [dashboardKey, dashboard] of Object.entries(config.dashboards)) {
195
+ if (!dashboard.widgets || typeof dashboard.widgets !== "object" || Array.isArray(dashboard.widgets)) {
196
+ throw new Error(
197
+ `Dashboard "${dashboardKey}" must define a "widgets" record`
198
+ );
199
+ }
200
+ if (!SAFE_KEY_RE.test(dashboardKey)) {
201
+ throw new Error(
202
+ `Dashboard key "${dashboardKey}" contains URL-unsafe characters; use only letters, digits, hyphens, and underscores`
203
+ );
204
+ }
205
+ for (const [widgetKey, widget] of Object.entries(dashboard.widgets)) {
206
+ const ref = `Dashboard "${dashboardKey}", widget "${widgetKey}"`;
207
+ if (!SAFE_KEY_RE.test(widgetKey)) {
208
+ throw new Error(
209
+ `${ref}: widget key contains URL-unsafe characters; use only letters, digits, hyphens, and underscores`
210
+ );
211
+ }
212
+ if (widget.kind === "status") {
213
+ continue;
214
+ }
215
+ const { connectorId, shape, fn } = widget.metric;
216
+ if (!connectorIds.has(connectorId)) {
217
+ throw new Error(
218
+ `${ref}: connector "${connectorId}" is not listed in connectors`
219
+ );
220
+ }
221
+ if (!VALID_SHAPES.has(shape)) {
222
+ throw new Error(`${ref}: invalid shape "${shape}"`);
223
+ }
224
+ if (!VALID_FNS.has(fn)) {
225
+ throw new Error(`${ref}: invalid fn "${fn}"`);
226
+ }
227
+ }
228
+ }
229
+ }
230
+ function defineConfig(config) {
231
+ validateConfig(config);
232
+ return config;
233
+ }
234
+
235
+ // src/retention.ts
236
+ function selectForDeletion(rows, getTs, config, nowMs = Date.now()) {
237
+ const { maxAge, maxSize, floor = 0 } = config;
238
+ if (maxAge === void 0 && maxSize === void 0) {
239
+ return [];
240
+ }
241
+ const toDelete = [];
242
+ for (let i = 0; i < rows.length; i++) {
243
+ const row = rows[i];
244
+ if (i < floor) {
245
+ continue;
246
+ }
247
+ const overSize = maxSize !== void 0 && i >= maxSize;
248
+ const tooOld = maxAge !== void 0 && getTs(row) < nowMs - maxAge;
249
+ if (overSize || tooOld) {
250
+ toDelete.push(row);
251
+ }
252
+ }
253
+ return toDelete;
254
+ }
255
+ async function computeRetention(handle, config, nowMs = Date.now()) {
256
+ const [events, metrics, distributions] = await Promise.all([
257
+ handle.queryEvents({}),
258
+ handle.queryMetrics({}),
259
+ handle.queryDistributions({})
260
+ ]);
261
+ const sortedEvents = [...events].sort((a, b) => b.start_ts - a.start_ts);
262
+ const sortedMetrics = [...metrics].sort((a, b) => b.ts - a.ts);
263
+ const sortedDistributions = [...distributions].sort((a, b) => b.ts - a.ts);
264
+ return {
265
+ events: selectForDeletion(sortedEvents, (e) => e.start_ts, config, nowMs),
266
+ metrics: selectForDeletion(sortedMetrics, (m) => m.ts, config, nowMs),
267
+ distributions: selectForDeletion(
268
+ sortedDistributions,
269
+ (d) => d.ts,
270
+ config,
271
+ nowMs
272
+ )
273
+ };
274
+ }
275
+
276
+ // src/config-fields.ts
277
+ import { z as z2 } from "zod";
278
+ function defineConfigFields(schema) {
279
+ if (!(schema instanceof z2.ZodObject)) {
280
+ throw new Error(
281
+ `configFields must be a Zod object schema (z.object({...})). Received: ${Object.prototype.toString.call(schema)}`
282
+ );
283
+ }
284
+ return schema;
285
+ }
286
+ export {
287
+ BaseConnector,
288
+ EnvSecretsResolver,
289
+ computeRetention,
290
+ defineConfig,
291
+ defineConfigFields,
292
+ defineConnector,
293
+ defineDashboard,
294
+ defineMetric,
295
+ getWidgetSchema,
296
+ isSecretRef,
297
+ resolveSecretRefs,
298
+ secret,
299
+ selectForDeletion,
300
+ widgetSchemas
301
+ };
302
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/secrets.ts","../src/connector.ts","../src/widget-schemas.ts","../src/config.ts","../src/retention.ts","../src/config-fields.ts"],"sourcesContent":["export type SecretRef = { $secret: string };\n\nexport function secret(name: string): SecretRef {\n if (!/^[A-Z][A-Z0-9_]*$/.test(name)) {\n throw new Error(\n `Invalid secret name \"${name}\". Must match /^[A-Z][A-Z0-9_]*$/ ` +\n `(uppercase letters, digits, underscores; must start with a letter).`,\n );\n }\n return { $secret: name };\n}\n\nexport function isSecretRef(value: unknown): value is SecretRef {\n return (\n typeof value === 'object' &&\n value !== null &&\n '$secret' in value &&\n typeof (value as SecretRef).$secret === 'string'\n );\n}\n\nexport interface SecretsResolver {\n resolve(name: string): string | undefined;\n}\n\nexport class EnvSecretsResolver implements SecretsResolver {\n resolve(name: string): string | undefined {\n const env = (\n globalThis as { process?: { env?: Record<string, string | undefined> } }\n ).process?.env;\n return env?.[name];\n }\n}\n\nexport function resolveSecretRefs<T>(obj: T, resolver: SecretsResolver): T {\n if (isSecretRef(obj)) {\n const name = obj.$secret;\n const value = resolver.resolve(name);\n if (value === undefined) {\n throw new Error(\n `Missing secret \"${name}\". Set it via process.env.${name} or the CLI: rawdash secrets set ${name} ...`,\n );\n }\n return value as unknown as T;\n }\n if (Array.isArray(obj)) {\n return obj.map((item) => resolveSecretRefs(item, resolver)) as unknown as T;\n }\n if (typeof obj === 'object' && obj !== null) {\n const result: Record<string, unknown> = {};\n for (const [key, val] of Object.entries(obj as object)) {\n Object.defineProperty(result, key, {\n value: resolveSecretRefs(val, resolver),\n enumerable: true,\n configurable: true,\n writable: true,\n });\n }\n return result as T;\n }\n return obj;\n}\n","import {\n EnvSecretsResolver,\n type SecretRef,\n resolveSecretRefs,\n} from './secrets';\n\nexport type JSONValue =\n | string\n | number\n | boolean\n | null\n | JSONValue[]\n | { [key: string]: JSONValue };\n\n// ---------------------------------------------------------------------------\n// Five storage shapes\n// ---------------------------------------------------------------------------\n\nexport interface Event {\n name: string;\n start_ts: number;\n end_ts: number | null;\n attributes: Record<string, JSONValue>;\n}\n\nexport interface Entity {\n type: string;\n id: string;\n attributes: Record<string, JSONValue>;\n updated_at: number;\n}\n\nexport interface Metric {\n name: string;\n ts: number;\n value: number;\n attributes: Record<string, JSONValue>;\n}\n\nexport interface Edge {\n from_type: string;\n from_id: string;\n kind: string;\n to_type: string;\n to_id: string;\n attributes: Record<string, JSONValue>;\n updated_at: number;\n}\n\nexport type Distribution =\n | {\n name: string;\n ts: number;\n kind: 'histogram';\n data: {\n buckets: Array<{ le: number; count: number }>;\n count: number;\n sum: number;\n };\n attributes: Record<string, JSONValue>;\n }\n | {\n name: string;\n ts: number;\n kind: 'summary';\n data: {\n quantiles: Array<{ q: number; value: number }>;\n count: number;\n sum: number;\n };\n attributes: Record<string, JSONValue>;\n };\n\n// ---------------------------------------------------------------------------\n// Storage query types\n// ---------------------------------------------------------------------------\n\nexport interface EventQuery {\n name?: string;\n start?: number;\n end?: number;\n}\n\nexport interface EntityQuery {\n type: string;\n}\n\nexport interface MetricQuery {\n name?: string;\n start?: number;\n end?: number;\n}\n\nexport interface EdgeQuery {\n fromType?: string;\n fromId?: string;\n kind?: string;\n toType?: string;\n toId?: string;\n}\n\nexport interface DistributionQuery {\n name?: string;\n start?: number;\n end?: number;\n}\n\n// ---------------------------------------------------------------------------\n// StorageHandle — write and read surface\n// ---------------------------------------------------------------------------\n\nexport interface StorageHandle {\n event(e: Event): Promise<void>;\n entity(e: Entity): Promise<void>;\n metric(m: Metric): Promise<void>;\n edge(e: Edge): Promise<void>;\n distribution(d: Distribution): Promise<void>;\n\n events(es: Event[], scope?: { names?: string[] }): Promise<void>;\n entities(es: Entity[], scope?: { types?: string[] }): Promise<void>;\n metrics(ms: Metric[], scope?: { names?: string[] }): Promise<void>;\n edges(es: Edge[], scope?: { kinds?: string[] }): Promise<void>;\n distributions(\n ds: Distribution[],\n scope?: { names?: string[] },\n ): Promise<void>;\n\n queryEvents(q: EventQuery): Promise<Event[]>;\n getEntity(type: string, id: string): Promise<Entity | null>;\n queryEntities(q: EntityQuery): Promise<Entity[]>;\n queryMetrics(q: MetricQuery): Promise<Metric[]>;\n traverse(q: EdgeQuery): Promise<Edge[]>;\n queryDistributions(q: DistributionQuery): Promise<Distribution[]>;\n\n // Deletes all rows in the given time-series shape whose timestamp column is\n // strictly less than `tsUnixMs`. Only covers append-only shapes (events,\n // metrics, distributions). Entities and edges are excluded because they hold\n // the latest known state per primary key — deleting by age would lose live\n // data. The right model for those shapes is \"expire when source disappears.\"\n deleteOlderThan(\n shape: 'events' | 'metrics' | 'distributions',\n tsUnixMs: number,\n ): Promise<{ rowsDeleted: number }>;\n}\n\n// ---------------------------------------------------------------------------\n// Credentials\n// ---------------------------------------------------------------------------\n\nexport interface CredentialEntry {\n description: string;\n auth?: 'none' | 'optional' | 'required';\n}\n\nexport type CredentialSchema = Record<string, CredentialEntry>;\n\nexport type InferCredentials<TCreds extends CredentialSchema> = {\n [K in keyof TCreds]: TCreds[K] extends { auth: 'required' }\n ? string\n : string | undefined;\n};\n\nexport type InferCredentialInput<TCreds extends CredentialSchema> = {\n [K in keyof TCreds]: TCreds[K] extends { auth: 'required' }\n ? string | SecretRef\n : string | SecretRef | undefined;\n};\n\n// ---------------------------------------------------------------------------\n// Sync + Connector\n// ---------------------------------------------------------------------------\n\nexport interface SyncRequest {\n mode: 'full' | 'latest';\n since?: string;\n}\n\nexport interface Connector {\n readonly id: string;\n readonly credentials?: CredentialSchema;\n sync(\n request: SyncRequest,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<void>;\n}\n\nexport abstract class BaseConnector<\n TSettings = unknown,\n TCreds extends CredentialSchema = CredentialSchema,\n> implements Connector {\n abstract readonly id: string;\n readonly credentials?: TCreds;\n\n protected settings: TSettings;\n protected creds: InferCredentials<TCreds>;\n\n constructor(settings: TSettings, creds?: InferCredentialInput<TCreds>) {\n this.settings = settings;\n this.creds = creds\n ? (resolveSecretRefs(\n creds,\n new EnvSecretsResolver(),\n ) as InferCredentials<TCreds>)\n : ({} as InferCredentials<TCreds>);\n }\n\n abstract sync(\n request: SyncRequest,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<void>;\n}\n\nexport function defineConnector<TSettings>() {\n return function <\n TCreds extends CredentialSchema = Record<string, never>,\n >(def: {\n id: string;\n credentials?: TCreds;\n sync: (\n this: { settings: TSettings; creds: InferCredentials<TCreds> },\n request: SyncRequest,\n storage: StorageHandle,\n signal?: AbortSignal,\n ) => Promise<void>;\n }): {\n new (settings: TSettings, creds?: InferCredentialInput<TCreds>): Connector;\n readonly id: string;\n readonly credentials: TCreds | undefined;\n } {\n class DynamicConnector extends BaseConnector<TSettings, TCreds> {\n static readonly id = def.id;\n static readonly credentials = def.credentials;\n\n readonly id = def.id;\n override readonly credentials = def.credentials;\n\n async sync(\n request: SyncRequest,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<void> {\n return def.sync.call(\n { settings: this.settings, creds: this.creds },\n request,\n storage,\n signal,\n );\n }\n }\n\n return DynamicConnector as unknown as {\n new (\n settings: TSettings,\n creds?: InferCredentialInput<TCreds>,\n ): Connector;\n readonly id: string;\n readonly credentials: TCreds | undefined;\n };\n };\n}\n","import { z } from 'zod';\n\nexport const widgetSchemas = {\n stat: z.object({\n title: z.string().meta({ label: 'Title', description: 'Widget title.' }),\n metric: z\n .string()\n .meta({ label: 'Metric', description: 'Metric reference.' }),\n window: z\n .string()\n .optional()\n .meta({ label: 'Window', description: \"Time window, e.g. '7d'.\" }),\n compare: z\n .enum(['none', 'previous-period'])\n .default('none')\n .meta({ label: 'Compare', description: 'Comparison mode.' }),\n }),\n status: z.object({\n title: z.string().meta({ label: 'Title', description: 'Widget title.' }),\n source: z.string().meta({\n label: 'Source',\n description: 'Connector or data source reference.',\n }),\n }),\n timeseries: z.object({\n title: z.string().meta({ label: 'Title', description: 'Widget title.' }),\n metric: z\n .string()\n .meta({ label: 'Metric', description: 'Metric reference.' }),\n window: z\n .string()\n .meta({ label: 'Window', description: \"Time window, e.g. '30d'.\" }),\n granularity: z\n .enum(['hour', 'day', 'week'])\n .default('day')\n .meta({ label: 'Granularity', description: 'Time bucket size.' }),\n }),\n distribution: z.object({\n title: z.string().meta({ label: 'Title', description: 'Widget title.' }),\n metric: z\n .string()\n .meta({ label: 'Metric', description: 'Metric reference.' }),\n window: z\n .string()\n .meta({ label: 'Window', description: \"Time window, e.g. '7d'.\" }),\n }),\n} as const;\n\nexport type WidgetKind = keyof typeof widgetSchemas;\n\nexport function getWidgetSchema(kind: WidgetKind) {\n return widgetSchemas[kind];\n}\n","import type { Connector } from './connector';\nimport type { RetentionConfig } from './retention';\nimport { getWidgetSchema, widgetSchemas } from './widget-schemas';\nimport type { WidgetKind } from './widget-schemas';\n\n// ---------------------------------------------------------------------------\n// Aggregation functions\n// ---------------------------------------------------------------------------\n\nexport type AggFn =\n | 'count'\n | 'sum'\n | 'avg'\n | 'min'\n | 'max'\n | 'latest'\n | 'first';\n\n// ---------------------------------------------------------------------------\n// Shape\n// ---------------------------------------------------------------------------\n\nexport type Shape = 'event' | 'entity' | 'metric' | 'edge' | 'distribution';\n\n// ---------------------------------------------------------------------------\n// Filters\n// ---------------------------------------------------------------------------\n\nexport type FilterOperator =\n | 'eq'\n | 'neq'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'contains';\n\nexport interface FilterCondition {\n field: string;\n op: FilterOperator;\n value: string | number | boolean;\n}\n\nexport type FilterClause = FilterCondition | { or: FilterCondition[] };\n\n// ---------------------------------------------------------------------------\n// GroupBy\n// ---------------------------------------------------------------------------\n\nexport interface GroupBy {\n field: string;\n granularity: 'hour' | 'day' | 'week' | 'month';\n}\n\n// ---------------------------------------------------------------------------\n// Metric definition\n// ---------------------------------------------------------------------------\n\nexport interface MetricDef {\n connector: { id: string };\n shape: Shape;\n name?: string;\n entityType?: string;\n field: string;\n fn: AggFn;\n window?: string;\n filter?: FilterClause[];\n groupBy?: GroupBy;\n}\n\nexport interface ResolvedMetric {\n readonly connectorId: string;\n readonly shape: Shape;\n readonly name?: string;\n readonly entityType?: string;\n readonly field: string;\n readonly fn: string;\n readonly window?: string;\n readonly filter?: FilterClause[];\n readonly groupBy?: GroupBy;\n}\n\n// ---------------------------------------------------------------------------\n// Widget definition\n// ---------------------------------------------------------------------------\n\nexport interface StatWidget {\n kind: 'stat';\n title: string;\n metric: ResolvedMetric;\n window?: string;\n compare?: 'none' | 'previous-period';\n}\n\nexport interface StatusWidget {\n kind: 'status';\n title: string;\n source: string;\n}\n\nexport interface TimeseriesWidget {\n kind: 'timeseries';\n title: string;\n metric: ResolvedMetric;\n window: string;\n granularity?: 'hour' | 'day' | 'week';\n}\n\nexport interface DistributionWidget {\n kind: 'distribution';\n title: string;\n metric: ResolvedMetric;\n window: string;\n}\n\nexport type Widget =\n | StatWidget\n | StatusWidget\n | TimeseriesWidget\n | DistributionWidget;\n\nexport type { WidgetKind };\n\n// ---------------------------------------------------------------------------\n// Dashboard config\n// ---------------------------------------------------------------------------\n\nexport interface ConnectorEntry {\n connector: Connector;\n}\n\nexport interface Dashboard {\n widgets: Record<string, Widget>;\n}\n\nexport interface DashboardConfig {\n connectors: ConnectorEntry[];\n dashboards: Record<string, Dashboard>;\n retention?: RetentionConfig;\n}\n\n// ---------------------------------------------------------------------------\n// defineDashboard\n// ---------------------------------------------------------------------------\n\nconst VALID_WIDGET_KINDS = new Set<string>(Object.keys(widgetSchemas));\n\nexport function defineDashboard(options: {\n widgets: Record<string, Widget>;\n}): Dashboard {\n for (const [key, widget] of Object.entries(options.widgets)) {\n if (!VALID_WIDGET_KINDS.has(widget.kind)) {\n throw new Error(\n `Widget \"${key}\": unknown kind \"${widget.kind}\". Must be one of: ${[...VALID_WIDGET_KINDS].join(', ')}`,\n );\n }\n const schema = getWidgetSchema(widget.kind as WidgetKind);\n const parseInput: Record<string, unknown> = { ...widget };\n if (widget.kind !== 'status') {\n const m = (widget as { metric?: unknown }).metric;\n if (typeof m !== 'object' || m === null) {\n throw new Error(\n `Widget \"${key}\" (kind \"${widget.kind}\"): metric is required`,\n );\n }\n parseInput.metric = 'placeholder';\n }\n const result = schema.safeParse(parseInput);\n if (!result.success) {\n throw new Error(\n `Widget \"${key}\" (kind \"${widget.kind}\"): ${result.error.issues.map((i) => i.message).join('; ')}`,\n );\n }\n }\n return { widgets: options.widgets };\n}\n\n// ---------------------------------------------------------------------------\n// defineMetric\n// ---------------------------------------------------------------------------\n\nexport function defineMetric(options: MetricDef): ResolvedMetric {\n return {\n connectorId: options.connector.id,\n shape: options.shape,\n name: options.name,\n entityType: options.entityType,\n field: options.field,\n fn: options.fn,\n window: options.window,\n filter: options.filter,\n groupBy: options.groupBy,\n };\n}\n\n// ---------------------------------------------------------------------------\n// defineConfig\n// ---------------------------------------------------------------------------\n\nconst VALID_SHAPES = new Set<string>([\n 'event',\n 'entity',\n 'metric',\n 'edge',\n 'distribution',\n]);\nconst VALID_FNS = new Set<string>([\n 'count',\n 'sum',\n 'avg',\n 'min',\n 'max',\n 'latest',\n 'first',\n]);\n\nconst SAFE_KEY_RE = /^[a-zA-Z0-9_-]+$/;\n\nfunction validateConfig(config: DashboardConfig): void {\n if (config.retention) {\n const { maxAge, maxSize, floor, intervalMs } = config.retention;\n if (maxAge !== undefined && (!Number.isFinite(maxAge) || maxAge < 0)) {\n throw new Error('retention.maxAge must be a finite number >= 0');\n }\n if (maxSize !== undefined && (!Number.isInteger(maxSize) || maxSize < 0)) {\n throw new Error('retention.maxSize must be an integer >= 0');\n }\n if (floor !== undefined && (!Number.isInteger(floor) || floor < 0)) {\n throw new Error('retention.floor must be an integer >= 0');\n }\n if (\n intervalMs !== undefined &&\n (!Number.isFinite(intervalMs) || intervalMs <= 0)\n ) {\n throw new Error('retention.intervalMs must be a finite number > 0');\n }\n }\n\n if (\n !config.dashboards ||\n typeof config.dashboards !== 'object' ||\n Array.isArray(config.dashboards)\n ) {\n throw new Error(\n 'defineConfig: config must include a \"dashboards\" record — did you mean to migrate from the old flat \"widgets\" shape?',\n );\n }\n\n const connectorIds = new Set(config.connectors.map((e) => e.connector.id));\n\n for (const [dashboardKey, dashboard] of Object.entries(config.dashboards)) {\n if (\n !dashboard.widgets ||\n typeof dashboard.widgets !== 'object' ||\n Array.isArray(dashboard.widgets)\n ) {\n throw new Error(\n `Dashboard \"${dashboardKey}\" must define a \"widgets\" record`,\n );\n }\n\n if (!SAFE_KEY_RE.test(dashboardKey)) {\n throw new Error(\n `Dashboard key \"${dashboardKey}\" contains URL-unsafe characters; use only letters, digits, hyphens, and underscores`,\n );\n }\n\n for (const [widgetKey, widget] of Object.entries(dashboard.widgets)) {\n const ref = `Dashboard \"${dashboardKey}\", widget \"${widgetKey}\"`;\n\n if (!SAFE_KEY_RE.test(widgetKey)) {\n throw new Error(\n `${ref}: widget key contains URL-unsafe characters; use only letters, digits, hyphens, and underscores`,\n );\n }\n\n if (widget.kind === 'status') {\n continue;\n }\n\n const { connectorId, shape, fn } = widget.metric;\n\n if (!connectorIds.has(connectorId)) {\n throw new Error(\n `${ref}: connector \"${connectorId}\" is not listed in connectors`,\n );\n }\n\n if (!VALID_SHAPES.has(shape)) {\n throw new Error(`${ref}: invalid shape \"${shape}\"`);\n }\n\n if (!VALID_FNS.has(fn)) {\n throw new Error(`${ref}: invalid fn \"${fn}\"`);\n }\n }\n }\n}\n\nexport function defineConfig(config: DashboardConfig): DashboardConfig {\n validateConfig(config);\n return config;\n}\n","import type { Distribution, Event, Metric, StorageHandle } from './connector';\n\n// ---------------------------------------------------------------------------\n// RetentionConfig\n// ---------------------------------------------------------------------------\n\nexport interface RetentionConfig {\n maxAge?: number;\n maxSize?: number;\n floor?: number;\n intervalMs?: number;\n}\n\n// ---------------------------------------------------------------------------\n// RetentionCandidates — rows eligible for deletion across time-series shapes\n// ---------------------------------------------------------------------------\n\nexport interface RetentionCandidates {\n events: Event[];\n metrics: Metric[];\n distributions: Distribution[];\n}\n\n// ---------------------------------------------------------------------------\n// selectForDeletion — pure computation\n//\n// Receives rows pre-sorted newest-first (descending by timestamp).\n// Returns the subset that should be deleted given the policy.\n//\n// Rules applied in order:\n// 1. Rows beyond maxSize are candidates.\n// 2. Rows older than maxAge milliseconds are candidates.\n// 3. Rows within the newest `floor` positions are always kept (overrides 1 & 2).\n// ---------------------------------------------------------------------------\n\nexport function selectForDeletion<T>(\n rows: T[],\n getTs: (row: T) => number,\n config: RetentionConfig,\n nowMs: number = Date.now(),\n): T[] {\n const { maxAge, maxSize, floor = 0 } = config;\n\n if (maxAge === undefined && maxSize === undefined) {\n return [];\n }\n\n const toDelete: T[] = [];\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!;\n if (i < floor) {\n continue;\n }\n\n const overSize = maxSize !== undefined && i >= maxSize;\n const tooOld = maxAge !== undefined && getTs(row) < nowMs - maxAge;\n\n if (overSize || tooOld) {\n toDelete.push(row);\n }\n }\n\n return toDelete;\n}\n\n// ---------------------------------------------------------------------------\n// computeRetention — async, queries the handle and returns deletion candidates\n//\n// Only covers time-series shapes (events, metrics, distributions) since those\n// grow unboundedly via append. Entities and edges are upsert-keyed and do not\n// accumulate the same way.\n// ---------------------------------------------------------------------------\n\nexport async function computeRetention(\n handle: StorageHandle,\n config: RetentionConfig,\n nowMs: number = Date.now(),\n): Promise<RetentionCandidates> {\n const [events, metrics, distributions] = await Promise.all([\n handle.queryEvents({}),\n handle.queryMetrics({}),\n handle.queryDistributions({}),\n ]);\n\n const sortedEvents = [...events].sort((a, b) => b.start_ts - a.start_ts);\n const sortedMetrics = [...metrics].sort((a, b) => b.ts - a.ts);\n const sortedDistributions = [...distributions].sort((a, b) => b.ts - a.ts);\n\n return {\n events: selectForDeletion(sortedEvents, (e) => e.start_ts, config, nowMs),\n metrics: selectForDeletion(sortedMetrics, (m) => m.ts, config, nowMs),\n distributions: selectForDeletion(\n sortedDistributions,\n (d) => d.ts,\n config,\n nowMs,\n ),\n };\n}\n","import { z } from 'zod';\n\nexport type ConfigFieldsSchema = z.ZodObject<z.ZodRawShape>;\n\nexport function defineConfigFields<T extends z.ZodRawShape>(\n schema: z.ZodObject<T>,\n): z.ZodObject<T> {\n if (!(schema instanceof z.ZodObject)) {\n throw new Error(\n `configFields must be a Zod object schema (z.object({...})). Received: ${Object.prototype.toString.call(schema)}`,\n );\n }\n return schema;\n}\n"],"mappings":";AAEO,SAAS,OAAO,MAAyB;AAC9C,MAAI,CAAC,oBAAoB,KAAK,IAAI,GAAG;AACnC,UAAM,IAAI;AAAA,MACR,wBAAwB,IAAI;AAAA,IAE9B;AAAA,EACF;AACA,SAAO,EAAE,SAAS,KAAK;AACzB;AAEO,SAAS,YAAY,OAAoC;AAC9D,SACE,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,OAAQ,MAAoB,YAAY;AAE5C;AAMO,IAAM,qBAAN,MAAoD;AAAA,EACzD,QAAQ,MAAkC;AACxC,UAAM,MACJ,WACA,SAAS;AACX,WAAO,MAAM,IAAI;AAAA,EACnB;AACF;AAEO,SAAS,kBAAqB,KAAQ,UAA8B;AACzE,MAAI,YAAY,GAAG,GAAG;AACpB,UAAM,OAAO,IAAI;AACjB,UAAM,QAAQ,SAAS,QAAQ,IAAI;AACnC,QAAI,UAAU,QAAW;AACvB,YAAM,IAAI;AAAA,QACR,mBAAmB,IAAI,6BAA6B,IAAI,oCAAoC,IAAI;AAAA,MAClG;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,IAAI,CAAC,SAAS,kBAAkB,MAAM,QAAQ,CAAC;AAAA,EAC5D;AACA,MAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,UAAM,SAAkC,CAAC;AACzC,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAQ,GAAa,GAAG;AACtD,aAAO,eAAe,Q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D,OAAO,YAAY,CAAC,CAAC;AAAA,IACrB,OAAO,aAAa,CAAC,CAAC;AAAA,IACtB,OAAO,mBAAmB,CAAC,CAAC;AAAA,EAC9B,CAAC;AAED,QAAM,eAAe,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AACvE,QAAM,gBAAgB,CAAC,GAAG,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE;AAC7D,QAAM,sBAAsB,CAAC,GAAG,aAAa,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE;AAEzE,SAAO;AAAA,IACL,QAAQ,kBAAkB,cAAc,CAAC,MAAM,EAAE,UAAU,QAAQ,KAAK;AAAA,IACxE,SAAS,kBAAkB,eAAe,CAAC,MAAM,EAAE,IAAI,QAAQ,KAAK;AAAA,IACpE,eAAe;AAAA,MACb;AAAA,MACA,CAAC,MAAM,EAAE;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;;;ACnGA,SAAS,KAAAA,UAAS;AAIX,SAAS,mBACd,QACgB;AAChB,MAAI,EAAE,kBAAkBA,GAAE,YAAY;AACpC,UAAM,IAAI;AAAA,MACR,yEAAyE,OAAO,UAAU,SAAS,KAAK,MAAM,CAAC;AAAA,IACjH;AAAA,EACF;AACA,SAAO;AACT;","names":["z"]}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@rawdash/core",
3
+ "version": "0.1.0",
4
+ "description": "Rawdash core — headless dashboard backend primitives",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/rawdash/rawdash.git",
10
+ "directory": "packages/core"
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
+ "zod": "^4.4.3"
26
+ },
27
+ "devDependencies": {
28
+ "tsup": "^8.0.0",
29
+ "typescript": "^5.7.2"
30
+ },
31
+ "scripts": {
32
+ "build": "tsup",
33
+ "typecheck": "tsc --noEmit",
34
+ "lint": "eslint src",
35
+ "test": "vitest run"
36
+ }
37
+ }