@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.
Files changed (60) hide show
  1. package/README.md +5 -7
  2. package/dist/src/constants.d.ts +1 -1
  3. package/dist/src/constants.js.map +2 -2
  4. package/dist/src/db/index.d.ts +3 -64
  5. package/dist/src/db/index.js +2 -2
  6. package/dist/src/db/index.js.map +2 -2
  7. package/dist/src/db/queries/accounts.d.ts +2 -51
  8. package/dist/src/db/queries/integrity.d.ts +2 -51
  9. package/dist/src/db/queries/marketplace.d.ts +2 -51
  10. package/dist/src/db/queries/projects.d.ts +2 -51
  11. package/dist/src/db/queries/subgraph-gaps.d.ts +2 -51
  12. package/dist/src/db/queries/subgraphs.d.ts +3 -51
  13. package/dist/src/db/queries/subgraphs.js +3 -1
  14. package/dist/src/db/queries/subgraphs.js.map +3 -3
  15. package/dist/src/db/queries/usage.d.ts +3 -56
  16. package/dist/src/db/queries/usage.js +1 -19
  17. package/dist/src/db/queries/usage.js.map +4 -4
  18. package/dist/src/db/queries/workflows.d.ts +7 -53
  19. package/dist/src/db/queries/workflows.js +130 -13
  20. package/dist/src/db/queries/workflows.js.map +5 -4
  21. package/dist/src/db/schema.d.ts +3 -64
  22. package/dist/src/errors.d.ts +19 -50
  23. package/dist/src/errors.js +28 -45
  24. package/dist/src/errors.js.map +3 -3
  25. package/dist/src/index.d.ts +25 -256
  26. package/dist/src/index.js +32 -234
  27. package/dist/src/index.js.map +7 -9
  28. package/dist/src/lib/plans.d.ts +0 -1
  29. package/dist/src/lib/plans.js +1 -2
  30. package/dist/src/lib/plans.js.map +3 -3
  31. package/dist/src/node/local-client.d.ts +2 -51
  32. package/dist/src/queue/listener.d.ts +1 -18
  33. package/dist/src/queue/listener.js +2 -12
  34. package/dist/src/queue/listener.js.map +3 -3
  35. package/dist/src/schemas/filters.d.ts +3 -3
  36. package/dist/src/schemas/filters.js +3 -3
  37. package/dist/src/schemas/filters.js.map +3 -3
  38. package/dist/src/schemas/index.d.ts +5 -100
  39. package/dist/src/schemas/index.js +4 -88
  40. package/dist/src/schemas/index.js.map +5 -6
  41. package/dist/src/schemas/subgraphs.d.ts +2 -0
  42. package/dist/src/schemas/subgraphs.js +2 -1
  43. package/dist/src/schemas/subgraphs.js.map +3 -3
  44. package/dist/src/schemas/workflows.d.ts +4 -0
  45. package/dist/src/schemas/workflows.js +5 -1
  46. package/dist/src/schemas/workflows.js.map +3 -3
  47. package/dist/src/types.d.ts +1 -53
  48. package/migrations/0030_workflow_source_code.ts +21 -0
  49. package/migrations/0031_subgraph_source_code.ts +18 -0
  50. package/migrations/0032_drop_streams_tables.ts +43 -0
  51. package/package.json +2 -14
  52. package/dist/src/db/queries/metrics.d.ts +0 -419
  53. package/dist/src/db/queries/metrics.js +0 -55
  54. package/dist/src/db/queries/metrics.js.map +0 -10
  55. package/dist/src/queue/index.d.ts +0 -50
  56. package/dist/src/queue/index.js +0 -184
  57. package/dist/src/queue/index.js.map +0 -12
  58. package/dist/src/queue/recovery.d.ts +0 -14
  59. package/dist/src/queue/recovery.js +0 -108
  60. package/dist/src/queue/recovery.js.map +0 -12
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/errors.ts"],
4
4
  "sourcesContent": [
5
- "export const ErrorCodes = {\n\tSTREAM_NOT_FOUND: \"STREAM_NOT_FOUND\",\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tDELIVERY_ERROR: \"DELIVERY_ERROR\",\n\tFILTER_EVALUATION_ERROR: \"FILTER_EVALUATION_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tFORBIDDEN: \"FORBIDDEN\",\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n/**\n * Base error class for all Stacks Streams errors\n */\nexport class StreamsError extends Error {\n\tpublic code: ErrorCode;\n\tpublic override cause?: unknown;\n\n\tconstructor(code: ErrorCode, message: string, cause?: unknown) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\tstack: this.stack,\n\t\t\tcause: this.cause,\n\t\t};\n\t}\n}\n\n/**\n * Stream not found error\n */\nexport class StreamNotFoundError extends StreamsError {\n\tconstructor(streamId: string) {\n\t\tsuper(\"STREAM_NOT_FOUND\", `Stream not found: ${streamId}`);\n\t}\n}\n\n/**\n * Validation error for invalid input\n */\nexport class ValidationError extends StreamsError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"VALIDATION_ERROR\", message, cause);\n\t}\n}\n\n/**\n * Database operation error\n */\nexport class DatabaseError extends StreamsError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"DATABASE_ERROR\", message, cause);\n\t}\n}\n\n/**\n * Delivery error\n */\nexport class DeliveryError extends StreamsError {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic statusCode?: number,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(\"DELIVERY_ERROR\", message, cause);\n\t}\n\n\toverride toJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t\tstatusCode: number | undefined;\n\t} {\n\t\tconst base = super.toJSON();\n\t\treturn {\n\t\t\tname: base.name,\n\t\t\tcode: base.code,\n\t\t\tmessage: base.message,\n\t\t\tstack: base.stack,\n\t\t\tcause: base.cause,\n\t\t\tstatusCode: this.statusCode,\n\t\t};\n\t}\n}\n\n/**\n * Filter evaluation error\n */\nexport class FilterEvaluationError extends StreamsError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"FILTER_EVALUATION_ERROR\", message, cause);\n\t}\n}\n\nexport class AuthenticationError extends StreamsError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHENTICATION_ERROR\", message);\n\t}\n}\n\nexport class AuthorizationError extends StreamsError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHORIZATION_ERROR\", message);\n\t}\n}\n\nexport class RateLimitError extends StreamsError {\n\tconstructor(message: string) {\n\t\tsuper(\"RATE_LIMIT_ERROR\", message);\n\t}\n}\n\nexport class ForbiddenError extends StreamsError {\n\tconstructor(message = \"Forbidden\") {\n\t\tsuper(\"FORBIDDEN\", message);\n\t}\n}\n\n/** Error code → HTTP status. Used by API middleware for code-based matching\n * (avoids cross-bundle instanceof failures from bunup class duplication). */\ntype MappedCode = Extract<\n\tErrorCode,\n\t| \"AUTHENTICATION_ERROR\"\n\t| \"AUTHORIZATION_ERROR\"\n\t| \"RATE_LIMIT_ERROR\"\n\t| \"FORBIDDEN\"\n\t| \"STREAM_NOT_FOUND\"\n\t| \"VALIDATION_ERROR\"\n>;\nexport const CODE_TO_STATUS: Record<MappedCode, 400 | 401 | 403 | 404 | 429> = {\n\tAUTHENTICATION_ERROR: 401,\n\tAUTHORIZATION_ERROR: 403,\n\tRATE_LIMIT_ERROR: 429,\n\tFORBIDDEN: 403,\n\tSTREAM_NOT_FOUND: 404,\n\tVALIDATION_ERROR: 400,\n} as const;\n\n/**\n * Safely extract error message from unknown error value\n */\nexport function getErrorMessage(err: unknown): string {\n\treturn err instanceof Error ? err.message : String(err);\n}\n"
5
+ "export const ErrorCodes = {\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tFORBIDDEN: \"FORBIDDEN\",\n\tVERSION_CONFLICT: \"VERSION_CONFLICT\",\n\tNOT_FOUND: \"NOT_FOUND\",\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n/** Base error class for all Secondlayer errors. */\nexport class SecondLayerError extends Error {\n\tpublic code: ErrorCode;\n\tpublic override cause?: unknown;\n\n\tconstructor(code: ErrorCode, message: string, cause?: unknown) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\tstack: this.stack,\n\t\t\tcause: this.cause,\n\t\t};\n\t}\n}\n\nexport class NotFoundError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"NOT_FOUND\", message);\n\t}\n}\n\nexport class ValidationError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"VALIDATION_ERROR\", message, cause);\n\t}\n}\n\nexport class DatabaseError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"DATABASE_ERROR\", message, cause);\n\t}\n}\n\nexport class AuthenticationError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHENTICATION_ERROR\", message);\n\t}\n}\n\nexport class AuthorizationError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHORIZATION_ERROR\", message);\n\t}\n}\n\nexport class RateLimitError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"RATE_LIMIT_ERROR\", message);\n\t}\n}\n\nexport class ForbiddenError extends SecondLayerError {\n\tconstructor(message = \"Forbidden\") {\n\t\tsuper(\"FORBIDDEN\", message);\n\t}\n}\n\nexport class VersionConflictError extends SecondLayerError {\n\tpublic currentVersion: string;\n\tpublic expectedVersion: string;\n\n\tconstructor(currentVersion: string, expectedVersion: string) {\n\t\tsuper(\n\t\t\t\"VERSION_CONFLICT\",\n\t\t\t`Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t\t);\n\t\tthis.currentVersion = currentVersion;\n\t\tthis.expectedVersion = expectedVersion;\n\t}\n}\n\n/** Error code → HTTP status. Used by API middleware for code-based matching\n * (avoids cross-bundle instanceof failures from bunup class duplication). */\ntype MappedCode = Extract<\n\tErrorCode,\n\t| \"AUTHENTICATION_ERROR\"\n\t| \"AUTHORIZATION_ERROR\"\n\t| \"RATE_LIMIT_ERROR\"\n\t| \"FORBIDDEN\"\n\t| \"NOT_FOUND\"\n\t| \"VALIDATION_ERROR\"\n>;\nexport const CODE_TO_STATUS: Record<MappedCode, 400 | 401 | 403 | 404 | 429> = {\n\tAUTHENTICATION_ERROR: 401,\n\tAUTHORIZATION_ERROR: 403,\n\tRATE_LIMIT_ERROR: 429,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tVALIDATION_ERROR: 400,\n} as const;\n\nexport function getErrorMessage(err: unknown): string {\n\treturn err instanceof Error ? err.message : String(err);\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;AAAO,IAAM,aAAa;AAAA,EACzB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,yBAAyB;AAAA,EACzB,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,kBAAkB;AAAA,EAClB,WAAW;AACZ;AAAA;AAOO,MAAM,qBAAqB,MAAM;AAAA,EAChC;AAAA,EACS;AAAA,EAEhB,WAAW,CAAC,MAAiB,SAAiB,OAAiB;AAAA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;AAAA,EAClB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,kBAAkB;AACnB;AAEO,SAAS,eAAe,CAAC,KAAsB;AAAA,EACrD,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA;",
8
+ "debugId": "49DAFCD22173A4BC64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -31,40 +31,6 @@ interface EventsTable {
31
31
  data: unknown;
32
32
  created_at: Generated<Date>;
33
33
  }
34
- interface StreamsTable {
35
- id: Generated<string>;
36
- name: string;
37
- status: Generated<string>;
38
- filters: unknown;
39
- options: Generated<unknown>;
40
- endpoint_url: string;
41
- signing_secret: string | null;
42
- api_key_id: string;
43
- project_id: string | null;
44
- created_at: Generated<Date>;
45
- updated_at: Generated<Date>;
46
- }
47
- interface StreamMetricsTable {
48
- stream_id: string;
49
- last_triggered_at: Date | null;
50
- last_triggered_block: number | null;
51
- total_deliveries: Generated<number>;
52
- failed_deliveries: Generated<number>;
53
- error_message: string | null;
54
- }
55
- interface JobsTable {
56
- id: Generated<string>;
57
- stream_id: string;
58
- block_height: number;
59
- status: Generated<string>;
60
- attempts: Generated<number>;
61
- locked_at: Date | null;
62
- locked_by: string | null;
63
- error: string | null;
64
- backfill: Generated<boolean>;
65
- created_at: Generated<Date>;
66
- completed_at: Date | null;
67
- }
68
34
  interface IndexProgressTable {
69
35
  network: string;
70
36
  last_indexed_block: Generated<number>;
@@ -72,19 +38,6 @@ interface IndexProgressTable {
72
38
  highest_seen_block: Generated<number>;
73
39
  updated_at: Generated<Date>;
74
40
  }
75
- interface DeliveriesTable {
76
- id: Generated<string>;
77
- stream_id: string;
78
- job_id: string | null;
79
- block_height: number;
80
- status: string;
81
- status_code: number | null;
82
- response_time_ms: number | null;
83
- attempts: Generated<number>;
84
- error: string | null;
85
- payload: unknown;
86
- created_at: Generated<Date>;
87
- }
88
41
  interface SubgraphsTable {
89
42
  id: Generated<string>;
90
43
  name: string;
@@ -105,6 +58,7 @@ interface SubgraphsTable {
105
58
  api_key_id: string | null;
106
59
  account_id: string;
107
60
  handler_code: string | null;
61
+ source_code: string | null;
108
62
  project_id: string | null;
109
63
  is_public: Generated<boolean>;
110
64
  tags: Generated<string[]>;
@@ -303,6 +257,7 @@ interface WorkflowDefinitionsTable {
303
257
  trigger_type: string;
304
258
  trigger_config: unknown;
305
259
  handler_path: string;
260
+ source_code: string | null;
306
261
  retries_config: unknown | null;
307
262
  timeout_ms: number | null;
308
263
  api_key_id: string;
@@ -373,11 +328,7 @@ interface Database {
373
328
  blocks: BlocksTable;
374
329
  transactions: TransactionsTable;
375
330
  events: EventsTable;
376
- streams: StreamsTable;
377
- stream_metrics: StreamMetricsTable;
378
- jobs: JobsTable;
379
331
  index_progress: IndexProgressTable;
380
- deliveries: DeliveriesTable;
381
332
  subgraphs: SubgraphsTable;
382
333
  api_keys: ApiKeysTable;
383
334
  accounts: AccountsTable;
@@ -414,21 +365,9 @@ type UpdateTransaction = Updateable<TransactionsTable>;
414
365
  type Event = Selectable<EventsTable>;
415
366
  type InsertEvent = Insertable<EventsTable>;
416
367
  type UpdateEvent = Updateable<EventsTable>;
417
- type Stream = Selectable<StreamsTable>;
418
- type InsertStream = Insertable<StreamsTable>;
419
- type UpdateStreamRow = Updateable<StreamsTable>;
420
- type StreamMetrics = Selectable<StreamMetricsTable>;
421
- type InsertStreamMetrics = Insertable<StreamMetricsTable>;
422
- type UpdateStreamMetrics = Updateable<StreamMetricsTable>;
423
- type Job = Selectable<JobsTable>;
424
- type InsertJob = Insertable<JobsTable>;
425
- type UpdateJob = Updateable<JobsTable>;
426
368
  type IndexProgress = Selectable<IndexProgressTable>;
427
369
  type InsertIndexProgress = Insertable<IndexProgressTable>;
428
370
  type UpdateIndexProgress = Updateable<IndexProgressTable>;
429
- type Delivery = Selectable<DeliveriesTable>;
430
- type InsertDelivery = Insertable<DeliveriesTable>;
431
- type UpdateDelivery = Updateable<DeliveriesTable>;
432
371
  type Subgraph = Selectable<SubgraphsTable>;
433
372
  type InsertSubgraph = Insertable<SubgraphsTable>;
434
373
  type UpdateSubgraph = Updateable<SubgraphsTable>;
@@ -491,13 +430,6 @@ type Env = EnvSchemaOutput & {
491
430
  enabledNetworks: ("mainnet" | "testnet")[]
492
431
  };
493
432
  declare function getEnv(): Env;
494
- interface QueueStats {
495
- pending: number;
496
- processing: number;
497
- completed: number;
498
- failed: number;
499
- total: number;
500
- }
501
433
  import { RawBuilder } from "kysely";
502
434
  /**
503
435
  * Safely encode a JS value as a JSONB literal for Kysely inserts/updates.
@@ -520,21 +452,18 @@ declare function getRawClient(): ReturnType<typeof postgres>;
520
452
  /** Close the DB connection pool. Call in CLI commands to allow process exit. */
521
453
  declare function closeDb(): Promise<void>;
522
454
  declare const ErrorCodes: {
523
- readonly STREAM_NOT_FOUND: "STREAM_NOT_FOUND"
524
455
  readonly VALIDATION_ERROR: "VALIDATION_ERROR"
525
456
  readonly DATABASE_ERROR: "DATABASE_ERROR"
526
- readonly DELIVERY_ERROR: "DELIVERY_ERROR"
527
- readonly FILTER_EVALUATION_ERROR: "FILTER_EVALUATION_ERROR"
528
457
  readonly AUTHENTICATION_ERROR: "AUTHENTICATION_ERROR"
529
458
  readonly AUTHORIZATION_ERROR: "AUTHORIZATION_ERROR"
530
459
  readonly RATE_LIMIT_ERROR: "RATE_LIMIT_ERROR"
531
460
  readonly FORBIDDEN: "FORBIDDEN"
461
+ readonly VERSION_CONFLICT: "VERSION_CONFLICT"
462
+ readonly NOT_FOUND: "NOT_FOUND"
532
463
  };
533
464
  type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
534
- /**
535
- * Base error class for all Stacks Streams errors
536
- */
537
- declare class StreamsError extends Error {
465
+ /** Base error class for all Secondlayer errors. */
466
+ declare class SecondLayerError extends Error {
538
467
  code: ErrorCode;
539
468
  cause?: unknown;
540
469
  constructor(code: ErrorCode, message: string, cause?: unknown);
@@ -546,64 +475,36 @@ declare class StreamsError extends Error {
546
475
  cause: unknown
547
476
  };
548
477
  }
549
- /**
550
- * Stream not found error
551
- */
552
- declare class StreamNotFoundError extends StreamsError {
553
- constructor(streamId: string);
478
+ declare class NotFoundError extends SecondLayerError {
479
+ constructor(message: string);
554
480
  }
555
- /**
556
- * Validation error for invalid input
557
- */
558
- declare class ValidationError extends StreamsError {
481
+ declare class ValidationError extends SecondLayerError {
559
482
  constructor(message: string, cause?: unknown);
560
483
  }
561
- /**
562
- * Database operation error
563
- */
564
- declare class DatabaseError extends StreamsError {
484
+ declare class DatabaseError extends SecondLayerError {
565
485
  constructor(message: string, cause?: unknown);
566
486
  }
567
- /**
568
- * Delivery error
569
- */
570
- declare class DeliveryError extends StreamsError {
571
- statusCode?: number;
572
- constructor(message: string, statusCode?: number, cause?: unknown);
573
- toJSON(): {
574
- name: string
575
- code: string
576
- message: string
577
- stack: string | undefined
578
- cause: unknown
579
- statusCode: number | undefined
580
- };
581
- }
582
- /**
583
- * Filter evaluation error
584
- */
585
- declare class FilterEvaluationError extends StreamsError {
586
- constructor(message: string, cause?: unknown);
587
- }
588
- declare class AuthenticationError extends StreamsError {
487
+ declare class AuthenticationError extends SecondLayerError {
589
488
  constructor(message: string);
590
489
  }
591
- declare class AuthorizationError extends StreamsError {
490
+ declare class AuthorizationError extends SecondLayerError {
592
491
  constructor(message: string);
593
492
  }
594
- declare class RateLimitError extends StreamsError {
493
+ declare class RateLimitError extends SecondLayerError {
595
494
  constructor(message: string);
596
495
  }
597
- declare class ForbiddenError extends StreamsError {
496
+ declare class ForbiddenError extends SecondLayerError {
598
497
  constructor(message?: string);
599
498
  }
499
+ declare class VersionConflictError extends SecondLayerError {
500
+ currentVersion: string;
501
+ expectedVersion: string;
502
+ constructor(currentVersion: string, expectedVersion: string);
503
+ }
600
504
  /** Error code → HTTP status. Used by API middleware for code-based matching
601
505
  * (avoids cross-bundle instanceof failures from bunup class duplication). */
602
- type MappedCode = Extract<ErrorCode, "AUTHENTICATION_ERROR" | "AUTHORIZATION_ERROR" | "RATE_LIMIT_ERROR" | "FORBIDDEN" | "STREAM_NOT_FOUND" | "VALIDATION_ERROR">;
506
+ type MappedCode = Extract<ErrorCode, "AUTHENTICATION_ERROR" | "AUTHORIZATION_ERROR" | "RATE_LIMIT_ERROR" | "FORBIDDEN" | "NOT_FOUND" | "VALIDATION_ERROR">;
603
507
  declare const CODE_TO_STATUS: Record<MappedCode, 400 | 401 | 403 | 404 | 429>;
604
- /**
605
- * Safely extract error message from unknown error value
606
- */
607
508
  declare function getErrorMessage(err: unknown): string;
608
509
  declare class Logger {
609
510
  private _level?;
@@ -620,43 +521,6 @@ declare class Logger {
620
521
  error(message: string, meta?: Record<string, any>): void;
621
522
  }
622
523
  declare const logger: Logger;
623
- declare namespace exports_queue {
624
- export { stats, getWorkerId, fail, enqueue, complete, claim, WORKER_ID, QueueStats2 as QueueStats };
625
- }
626
- interface QueueStats2 {
627
- pending: number;
628
- processing: number;
629
- completed: number;
630
- failed: number;
631
- total: number;
632
- }
633
- declare const WORKER_ID: string;
634
- /**
635
- * Enqueue a new job for stream evaluation
636
- */
637
- declare function enqueue(streamId: string, blockHeight: number, backfill?: boolean): Promise<string>;
638
- /**
639
- * Claim a pending job using SKIP LOCKED to prevent concurrent access
640
- * Returns null if no jobs available
641
- */
642
- declare function claim(): Promise<Job | null>;
643
- /**
644
- * Mark a job as completed
645
- */
646
- declare function complete(jobId: string): Promise<void>;
647
- /**
648
- * Mark a job as failed
649
- * Re-queues if under max attempts, otherwise marks as permanently failed
650
- */
651
- declare function fail(jobId: string, error: string, maxAttempts?: number): Promise<void>;
652
- /**
653
- * Get queue statistics
654
- */
655
- declare function stats(): Promise<QueueStats2>;
656
- /**
657
- * Get worker ID for this process
658
- */
659
- declare function getWorkerId(): string;
660
524
  import { z as z2 } from "zod/v4";
661
525
  interface StxTransferFilter {
662
526
  type: "stx_transfer";
@@ -735,7 +599,7 @@ interface PrintEventFilter {
735
599
  topic?: string;
736
600
  contains?: string;
737
601
  }
738
- type StreamFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter;
602
+ type EventFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter;
739
603
  declare const StxTransferFilterSchema: z2.ZodType<StxTransferFilter>;
740
604
  declare const StxMintFilterSchema: z2.ZodType<StxMintFilter>;
741
605
  declare const StxBurnFilterSchema: z2.ZodType<StxBurnFilter>;
@@ -749,7 +613,7 @@ declare const NftBurnFilterSchema: z2.ZodType<NftBurnFilter>;
749
613
  declare const ContractCallFilterSchema: z2.ZodType<ContractCallFilter>;
750
614
  declare const ContractDeployFilterSchema: z2.ZodType<ContractDeployFilter>;
751
615
  declare const PrintEventFilterSchema: z2.ZodType<PrintEventFilter>;
752
- declare const StreamFilterSchema: z2.ZodType<StreamFilter>;
616
+ declare const EventFilterSchema: z2.ZodType<EventFilter>;
753
617
  import { z as z3 } from "zod/v4";
754
618
  interface PublishSubgraphRequest {
755
619
  tags?: string[];
@@ -820,6 +684,8 @@ interface DeploySubgraphRequest {
820
684
  sources: Record<string, Record<string, unknown>>;
821
685
  schema: Record<string, unknown>;
822
686
  handlerCode: string;
687
+ /** Original TypeScript source, persisted so chat can read/diff/edit later. */
688
+ sourceCode?: string;
823
689
  /** @deprecated Use server auto-reindex on breaking changes instead */
824
690
  reindex?: boolean;
825
691
  }
@@ -925,103 +791,6 @@ interface SubgraphQueryParams {
925
791
  fields?: string;
926
792
  filters?: Record<string, string>;
927
793
  }
928
- import { z as z5 } from "zod/v4";
929
- interface StreamOptions {
930
- decodeClarityValues: boolean;
931
- includeRawTx: boolean;
932
- includeBlockMetadata: boolean;
933
- rateLimit: number;
934
- timeoutMs: number;
935
- maxRetries: number;
936
- }
937
- interface CreateStream {
938
- name: string;
939
- endpointUrl: string;
940
- filters: StreamFilter[];
941
- options?: StreamOptions;
942
- startBlock?: number;
943
- endBlock?: number;
944
- }
945
- interface UpdateStream {
946
- name?: string;
947
- endpointUrl?: string;
948
- filters?: StreamFilter[];
949
- options?: Partial<StreamOptions>;
950
- }
951
- interface DeliveryPayload {
952
- streamId: string;
953
- streamName: string;
954
- block: {
955
- height: number
956
- hash: string
957
- parentHash: string
958
- burnBlockHeight: number
959
- timestamp: number
960
- };
961
- matches: {
962
- transactions: Array<{
963
- txId: string
964
- type: string
965
- sender: string
966
- status: string
967
- contractId: string | null
968
- functionName: string | null
969
- rawTx?: string
970
- }>
971
- events: Array<{
972
- txId: string
973
- eventIndex: number
974
- type: string
975
- data?: any
976
- }>
977
- };
978
- isBackfill: boolean;
979
- deliveredAt: string;
980
- }
981
- interface StreamMetricsResponse {
982
- totalDeliveries: number;
983
- failedDeliveries: number;
984
- lastTriggeredAt: string | null;
985
- lastTriggeredBlock: number | null;
986
- errorMessage: string | null;
987
- }
988
- interface StreamResponse {
989
- id: string;
990
- name: string;
991
- status: "inactive" | "active" | "paused" | "failed";
992
- endpointUrl: string;
993
- filters: StreamFilter[];
994
- options: StreamOptions;
995
- totalDeliveries: number;
996
- failedDeliveries: number;
997
- lastTriggeredAt?: string | null;
998
- lastTriggeredBlock?: number | null;
999
- errorMessage?: string | null;
1000
- createdAt: string;
1001
- updatedAt: string;
1002
- }
1003
- declare const StreamOptionsSchema: z5.ZodType<StreamOptions>;
1004
- declare const CreateStreamSchema: z5.ZodType<CreateStream>;
1005
- declare const UpdateStreamSchema: z5.ZodType<UpdateStream>;
1006
- declare const DeliveryPayloadSchema: z5.ZodType<DeliveryPayload>;
1007
- declare const StreamMetricsSchema: z5.ZodType<StreamMetricsResponse>;
1008
- declare const StreamResponseSchema: z5.ZodType<StreamResponse>;
1009
- interface CreateStreamResponse {
1010
- stream: StreamResponse;
1011
- signingSecret: string;
1012
- }
1013
- interface ListStreamsResponse {
1014
- streams: StreamResponse[];
1015
- total: number;
1016
- }
1017
- interface BulkPauseResponse {
1018
- paused: number;
1019
- streams: StreamResponse[];
1020
- }
1021
- interface BulkResumeResponse {
1022
- resumed: number;
1023
- streams: StreamResponse[];
1024
- }
1025
794
  declare namespace exports_hmac {
1026
795
  export { verifySignatureHeader, verifySignature, signPayload, generateSecret, createSignatureHeader };
1027
796
  }
@@ -1050,4 +819,4 @@ declare function createSignatureHeader(payload: string, secret: string, timestam
1050
819
  * Returns true if valid, false otherwise
1051
820
  */
1052
821
  declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
1053
- export { sql, exports_queue as queue, parseJsonb, logger, jsonb, getRawClient, getErrorMessage, getEnv, getDb, exports_hmac as crypto, closeDb, WorkflowStepsTable, WorkflowStep, WorkflowSchedulesTable, WorkflowSchedule, WorkflowRunsTable, WorkflowRun, WorkflowQueueTable, WorkflowQueueItem, WorkflowDefinitionsTable, WorkflowDefinition, WorkflowCursorsTable, WorkflowCursor, WaitlistTable, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateWorkflowStep, UpdateWorkflowSchedule, UpdateWorkflowRun, UpdateWorkflowDefinition, UpdateTransaction, UpdateSubgraph, UpdateStreamSchema, UpdateStreamRow, UpdateStreamMetrics, UpdateStream, UpdateProject, UpdateProfileRequestSchema, UpdateProfileRequest, UpdateJob, UpdateIndexProgress, UpdateEvent, UpdateDelivery, UpdateChatSession, UpdateBlock, UpdateApiKey, TransactionsTable, Transaction, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphSyncInfo, SubgraphSummary, SubgraphQueryParams, SubgraphProcessingStatsTable, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGapsResponse, SubgraphGapRange, SubgraphGapEntry, SubgraphGap, SubgraphDetail, Subgraph, StxTransferFilterSchema, StxTransferFilter, StxMintFilterSchema, StxMintFilter, StxLockFilterSchema, StxLockFilter, StxBurnFilterSchema, StxBurnFilter, StreamsTable, StreamsError, StreamResponseSchema, StreamResponse, StreamOptionsSchema, StreamOptions, StreamNotFoundError, StreamMetricsTable, StreamMetricsSchema, StreamMetricsResponse, StreamMetrics, StreamFilterSchema, StreamFilter, Stream, SessionsTable, Session, ReindexResponse, RateLimitError, QueueStats, PublishSubgraphRequestSchema, PublishSubgraphRequest, ProjectsTable, Project, PrintEventFilterSchema, PrintEventFilter, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MarketplaceSubgraphSummary, MarketplaceSubgraphDetail, MarketplaceCreator, MagicLinksTable, MagicLink, ListStreamsResponse, JobsTable, Job, InsertWorkflowStep, InsertWorkflowSchedule, InsertWorkflowRun, InsertWorkflowQueueItem, InsertWorkflowDefinition, InsertTransaction, InsertTeamMember, InsertTeamInvitation, InsertSubgraphUsageDaily, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertStreamMetrics, InsertStream, InsertSession, InsertProject, InsertMagicLink, InsertJob, InsertIndexProgress, InsertEvent, InsertDelivery, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, FtTransferFilterSchema, FtTransferFilter, FtMintFilterSchema, FtMintFilter, FtBurnFilterSchema, FtBurnFilter, ForkSubgraphRequestSchema, ForkSubgraphRequest, ForbiddenError, FilterEvaluationError, EventsTable, Event, ErrorCodes, ErrorCode, Env, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DeliveryPayloadSchema, DeliveryPayload, DeliveryError, Delivery, DeliveriesTable, DatabaseError, Database, CreatorProfile, CreateStreamSchema, CreateStreamResponse, CreateStream, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, CODE_TO_STATUS, BulkResumeResponse, BulkPauseResponse, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
822
+ export { sql, parseJsonb, logger, jsonb, getRawClient, getErrorMessage, getEnv, getDb, exports_hmac as crypto, closeDb, WorkflowStepsTable, WorkflowStep, WorkflowSchedulesTable, WorkflowSchedule, WorkflowRunsTable, WorkflowRun, WorkflowQueueTable, WorkflowQueueItem, WorkflowDefinitionsTable, WorkflowDefinition, WorkflowCursorsTable, WorkflowCursor, WaitlistTable, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateWorkflowStep, UpdateWorkflowSchedule, UpdateWorkflowRun, UpdateWorkflowDefinition, UpdateTransaction, UpdateSubgraph, UpdateProject, UpdateProfileRequestSchema, UpdateProfileRequest, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, TransactionsTable, Transaction, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphSyncInfo, SubgraphSummary, SubgraphQueryParams, SubgraphProcessingStatsTable, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGapsResponse, SubgraphGapRange, SubgraphGapEntry, SubgraphGap, SubgraphDetail, Subgraph, StxTransferFilterSchema, StxTransferFilter, StxMintFilterSchema, StxMintFilter, StxLockFilterSchema, StxLockFilter, StxBurnFilterSchema, StxBurnFilter, SessionsTable, Session, SecondLayerError, ReindexResponse, RateLimitError, PublishSubgraphRequestSchema, PublishSubgraphRequest, ProjectsTable, Project, PrintEventFilterSchema, PrintEventFilter, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MarketplaceSubgraphSummary, MarketplaceSubgraphDetail, MarketplaceCreator, MagicLinksTable, MagicLink, InsertWorkflowStep, InsertWorkflowSchedule, InsertWorkflowRun, InsertWorkflowQueueItem, InsertWorkflowDefinition, InsertTransaction, InsertTeamMember, InsertTeamInvitation, InsertSubgraphUsageDaily, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, FtTransferFilterSchema, FtTransferFilter, FtMintFilterSchema, FtMintFilter, FtBurnFilterSchema, FtBurnFilter, ForkSubgraphRequestSchema, ForkSubgraphRequest, ForbiddenError, EventsTable, EventFilterSchema, EventFilter, Event, ErrorCodes, ErrorCode, Env, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DatabaseError, Database, CreatorProfile, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, CODE_TO_STATUS, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };