@hatchet-dev/typescript-sdk 0.1.23 → 0.1.25
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/clients/event/event-client.d.ts +7 -0
- package/clients/event/event-client.js +36 -1
- package/clients/rest/generated/Api.d.ts +48 -1
- package/clients/rest/generated/Api.js +28 -0
- package/clients/rest/generated/data-contracts.d.ts +30 -0
- package/clients/rest/generated/data-contracts.js +17 -1
- package/clients/worker/worker.js +2 -2
- package/package.json +2 -1
- package/protoc/events/events.d.ts +54 -0
- package/protoc/events/events.js +155 -1
- package/step.d.ts +6 -1
- package/step.js +15 -2
- package/util/parse.d.ts +1 -0
- package/util/parse.js +20 -0
|
@@ -2,10 +2,17 @@ import { Channel, ClientFactory } from 'nice-grpc';
|
|
|
2
2
|
import { EventsServiceClient } from '../../protoc/events/events';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
import { Logger } from '../../util/logger';
|
|
5
|
+
export declare enum LogLevel {
|
|
6
|
+
INFO = "INFO",
|
|
7
|
+
WARN = "WARN",
|
|
8
|
+
ERROR = "ERROR",
|
|
9
|
+
DEBUG = "DEBUG"
|
|
10
|
+
}
|
|
5
11
|
export declare class EventClient {
|
|
6
12
|
config: ClientConfig;
|
|
7
13
|
client: EventsServiceClient;
|
|
8
14
|
logger: Logger;
|
|
9
15
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
10
16
|
push<T>(type: string, input: T): Promise<import("../../protoc/events/events").Event>;
|
|
17
|
+
putLog(stepRunId: string, log: string, level?: LogLevel): void;
|
|
11
18
|
}
|
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EventClient = void 0;
|
|
15
|
+
exports.EventClient = exports.LogLevel = void 0;
|
|
7
16
|
const events_1 = require("../../protoc/events/events");
|
|
8
17
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
9
18
|
const logger_1 = require("../../util/logger");
|
|
19
|
+
const retrier_1 = require("../../util/retrier");
|
|
20
|
+
// eslint-disable-next-line no-shadow
|
|
21
|
+
var LogLevel;
|
|
22
|
+
(function (LogLevel) {
|
|
23
|
+
LogLevel["INFO"] = "INFO";
|
|
24
|
+
LogLevel["WARN"] = "WARN";
|
|
25
|
+
LogLevel["ERROR"] = "ERROR";
|
|
26
|
+
LogLevel["DEBUG"] = "DEBUG";
|
|
27
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
10
28
|
class EventClient {
|
|
11
29
|
constructor(config, channel, factory) {
|
|
12
30
|
this.config = config;
|
|
@@ -28,5 +46,22 @@ class EventClient {
|
|
|
28
46
|
throw new hatchet_error_1.default(e.message);
|
|
29
47
|
}
|
|
30
48
|
}
|
|
49
|
+
putLog(stepRunId, log, level) {
|
|
50
|
+
const createdAt = new Date();
|
|
51
|
+
try {
|
|
52
|
+
(0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return this.client.putLog({
|
|
54
|
+
stepRunId,
|
|
55
|
+
createdAt,
|
|
56
|
+
message: log,
|
|
57
|
+
level: level || LogLevel.INFO,
|
|
58
|
+
});
|
|
59
|
+
}), this.logger);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
// log a warning, but this is not a fatal error
|
|
63
|
+
this.logger.warn(`Could not put log: ${e.message}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
31
66
|
}
|
|
32
67
|
exports.EventClient = EventClient;
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
import { APIMeta, AcceptInviteRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreatePullRequestFromStepRun, CreateTenantInviteRequest, CreateTenantRequest, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, GetStepRunDiffResponse, LinkGithubRepositoryRequest, ListAPIMetaIntegration, ListAPITokensResponse, ListGithubAppInstallationsResponse, ListGithubBranchesResponse, ListGithubReposResponse, ListPullRequestsResponse, PullRequestState, RejectInviteRequest, ReplayEventRequest, RerunStepRunRequest, StepRun, Tenant, TenantInvite, TenantInviteList, TenantMemberList, TriggerWorkflowRunRequest, UpdateTenantInviteRequest, User, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, Worker, WorkerList, Workflow, WorkflowID, WorkflowList, WorkflowRun, WorkflowRunList, WorkflowVersion, WorkflowVersionDefinition } from './data-contracts';
|
|
1
|
+
import { APIMeta, AcceptInviteRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreatePullRequestFromStepRun, CreateTenantInviteRequest, CreateTenantRequest, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, GetStepRunDiffResponse, LinkGithubRepositoryRequest, ListAPIMetaIntegration, ListAPITokensResponse, ListGithubAppInstallationsResponse, ListGithubBranchesResponse, ListGithubReposResponse, ListPullRequestsResponse, LogLineLevelField, LogLineList, LogLineOrderByDirection, LogLineOrderByField, LogLineSearch, PullRequestState, RejectInviteRequest, ReplayEventRequest, RerunStepRunRequest, StepRun, Tenant, TenantInvite, TenantInviteList, TenantMemberList, TriggerWorkflowRunRequest, UpdateTenantInviteRequest, User, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, Worker, WorkerList, Workflow, WorkflowID, WorkflowList, WorkflowRun, WorkflowRunList, WorkflowVersion, WorkflowVersionDefinition } from './data-contracts';
|
|
2
2
|
import { HttpClient, RequestParams } from './http-client';
|
|
3
3
|
export declare class Api<SecurityDataType = unknown> extends HttpClient<SecurityDataType> {
|
|
4
|
+
/**
|
|
5
|
+
* @description Gets the readiness status
|
|
6
|
+
*
|
|
7
|
+
* @tags Healthcheck
|
|
8
|
+
* @name ReadinessGet
|
|
9
|
+
* @summary Get readiness
|
|
10
|
+
* @request GET:/api/ready
|
|
11
|
+
*/
|
|
12
|
+
readinessGet: (params?: RequestParams) => Promise<import("axios").AxiosResponse<void, any>>;
|
|
13
|
+
/**
|
|
14
|
+
* @description Gets the liveness status
|
|
15
|
+
*
|
|
16
|
+
* @tags Healthcheck
|
|
17
|
+
* @name LivenessGet
|
|
18
|
+
* @summary Get liveness
|
|
19
|
+
* @request GET:/api/live
|
|
20
|
+
*/
|
|
21
|
+
livenessGet: (params?: RequestParams) => Promise<import("axios").AxiosResponse<void, any>>;
|
|
4
22
|
/**
|
|
5
23
|
* @description Gets metadata for the Hatchet instance
|
|
6
24
|
*
|
|
@@ -397,6 +415,35 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
|
|
|
397
415
|
* @secure
|
|
398
416
|
*/
|
|
399
417
|
stepRunUpdateCreatePr: (stepRun: string, data: CreatePullRequestFromStepRun, params?: RequestParams) => Promise<import("axios").AxiosResponse<CreatePullRequestFromStepRun, any>>;
|
|
418
|
+
/**
|
|
419
|
+
* @description Lists log lines for a step run.
|
|
420
|
+
*
|
|
421
|
+
* @tags Log
|
|
422
|
+
* @name LogLineList
|
|
423
|
+
* @summary List log lines
|
|
424
|
+
* @request GET:/api/v1/step-runs/{step-run}/logs
|
|
425
|
+
* @secure
|
|
426
|
+
*/
|
|
427
|
+
logLineList: (stepRun: string, query?: {
|
|
428
|
+
/**
|
|
429
|
+
* The number to skip
|
|
430
|
+
* @format int64
|
|
431
|
+
*/
|
|
432
|
+
offset?: number;
|
|
433
|
+
/**
|
|
434
|
+
* The number to limit by
|
|
435
|
+
* @format int64
|
|
436
|
+
*/
|
|
437
|
+
limit?: number;
|
|
438
|
+
/** A list of levels to filter by */
|
|
439
|
+
levels?: LogLineLevelField;
|
|
440
|
+
/** The search query to filter for */
|
|
441
|
+
search?: LogLineSearch;
|
|
442
|
+
/** What to order by */
|
|
443
|
+
orderByField?: LogLineOrderByField;
|
|
444
|
+
/** The order direction */
|
|
445
|
+
orderByDirection?: LogLineOrderByDirection;
|
|
446
|
+
}, params?: RequestParams) => Promise<import("axios").AxiosResponse<LogLineList, any>>;
|
|
400
447
|
/**
|
|
401
448
|
* @description Get the diff for a step run between the most recent run and the first run.
|
|
402
449
|
*
|
|
@@ -15,6 +15,24 @@ const http_client_1 = require("./http-client");
|
|
|
15
15
|
class Api extends http_client_1.HttpClient {
|
|
16
16
|
constructor() {
|
|
17
17
|
super(...arguments);
|
|
18
|
+
/**
|
|
19
|
+
* @description Gets the readiness status
|
|
20
|
+
*
|
|
21
|
+
* @tags Healthcheck
|
|
22
|
+
* @name ReadinessGet
|
|
23
|
+
* @summary Get readiness
|
|
24
|
+
* @request GET:/api/ready
|
|
25
|
+
*/
|
|
26
|
+
this.readinessGet = (params = {}) => this.request(Object.assign({ path: `/api/ready`, method: 'GET' }, params));
|
|
27
|
+
/**
|
|
28
|
+
* @description Gets the liveness status
|
|
29
|
+
*
|
|
30
|
+
* @tags Healthcheck
|
|
31
|
+
* @name LivenessGet
|
|
32
|
+
* @summary Get liveness
|
|
33
|
+
* @request GET:/api/live
|
|
34
|
+
*/
|
|
35
|
+
this.livenessGet = (params = {}) => this.request(Object.assign({ path: `/api/live`, method: 'GET' }, params));
|
|
18
36
|
/**
|
|
19
37
|
* @description Gets metadata for the Hatchet instance
|
|
20
38
|
*
|
|
@@ -366,6 +384,16 @@ class Api extends http_client_1.HttpClient {
|
|
|
366
384
|
* @secure
|
|
367
385
|
*/
|
|
368
386
|
this.stepRunUpdateCreatePr = (stepRun, data, params = {}) => this.request(Object.assign({ path: `/api/v1/step-runs/${stepRun}/create-pr`, method: 'POST', body: data, secure: true, type: http_client_1.ContentType.Json, format: 'json' }, params));
|
|
387
|
+
/**
|
|
388
|
+
* @description Lists log lines for a step run.
|
|
389
|
+
*
|
|
390
|
+
* @tags Log
|
|
391
|
+
* @name LogLineList
|
|
392
|
+
* @summary List log lines
|
|
393
|
+
* @request GET:/api/v1/step-runs/{step-run}/logs
|
|
394
|
+
* @secure
|
|
395
|
+
*/
|
|
396
|
+
this.logLineList = (stepRun, query, params = {}) => this.request(Object.assign({ path: `/api/v1/step-runs/${stepRun}/logs`, method: 'GET', query: query, secure: true, format: 'json' }, params));
|
|
369
397
|
/**
|
|
370
398
|
* @description Get the diff for a step run between the most recent run and the first run.
|
|
371
399
|
*
|
|
@@ -597,3 +597,33 @@ export declare enum PullRequestState {
|
|
|
597
597
|
Open = "open",
|
|
598
598
|
Closed = "closed"
|
|
599
599
|
}
|
|
600
|
+
export interface LogLine {
|
|
601
|
+
/**
|
|
602
|
+
* The creation date of the log line.
|
|
603
|
+
* @format date-time
|
|
604
|
+
*/
|
|
605
|
+
createdAt: string;
|
|
606
|
+
/** The log message. */
|
|
607
|
+
message: string;
|
|
608
|
+
/** The log metadata. */
|
|
609
|
+
metadata: object;
|
|
610
|
+
}
|
|
611
|
+
export declare enum LogLineLevel {
|
|
612
|
+
DEBUG = "DEBUG",
|
|
613
|
+
INFO = "INFO",
|
|
614
|
+
WARN = "WARN",
|
|
615
|
+
ERROR = "ERROR"
|
|
616
|
+
}
|
|
617
|
+
export interface LogLineList {
|
|
618
|
+
pagination?: PaginationResponse;
|
|
619
|
+
rows?: LogLine[];
|
|
620
|
+
}
|
|
621
|
+
export declare enum LogLineOrderByField {
|
|
622
|
+
CreatedAt = "createdAt"
|
|
623
|
+
}
|
|
624
|
+
export declare enum LogLineOrderByDirection {
|
|
625
|
+
Asc = "asc",
|
|
626
|
+
Desc = "desc"
|
|
627
|
+
}
|
|
628
|
+
export type LogLineSearch = string;
|
|
629
|
+
export type LogLineLevelField = LogLineLevel[];
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* ---------------------------------------------------------------
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.PullRequestState = exports.StepRunStatus = exports.JobRunStatus = exports.WorkflowRunStatus = exports.EventOrderByDirection = exports.EventOrderByField = exports.TenantMemberRole = void 0;
|
|
13
|
+
exports.LogLineOrderByDirection = exports.LogLineOrderByField = exports.LogLineLevel = exports.PullRequestState = exports.StepRunStatus = exports.JobRunStatus = exports.WorkflowRunStatus = exports.EventOrderByDirection = exports.EventOrderByField = exports.TenantMemberRole = void 0;
|
|
14
14
|
var TenantMemberRole;
|
|
15
15
|
(function (TenantMemberRole) {
|
|
16
16
|
TenantMemberRole["OWNER"] = "OWNER";
|
|
@@ -57,3 +57,19 @@ var PullRequestState;
|
|
|
57
57
|
PullRequestState["Open"] = "open";
|
|
58
58
|
PullRequestState["Closed"] = "closed";
|
|
59
59
|
})(PullRequestState || (exports.PullRequestState = PullRequestState = {}));
|
|
60
|
+
var LogLineLevel;
|
|
61
|
+
(function (LogLineLevel) {
|
|
62
|
+
LogLineLevel["DEBUG"] = "DEBUG";
|
|
63
|
+
LogLineLevel["INFO"] = "INFO";
|
|
64
|
+
LogLineLevel["WARN"] = "WARN";
|
|
65
|
+
LogLineLevel["ERROR"] = "ERROR";
|
|
66
|
+
})(LogLineLevel || (exports.LogLineLevel = LogLineLevel = {}));
|
|
67
|
+
var LogLineOrderByField;
|
|
68
|
+
(function (LogLineOrderByField) {
|
|
69
|
+
LogLineOrderByField["CreatedAt"] = "createdAt";
|
|
70
|
+
})(LogLineOrderByField || (exports.LogLineOrderByField = LogLineOrderByField = {}));
|
|
71
|
+
var LogLineOrderByDirection;
|
|
72
|
+
(function (LogLineOrderByDirection) {
|
|
73
|
+
LogLineOrderByDirection["Asc"] = "asc";
|
|
74
|
+
LogLineOrderByDirection["Desc"] = "desc";
|
|
75
|
+
})(LogLineOrderByDirection || (exports.LogLineOrderByDirection = LogLineOrderByDirection = {}));
|
package/clients/worker/worker.js
CHANGED
|
@@ -100,7 +100,7 @@ class Worker {
|
|
|
100
100
|
handleStartStepRun(action) {
|
|
101
101
|
const { actionId } = action;
|
|
102
102
|
try {
|
|
103
|
-
const context = new step_1.Context(action, this.client.dispatcher);
|
|
103
|
+
const context = new step_1.Context(action, this.client.dispatcher, this.client.event);
|
|
104
104
|
this.contexts[action.stepRunId] = context;
|
|
105
105
|
const step = this.action_registry[actionId];
|
|
106
106
|
if (!step) {
|
|
@@ -149,7 +149,7 @@ class Worker {
|
|
|
149
149
|
handleStartGroupKeyRun(action) {
|
|
150
150
|
const { actionId } = action;
|
|
151
151
|
try {
|
|
152
|
-
const context = new step_1.Context(action, this.client.dispatcher);
|
|
152
|
+
const context = new step_1.Context(action, this.client.dispatcher, this.client.event);
|
|
153
153
|
const key = action.getGroupKeyRunId;
|
|
154
154
|
this.contexts[key] = context;
|
|
155
155
|
this.logger.debug(`Starting group key run ${key}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"worker:playground": "npm run exec -- ./examples/playground.ts",
|
|
39
39
|
"worker:retries": "npm run exec -- ./examples/retries-worker.ts",
|
|
40
40
|
"worker:multi-workflow": "npm run exec -- ./examples/multi-workflow.ts",
|
|
41
|
+
"worker:logger": "npm run exec -- ./examples/logger.ts",
|
|
41
42
|
"api": "npm run exec -- ./examples/api.ts",
|
|
42
43
|
"prepublish": "cp package.json dist/package.json;",
|
|
43
44
|
"publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks",
|
|
@@ -13,6 +13,20 @@ export interface Event {
|
|
|
13
13
|
/** when the event was generated */
|
|
14
14
|
eventTimestamp: Date | undefined;
|
|
15
15
|
}
|
|
16
|
+
export interface PutLogRequest {
|
|
17
|
+
/** the step run id for the request */
|
|
18
|
+
stepRunId: string;
|
|
19
|
+
/** when the log line was created */
|
|
20
|
+
createdAt: Date | undefined;
|
|
21
|
+
/** the log line message */
|
|
22
|
+
message: string;
|
|
23
|
+
/** the log line level */
|
|
24
|
+
level?: string | undefined;
|
|
25
|
+
/** associated log line metadata */
|
|
26
|
+
metadata: string;
|
|
27
|
+
}
|
|
28
|
+
export interface PutLogResponse {
|
|
29
|
+
}
|
|
16
30
|
export interface PushEventRequest {
|
|
17
31
|
/** the key for the event */
|
|
18
32
|
key: string;
|
|
@@ -43,6 +57,22 @@ export declare const Event: {
|
|
|
43
57
|
create(base?: DeepPartial<Event>): Event;
|
|
44
58
|
fromPartial(object: DeepPartial<Event>): Event;
|
|
45
59
|
};
|
|
60
|
+
export declare const PutLogRequest: {
|
|
61
|
+
encode(message: PutLogRequest, writer?: _m0.Writer): _m0.Writer;
|
|
62
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PutLogRequest;
|
|
63
|
+
fromJSON(object: any): PutLogRequest;
|
|
64
|
+
toJSON(message: PutLogRequest): unknown;
|
|
65
|
+
create(base?: DeepPartial<PutLogRequest>): PutLogRequest;
|
|
66
|
+
fromPartial(object: DeepPartial<PutLogRequest>): PutLogRequest;
|
|
67
|
+
};
|
|
68
|
+
export declare const PutLogResponse: {
|
|
69
|
+
encode(_: PutLogResponse, writer?: _m0.Writer): _m0.Writer;
|
|
70
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PutLogResponse;
|
|
71
|
+
fromJSON(_: any): PutLogResponse;
|
|
72
|
+
toJSON(_: PutLogResponse): unknown;
|
|
73
|
+
create(base?: DeepPartial<PutLogResponse>): PutLogResponse;
|
|
74
|
+
fromPartial(_: DeepPartial<PutLogResponse>): PutLogResponse;
|
|
75
|
+
};
|
|
46
76
|
export declare const PushEventRequest: {
|
|
47
77
|
encode(message: PushEventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
48
78
|
decode(input: _m0.Reader | Uint8Array, length?: number): PushEventRequest;
|
|
@@ -146,17 +176,41 @@ export declare const EventsServiceDefinition: {
|
|
|
146
176
|
readonly responseStream: false;
|
|
147
177
|
readonly options: {};
|
|
148
178
|
};
|
|
179
|
+
readonly putLog: {
|
|
180
|
+
readonly name: "PutLog";
|
|
181
|
+
readonly requestType: {
|
|
182
|
+
encode(message: PutLogRequest, writer?: _m0.Writer): _m0.Writer;
|
|
183
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PutLogRequest;
|
|
184
|
+
fromJSON(object: any): PutLogRequest;
|
|
185
|
+
toJSON(message: PutLogRequest): unknown;
|
|
186
|
+
create(base?: DeepPartial<PutLogRequest>): PutLogRequest;
|
|
187
|
+
fromPartial(object: DeepPartial<PutLogRequest>): PutLogRequest;
|
|
188
|
+
};
|
|
189
|
+
readonly requestStream: false;
|
|
190
|
+
readonly responseType: {
|
|
191
|
+
encode(_: PutLogResponse, writer?: _m0.Writer): _m0.Writer;
|
|
192
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PutLogResponse;
|
|
193
|
+
fromJSON(_: any): PutLogResponse;
|
|
194
|
+
toJSON(_: PutLogResponse): unknown;
|
|
195
|
+
create(base?: DeepPartial<PutLogResponse>): PutLogResponse;
|
|
196
|
+
fromPartial(_: DeepPartial<PutLogResponse>): PutLogResponse;
|
|
197
|
+
};
|
|
198
|
+
readonly responseStream: false;
|
|
199
|
+
readonly options: {};
|
|
200
|
+
};
|
|
149
201
|
};
|
|
150
202
|
};
|
|
151
203
|
export interface EventsServiceImplementation<CallContextExt = {}> {
|
|
152
204
|
push(request: PushEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Event>>;
|
|
153
205
|
list(request: ListEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<ListEventResponse>>;
|
|
154
206
|
replaySingleEvent(request: ReplayEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Event>>;
|
|
207
|
+
putLog(request: PutLogRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PutLogResponse>>;
|
|
155
208
|
}
|
|
156
209
|
export interface EventsServiceClient<CallOptionsExt = {}> {
|
|
157
210
|
push(request: DeepPartial<PushEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Event>;
|
|
158
211
|
list(request: DeepPartial<ListEventRequest>, options?: CallOptions & CallOptionsExt): Promise<ListEventResponse>;
|
|
159
212
|
replaySingleEvent(request: DeepPartial<ReplayEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Event>;
|
|
213
|
+
putLog(request: DeepPartial<PutLogRequest>, options?: CallOptions & CallOptionsExt): Promise<PutLogResponse>;
|
|
160
214
|
}
|
|
161
215
|
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
162
216
|
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
package/protoc/events/events.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.EventsServiceDefinition = exports.ReplayEventRequest = exports.ListEventResponse = exports.ListEventRequest = exports.PushEventRequest = exports.Event = exports.protobufPackage = void 0;
|
|
26
|
+
exports.EventsServiceDefinition = exports.ReplayEventRequest = exports.ListEventResponse = exports.ListEventRequest = exports.PushEventRequest = exports.PutLogResponse = exports.PutLogRequest = exports.Event = exports.protobufPackage = void 0;
|
|
27
27
|
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
28
28
|
const timestamp_1 = require("../google/protobuf/timestamp");
|
|
29
29
|
exports.protobufPackage = "";
|
|
@@ -136,6 +136,152 @@ exports.Event = {
|
|
|
136
136
|
return message;
|
|
137
137
|
},
|
|
138
138
|
};
|
|
139
|
+
function createBasePutLogRequest() {
|
|
140
|
+
return { stepRunId: "", createdAt: undefined, message: "", level: undefined, metadata: "" };
|
|
141
|
+
}
|
|
142
|
+
exports.PutLogRequest = {
|
|
143
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
144
|
+
if (message.stepRunId !== "") {
|
|
145
|
+
writer.uint32(10).string(message.stepRunId);
|
|
146
|
+
}
|
|
147
|
+
if (message.createdAt !== undefined) {
|
|
148
|
+
timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(18).fork()).ldelim();
|
|
149
|
+
}
|
|
150
|
+
if (message.message !== "") {
|
|
151
|
+
writer.uint32(26).string(message.message);
|
|
152
|
+
}
|
|
153
|
+
if (message.level !== undefined) {
|
|
154
|
+
writer.uint32(34).string(message.level);
|
|
155
|
+
}
|
|
156
|
+
if (message.metadata !== "") {
|
|
157
|
+
writer.uint32(42).string(message.metadata);
|
|
158
|
+
}
|
|
159
|
+
return writer;
|
|
160
|
+
},
|
|
161
|
+
decode(input, length) {
|
|
162
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
163
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
164
|
+
const message = createBasePutLogRequest();
|
|
165
|
+
while (reader.pos < end) {
|
|
166
|
+
const tag = reader.uint32();
|
|
167
|
+
switch (tag >>> 3) {
|
|
168
|
+
case 1:
|
|
169
|
+
if (tag !== 10) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
message.stepRunId = reader.string();
|
|
173
|
+
continue;
|
|
174
|
+
case 2:
|
|
175
|
+
if (tag !== 18) {
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
|
|
179
|
+
continue;
|
|
180
|
+
case 3:
|
|
181
|
+
if (tag !== 26) {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
message.message = reader.string();
|
|
185
|
+
continue;
|
|
186
|
+
case 4:
|
|
187
|
+
if (tag !== 34) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
message.level = reader.string();
|
|
191
|
+
continue;
|
|
192
|
+
case 5:
|
|
193
|
+
if (tag !== 42) {
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
message.metadata = reader.string();
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
reader.skipType(tag & 7);
|
|
203
|
+
}
|
|
204
|
+
return message;
|
|
205
|
+
},
|
|
206
|
+
fromJSON(object) {
|
|
207
|
+
return {
|
|
208
|
+
stepRunId: isSet(object.stepRunId) ? globalThis.String(object.stepRunId) : "",
|
|
209
|
+
createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined,
|
|
210
|
+
message: isSet(object.message) ? globalThis.String(object.message) : "",
|
|
211
|
+
level: isSet(object.level) ? globalThis.String(object.level) : undefined,
|
|
212
|
+
metadata: isSet(object.metadata) ? globalThis.String(object.metadata) : "",
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
toJSON(message) {
|
|
216
|
+
const obj = {};
|
|
217
|
+
if (message.stepRunId !== "") {
|
|
218
|
+
obj.stepRunId = message.stepRunId;
|
|
219
|
+
}
|
|
220
|
+
if (message.createdAt !== undefined) {
|
|
221
|
+
obj.createdAt = message.createdAt.toISOString();
|
|
222
|
+
}
|
|
223
|
+
if (message.message !== "") {
|
|
224
|
+
obj.message = message.message;
|
|
225
|
+
}
|
|
226
|
+
if (message.level !== undefined) {
|
|
227
|
+
obj.level = message.level;
|
|
228
|
+
}
|
|
229
|
+
if (message.metadata !== "") {
|
|
230
|
+
obj.metadata = message.metadata;
|
|
231
|
+
}
|
|
232
|
+
return obj;
|
|
233
|
+
},
|
|
234
|
+
create(base) {
|
|
235
|
+
return exports.PutLogRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
236
|
+
},
|
|
237
|
+
fromPartial(object) {
|
|
238
|
+
var _a, _b, _c, _d, _e;
|
|
239
|
+
const message = createBasePutLogRequest();
|
|
240
|
+
message.stepRunId = (_a = object.stepRunId) !== null && _a !== void 0 ? _a : "";
|
|
241
|
+
message.createdAt = (_b = object.createdAt) !== null && _b !== void 0 ? _b : undefined;
|
|
242
|
+
message.message = (_c = object.message) !== null && _c !== void 0 ? _c : "";
|
|
243
|
+
message.level = (_d = object.level) !== null && _d !== void 0 ? _d : undefined;
|
|
244
|
+
message.metadata = (_e = object.metadata) !== null && _e !== void 0 ? _e : "";
|
|
245
|
+
return message;
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
function createBasePutLogResponse() {
|
|
249
|
+
return {};
|
|
250
|
+
}
|
|
251
|
+
exports.PutLogResponse = {
|
|
252
|
+
encode(_, writer = _m0.Writer.create()) {
|
|
253
|
+
return writer;
|
|
254
|
+
},
|
|
255
|
+
decode(input, length) {
|
|
256
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
257
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
258
|
+
const message = createBasePutLogResponse();
|
|
259
|
+
while (reader.pos < end) {
|
|
260
|
+
const tag = reader.uint32();
|
|
261
|
+
switch (tag >>> 3) {
|
|
262
|
+
}
|
|
263
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
reader.skipType(tag & 7);
|
|
267
|
+
}
|
|
268
|
+
return message;
|
|
269
|
+
},
|
|
270
|
+
fromJSON(_) {
|
|
271
|
+
return {};
|
|
272
|
+
},
|
|
273
|
+
toJSON(_) {
|
|
274
|
+
const obj = {};
|
|
275
|
+
return obj;
|
|
276
|
+
},
|
|
277
|
+
create(base) {
|
|
278
|
+
return exports.PutLogResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
279
|
+
},
|
|
280
|
+
fromPartial(_) {
|
|
281
|
+
const message = createBasePutLogResponse();
|
|
282
|
+
return message;
|
|
283
|
+
},
|
|
284
|
+
};
|
|
139
285
|
function createBasePushEventRequest() {
|
|
140
286
|
return { key: "", payload: "", eventTimestamp: undefined };
|
|
141
287
|
}
|
|
@@ -415,6 +561,14 @@ exports.EventsServiceDefinition = {
|
|
|
415
561
|
responseStream: false,
|
|
416
562
|
options: {},
|
|
417
563
|
},
|
|
564
|
+
putLog: {
|
|
565
|
+
name: "PutLog",
|
|
566
|
+
requestType: exports.PutLogRequest,
|
|
567
|
+
requestStream: false,
|
|
568
|
+
responseType: exports.PutLogResponse,
|
|
569
|
+
responseStream: false,
|
|
570
|
+
options: {},
|
|
571
|
+
},
|
|
418
572
|
},
|
|
419
573
|
};
|
|
420
574
|
function toTimestamp(date) {
|
package/step.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import { Action } from './clients/dispatcher/action-listener';
|
|
3
3
|
import { DispatcherClient } from './clients/dispatcher/dispatcher-client';
|
|
4
|
+
import { EventClient, LogLevel } from './clients/event/event-client';
|
|
5
|
+
import { Logger } from './util/logger';
|
|
4
6
|
export declare const CreateStepSchema: z.ZodObject<{
|
|
5
7
|
name: z.ZodString;
|
|
6
8
|
parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -33,8 +35,10 @@ export declare class Context<T, K> {
|
|
|
33
35
|
controller: AbortController;
|
|
34
36
|
action: Action;
|
|
35
37
|
client: DispatcherClient;
|
|
38
|
+
eventClient: EventClient;
|
|
36
39
|
overridesData: Record<string, any>;
|
|
37
|
-
|
|
40
|
+
logger: Logger;
|
|
41
|
+
constructor(action: Action, client: DispatcherClient, eventClient: EventClient);
|
|
38
42
|
stepOutput(step: string): NextStep;
|
|
39
43
|
triggeredByEvent(): boolean;
|
|
40
44
|
workflowInput(): T;
|
|
@@ -42,6 +46,7 @@ export declare class Context<T, K> {
|
|
|
42
46
|
stepName(): string;
|
|
43
47
|
workflowRunId(): string;
|
|
44
48
|
playground(name: string, defaultValue?: string): string;
|
|
49
|
+
log(message: string, level?: LogLevel): void;
|
|
45
50
|
}
|
|
46
51
|
export type StepRunFunction<T, K> = (ctx: Context<T, K>) => Promise<NextStep> | NextStep | void;
|
|
47
52
|
export interface CreateStep<T, K> extends z.infer<typeof CreateStepSchema> {
|
package/step.js
CHANGED
|
@@ -30,6 +30,8 @@ exports.Context = exports.CreateStepSchema = void 0;
|
|
|
30
30
|
const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
|
|
31
31
|
const z = __importStar(require("zod"));
|
|
32
32
|
const workflow_1 = require("./workflow");
|
|
33
|
+
const logger_1 = require("./util/logger");
|
|
34
|
+
const parse_1 = require("./util/parse");
|
|
33
35
|
exports.CreateStepSchema = z.object({
|
|
34
36
|
name: z.string(),
|
|
35
37
|
parents: z.array(z.string()).optional(),
|
|
@@ -37,14 +39,16 @@ exports.CreateStepSchema = z.object({
|
|
|
37
39
|
retries: z.number().optional(),
|
|
38
40
|
});
|
|
39
41
|
class Context {
|
|
40
|
-
constructor(action, client) {
|
|
42
|
+
constructor(action, client, eventClient) {
|
|
41
43
|
this.controller = new AbortController();
|
|
42
44
|
this.overridesData = {};
|
|
43
45
|
try {
|
|
44
|
-
const data =
|
|
46
|
+
const data = (0, parse_1.parseJSON)(action.actionPayload);
|
|
45
47
|
this.data = data;
|
|
46
48
|
this.action = action;
|
|
47
49
|
this.client = client;
|
|
50
|
+
this.eventClient = eventClient;
|
|
51
|
+
this.logger = new logger_1.Logger(`Context Logger`, client.config.log_level);
|
|
48
52
|
// if this is a getGroupKeyRunId, the data is the workflow input
|
|
49
53
|
if (action.getGroupKeyRunId !== '') {
|
|
50
54
|
this.input = data;
|
|
@@ -95,5 +99,14 @@ class Context {
|
|
|
95
99
|
});
|
|
96
100
|
return defaultValue;
|
|
97
101
|
}
|
|
102
|
+
log(message, level) {
|
|
103
|
+
const { stepRunId } = this.action;
|
|
104
|
+
if (!stepRunId) {
|
|
105
|
+
// log a warning
|
|
106
|
+
this.logger.warn('cannot log from context without stepRunId');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.eventClient.putLog(stepRunId, message, level);
|
|
110
|
+
}
|
|
98
111
|
}
|
|
99
112
|
exports.Context = Context;
|
package/util/parse.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseJSON(json: string): any;
|
package/util/parse.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseJSON = void 0;
|
|
4
|
+
function parseJSON(json) {
|
|
5
|
+
try {
|
|
6
|
+
const firstParse = JSON.parse(json);
|
|
7
|
+
// Hatchet engine versions <=0.14.0 return JSON as a quoted string which needs to be parsed again.
|
|
8
|
+
// This is a workaround for that issue, but will not be needed in future versions.
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(firstParse);
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
return firstParse;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
throw new Error(`Could not parse JSON: ${e.message}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.parseJSON = parseJSON;
|