@secondlayer/shared 0.12.3 → 1.0.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/README.md +5 -7
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.js.map +2 -2
- package/dist/src/db/index.d.ts +3 -64
- package/dist/src/db/index.js +2 -2
- package/dist/src/db/index.js.map +2 -2
- package/dist/src/db/queries/accounts.d.ts +2 -51
- package/dist/src/db/queries/integrity.d.ts +2 -51
- package/dist/src/db/queries/marketplace.d.ts +2 -51
- package/dist/src/db/queries/projects.d.ts +2 -51
- package/dist/src/db/queries/subgraph-gaps.d.ts +2 -51
- package/dist/src/db/queries/subgraphs.d.ts +3 -51
- package/dist/src/db/queries/subgraphs.js +3 -1
- package/dist/src/db/queries/subgraphs.js.map +3 -3
- package/dist/src/db/queries/usage.d.ts +3 -56
- package/dist/src/db/queries/usage.js +1 -19
- package/dist/src/db/queries/usage.js.map +4 -4
- package/dist/src/db/queries/workflows.d.ts +7 -53
- package/dist/src/db/queries/workflows.js +130 -13
- package/dist/src/db/queries/workflows.js.map +5 -4
- package/dist/src/db/schema.d.ts +3 -64
- package/dist/src/errors.d.ts +19 -50
- package/dist/src/errors.js +28 -45
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index.d.ts +25 -256
- package/dist/src/index.js +32 -234
- package/dist/src/index.js.map +7 -9
- package/dist/src/lib/plans.d.ts +0 -1
- package/dist/src/lib/plans.js +1 -2
- package/dist/src/lib/plans.js.map +3 -3
- package/dist/src/node/local-client.d.ts +2 -51
- package/dist/src/queue/listener.d.ts +1 -18
- package/dist/src/queue/listener.js +2 -12
- package/dist/src/queue/listener.js.map +3 -3
- package/dist/src/schemas/filters.d.ts +3 -3
- package/dist/src/schemas/filters.js +3 -3
- package/dist/src/schemas/filters.js.map +3 -3
- package/dist/src/schemas/index.d.ts +5 -100
- package/dist/src/schemas/index.js +4 -88
- package/dist/src/schemas/index.js.map +5 -6
- package/dist/src/schemas/subgraphs.d.ts +2 -0
- package/dist/src/schemas/subgraphs.js +2 -1
- package/dist/src/schemas/subgraphs.js.map +3 -3
- package/dist/src/schemas/workflows.d.ts +4 -0
- package/dist/src/schemas/workflows.js +5 -1
- package/dist/src/schemas/workflows.js.map +3 -3
- package/dist/src/types.d.ts +1 -53
- package/migrations/0030_workflow_source_code.ts +21 -0
- package/migrations/0031_subgraph_source_code.ts +18 -0
- package/migrations/0032_drop_streams_tables.ts +43 -0
- package/package.json +2 -14
- package/dist/src/db/queries/metrics.d.ts +0 -419
- package/dist/src/db/queries/metrics.js +0 -55
- package/dist/src/db/queries/metrics.js.map +0 -10
- package/dist/src/queue/index.d.ts +0 -50
- package/dist/src/queue/index.js +0 -184
- package/dist/src/queue/index.js.map +0 -12
- package/dist/src/queue/recovery.d.ts +0 -14
- package/dist/src/queue/recovery.js +0 -108
- package/dist/src/queue/recovery.js.map +0 -12
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
import { Kysely } from "kysely";
|
|
2
|
-
import { Generated, Selectable } from "kysely";
|
|
3
|
-
interface BlocksTable {
|
|
4
|
-
height: number;
|
|
5
|
-
hash: string;
|
|
6
|
-
parent_hash: string;
|
|
7
|
-
burn_block_height: number;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
canonical: Generated<boolean>;
|
|
10
|
-
created_at: Generated<Date>;
|
|
11
|
-
}
|
|
12
|
-
interface TransactionsTable {
|
|
13
|
-
tx_id: string;
|
|
14
|
-
block_height: number;
|
|
15
|
-
tx_index: Generated<number>;
|
|
16
|
-
type: string;
|
|
17
|
-
sender: string;
|
|
18
|
-
status: string;
|
|
19
|
-
contract_id: string | null;
|
|
20
|
-
function_name: string | null;
|
|
21
|
-
function_args: Generated<unknown | null>;
|
|
22
|
-
raw_result: Generated<string | null>;
|
|
23
|
-
raw_tx: string;
|
|
24
|
-
created_at: Generated<Date>;
|
|
25
|
-
}
|
|
26
|
-
interface EventsTable {
|
|
27
|
-
id: Generated<string>;
|
|
28
|
-
tx_id: string;
|
|
29
|
-
block_height: number;
|
|
30
|
-
event_index: number;
|
|
31
|
-
type: string;
|
|
32
|
-
data: unknown;
|
|
33
|
-
created_at: Generated<Date>;
|
|
34
|
-
}
|
|
35
|
-
interface StreamsTable {
|
|
36
|
-
id: Generated<string>;
|
|
37
|
-
name: string;
|
|
38
|
-
status: Generated<string>;
|
|
39
|
-
filters: unknown;
|
|
40
|
-
options: Generated<unknown>;
|
|
41
|
-
endpoint_url: string;
|
|
42
|
-
signing_secret: string | null;
|
|
43
|
-
api_key_id: string;
|
|
44
|
-
project_id: string | null;
|
|
45
|
-
created_at: Generated<Date>;
|
|
46
|
-
updated_at: Generated<Date>;
|
|
47
|
-
}
|
|
48
|
-
interface StreamMetricsTable {
|
|
49
|
-
stream_id: string;
|
|
50
|
-
last_triggered_at: Date | null;
|
|
51
|
-
last_triggered_block: number | null;
|
|
52
|
-
total_deliveries: Generated<number>;
|
|
53
|
-
failed_deliveries: Generated<number>;
|
|
54
|
-
error_message: string | null;
|
|
55
|
-
}
|
|
56
|
-
interface JobsTable {
|
|
57
|
-
id: Generated<string>;
|
|
58
|
-
stream_id: string;
|
|
59
|
-
block_height: number;
|
|
60
|
-
status: Generated<string>;
|
|
61
|
-
attempts: Generated<number>;
|
|
62
|
-
locked_at: Date | null;
|
|
63
|
-
locked_by: string | null;
|
|
64
|
-
error: string | null;
|
|
65
|
-
backfill: Generated<boolean>;
|
|
66
|
-
created_at: Generated<Date>;
|
|
67
|
-
completed_at: Date | null;
|
|
68
|
-
}
|
|
69
|
-
interface IndexProgressTable {
|
|
70
|
-
network: string;
|
|
71
|
-
last_indexed_block: Generated<number>;
|
|
72
|
-
last_contiguous_block: Generated<number>;
|
|
73
|
-
highest_seen_block: Generated<number>;
|
|
74
|
-
updated_at: Generated<Date>;
|
|
75
|
-
}
|
|
76
|
-
interface DeliveriesTable {
|
|
77
|
-
id: Generated<string>;
|
|
78
|
-
stream_id: string;
|
|
79
|
-
job_id: string | null;
|
|
80
|
-
block_height: number;
|
|
81
|
-
status: string;
|
|
82
|
-
status_code: number | null;
|
|
83
|
-
response_time_ms: number | null;
|
|
84
|
-
attempts: Generated<number>;
|
|
85
|
-
error: string | null;
|
|
86
|
-
payload: unknown;
|
|
87
|
-
created_at: Generated<Date>;
|
|
88
|
-
}
|
|
89
|
-
interface SubgraphsTable {
|
|
90
|
-
id: Generated<string>;
|
|
91
|
-
name: string;
|
|
92
|
-
version: Generated<string>;
|
|
93
|
-
status: Generated<string>;
|
|
94
|
-
definition: Record<string, unknown>;
|
|
95
|
-
schema_hash: string;
|
|
96
|
-
handler_path: string;
|
|
97
|
-
schema_name: string | null;
|
|
98
|
-
start_block: Generated<number>;
|
|
99
|
-
last_processed_block: Generated<number>;
|
|
100
|
-
reindex_from_block: number | null;
|
|
101
|
-
reindex_to_block: number | null;
|
|
102
|
-
last_error: string | null;
|
|
103
|
-
last_error_at: Date | null;
|
|
104
|
-
total_processed: Generated<number>;
|
|
105
|
-
total_errors: Generated<number>;
|
|
106
|
-
api_key_id: string | null;
|
|
107
|
-
account_id: string;
|
|
108
|
-
handler_code: string | null;
|
|
109
|
-
project_id: string | null;
|
|
110
|
-
is_public: Generated<boolean>;
|
|
111
|
-
tags: Generated<string[]>;
|
|
112
|
-
description: string | null;
|
|
113
|
-
forked_from_id: string | null;
|
|
114
|
-
created_at: Generated<Date>;
|
|
115
|
-
updated_at: Generated<Date>;
|
|
116
|
-
}
|
|
117
|
-
interface SubgraphGapsTable {
|
|
118
|
-
id: Generated<string>;
|
|
119
|
-
subgraph_id: string;
|
|
120
|
-
subgraph_name: string;
|
|
121
|
-
gap_start: number;
|
|
122
|
-
gap_end: number;
|
|
123
|
-
reason: string;
|
|
124
|
-
detected_at: Generated<Date>;
|
|
125
|
-
resolved_at: Date | null;
|
|
126
|
-
}
|
|
127
|
-
interface ApiKeysTable {
|
|
128
|
-
id: Generated<string>;
|
|
129
|
-
key_hash: string;
|
|
130
|
-
key_prefix: string;
|
|
131
|
-
name: string | null;
|
|
132
|
-
status: Generated<string>;
|
|
133
|
-
rate_limit: Generated<number>;
|
|
134
|
-
ip_address: string;
|
|
135
|
-
account_id: string;
|
|
136
|
-
last_used_at: Date | null;
|
|
137
|
-
revoked_at: Date | null;
|
|
138
|
-
created_at: Generated<Date>;
|
|
139
|
-
}
|
|
140
|
-
interface AccountsTable {
|
|
141
|
-
id: Generated<string>;
|
|
142
|
-
email: string;
|
|
143
|
-
plan: Generated<string>;
|
|
144
|
-
display_name: string | null;
|
|
145
|
-
bio: string | null;
|
|
146
|
-
avatar_url: string | null;
|
|
147
|
-
slug: string | null;
|
|
148
|
-
created_at: Generated<Date>;
|
|
149
|
-
}
|
|
150
|
-
interface SessionsTable {
|
|
151
|
-
id: Generated<string>;
|
|
152
|
-
token_hash: string;
|
|
153
|
-
token_prefix: string;
|
|
154
|
-
account_id: string;
|
|
155
|
-
ip_address: string;
|
|
156
|
-
expires_at: Generated<Date>;
|
|
157
|
-
revoked_at: Date | null;
|
|
158
|
-
last_used_at: Date | null;
|
|
159
|
-
created_at: Generated<Date>;
|
|
160
|
-
}
|
|
161
|
-
interface MagicLinksTable {
|
|
162
|
-
id: Generated<string>;
|
|
163
|
-
email: string;
|
|
164
|
-
token: string;
|
|
165
|
-
code: string | null;
|
|
166
|
-
expires_at: Date;
|
|
167
|
-
used_at: Date | null;
|
|
168
|
-
failed_attempts: Generated<number>;
|
|
169
|
-
created_at: Generated<Date>;
|
|
170
|
-
}
|
|
171
|
-
interface UsageDailyTable {
|
|
172
|
-
account_id: string;
|
|
173
|
-
date: string;
|
|
174
|
-
api_requests: Generated<number>;
|
|
175
|
-
deliveries: Generated<number>;
|
|
176
|
-
}
|
|
177
|
-
interface UsageSnapshotsTable {
|
|
178
|
-
id: Generated<string>;
|
|
179
|
-
account_id: string;
|
|
180
|
-
measured_at: Generated<Date>;
|
|
181
|
-
storage_bytes: Generated<number>;
|
|
182
|
-
}
|
|
183
|
-
interface WaitlistTable {
|
|
184
|
-
id: Generated<string>;
|
|
185
|
-
email: string;
|
|
186
|
-
source: Generated<string>;
|
|
187
|
-
status: Generated<string>;
|
|
188
|
-
created_at: Generated<Date>;
|
|
189
|
-
}
|
|
190
|
-
interface AccountInsightsTable {
|
|
191
|
-
id: Generated<string>;
|
|
192
|
-
account_id: string;
|
|
193
|
-
category: string;
|
|
194
|
-
insight_type: string;
|
|
195
|
-
resource_id: string | null;
|
|
196
|
-
severity: string;
|
|
197
|
-
title: string;
|
|
198
|
-
body: string;
|
|
199
|
-
data: unknown;
|
|
200
|
-
dismissed_at: Date | null;
|
|
201
|
-
expires_at: Date | null;
|
|
202
|
-
created_at: Generated<Date>;
|
|
203
|
-
}
|
|
204
|
-
interface AccountAgentRunsTable {
|
|
205
|
-
id: Generated<string>;
|
|
206
|
-
account_id: string;
|
|
207
|
-
started_at: Generated<Date>;
|
|
208
|
-
completed_at: Date | null;
|
|
209
|
-
status: Generated<string>;
|
|
210
|
-
input_tokens: Generated<number>;
|
|
211
|
-
output_tokens: Generated<number>;
|
|
212
|
-
cost_usd: Generated<number>;
|
|
213
|
-
insights_created: Generated<number>;
|
|
214
|
-
error: string | null;
|
|
215
|
-
}
|
|
216
|
-
interface SubgraphProcessingStatsTable {
|
|
217
|
-
id: Generated<string>;
|
|
218
|
-
subgraph_name: string;
|
|
219
|
-
api_key_id: string | null;
|
|
220
|
-
bucket_start: Date | null;
|
|
221
|
-
bucket_end: Date | null;
|
|
222
|
-
blocks_processed: number | null;
|
|
223
|
-
total_time_ms: number | null;
|
|
224
|
-
handler_time_ms: number | null;
|
|
225
|
-
flush_time_ms: number | null;
|
|
226
|
-
max_block_time_ms: number | null;
|
|
227
|
-
max_handler_time_ms: number | null;
|
|
228
|
-
avg_ops_per_block: number | null;
|
|
229
|
-
is_catchup: Generated<boolean>;
|
|
230
|
-
created_at: Generated<Date>;
|
|
231
|
-
}
|
|
232
|
-
interface SubgraphTableSnapshotsTable {
|
|
233
|
-
id: Generated<string>;
|
|
234
|
-
subgraph_name: string;
|
|
235
|
-
api_key_id: string | null;
|
|
236
|
-
table_name: string;
|
|
237
|
-
row_count: number | null;
|
|
238
|
-
created_at: Generated<Date>;
|
|
239
|
-
}
|
|
240
|
-
interface SubgraphHealthSnapshotsTable {
|
|
241
|
-
id: Generated<string>;
|
|
242
|
-
subgraph_id: string;
|
|
243
|
-
total_processed: number;
|
|
244
|
-
total_errors: number;
|
|
245
|
-
last_processed_block: number | null;
|
|
246
|
-
captured_at: Generated<Date>;
|
|
247
|
-
}
|
|
248
|
-
interface SubgraphUsageDailyTable {
|
|
249
|
-
subgraph_id: string;
|
|
250
|
-
date: string;
|
|
251
|
-
query_count: Generated<number>;
|
|
252
|
-
}
|
|
253
|
-
interface ProjectsTable {
|
|
254
|
-
id: Generated<string>;
|
|
255
|
-
name: string;
|
|
256
|
-
slug: string;
|
|
257
|
-
account_id: string;
|
|
258
|
-
settings: Generated<Record<string, unknown>>;
|
|
259
|
-
network: Generated<string>;
|
|
260
|
-
node_rpc: string | null;
|
|
261
|
-
created_at: Generated<Date>;
|
|
262
|
-
updated_at: Generated<Date>;
|
|
263
|
-
}
|
|
264
|
-
interface TeamMembersTable {
|
|
265
|
-
id: Generated<string>;
|
|
266
|
-
project_id: string;
|
|
267
|
-
account_id: string;
|
|
268
|
-
role: Generated<string>;
|
|
269
|
-
invited_by: string | null;
|
|
270
|
-
created_at: Generated<Date>;
|
|
271
|
-
}
|
|
272
|
-
interface TeamInvitationsTable {
|
|
273
|
-
id: Generated<string>;
|
|
274
|
-
project_id: string;
|
|
275
|
-
email: string;
|
|
276
|
-
role: Generated<string>;
|
|
277
|
-
token: string;
|
|
278
|
-
invited_by: string | null;
|
|
279
|
-
expires_at: Date;
|
|
280
|
-
accepted_at: Date | null;
|
|
281
|
-
created_at: Generated<Date>;
|
|
282
|
-
}
|
|
283
|
-
interface ChatSessionsTable {
|
|
284
|
-
id: Generated<string>;
|
|
285
|
-
account_id: string;
|
|
286
|
-
title: string | null;
|
|
287
|
-
summary: unknown | null;
|
|
288
|
-
created_at: Generated<Date>;
|
|
289
|
-
updated_at: Generated<Date>;
|
|
290
|
-
}
|
|
291
|
-
interface ChatMessagesTable {
|
|
292
|
-
id: Generated<string>;
|
|
293
|
-
chat_session_id: string;
|
|
294
|
-
role: string;
|
|
295
|
-
parts: unknown;
|
|
296
|
-
metadata: unknown | null;
|
|
297
|
-
created_at: Generated<Date>;
|
|
298
|
-
}
|
|
299
|
-
interface WorkflowDefinitionsTable {
|
|
300
|
-
id: Generated<string>;
|
|
301
|
-
name: string;
|
|
302
|
-
version: Generated<string>;
|
|
303
|
-
status: Generated<string>;
|
|
304
|
-
trigger_type: string;
|
|
305
|
-
trigger_config: unknown;
|
|
306
|
-
handler_path: string;
|
|
307
|
-
retries_config: unknown | null;
|
|
308
|
-
timeout_ms: number | null;
|
|
309
|
-
api_key_id: string;
|
|
310
|
-
project_id: string | null;
|
|
311
|
-
created_at: Generated<Date>;
|
|
312
|
-
updated_at: Generated<Date>;
|
|
313
|
-
}
|
|
314
|
-
interface WorkflowRunsTable {
|
|
315
|
-
id: Generated<string>;
|
|
316
|
-
definition_id: string;
|
|
317
|
-
status: Generated<string>;
|
|
318
|
-
trigger_type: string;
|
|
319
|
-
trigger_data: unknown | null;
|
|
320
|
-
dedup_key: string | null;
|
|
321
|
-
error: string | null;
|
|
322
|
-
started_at: Date | null;
|
|
323
|
-
completed_at: Date | null;
|
|
324
|
-
duration_ms: number | null;
|
|
325
|
-
total_ai_tokens: Generated<number>;
|
|
326
|
-
created_at: Generated<Date>;
|
|
327
|
-
}
|
|
328
|
-
interface WorkflowStepsTable {
|
|
329
|
-
id: Generated<string>;
|
|
330
|
-
run_id: string;
|
|
331
|
-
step_index: number;
|
|
332
|
-
step_id: string;
|
|
333
|
-
step_type: string;
|
|
334
|
-
status: Generated<string>;
|
|
335
|
-
input: unknown | null;
|
|
336
|
-
output: unknown | null;
|
|
337
|
-
error: string | null;
|
|
338
|
-
retry_count: Generated<number>;
|
|
339
|
-
ai_tokens_used: Generated<number>;
|
|
340
|
-
started_at: Date | null;
|
|
341
|
-
completed_at: Date | null;
|
|
342
|
-
duration_ms: number | null;
|
|
343
|
-
created_at: Generated<Date>;
|
|
344
|
-
}
|
|
345
|
-
interface WorkflowQueueTable {
|
|
346
|
-
id: Generated<string>;
|
|
347
|
-
run_id: string;
|
|
348
|
-
status: Generated<string>;
|
|
349
|
-
attempts: Generated<number>;
|
|
350
|
-
max_attempts: Generated<number>;
|
|
351
|
-
scheduled_for: Generated<Date>;
|
|
352
|
-
locked_at: Date | null;
|
|
353
|
-
locked_by: string | null;
|
|
354
|
-
error: string | null;
|
|
355
|
-
created_at: Generated<Date>;
|
|
356
|
-
completed_at: Date | null;
|
|
357
|
-
}
|
|
358
|
-
interface WorkflowSchedulesTable {
|
|
359
|
-
id: Generated<string>;
|
|
360
|
-
definition_id: string;
|
|
361
|
-
cron_expr: string;
|
|
362
|
-
timezone: Generated<string>;
|
|
363
|
-
next_run_at: Date;
|
|
364
|
-
last_run_at: Date | null;
|
|
365
|
-
enabled: Generated<boolean>;
|
|
366
|
-
created_at: Generated<Date>;
|
|
367
|
-
}
|
|
368
|
-
interface WorkflowCursorsTable {
|
|
369
|
-
name: string;
|
|
370
|
-
block_height: Generated<number>;
|
|
371
|
-
updated_at: Generated<Date>;
|
|
372
|
-
}
|
|
373
|
-
interface Database {
|
|
374
|
-
blocks: BlocksTable;
|
|
375
|
-
transactions: TransactionsTable;
|
|
376
|
-
events: EventsTable;
|
|
377
|
-
streams: StreamsTable;
|
|
378
|
-
stream_metrics: StreamMetricsTable;
|
|
379
|
-
jobs: JobsTable;
|
|
380
|
-
index_progress: IndexProgressTable;
|
|
381
|
-
deliveries: DeliveriesTable;
|
|
382
|
-
subgraphs: SubgraphsTable;
|
|
383
|
-
api_keys: ApiKeysTable;
|
|
384
|
-
accounts: AccountsTable;
|
|
385
|
-
sessions: SessionsTable;
|
|
386
|
-
magic_links: MagicLinksTable;
|
|
387
|
-
usage_daily: UsageDailyTable;
|
|
388
|
-
usage_snapshots: UsageSnapshotsTable;
|
|
389
|
-
waitlist: WaitlistTable;
|
|
390
|
-
account_insights: AccountInsightsTable;
|
|
391
|
-
account_agent_runs: AccountAgentRunsTable;
|
|
392
|
-
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
393
|
-
subgraph_processing_stats: SubgraphProcessingStatsTable;
|
|
394
|
-
subgraph_table_snapshots: SubgraphTableSnapshotsTable;
|
|
395
|
-
subgraph_gaps: SubgraphGapsTable;
|
|
396
|
-
subgraph_usage_daily: SubgraphUsageDailyTable;
|
|
397
|
-
projects: ProjectsTable;
|
|
398
|
-
team_members: TeamMembersTable;
|
|
399
|
-
team_invitations: TeamInvitationsTable;
|
|
400
|
-
chat_sessions: ChatSessionsTable;
|
|
401
|
-
chat_messages: ChatMessagesTable;
|
|
402
|
-
workflow_definitions: WorkflowDefinitionsTable;
|
|
403
|
-
workflow_runs: WorkflowRunsTable;
|
|
404
|
-
workflow_steps: WorkflowStepsTable;
|
|
405
|
-
workflow_queue: WorkflowQueueTable;
|
|
406
|
-
workflow_schedules: WorkflowSchedulesTable;
|
|
407
|
-
workflow_cursors: WorkflowCursorsTable;
|
|
408
|
-
}
|
|
409
|
-
type StreamMetrics = Selectable<StreamMetricsTable>;
|
|
410
|
-
declare function getStreamMetrics(db: Kysely<Database>, streamId: string): Promise<StreamMetrics | null>;
|
|
411
|
-
declare function updateStreamMetrics(db: Kysely<Database>, streamId: string, updates: Partial<{
|
|
412
|
-
lastTriggeredAt: Date
|
|
413
|
-
lastTriggeredBlock: number
|
|
414
|
-
totalDeliveries: number
|
|
415
|
-
failedDeliveries: number
|
|
416
|
-
errorMessage: string | null
|
|
417
|
-
}>): Promise<void>;
|
|
418
|
-
declare function incrementDeliveryCount(db: Kysely<Database>, streamId: string, failed: boolean): Promise<void>;
|
|
419
|
-
export { updateStreamMetrics, incrementDeliveryCount, getStreamMetrics };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __returnValue = (v) => v;
|
|
4
|
-
function __exportSetter(name, newValue) {
|
|
5
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
-
}
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
set: __exportSetter.bind(all, name)
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// src/db/queries/metrics.ts
|
|
18
|
-
import { sql } from "kysely";
|
|
19
|
-
async function getStreamMetrics(db, streamId) {
|
|
20
|
-
return await db.selectFrom("stream_metrics").selectAll().where("stream_id", "=", streamId).executeTakeFirst() ?? null;
|
|
21
|
-
}
|
|
22
|
-
async function updateStreamMetrics(db, streamId, updates) {
|
|
23
|
-
await db.insertInto("stream_metrics").values({
|
|
24
|
-
stream_id: streamId,
|
|
25
|
-
last_triggered_at: updates.lastTriggeredAt ?? null,
|
|
26
|
-
last_triggered_block: updates.lastTriggeredBlock ?? null,
|
|
27
|
-
total_deliveries: updates.totalDeliveries ?? 0,
|
|
28
|
-
failed_deliveries: updates.failedDeliveries ?? 0,
|
|
29
|
-
error_message: updates.errorMessage ?? null
|
|
30
|
-
}).onConflict((oc) => oc.column("stream_id").doUpdateSet({
|
|
31
|
-
...updates.lastTriggeredAt !== undefined ? { last_triggered_at: updates.lastTriggeredAt } : {},
|
|
32
|
-
...updates.lastTriggeredBlock !== undefined ? { last_triggered_block: updates.lastTriggeredBlock } : {},
|
|
33
|
-
...updates.totalDeliveries !== undefined ? { total_deliveries: updates.totalDeliveries } : {},
|
|
34
|
-
...updates.failedDeliveries !== undefined ? { failed_deliveries: updates.failedDeliveries } : {},
|
|
35
|
-
...updates.errorMessage !== undefined ? { error_message: updates.errorMessage } : {}
|
|
36
|
-
})).execute();
|
|
37
|
-
}
|
|
38
|
-
async function incrementDeliveryCount(db, streamId, failed) {
|
|
39
|
-
await db.insertInto("stream_metrics").values({
|
|
40
|
-
stream_id: streamId,
|
|
41
|
-
total_deliveries: 1,
|
|
42
|
-
failed_deliveries: failed ? 1 : 0
|
|
43
|
-
}).onConflict((oc) => oc.column("stream_id").doUpdateSet({
|
|
44
|
-
total_deliveries: sql`stream_metrics.total_deliveries + 1`,
|
|
45
|
-
...failed ? { failed_deliveries: sql`stream_metrics.failed_deliveries + 1` } : {}
|
|
46
|
-
})).execute();
|
|
47
|
-
}
|
|
48
|
-
export {
|
|
49
|
-
updateStreamMetrics,
|
|
50
|
-
incrementDeliveryCount,
|
|
51
|
-
getStreamMetrics
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
//# debugId=B4106C2E1F1C5A3F64756E2164756E21
|
|
55
|
-
//# sourceMappingURL=metrics.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/db/queries/metrics.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { type Kysely, sql } from \"kysely\";\nimport type { Database, StreamMetrics } from \"../types.ts\";\n\nexport async function getStreamMetrics(\n\tdb: Kysely<Database>,\n\tstreamId: string,\n): Promise<StreamMetrics | null> {\n\treturn (\n\t\t(await db\n\t\t\t.selectFrom(\"stream_metrics\")\n\t\t\t.selectAll()\n\t\t\t.where(\"stream_id\", \"=\", streamId)\n\t\t\t.executeTakeFirst()) ?? null\n\t);\n}\n\nexport async function updateStreamMetrics(\n\tdb: Kysely<Database>,\n\tstreamId: string,\n\tupdates: Partial<{\n\t\tlastTriggeredAt: Date;\n\t\tlastTriggeredBlock: number;\n\t\ttotalDeliveries: number;\n\t\tfailedDeliveries: number;\n\t\terrorMessage: string | null;\n\t}>,\n): Promise<void> {\n\tawait db\n\t\t.insertInto(\"stream_metrics\")\n\t\t.values({\n\t\t\tstream_id: streamId,\n\t\t\tlast_triggered_at: updates.lastTriggeredAt ?? null,\n\t\t\tlast_triggered_block: updates.lastTriggeredBlock ?? null,\n\t\t\ttotal_deliveries: updates.totalDeliveries ?? 0,\n\t\t\tfailed_deliveries: updates.failedDeliveries ?? 0,\n\t\t\terror_message: updates.errorMessage ?? null,\n\t\t})\n\t\t.onConflict((oc) =>\n\t\t\toc.column(\"stream_id\").doUpdateSet({\n\t\t\t\t...(updates.lastTriggeredAt !== undefined\n\t\t\t\t\t? { last_triggered_at: updates.lastTriggeredAt }\n\t\t\t\t\t: {}),\n\t\t\t\t...(updates.lastTriggeredBlock !== undefined\n\t\t\t\t\t? { last_triggered_block: updates.lastTriggeredBlock }\n\t\t\t\t\t: {}),\n\t\t\t\t...(updates.totalDeliveries !== undefined\n\t\t\t\t\t? { total_deliveries: updates.totalDeliveries }\n\t\t\t\t\t: {}),\n\t\t\t\t...(updates.failedDeliveries !== undefined\n\t\t\t\t\t? { failed_deliveries: updates.failedDeliveries }\n\t\t\t\t\t: {}),\n\t\t\t\t...(updates.errorMessage !== undefined\n\t\t\t\t\t? { error_message: updates.errorMessage }\n\t\t\t\t\t: {}),\n\t\t\t}),\n\t\t)\n\t\t.execute();\n}\n\nexport async function incrementDeliveryCount(\n\tdb: Kysely<Database>,\n\tstreamId: string,\n\tfailed: boolean,\n): Promise<void> {\n\tawait db\n\t\t.insertInto(\"stream_metrics\")\n\t\t.values({\n\t\t\tstream_id: streamId,\n\t\t\ttotal_deliveries: 1,\n\t\t\tfailed_deliveries: failed ? 1 : 0,\n\t\t})\n\t\t.onConflict((oc) =>\n\t\t\toc.column(\"stream_id\").doUpdateSet({\n\t\t\t\ttotal_deliveries: sql`stream_metrics.total_deliveries + 1`,\n\t\t\t\t...(failed\n\t\t\t\t\t? { failed_deliveries: sql`stream_metrics.failed_deliveries + 1` }\n\t\t\t\t\t: {}),\n\t\t\t}),\n\t\t)\n\t\t.execute();\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAGA,eAAsB,gBAAgB,CACrC,IACA,UACgC;AAAA,EAChC,OACE,MAAM,GACL,WAAW,gBAAgB,EAC3B,UAAU,EACV,MAAM,aAAa,KAAK,QAAQ,EAChC,iBAAiB,KAAM;AAAA;AAI3B,eAAsB,mBAAmB,CACxC,IACA,UACA,SAOgB;AAAA,EAChB,MAAM,GACJ,WAAW,gBAAgB,EAC3B,OAAO;AAAA,IACP,WAAW;AAAA,IACX,mBAAmB,QAAQ,mBAAmB;AAAA,IAC9C,sBAAsB,QAAQ,sBAAsB;AAAA,IACpD,kBAAkB,QAAQ,mBAAmB;AAAA,IAC7C,mBAAmB,QAAQ,oBAAoB;AAAA,IAC/C,eAAe,QAAQ,gBAAgB;AAAA,EACxC,CAAC,EACA,WAAW,CAAC,OACZ,GAAG,OAAO,WAAW,EAAE,YAAY;AAAA,OAC9B,QAAQ,oBAAoB,YAC7B,EAAE,mBAAmB,QAAQ,gBAAgB,IAC7C,CAAC;AAAA,OACA,QAAQ,uBAAuB,YAChC,EAAE,sBAAsB,QAAQ,mBAAmB,IACnD,CAAC;AAAA,OACA,QAAQ,oBAAoB,YAC7B,EAAE,kBAAkB,QAAQ,gBAAgB,IAC5C,CAAC;AAAA,OACA,QAAQ,qBAAqB,YAC9B,EAAE,mBAAmB,QAAQ,iBAAiB,IAC9C,CAAC;AAAA,OACA,QAAQ,iBAAiB,YAC1B,EAAE,eAAe,QAAQ,aAAa,IACtC,CAAC;AAAA,EACL,CAAC,CACF,EACC,QAAQ;AAAA;AAGX,eAAsB,sBAAsB,CAC3C,IACA,UACA,QACgB;AAAA,EAChB,MAAM,GACJ,WAAW,gBAAgB,EAC3B,OAAO;AAAA,IACP,WAAW;AAAA,IACX,kBAAkB;AAAA,IAClB,mBAAmB,SAAS,IAAI;AAAA,EACjC,CAAC,EACA,WAAW,CAAC,OACZ,GAAG,OAAO,WAAW,EAAE,YAAY;AAAA,IAClC,kBAAkB;AAAA,OACd,SACD,EAAE,mBAAmB,0CAA0C,IAC/D,CAAC;AAAA,EACL,CAAC,CACF,EACC,QAAQ;AAAA;",
|
|
8
|
-
"debugId": "B4106C2E1F1C5A3F64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Generated, Selectable } from "kysely";
|
|
2
|
-
interface JobsTable {
|
|
3
|
-
id: Generated<string>;
|
|
4
|
-
stream_id: string;
|
|
5
|
-
block_height: number;
|
|
6
|
-
status: Generated<string>;
|
|
7
|
-
attempts: Generated<number>;
|
|
8
|
-
locked_at: Date | null;
|
|
9
|
-
locked_by: string | null;
|
|
10
|
-
error: string | null;
|
|
11
|
-
backfill: Generated<boolean>;
|
|
12
|
-
created_at: Generated<Date>;
|
|
13
|
-
completed_at: Date | null;
|
|
14
|
-
}
|
|
15
|
-
type Job = Selectable<JobsTable>;
|
|
16
|
-
interface QueueStats {
|
|
17
|
-
pending: number;
|
|
18
|
-
processing: number;
|
|
19
|
-
completed: number;
|
|
20
|
-
failed: number;
|
|
21
|
-
total: number;
|
|
22
|
-
}
|
|
23
|
-
declare const WORKER_ID: string;
|
|
24
|
-
/**
|
|
25
|
-
* Enqueue a new job for stream evaluation
|
|
26
|
-
*/
|
|
27
|
-
declare function enqueue(streamId: string, blockHeight: number, backfill?: boolean): Promise<string>;
|
|
28
|
-
/**
|
|
29
|
-
* Claim a pending job using SKIP LOCKED to prevent concurrent access
|
|
30
|
-
* Returns null if no jobs available
|
|
31
|
-
*/
|
|
32
|
-
declare function claim(): Promise<Job | null>;
|
|
33
|
-
/**
|
|
34
|
-
* Mark a job as completed
|
|
35
|
-
*/
|
|
36
|
-
declare function complete(jobId: string): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Mark a job as failed
|
|
39
|
-
* Re-queues if under max attempts, otherwise marks as permanently failed
|
|
40
|
-
*/
|
|
41
|
-
declare function fail(jobId: string, error: string, maxAttempts?: number): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Get queue statistics
|
|
44
|
-
*/
|
|
45
|
-
declare function stats(): Promise<QueueStats>;
|
|
46
|
-
/**
|
|
47
|
-
* Get worker ID for this process
|
|
48
|
-
*/
|
|
49
|
-
declare function getWorkerId(): string;
|
|
50
|
-
export { stats, getWorkerId, fail, enqueue, complete, claim, WORKER_ID, QueueStats };
|