duron 0.3.0-beta.9 → 0.3.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/dist/action-job.d.ts +33 -2
- package/dist/action-job.d.ts.map +1 -1
- package/dist/action-job.js +88 -23
- package/dist/action-manager.d.ts +44 -2
- package/dist/action-manager.d.ts.map +1 -1
- package/dist/action-manager.js +64 -3
- package/dist/action.d.ts +388 -7
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +44 -23
- package/dist/adapters/adapter.d.ts +365 -8
- package/dist/adapters/adapter.d.ts.map +1 -1
- package/dist/adapters/adapter.js +221 -15
- package/dist/adapters/postgres/base.d.ts +184 -6
- package/dist/adapters/postgres/base.d.ts.map +1 -1
- package/dist/adapters/postgres/base.js +436 -75
- package/dist/adapters/postgres/pglite.d.ts +37 -0
- package/dist/adapters/postgres/pglite.d.ts.map +1 -1
- package/dist/adapters/postgres/pglite.js +38 -0
- package/dist/adapters/postgres/postgres.d.ts +35 -0
- package/dist/adapters/postgres/postgres.d.ts.map +1 -1
- package/dist/adapters/postgres/postgres.js +42 -0
- package/dist/adapters/postgres/schema.d.ts +150 -37
- package/dist/adapters/postgres/schema.d.ts.map +1 -1
- package/dist/adapters/postgres/schema.default.d.ts +151 -38
- package/dist/adapters/postgres/schema.default.d.ts.map +1 -1
- package/dist/adapters/postgres/schema.default.js +2 -2
- package/dist/adapters/postgres/schema.js +60 -23
- package/dist/adapters/schemas.d.ts +124 -80
- package/dist/adapters/schemas.d.ts.map +1 -1
- package/dist/adapters/schemas.js +139 -26
- package/dist/client.d.ts +426 -22
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +370 -20
- package/dist/constants.js +6 -0
- package/dist/errors.d.ts +140 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +152 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/server.d.ts +99 -37
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +84 -25
- package/dist/step-manager.d.ts +111 -4
- package/dist/step-manager.d.ts.map +1 -1
- package/dist/step-manager.js +403 -75
- package/dist/telemetry/index.d.ts +1 -4
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +2 -4
- package/dist/telemetry/local-span-exporter.d.ts +56 -0
- package/dist/telemetry/local-span-exporter.d.ts.map +1 -0
- package/dist/telemetry/local-span-exporter.js +118 -0
- package/dist/utils/p-retry.d.ts +5 -0
- package/dist/utils/p-retry.d.ts.map +1 -1
- package/dist/utils/p-retry.js +8 -0
- package/dist/utils/wait-for-abort.d.ts +1 -0
- package/dist/utils/wait-for-abort.d.ts.map +1 -1
- package/dist/utils/wait-for-abort.js +1 -0
- package/migrations/postgres/{20260119153838_flimsy_thor_girl → 20260121160012_normal_bloodstrike}/migration.sql +32 -20
- package/migrations/postgres/{20260119153838_flimsy_thor_girl → 20260121160012_normal_bloodstrike}/snapshot.json +241 -66
- package/package.json +42 -26
- package/src/action-job.ts +33 -29
- package/src/action-manager.ts +5 -5
- package/src/action.ts +317 -149
- package/src/adapters/adapter.ts +54 -54
- package/src/adapters/postgres/base.ts +266 -86
- package/src/adapters/postgres/schema.default.ts +2 -2
- package/src/adapters/postgres/schema.ts +52 -24
- package/src/adapters/schemas.ts +91 -36
- package/src/client.ts +322 -68
- package/src/errors.ts +84 -12
- package/src/index.ts +2 -0
- package/src/server.ts +39 -37
- package/src/step-manager.ts +246 -95
- package/src/telemetry/index.ts +2 -20
- package/src/telemetry/local-span-exporter.ts +148 -0
- package/dist/telemetry/adapter.d.ts +0 -107
- package/dist/telemetry/adapter.d.ts.map +0 -1
- package/dist/telemetry/adapter.js +0 -134
- package/dist/telemetry/local.d.ts +0 -22
- package/dist/telemetry/local.d.ts.map +0 -1
- package/dist/telemetry/local.js +0 -243
- package/dist/telemetry/noop.d.ts +0 -17
- package/dist/telemetry/noop.d.ts.map +0 -1
- package/dist/telemetry/noop.js +0 -66
- package/dist/telemetry/opentelemetry.d.ts +0 -25
- package/dist/telemetry/opentelemetry.d.ts.map +0 -1
- package/dist/telemetry/opentelemetry.js +0 -312
- package/src/telemetry/adapter.ts +0 -642
- package/src/telemetry/local.ts +0 -429
- package/src/telemetry/noop.ts +0 -141
- package/src/telemetry/opentelemetry.ts +0 -453
package/dist/step-manager.d.ts
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
|
+
import { type Span, type Tracer } from '@opentelemetry/api';
|
|
1
2
|
import type { Logger } from 'pino';
|
|
2
3
|
import type { z } from 'zod';
|
|
3
4
|
import { type Action, type ActionHandlerContext, type StepHandlerContext, type StepOptions } from './action.js';
|
|
4
5
|
import type { Adapter } from './adapters/adapter.js';
|
|
5
6
|
import { type StepStatus } from './constants.js';
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Telemetry context provided to action and step handlers.
|
|
9
|
+
* Provides access to OpenTelemetry APIs for recording traces and metrics.
|
|
10
|
+
*/
|
|
11
|
+
export interface TelemetryContext {
|
|
12
|
+
/**
|
|
13
|
+
* Get the active OpenTelemetry span for the current job/step.
|
|
14
|
+
*/
|
|
15
|
+
getActiveSpan(): Span | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Get an OpenTelemetry tracer for creating custom spans.
|
|
18
|
+
*/
|
|
19
|
+
getTracer(name: string): Tracer;
|
|
20
|
+
/**
|
|
21
|
+
* Start a new span as a child of the current job/step span.
|
|
22
|
+
* This is a convenience method that properly links the span to the trace hierarchy.
|
|
23
|
+
*/
|
|
24
|
+
startSpan(name: string, options?: {
|
|
25
|
+
attributes?: Record<string, any>;
|
|
26
|
+
}): Span;
|
|
27
|
+
/**
|
|
28
|
+
* Record a custom metric as a span event.
|
|
29
|
+
*/
|
|
30
|
+
recordMetric(name: string, value: number, attributes?: Record<string, any>): void;
|
|
31
|
+
}
|
|
7
32
|
export interface TaskStep {
|
|
8
33
|
name: string;
|
|
9
34
|
cb: (ctx: StepHandlerContext) => Promise<any>;
|
|
@@ -12,9 +37,30 @@ export interface TaskStep {
|
|
|
12
37
|
parentStepId: string | null;
|
|
13
38
|
parallel: boolean;
|
|
14
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* StepStore manages step records in the database.
|
|
42
|
+
* Provides methods to create, update, and delay steps.
|
|
43
|
+
*/
|
|
15
44
|
export declare class StepStore {
|
|
16
45
|
#private;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new StepStore instance.
|
|
48
|
+
*
|
|
49
|
+
* @param adapter - The database adapter to use for step operations
|
|
50
|
+
*/
|
|
17
51
|
constructor(adapter: Adapter);
|
|
52
|
+
/**
|
|
53
|
+
* Get or create a step record in the database.
|
|
54
|
+
*
|
|
55
|
+
* @param jobId - The ID of the job this step belongs to
|
|
56
|
+
* @param name - The name of the step
|
|
57
|
+
* @param timeoutMs - Timeout in milliseconds for the step
|
|
58
|
+
* @param retriesLimit - Maximum number of retries for the step
|
|
59
|
+
* @param parentStepId - The ID of the parent step (null for root steps)
|
|
60
|
+
* @param parallel - Whether this step runs in parallel (independent from siblings during time travel)
|
|
61
|
+
* @returns Promise resolving to the created step ID
|
|
62
|
+
* @throws Error if step creation fails
|
|
63
|
+
*/
|
|
18
64
|
getOrCreate(jobId: string, name: string, timeoutMs: number, retriesLimit: number, parentStepId?: string | null, parallel?: boolean): Promise<{
|
|
19
65
|
id: string;
|
|
20
66
|
status: "active" | "completed" | "failed" | "cancelled";
|
|
@@ -25,29 +71,90 @@ export declare class StepStore {
|
|
|
25
71
|
output: any;
|
|
26
72
|
isNew: boolean;
|
|
27
73
|
} | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Update the status of a step in the database.
|
|
76
|
+
*
|
|
77
|
+
* @param stepId - The ID of the step to update
|
|
78
|
+
* @param status - The new status (completed, failed, or cancelled)
|
|
79
|
+
* @param output - Optional output data for completed steps
|
|
80
|
+
* @param error - Optional error data for failed steps
|
|
81
|
+
* @returns Promise resolving to `true` if update succeeded, `false` otherwise
|
|
82
|
+
*/
|
|
28
83
|
updateStatus(stepId: string, status: StepStatus, output?: any, error?: any): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Delay a step execution.
|
|
86
|
+
* Used when a step fails and needs to be retried after a delay.
|
|
87
|
+
*
|
|
88
|
+
* @param stepId - The ID of the step to delay
|
|
89
|
+
* @param delayMs - The delay in milliseconds before retrying
|
|
90
|
+
* @param error - The error that caused the delay
|
|
91
|
+
* @returns Promise resolving to `true` if delayed successfully, `false` otherwise
|
|
92
|
+
*/
|
|
29
93
|
delay(stepId: string, delayMs: number, error: any): Promise<boolean>;
|
|
30
94
|
}
|
|
31
95
|
export interface StepManagerOptions {
|
|
32
96
|
jobId: string;
|
|
33
97
|
actionName: string;
|
|
34
98
|
adapter: Adapter;
|
|
35
|
-
|
|
99
|
+
tracer: Tracer;
|
|
36
100
|
logger: Logger;
|
|
37
101
|
concurrencyLimit: number;
|
|
38
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* StepManager manages steps for a single ActionJob.
|
|
105
|
+
* Each ActionJob has its own StepManager instance.
|
|
106
|
+
*/
|
|
39
107
|
export declare class StepManager {
|
|
40
108
|
#private;
|
|
109
|
+
/**
|
|
110
|
+
* Create a new StepManager instance.
|
|
111
|
+
*
|
|
112
|
+
* @param options - Configuration options for the step manager
|
|
113
|
+
*/
|
|
41
114
|
constructor(options: StepManagerOptions);
|
|
115
|
+
/**
|
|
116
|
+
* Set the job span for this step manager.
|
|
117
|
+
* Called from ActionJob after the job span is created.
|
|
118
|
+
*/
|
|
42
119
|
setJobSpan(span: Span): void;
|
|
120
|
+
/**
|
|
121
|
+
* Set the run function factory for executing step definitions from inline steps.
|
|
122
|
+
* Called from ActionContext after it's initialized.
|
|
123
|
+
*
|
|
124
|
+
* @param factory - A function that creates run functions with the correct parent step ID and abort signal
|
|
125
|
+
*/
|
|
43
126
|
setRunFnFactory(factory: (parentStepId: string | null, abortSignal: AbortSignal) => StepHandlerContext['run']): void;
|
|
127
|
+
/**
|
|
128
|
+
* Create an ActionContext for the action handler.
|
|
129
|
+
* The context provides access to input, variables, logger, and the step function.
|
|
130
|
+
*
|
|
131
|
+
* @param job - The job data including ID, input, and optional group key
|
|
132
|
+
* @param action - The action definition
|
|
133
|
+
* @param variables - Variables available to the action
|
|
134
|
+
* @param abortSignal - Abort signal for cancelling the action
|
|
135
|
+
* @param logger - Pino child logger for this job
|
|
136
|
+
* @returns ActionHandlerContext instance
|
|
137
|
+
*/
|
|
44
138
|
createActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVariables = Record<string, unknown>>(job: {
|
|
45
139
|
id: string;
|
|
46
140
|
input: z.infer<TInput>;
|
|
47
141
|
groupKey?: string;
|
|
48
|
-
}, action: Action<TInput, TOutput, TVariables>, variables: TVariables, abortSignal: AbortSignal, logger: Logger
|
|
49
|
-
|
|
142
|
+
}, action: Action<TInput, TOutput, TVariables>, variables: TVariables, abortSignal: AbortSignal, logger: Logger): ActionHandlerContext<TInput, TVariables>;
|
|
143
|
+
/**
|
|
144
|
+
* Create a telemetry context for a step.
|
|
145
|
+
*/
|
|
146
|
+
createStepTelemetryContext(stepId: string): TelemetryContext;
|
|
147
|
+
/**
|
|
148
|
+
* Queue a step task for execution.
|
|
149
|
+
*
|
|
150
|
+
* @param task - The step task to queue
|
|
151
|
+
* @returns Promise resolving to the step result
|
|
152
|
+
*/
|
|
50
153
|
push(task: TaskStep): Promise<any>;
|
|
154
|
+
/**
|
|
155
|
+
* Clean up step queues by waiting for them to drain.
|
|
156
|
+
* Should be called when the job completes or is cancelled.
|
|
157
|
+
*/
|
|
51
158
|
drain(): Promise<void>;
|
|
52
159
|
}
|
|
53
160
|
//# sourceMappingURL=step-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-manager.d.ts","sourceRoot":"","sources":["../src/step-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"step-manager.d.ts","sourceRoot":"","sources":["../src/step-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KA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