@rawdash/core 0.2.0 → 0.4.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.
@@ -1,209 +0,0 @@
1
- type SecretRef = {
2
- $secret: string;
3
- };
4
- declare function secret(name: string): SecretRef;
5
- declare function isSecretRef(value: unknown): value is SecretRef;
6
- interface SecretsResolver {
7
- resolve(name: string): string | undefined;
8
- }
9
- declare class EnvSecretsResolver implements SecretsResolver {
10
- resolve(name: string): string | undefined;
11
- }
12
- declare function resolveSecretRefs<T>(obj: T, resolver: SecretsResolver): T;
13
-
14
- type JSONValue = string | number | boolean | null | JSONValue[] | {
15
- [key: string]: JSONValue;
16
- };
17
- interface Event {
18
- name: string;
19
- start_ts: number;
20
- end_ts: number | null;
21
- attributes: Record<string, JSONValue>;
22
- }
23
- interface Entity {
24
- type: string;
25
- id: string;
26
- attributes: Record<string, JSONValue>;
27
- updated_at: number;
28
- }
29
- interface Metric {
30
- name: string;
31
- ts: number;
32
- value: number;
33
- attributes: Record<string, JSONValue>;
34
- }
35
- interface Edge {
36
- from_type: string;
37
- from_id: string;
38
- kind: string;
39
- to_type: string;
40
- to_id: string;
41
- attributes: Record<string, JSONValue>;
42
- updated_at: number;
43
- }
44
- type Distribution = {
45
- name: string;
46
- ts: number;
47
- kind: 'histogram';
48
- data: {
49
- buckets: Array<{
50
- le: number;
51
- count: number;
52
- }>;
53
- count: number;
54
- sum: number;
55
- };
56
- attributes: Record<string, JSONValue>;
57
- } | {
58
- name: string;
59
- ts: number;
60
- kind: 'summary';
61
- data: {
62
- quantiles: Array<{
63
- q: number;
64
- value: number;
65
- }>;
66
- count: number;
67
- sum: number;
68
- };
69
- attributes: Record<string, JSONValue>;
70
- };
71
- interface EventQuery {
72
- name?: string;
73
- start?: number;
74
- end?: number;
75
- }
76
- interface EntityQuery {
77
- type: string;
78
- }
79
- interface MetricQuery {
80
- name?: string;
81
- start?: number;
82
- end?: number;
83
- }
84
- interface EdgeQuery {
85
- fromType?: string;
86
- fromId?: string;
87
- kind?: string;
88
- toType?: string;
89
- toId?: string;
90
- }
91
- interface DistributionQuery {
92
- name?: string;
93
- start?: number;
94
- end?: number;
95
- }
96
- interface StorageHandle {
97
- event(e: Event): Promise<void>;
98
- entity(e: Entity): Promise<void>;
99
- metric(m: Metric): Promise<void>;
100
- edge(e: Edge): Promise<void>;
101
- distribution(d: Distribution): Promise<void>;
102
- events(es: Event[], scope?: {
103
- names?: string[];
104
- }): Promise<void>;
105
- entities(es: Entity[], scope?: {
106
- types?: string[];
107
- }): Promise<void>;
108
- metrics(ms: Metric[], scope?: {
109
- names?: string[];
110
- }): Promise<void>;
111
- edges(es: Edge[], scope?: {
112
- kinds?: string[];
113
- }): Promise<void>;
114
- distributions(ds: Distribution[], scope?: {
115
- names?: string[];
116
- }): Promise<void>;
117
- queryEvents(q: EventQuery): Promise<Event[]>;
118
- getEntity(type: string, id: string): Promise<Entity | null>;
119
- queryEntities(q: EntityQuery): Promise<Entity[]>;
120
- queryMetrics(q: MetricQuery): Promise<Metric[]>;
121
- traverse(q: EdgeQuery): Promise<Edge[]>;
122
- queryDistributions(q: DistributionQuery): Promise<Distribution[]>;
123
- deleteOlderThan(shape: 'events' | 'metrics' | 'distributions', tsUnixMs: number): Promise<{
124
- rowsDeleted: number;
125
- }>;
126
- }
127
- interface CredentialEntry {
128
- description: string;
129
- auth?: 'none' | 'optional' | 'required';
130
- }
131
- type CredentialSchema = Record<string, CredentialEntry>;
132
- type InferCredentials<TCreds extends CredentialSchema> = {
133
- [K in keyof TCreds]: TCreds[K] extends {
134
- auth: 'required';
135
- } ? string : string | undefined;
136
- };
137
- type InferCredentialInput<TCreds extends CredentialSchema> = {
138
- [K in keyof TCreds]: TCreds[K] extends {
139
- auth: 'required';
140
- } ? string | SecretRef : string | SecretRef | undefined;
141
- };
142
- interface SyncRequest {
143
- mode: 'full' | 'latest';
144
- since?: string;
145
- }
146
- interface Connector {
147
- readonly id: string;
148
- readonly credentials?: CredentialSchema;
149
- serializeConfig(): Record<string, unknown>;
150
- sync(request: SyncRequest, storage: StorageHandle, signal?: AbortSignal): Promise<void>;
151
- }
152
- interface RetryOptions {
153
- maxAttempts?: number;
154
- initialDelayMs?: number;
155
- maxDelayMs?: number;
156
- signal?: AbortSignal;
157
- }
158
- declare abstract class BaseConnector<TSettings = unknown, TCreds extends CredentialSchema = CredentialSchema> implements Connector {
159
- abstract readonly id: string;
160
- readonly credentials?: TCreds;
161
- protected settings: TSettings;
162
- protected creds: InferCredentials<TCreds>;
163
- private rawCredInput;
164
- constructor(settings: TSettings, creds?: InferCredentialInput<TCreds>);
165
- serializeConfig(): Record<string, unknown>;
166
- protected sleep(ms: number, signal?: AbortSignal): Promise<void>;
167
- protected withRetry<T>(fn: (signal?: AbortSignal) => Promise<{
168
- status: 'done';
169
- value: T;
170
- } | {
171
- status: 'retry';
172
- }>, options?: RetryOptions): Promise<T | null>;
173
- abstract sync(request: SyncRequest, storage: StorageHandle, signal?: AbortSignal): Promise<void>;
174
- }
175
- declare function defineConnector<TSettings>(): <TCreds extends CredentialSchema = Record<string, never>>(def: {
176
- id: string;
177
- credentials?: TCreds;
178
- sync: (this: {
179
- settings: TSettings;
180
- creds: InferCredentials<TCreds>;
181
- }, request: SyncRequest, storage: StorageHandle, signal?: AbortSignal) => Promise<void>;
182
- }) => {
183
- new (settings: TSettings, creds?: InferCredentialInput<TCreds>): Connector;
184
- readonly id: string;
185
- readonly credentials: TCreds | undefined;
186
- };
187
-
188
- interface WidgetEntry {
189
- id: string;
190
- widgetId: string;
191
- connectorId: string;
192
- data: unknown;
193
- cachedAt: string | null;
194
- }
195
- interface SyncState {
196
- status: 'idle' | 'syncing' | 'error';
197
- lastSyncAt: string | null;
198
- lastError: string | null;
199
- }
200
-
201
- interface ServerStorage {
202
- getStorageHandle(connectorId: string): StorageHandle;
203
- getSyncState(): Promise<SyncState>;
204
- setSyncing(): Promise<boolean>;
205
- setSyncSuccess(): Promise<void>;
206
- setSyncError(error: string): Promise<void>;
207
- }
208
-
209
- export { BaseConnector as B, type Connector as C, type Distribution as D, type Event as E, type InferCredentialInput as I, type JSONValue as J, type Metric as M, type StorageHandle as S, type WidgetEntry as W, type ServerStorage as a, type SyncState as b, type CredentialEntry as c, type CredentialSchema as d, type DistributionQuery as e, type Edge as f, type EdgeQuery as g, type Entity as h, type EntityQuery as i, EnvSecretsResolver as j, type EventQuery as k, type InferCredentials as l, type MetricQuery as m, type SecretRef as n, type SecretsResolver as o, type SyncRequest as p, defineConnector as q, isSecretRef as r, resolveSecretRefs as s, secret as t };