@gobing-ai/ts-infra 0.3.0 → 0.3.2

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 (101) hide show
  1. package/README.md +52 -29
  2. package/dist/api-client.d.ts +13 -0
  3. package/dist/api-client.d.ts.map +1 -1
  4. package/dist/api-client.js +15 -4
  5. package/dist/event-bus/default-observers.d.ts +53 -0
  6. package/dist/event-bus/default-observers.d.ts.map +1 -0
  7. package/dist/event-bus/default-observers.js +107 -0
  8. package/dist/event-bus/event-bus.d.ts.map +1 -1
  9. package/dist/event-bus/event-bus.js +1 -0
  10. package/dist/event-bus/file-observer.d.ts +25 -0
  11. package/dist/event-bus/file-observer.d.ts.map +1 -0
  12. package/dist/event-bus/file-observer.js +110 -0
  13. package/dist/event-bus/index.d.ts +2 -0
  14. package/dist/event-bus/index.d.ts.map +1 -1
  15. package/dist/event-bus/index.js +2 -0
  16. package/dist/event-bus/types.d.ts +6 -0
  17. package/dist/event-bus/types.d.ts.map +1 -1
  18. package/dist/events.d.ts +100 -0
  19. package/dist/events.d.ts.map +1 -0
  20. package/dist/events.js +12 -0
  21. package/dist/index.d.ts +4 -4
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +3 -5
  24. package/dist/job-queue/db-job-queue.d.ts.map +1 -1
  25. package/dist/job-queue/db-job-queue.js +45 -34
  26. package/dist/job-queue/index.d.ts +0 -1
  27. package/dist/job-queue/index.d.ts.map +1 -1
  28. package/dist/job-queue/index.js +0 -1
  29. package/dist/job-queue/types.d.ts +7 -0
  30. package/dist/job-queue/types.d.ts.map +1 -1
  31. package/dist/job-queue-db.d.ts +2 -0
  32. package/dist/job-queue-db.d.ts.map +1 -0
  33. package/dist/job-queue-db.js +1 -0
  34. package/dist/logger.d.ts +39 -7
  35. package/dist/logger.d.ts.map +1 -1
  36. package/dist/logger.js +76 -73
  37. package/dist/scheduler/action.d.ts +97 -1
  38. package/dist/scheduler/action.d.ts.map +1 -1
  39. package/dist/scheduler/action.js +111 -0
  40. package/dist/scheduler/cloudflare.d.ts +6 -0
  41. package/dist/scheduler/cloudflare.d.ts.map +1 -1
  42. package/dist/scheduler/cloudflare.js +6 -0
  43. package/dist/scheduler/factory.d.ts +2 -0
  44. package/dist/scheduler/factory.d.ts.map +1 -1
  45. package/dist/scheduler/factory.js +2 -0
  46. package/dist/scheduler/index.d.ts +2 -2
  47. package/dist/scheduler/index.d.ts.map +1 -1
  48. package/dist/scheduler/index.js +2 -2
  49. package/dist/scheduler/node.d.ts +4 -0
  50. package/dist/scheduler/node.d.ts.map +1 -1
  51. package/dist/scheduler/node.js +4 -0
  52. package/dist/scheduler/noop.d.ts +1 -0
  53. package/dist/scheduler/noop.d.ts.map +1 -1
  54. package/dist/scheduler/noop.js +1 -0
  55. package/dist/scheduler/wrap-handler.d.ts +18 -0
  56. package/dist/scheduler/wrap-handler.d.ts.map +1 -0
  57. package/dist/scheduler/wrap-handler.js +41 -0
  58. package/dist/scheduler-cloudflare.d.ts +2 -0
  59. package/dist/scheduler-cloudflare.d.ts.map +1 -0
  60. package/dist/scheduler-cloudflare.js +1 -0
  61. package/dist/scheduler-node.d.ts +2 -0
  62. package/dist/scheduler-node.d.ts.map +1 -0
  63. package/dist/scheduler-node.js +1 -0
  64. package/dist/telemetry/config.d.ts +4 -0
  65. package/dist/telemetry/config.d.ts.map +1 -1
  66. package/dist/telemetry/metrics.d.ts +19 -0
  67. package/dist/telemetry/metrics.d.ts.map +1 -1
  68. package/dist/telemetry/metrics.js +19 -0
  69. package/dist/telemetry/sdk.d.ts +4 -0
  70. package/dist/telemetry/sdk.d.ts.map +1 -1
  71. package/dist/telemetry/sdk.js +4 -0
  72. package/dist/telemetry/tracing.d.ts +12 -0
  73. package/dist/telemetry/tracing.d.ts.map +1 -1
  74. package/dist/telemetry/tracing.js +12 -0
  75. package/package.json +19 -2
  76. package/src/api-client.ts +15 -4
  77. package/src/event-bus/default-observers.ts +117 -0
  78. package/src/event-bus/event-bus.ts +1 -0
  79. package/src/event-bus/file-observer.ts +142 -0
  80. package/src/event-bus/index.ts +7 -0
  81. package/src/event-bus/types.ts +6 -0
  82. package/src/events.ts +108 -0
  83. package/src/index.ts +44 -7
  84. package/src/job-queue/db-job-queue.ts +50 -38
  85. package/src/job-queue/index.ts +0 -1
  86. package/src/job-queue/types.ts +7 -0
  87. package/src/job-queue-db.ts +1 -0
  88. package/src/logger.ts +102 -77
  89. package/src/scheduler/action.ts +164 -1
  90. package/src/scheduler/cloudflare.ts +6 -0
  91. package/src/scheduler/factory.ts +2 -0
  92. package/src/scheduler/index.ts +13 -2
  93. package/src/scheduler/node.ts +4 -0
  94. package/src/scheduler/noop.ts +1 -0
  95. package/src/scheduler/wrap-handler.ts +50 -0
  96. package/src/scheduler-cloudflare.ts +1 -0
  97. package/src/scheduler-node.ts +1 -0
  98. package/src/telemetry/config.ts +4 -0
  99. package/src/telemetry/metrics.ts +19 -0
  100. package/src/telemetry/sdk.ts +4 -0
  101. package/src/telemetry/tracing.ts +12 -0
@@ -1,11 +1,14 @@
1
1
  /**
2
2
  * Event bus types — shared constraints for typed pub-sub.
3
3
  */
4
+ /** Type constraint for event maps — keys are event names, values are listener signatures. */
4
5
  export type EventMap = Record<string, (...args: never[]) => void>;
6
+ /** Options for subscribing to an event, including async dispatch mode. */
5
7
  export interface SubscribeOptions {
6
8
  /** When true, the handler is dispatched through the async handler path. */
7
9
  async?: boolean;
8
10
  }
11
+ /** Payload emitted on `bus.emit.done` after synchronous handlers complete. */
9
12
  export interface EmitDoneDetail {
10
13
  event: string;
11
14
  syncCount: number;
@@ -14,16 +17,19 @@ export interface EmitDoneDetail {
14
17
  errors: number;
15
18
  detail?: unknown;
16
19
  }
20
+ /** Payload emitted on `bus.handler.error` when a handler throws. */
17
21
  export interface HandlerErrorDetail {
18
22
  event: string;
19
23
  mode: 'sync' | 'async';
20
24
  error: string;
21
25
  }
26
+ /** Payload emitted on `bus.handler.async.enqueued` when async handlers are scheduled. */
22
27
  export interface AsyncEnqueuedDetail {
23
28
  event: string;
24
29
  jobId: string;
25
30
  handlerCount: number;
26
31
  }
32
+ /** Strongly-typed lifecycle events emitted by the event bus. */
27
33
  export type BusLifecycleEvents = {
28
34
  'bus.emit.done': (detail: EmitDoneDetail) => void;
29
35
  'bus.emit.noop': (detail: {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/event-bus/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC,CAAC;AAElE,MAAM,WAAW,gBAAgB;IAC7B,2EAA2E;IAC3E,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAID,MAAM,WAAW,cAAc;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC7B,eAAe,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAClD,eAAe,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACrD,mBAAmB,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC1D,4BAA4B,EA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}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Infrastructure-level event definitions for ts-infra observability.
3
+ *
4
+ * Mirrors the package-local pattern in `@gobing-ai/ts-ai-runner` (`events.ts`):
5
+ * only the events ts-infra components actually emit live here. Application-domain
6
+ * events (history import, HTTP server, …) belong to the consuming app, not this
7
+ * library. Process events belong to `@gobing-ai/ts-runtime` (the owner of
8
+ * `ProcessExecutor`) and are intentionally not re-exported here.
9
+ *
10
+ * Consume via `EventBus<InfraEvents>` or compose individual maps into a wider
11
+ * app event map.
12
+ */
13
+ import type { QueueStats } from './job-queue/types';
14
+ /** Payload for `db.connection.error`. */
15
+ export interface DbConnectionErrorDetail {
16
+ /** Error message. */
17
+ error: string;
18
+ /** Adapter type (e.g. 'sqlite', 'd1'). */
19
+ adapter: string;
20
+ }
21
+ /** Payload for `queue.job.failed` — a job exhausted retries. */
22
+ export interface QueueJobFailedDetail {
23
+ jobId: string;
24
+ type: string;
25
+ error: string;
26
+ /** Attempt number (0-indexed, incremented after each failure). */
27
+ attempt: number;
28
+ }
29
+ /** Payload for `queue.job.retrying` — a job will be retried after backoff. */
30
+ export interface QueueJobRetryingDetail {
31
+ jobId: string;
32
+ type: string;
33
+ attempt: number;
34
+ /** When the next retry will fire (epoch ms). */
35
+ nextRetryAt: number;
36
+ }
37
+ /** Payload for `scheduler.job.executed`. */
38
+ export interface SchedulerJobExecutedDetail {
39
+ /** Job name. */
40
+ name: string;
41
+ /** Wall-clock duration in milliseconds. */
42
+ durationMs: number;
43
+ /** Error message if the job threw. */
44
+ error?: string;
45
+ }
46
+ /** Payload for `api.request.error`. */
47
+ export interface ApiRequestErrorDetail {
48
+ url: string;
49
+ method: string;
50
+ /** HTTP status code, if a response was received. */
51
+ status?: number;
52
+ error: string;
53
+ }
54
+ /** Database lifecycle events emitted by DB-facing infra wiring. */
55
+ export type DbEvents = {
56
+ /** Database connection established. */
57
+ 'db.connected': () => void;
58
+ /** Database connection error. */
59
+ 'db.connection.error': (detail: DbConnectionErrorDetail) => void;
60
+ };
61
+ /** Job-queue lifecycle events emitted by the queue and its consumer. */
62
+ export type QueueEvents = {
63
+ /** A new job was enqueued. */
64
+ 'queue.job.enqueued': (detail: {
65
+ jobId: string;
66
+ type: string;
67
+ }) => void;
68
+ /** Consumer polling loop started. */
69
+ 'queue.consumer.started': () => void;
70
+ /** Consumer stopped. */
71
+ 'queue.consumer.stopped': () => void;
72
+ /** A job completed successfully. */
73
+ 'queue.job.completed': (detail: {
74
+ jobId: string;
75
+ type: string;
76
+ }) => void;
77
+ /** A job exhausted retries and is permanently failed. */
78
+ 'queue.job.failed': (detail: QueueJobFailedDetail) => void;
79
+ /** A job will be retried after backoff. */
80
+ 'queue.job.retrying': (detail: QueueJobRetryingDetail) => void;
81
+ /** Queue depth snapshot emitted on a poll cycle. */
82
+ 'queue.stats': (detail: QueueStats) => void;
83
+ };
84
+ /** Scheduler events emitted by scheduler adapters and the handler wrapper. */
85
+ export type SchedulerEvents = {
86
+ /** A scheduled job was executed (success or failure). */
87
+ 'scheduler.job.executed': (detail: SchedulerJobExecutedDetail) => void;
88
+ };
89
+ /** API-client events. */
90
+ export type ApiClientEvents = {
91
+ /** An API request failed (non-2xx or network error). */
92
+ 'api.request.error': (detail: ApiRequestErrorDetail) => void;
93
+ };
94
+ /**
95
+ * Aggregate of all infrastructure-level event maps ts-infra emits. Use with
96
+ * `EventBus<InfraEvents>`, or pick individual maps when composing a wider app
97
+ * event map.
98
+ */
99
+ export type InfraEvents = DbEvents & QueueEvents & SchedulerEvents & ApiClientEvents;
100
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD,yCAAyC;AACzC,MAAM,WAAW,uBAAuB;IACpC,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAA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,EAAE,MAAM,IAAI,CAAC;IACrC,oCAAoC;IACpC,qBAAqB,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACzE,yDAAyD;IACzD,kBAAkB,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC3D,2CAA2C;IAC3C,oBAAoB,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC/D,oDAAoD;IACpD,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF,8EAA8E;AAC9E,MAAM,MAAM,eAAe,GAAG;IAC1B,yDAAyD;IACzD,wBAAwB,EAAE,CAAC,MAAM,EAAE,0BAA0B,KAAK,IAAI,CAAC;CAC1E,CAAC;AAEF,yBAAyB;AACzB,MAAM,MAAM,eAAe,GAAG;IAC1B,wDAAwD;IACxD,mBAAmB,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAChE,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,eAAe,GAAG,eAAe,CAAC"}
package/dist/events.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Infrastructure-level event definitions for ts-infra observability.
3
+ *
4
+ * Mirrors the package-local pattern in `@gobing-ai/ts-ai-runner` (`events.ts`):
5
+ * only the events ts-infra components actually emit live here. Application-domain
6
+ * events (history import, HTTP server, …) belong to the consuming app, not this
7
+ * library. Process events belong to `@gobing-ai/ts-runtime` (the owner of
8
+ * `ProcessExecutor`) and are intentionally not re-exported here.
9
+ *
10
+ * Consume via `EventBus<InfraEvents>` or compose individual maps into a wider
11
+ * app event map.
12
+ */
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { APIClient, type APIClientConfig, APIError, type RequestOptions } from './api-client';
2
- export { EventBus, type EventMap, type SubscribeOptions } from './event-bus/index';
2
+ export { attachDefaultObservers, attachFileObserver, attachLogObserver, attachTelemetryObserver, createLifecycleBus, EventBus, type EventMap, type FileObserverWriter, type SubscribeOptions, } from './event-bus/index';
3
+ export type { ApiClientEvents, ApiRequestErrorDetail, DbConnectionErrorDetail, DbEvents, InfraEvents, QueueEvents, QueueJobFailedDetail, QueueJobRetryingDetail, SchedulerEvents, SchedulerJobExecutedDetail, } from './events';
3
4
  export type { EnqueueOptions, Job, JobHandler, JobQueue, QueueConsumer, QueueConsumerConfig, QueueStats, } from './job-queue/index';
4
- export { DBJobQueue, DBQueueConsumer } from './job-queue/index';
5
- export { getLogger, initializeLogger, type Logger, type LogLevel } from './logger';
6
- export { CloudflareSchedulerAdapter, getSchedulerAdapter, initScheduler, NodeSchedulerAdapter, NoopSchedulerAdapter, type ScheduledAction, type SchedulerAdapter, setSchedulerAdapter, } from './scheduler/index';
5
+ export { getLogger, type InitLoggerOptions, initializeLogger, type Logger, type LogLevel, setLoggerMuted, } from './logger';
6
+ export { ActionRegistry, type CreateDefaultRegistryOptions, createDefaultRegistry, getSchedulerAdapter, HealthPingAction, type HealthPingWriter, initScheduler, LogAction, NoopSchedulerAdapter, QueueStatsAction, type QueueStatsDaoProvider, type ScheduledAction, type SchedulerAction, type SchedulerAdapter, setSchedulerAdapter, toScheduledAction, wrapScheduledHandler, } from './scheduler/index';
7
7
  export { addSpanAttributes, addSpanEvent, extractSqlOperation, getActiveSpan, getEventbusEmitsTotal, getEventbusErrorsTotal, getHttpClientRequestDuration, getHttpClientRequestErrors, getHttpClientRequestTotal, getQueueJobCompletedTotal, getQueueJobEnqueuedTotal, getQueueJobFailedTotal, getQueueJobProcessingDuration, getSchedulerJobDuration, getSchedulerJobExecutedTotal, getSchedulerJobFailedTotal, getTelemetryConfig, getTracer, initMetrics, initTelemetry, isTelemetryEnabled, sanitizeSql, shutdownMetrics, shutdownTelemetry, type TelemetryConfig, type TelemetryConfigPartial, traceAsync, traceSync, withSpan, } from './telemetry/index';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9F,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEnF,YAAY,EACR,cAAc,EACd,GAAG,EACH,UAAU,EACV,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,UAAU,GACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGhE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGnF,OAAO,EACH,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,mBAAmB,GACtB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACH,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACvB,4BAA4B,EAC5B,0BAA0B,EAC1B,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,UAAU,EACV,SAAS,EACT,QAAQ,GACX,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index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AA6B,EAC7B,uBAAuB,EACvB,4BAA4B,EAC5B,0BAA0B,EAC1B,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,UAAU,EACV,SAAS,EACT,QAAQ,GACX,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  // API Client
2
2
  export { APIClient, APIError } from './api-client.js';
3
3
  // Event Bus
4
- export { EventBus } from './event-bus/index.js';
5
- // Job Queue
6
- export { DBJobQueue, DBQueueConsumer } from './job-queue/index.js';
4
+ export { attachDefaultObservers, attachFileObserver, attachLogObserver, attachTelemetryObserver, createLifecycleBus, EventBus, } from './event-bus/index.js';
7
5
  // Logger
8
- export { getLogger, initializeLogger } from './logger.js';
6
+ export { getLogger, initializeLogger, setLoggerMuted, } from './logger.js';
9
7
  // Scheduler
10
- export { CloudflareSchedulerAdapter, getSchedulerAdapter, initScheduler, NodeSchedulerAdapter, NoopSchedulerAdapter, setSchedulerAdapter, } from './scheduler/index.js';
8
+ export { ActionRegistry, createDefaultRegistry, getSchedulerAdapter, HealthPingAction, initScheduler, LogAction, NoopSchedulerAdapter, QueueStatsAction, setSchedulerAdapter, toScheduledAction, wrapScheduledHandler, } from './scheduler/index.js';
11
9
  // Telemetry
12
10
  export { addSpanAttributes, addSpanEvent, extractSqlOperation, getActiveSpan, getEventbusEmitsTotal, getEventbusErrorsTotal, getHttpClientRequestDuration, getHttpClientRequestErrors, getHttpClientRequestTotal, getQueueJobCompletedTotal, getQueueJobEnqueuedTotal, getQueueJobFailedTotal, getQueueJobProcessingDuration, getSchedulerJobDuration, getSchedulerJobExecutedTotal, getSchedulerJobFailedTotal, getTelemetryConfig, getTracer, initMetrics, initTelemetry, isTelemetryEnabled, sanitizeSql, shutdownMetrics, shutdownTelemetry, traceAsync, traceSync, withSpan, } from './telemetry/index.js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AC;IAM3F,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC;CAGrC;AAED,qFAAqF;AACrF,qBAAa,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAc7D,OAAO,CAAC,QAAQ,CAAC,GAAG;IAbxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;IAC7D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,KAAK,CAA8C;IAC3D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAK;gBAGA,GAAG,EAAE,WAAW,EACjC,MAAM,GAAE,mBAAwB;IAWpC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI;IAI9C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAarB,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC;IAIlC,sFAAsF;IAChF,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IA4BpC,OAAO,CAAC,QAAQ;YAMF,IAAI;YASJ,UAAU;YA4BV,WAAW;CAY5B"}
@@ -1,4 +1,5 @@
1
1
  import { getQueueJobCompletedTotal, getQueueJobEnqueuedTotal, getQueueJobFailedTotal, getQueueJobProcessingDuration, } from '../telemetry/metrics.js';
2
+ import { addSpanAttributes, traceAsync } from '../telemetry/tracing.js';
2
3
  /** DB-backed job queue implementation over `@gobing-ai/ts-db`'s `QueueJobDao`. */
3
4
  export class DBJobQueue {
4
5
  dao;
@@ -68,24 +69,27 @@ export class DBQueueConsumer {
68
69
  }
69
70
  /** Process one batch immediately. Useful for tests, schedulers, and manual drains. */
70
71
  async processOnce() {
71
- await this.dao.resetStuckJobs(this.visibilityTimeout);
72
- await this.dao.failExpiredJobs();
73
- const jobs = await this.dao.claimReady(this.batchSize);
74
- let processed = 0;
75
- for (let index = 0; index < jobs.length; index += this.maxConcurrency) {
76
- const batch = jobs.slice(index, index + this.maxConcurrency);
77
- await Promise.all(batch.map(async (job) => {
78
- this.inFlight += 1;
79
- try {
80
- await this.processJob(job);
81
- processed += 1;
82
- }
83
- finally {
84
- this.inFlight -= 1;
85
- }
86
- }));
87
- }
88
- return processed;
72
+ return traceAsync('queue.poll', async () => {
73
+ await this.dao.resetStuckJobs(this.visibilityTimeout);
74
+ await this.dao.failExpiredJobs();
75
+ const jobs = await this.dao.claimReady(this.batchSize);
76
+ let processed = 0;
77
+ for (let index = 0; index < jobs.length; index += this.maxConcurrency) {
78
+ const batch = jobs.slice(index, index + this.maxConcurrency);
79
+ await Promise.all(batch.map(async (job) => {
80
+ this.inFlight += 1;
81
+ try {
82
+ await this.processJob(job);
83
+ processed += 1;
84
+ }
85
+ finally {
86
+ this.inFlight -= 1;
87
+ }
88
+ }));
89
+ }
90
+ addSpanAttributes({ 'queue.claimed': jobs.length, 'queue.processed': processed });
91
+ return processed;
92
+ });
89
93
  }
90
94
  schedule(delay) {
91
95
  this.timer = setTimeout(() => {
@@ -105,22 +109,29 @@ export class DBQueueConsumer {
105
109
  }
106
110
  async processJob(record) {
107
111
  const job = toJob(record);
108
- const handler = this.handlers.get(job.type);
109
- if (handler === undefined) {
110
- await this.failOrRetry(job, new Error(`No handler registered for job type "${job.type}"`));
111
- return;
112
- }
113
- const startMs = performance.now();
114
- try {
115
- await handler(job);
116
- await this.dao.markCompleted(job.id);
117
- getQueueJobCompletedTotal().add(1, { type: job.type });
118
- getQueueJobProcessingDuration().record(performance.now() - startMs, { type: job.type });
119
- }
120
- catch (error) {
121
- getQueueJobProcessingDuration().record(performance.now() - startMs, { type: job.type });
122
- await this.failOrRetry(job, error);
123
- }
112
+ return traceAsync('queue.job.process', async () => {
113
+ addSpanAttributes({
114
+ 'queue.job_id': job.id,
115
+ 'queue.job_type': job.type,
116
+ 'queue.job_attempt': job.attempts,
117
+ });
118
+ const handler = this.handlers.get(job.type);
119
+ if (handler === undefined) {
120
+ await this.failOrRetry(job, new Error(`No handler registered for job type "${job.type}"`));
121
+ return;
122
+ }
123
+ const startMs = performance.now();
124
+ try {
125
+ await handler(job);
126
+ await this.dao.markCompleted(job.id);
127
+ getQueueJobCompletedTotal().add(1, { type: job.type });
128
+ getQueueJobProcessingDuration().record(performance.now() - startMs, { type: job.type });
129
+ }
130
+ catch (error) {
131
+ getQueueJobProcessingDuration().record(performance.now() - startMs, { type: job.type });
132
+ await this.failOrRetry(job, error);
133
+ }
134
+ });
124
135
  }
125
136
  async failOrRetry(job, error) {
126
137
  const attempts = job.attempts + 1;
@@ -1,3 +1,2 @@
1
- export { DBJobQueue, DBQueueConsumer } from './db-job-queue';
2
1
  export type { EnqueueOptions, Job, JobHandler, JobQueue, QueueConsumer, QueueConsumerConfig, QueueStats, } from './types';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/job-queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7D,YAAY,EACR,cAAc,EACd,GAAG,EACH,UAAU,EACV,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,UAAU,GACb,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/job-queue/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,cAAc,EACd,GAAG,EACH,UAAU,EACV,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,UAAU,GACb,MAAM,SAAS,CAAC"}
@@ -1 +0,0 @@
1
- export { DBJobQueue, DBQueueConsumer } from './db-job-queue.js';
@@ -4,6 +4,7 @@
4
4
  * The concrete DB-backed implementations live beside these interfaces in
5
5
  * `DBJobQueue` and `DBQueueConsumer`.
6
6
  */
7
+ /** A queued job with status tracking, retry metadata, and timestamps. */
7
8
  export interface Job<T = unknown> {
8
9
  id: string;
9
10
  type: string;
@@ -17,11 +18,13 @@ export interface Job<T = unknown> {
17
18
  lastError: string | null;
18
19
  processingAt: number | null;
19
20
  }
21
+ /** Options for enqueuing a job: retry policy, delay, and TTL. */
20
22
  export interface EnqueueOptions {
21
23
  maxRetries?: number;
22
24
  delay?: number;
23
25
  ttlMs?: number;
24
26
  }
27
+ /** Producer interface for the job queue — enqueue single jobs or batches. */
25
28
  export interface JobQueue<T = unknown> {
26
29
  enqueue(type: string, payload: T, options?: EnqueueOptions): Promise<string>;
27
30
  enqueueBatch(jobs: Array<{
@@ -30,13 +33,16 @@ export interface JobQueue<T = unknown> {
30
33
  } & EnqueueOptions>): Promise<string[]>;
31
34
  stats(): Promise<QueueStats>;
32
35
  }
36
+ /** Async handler that processes a single job. */
33
37
  export type JobHandler<T = unknown> = (job: Job<T>) => Promise<void>;
38
+ /** Aggregate statistics for a job queue: counts by status. */
34
39
  export interface QueueStats {
35
40
  pending: number;
36
41
  processing: number;
37
42
  completed: number;
38
43
  failed: number;
39
44
  }
45
+ /** Configuration for a queue consumer: polling, concurrency, and backoff. */
40
46
  export interface QueueConsumerConfig {
41
47
  pollInterval?: number;
42
48
  batchSize?: number;
@@ -46,6 +52,7 @@ export interface QueueConsumerConfig {
46
52
  maxDelay?: number;
47
53
  drainTimeoutMs?: number;
48
54
  }
55
+ /** Consumer interface for the job queue — register handlers and control the processing loop. */
49
56
  export interface QueueConsumer<T = unknown> {
50
57
  register(type: string, handler: JobHandler<T>): void;
51
58
  start(): Promise<void>;
@@ -1 +1 @@
1
- {"version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AED,gGAAgG;AAChG,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export { DBJobQueue, DBQueueConsumer } from './job-queue/db-job-queue';
2
+ //# sourceMappingURL=job-queue-db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-queue-db.d.ts","sourceRoot":"","sources":["../src/job-queue-db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1 @@
1
+ export { DBJobQueue, DBQueueConsumer } from './job-queue/db-job-queue.js';
package/dist/logger.d.ts CHANGED
@@ -1,9 +1,22 @@
1
1
  /**
2
- * Structured JSON logger with levels (trace/debug/info/warn/error/fatal).
2
+ * Structured logger for ts-infra, backed by LogTape.
3
3
  *
4
- * No external dependencies console-based implementation.
4
+ * LogTape owns level filtering, sink routing, and formatting; this module
5
+ * adapts LogTape's template-string logger to the ts-infra `Logger` contract
6
+ * (`method(msg, data?)` + `child(context)`) so call-sites stay backend-agnostic.
7
+ *
8
+ * ADR-011: ts-infra must not touch `node:fs`/`process.stderr`. The console sink
9
+ * is LogTape's own (`getConsoleSink`); the file sink is supplied by the caller
10
+ * (typically `@gobing-ai/ts-runtime`, which owns FileSystem) via
11
+ * {@link InitLoggerOptions.fileSink}.
5
12
  */
13
+ /** Log severity levels in ascending order: trace → debug → info → warn → error → fatal. */
6
14
  export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
15
+ /**
16
+ * Structured logger interface with level methods and context inheritance
17
+ * via {@link Logger.child}. `data` is attached as structured properties —
18
+ * `msg` is logged verbatim (no template substitution).
19
+ */
7
20
  export interface Logger {
8
21
  trace(msg: string, data?: Record<string, unknown>): void;
9
22
  debug(msg: string, data?: Record<string, unknown>): void;
@@ -14,15 +27,34 @@ export interface Logger {
14
27
  child(context: Record<string, unknown>): Logger;
15
28
  }
16
29
  /**
17
- * Mute or unmute all logger console output. Useful for tests.
30
+ * Mute or unmute all logger output. Useful for tests. Gating happens in the
31
+ * adapter before delegating to LogTape, so muting is synchronous and global.
18
32
  */
19
- export declare function setLoggerMuted(muted: boolean): void;
33
+ export declare function setLoggerMuted(value: boolean): void;
20
34
  /**
21
- * Get or create a logger for the given category.
35
+ * Get a logger for the given category. Categories are nested under the
36
+ * `app` root so a single `initializeLogger` rule configures them all.
22
37
  */
23
38
  export declare function getLogger(category: string): Logger;
39
+ /** Options for {@link initializeLogger}. */
40
+ export interface InitLoggerOptions {
41
+ /** Minimum level to emit. Default `info`. */
42
+ level?: LogLevel;
43
+ /** Enable the console sink. Default `true`. */
44
+ console?: boolean;
45
+ /**
46
+ * File sink writer. ts-infra never opens files itself (ADR-011); the
47
+ * caller (e.g. ts-runtime FileSystem) provides a writer that appends one
48
+ * already-formatted line per record. When omitted, no file sink is wired.
49
+ */
50
+ fileSink?: (line: string) => void;
51
+ /** Format records as JSON Lines (`true`) or human-readable text (`false`). Default `true`. */
52
+ json?: boolean;
53
+ }
24
54
  /**
25
- * Initialize the logger subsystem with a minimum log level.
55
+ * Configure LogTape with console and/or file sinks. Call once at startup;
56
+ * safe to call again to reconfigure — the prior config is reset first so the
57
+ * latest call wins (LogTape throws `ConfigError` on double-configure otherwise).
26
58
  */
27
- export declare function initializeLogger(level?: LogLevel): void;
59
+ export declare function initializeLogger(options?: InitLoggerOptions): Promise<void>;
28
60
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings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