From 93a6c6ef774872028075c4aabb8df56182b6fd1b Mon Sep 17 00:00:00 2001 From: Luca Steeb Date: Tue, 18 Jun 2024 21:38:40 +0100 Subject: [PATCH] chore: use camelCase instead of snake_case (#182) --- examples/api.ts | 8 +- examples/example-event-with-results.ts | 2 +- examples/fanout-worker.e2e.ts | 3 +- examples/manual-trigger.ts | 2 +- examples/rate-limit/worker.ts | 2 +- package.json | 4 +- src/clients/admin/admin-client.test.ts | 8 +- src/clients/admin/admin-client.ts | 117 +++++++++++++++++++++--- src/clients/worker/worker.test.ts | 6 +- src/clients/worker/worker.ts | 12 ++- src/protoc/dispatcher/dispatcher.ts | 2 +- src/protoc/events/events.ts | 2 +- src/protoc/google/protobuf/timestamp.ts | 2 +- src/protoc/workflows/workflows.ts | 2 +- src/step.ts | 2 +- 15 files changed, 135 insertions(+), 39 deletions(-) diff --git a/examples/api.ts b/examples/api.ts index 47d5e5d..5370b44 100644 --- a/examples/api.ts +++ b/examples/api.ts @@ -1,4 +1,4 @@ -import Hatchet, { Context, AdminClient } from '../src'; +import Hatchet, { Context } from '../src'; import { CreateWorkflowVersionOpts } from '../src/protoc/workflows'; type CustomUserData = { @@ -42,9 +42,9 @@ type StepOneInput = { async function main() { const hatchet = Hatchet.init(); - const admin = hatchet.admin; + const { admin } = hatchet; - await admin.put_workflow(opts); + await admin.putWorkflow(opts); const worker = await hatchet.worker('example-worker'); @@ -54,7 +54,7 @@ async function main() { return { step1: 'step1' }; }); - await hatchet.admin.run_workflow('api-workflow', {}); + await hatchet.admin.runWorkflow('api-workflow', {}); worker.start(); } diff --git a/examples/example-event-with-results.ts b/examples/example-event-with-results.ts index 33d5567..9a39fe9 100644 --- a/examples/example-event-with-results.ts +++ b/examples/example-event-with-results.ts @@ -3,7 +3,7 @@ import Hatchet from '../src/sdk'; async function main() { const hatchet = Hatchet.init(); - const workflowRunId = await hatchet.admin.run_workflow('simple-workflow', { + const workflowRunId = await hatchet.admin.runWorkflow('simple-workflow', { test: 'test', }); diff --git a/examples/fanout-worker.e2e.ts b/examples/fanout-worker.e2e.ts index e2f3c26..b3ef481 100644 --- a/examples/fanout-worker.e2e.ts +++ b/examples/fanout-worker.e2e.ts @@ -3,7 +3,6 @@ import sleep from '../src/util/sleep'; import Hatchet from '../src/sdk'; xdescribe('fanout-e2e', () => { - it('should pass a fanout workflow', async () => { let invoked = 0; const start = new Date(); @@ -63,7 +62,7 @@ xdescribe('fanout-e2e', () => { console.log('pushing event...'); - await hatchet.admin.run_workflow('parent-workflow', { input: 'parent-input' }); + await hatchet.admin.runWorkflow('parent-workflow', { input: 'parent-input' }); await sleep(10000); diff --git a/examples/manual-trigger.ts b/examples/manual-trigger.ts index 646f9ca..80cfd16 100644 --- a/examples/manual-trigger.ts +++ b/examples/manual-trigger.ts @@ -3,7 +3,7 @@ import Hatchet from '../src/sdk'; const hatchet = Hatchet.init(); async function main() { - const workflowRunId = await hatchet.admin.run_workflow('simple-workflow', {}); + const workflowRunId = await hatchet.admin.runWorkflow('simple-workflow', {}); const stream = await hatchet.listener.stream(workflowRunId); for await (const event of stream) { diff --git a/examples/rate-limit/worker.ts b/examples/rate-limit/worker.ts index a821fb7..a599cf9 100644 --- a/examples/rate-limit/worker.ts +++ b/examples/rate-limit/worker.ts @@ -23,7 +23,7 @@ const workflow: Workflow = { }; async function main() { - await hatchet.admin.put_rate_limit('test-limit', 1, RateLimitDuration.MINUTE); + await hatchet.admin.putRateLimit('test-limit', 1, RateLimitDuration.MINUTE); const worker = await hatchet.worker('example-worker'); await worker.registerWorkflow(workflow); worker.start(); diff --git a/package.json b/package.json index 10521a9..45945c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hatchet-dev/typescript-sdk", - "version": "0.7.4", + "version": "0.8.0", "description": "Background task orchestration & visibility for developers", "types": "dist/index.d.ts", "files": [ @@ -100,4 +100,4 @@ "yaml": "^2.3.4", "zod": "^3.22.4" } -} \ No newline at end of file +} diff --git a/src/clients/admin/admin-client.test.ts b/src/clients/admin/admin-client.test.ts index 767f2d8..07f4098 100644 --- a/src/clients/admin/admin-client.test.ts +++ b/src/clients/admin/admin-client.test.ts @@ -51,7 +51,7 @@ describe('AdminClient', () => { ); }); - describe('put_workflow', () => { + describe('putWorkflow', () => { it('should throw an error if no version and not auto version', async () => { const workflow: CreateWorkflowVersionOpts = { name: 'workflow1', @@ -64,7 +64,7 @@ describe('AdminClient', () => { concurrency: undefined, }; - expect(() => client.put_workflow(workflow)).rejects.toThrow( + expect(() => client.putWorkflow(workflow)).rejects.toThrow( 'PutWorkflow error: workflow version is required, or use autoVersion' ); }); @@ -90,7 +90,7 @@ describe('AdminClient', () => { updatedAt: undefined, }); - await client.put_workflow(workflow); + await client.putWorkflow(workflow); expect(putSpy).toHaveBeenCalled(); }); @@ -111,7 +111,7 @@ describe('AdminClient', () => { const now = new Date(); - client.schedule_workflow('workflowName', { + client.scheduleWorkflow('workflowName', { schedules: [now], }); diff --git a/src/clients/admin/admin-client.ts b/src/clients/admin/admin-client.ts index 60b91df..0a4f75c 100644 --- a/src/clients/admin/admin-client.ts +++ b/src/clients/admin/admin-client.ts @@ -57,12 +57,19 @@ export class AdminClient { this.logger = new Logger(`Admin`, config.log_level); } + /** + * @deprecated use putWorkflow instead + */ + async put_workflow(opts: CreateWorkflowVersionOpts) { + return this.putWorkflow(opts); + } + /** * Creates a new workflow or updates an existing workflow. If the workflow already exists, Hatchet will automatically * determine if the workflow definition has changed and create a new version if necessary. * @param workflow a workflow definition to create */ - async put_workflow(workflow: CreateWorkflowVersionOpts) { + async putWorkflow(workflow: CreateWorkflowVersionOpts) { try { await retrier(async () => this.client.putWorkflow({ opts: workflow }), this.logger); } catch (e: any) { @@ -70,7 +77,14 @@ export class AdminClient { } } - async put_rate_limit( + /** + * @deprecated use putRateLimit instead + */ + async put_rate_limit(key: string, limit: number, duration: RateLimitDuration) { + return this.putRateLimit(key, limit, duration); + } + + async putRateLimit( key: string, limit: number, duration: RateLimitDuration = RateLimitDuration.SECOND @@ -90,14 +104,32 @@ export class AdminClient { } } + /** + * @deprecated use runWorkflow instead + */ + async run_workflow( + workflowName: string, + input: T, + options?: { + parentId?: string | undefined; + parentStepRunId?: string | undefined; + childIndex?: number | undefined; + childKey?: string | undefined; + additionalMetadata?: Record | undefined; + } + ) { + return this.runWorkflow(workflowName, input, options); + } + /** * Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the * new run. * @param workflowName the name of the workflow to run * @param input an object containing the input to the workflow + * @param options an object containing the options to run the workflow * @returns the ID of the new workflow run */ - async run_workflow( + async runWorkflow( workflowName: string, input: T, options?: { @@ -132,32 +164,53 @@ export class AdminClient { } } + /** + * @deprecated use listWorkflows instead + */ + async list_workflows() { + return this.listWorkflows(); + } + /** * List workflows in the tenant associated with the API token. * @returns a list of all workflows in the tenant */ - async list_workflows() { + async listWorkflows() { const res = await this.api.workflowList(this.tenantId); return res.data; } + /** + * @deprecated use getWorkflow instead + */ + async get_workflow(workflowId: string) { + return this.getWorkflow(workflowId); + } + /** * Get a workflow by its ID. * @param workflowId the workflow ID (**note:** this is not the same as the workflow version id) * @returns */ - async get_workflow(workflowId: string) { + async getWorkflow(workflowId: string) { const res = await this.api.workflowGet(workflowId); return res.data; } + /** + * @deprecated use getWorkflowVersion instead + */ + async get_workflow_version(workflowId: string, version?: string) { + return this.getWorkflowVersion(workflowId, version); + } + /** * Get a workflow version. * @param workflowId the workflow ID * @param version the version of the workflow to get. If not provided, the latest version will be returned. * @returns the workflow version */ - async get_workflow_version(workflowId: string, version?: string) { + async getWorkflowVersion(workflowId: string, version?: string) { const res = await this.api.workflowVersionGet(workflowId, { version, }); @@ -165,22 +218,45 @@ export class AdminClient { return res.data; } + /** + * @deprecated use getWorkflowRun instead + */ + async get_workflow_run(workflowRunId: string) { + return this.getWorkflowRun(workflowRunId); + } + /** * Get a workflow run. * @param workflowRunId the id of the workflow run to get * @returns the workflow run */ - async get_workflow_run(workflowRunId: string) { + async getWorkflowRun(workflowRunId: string) { const res = await this.api.workflowRunGet(this.tenantId, workflowRunId); return res.data; } + /** + * @deprecated use listWorkflowRuns instead + */ + async list_workflow_runs(query: { + offset?: number | undefined; + limit?: number | undefined; + eventId?: string | undefined; + workflowId?: string | undefined; + parentWorkflowRunId?: string | undefined; + parentStepRunId?: string | undefined; + statuses?: WorkflowRunStatusList | undefined; + additionalMetadata?: string[] | undefined; + }) { + return this.listWorkflowRuns(query); + } + /** * List workflow runs in the tenant associated with the API token. * @param query the query to filter the list of workflow runs * @returns */ - async list_workflow_runs(query: { + async listWorkflowRuns(query: { offset?: number | undefined; limit?: number | undefined; eventId?: string | undefined; @@ -194,12 +270,24 @@ export class AdminClient { return res.data; } + /** + * @deprecated use scheduleWorkflow instead + */ + async schedule_workflow( + name: string, + options?: { + schedules?: Date[]; + } + ) { + return this.scheduleWorkflow(name, options); + } + /** * Schedule a workflow to run at a specific time or times. * @param name the name of the workflow to schedule * @param options an object containing the schedules to set */ - schedule_workflow(name: string, options?: { schedules?: Date[] }) { + scheduleWorkflow(name: string, options?: { schedules?: Date[] }) { try { this.client.scheduleWorkflow({ name, @@ -210,6 +298,13 @@ export class AdminClient { } } + /** + * @deprecated use getWorkflowMetrics instead + */ + async get_workflow_metrics(data: WorkflowMetricsQuery) { + return this.getWorkflowMetrics(data); + } + /** * Get the metrics for a workflow. * @@ -217,14 +312,14 @@ export class AdminClient { * @param workflowName the name of the workflow to get metrics for * @param query an object containing query parameters to filter the metrics */ - get_workflow_metrics({ workflowId, workflowName, status, groupKey }: WorkflowMetricsQuery) { + getWorkflowMetrics({ workflowId, workflowName, status, groupKey }: WorkflowMetricsQuery) { const params = { status, groupKey, }; if (workflowName) { - this.list_workflows().then((res) => { + this.listWorkflows().then((res) => { const workflow = res.rows?.find((row) => row.name === workflowName); if (workflow) { diff --git a/src/clients/worker/worker.test.ts b/src/clients/worker/worker.test.ts index e014ae0..23f3617 100644 --- a/src/clients/worker/worker.test.ts +++ b/src/clients/worker/worker.test.ts @@ -52,10 +52,10 @@ describe('Worker', () => { ); }); - describe('register_workflow', () => { + describe('registerWorkflow', () => { it('should update the registry', async () => { const worker = new Worker(hatchet, { name: 'WORKER_NAME' }); - const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue(); + const putWorkflowSpy = jest.spyOn(worker.client.admin, 'putWorkflow').mockResolvedValue(); const workflow = { id: 'workflow1', @@ -87,7 +87,7 @@ describe('Worker', () => { it('should start a step run', async () => { const worker = new Worker(hatchet, { name: 'WORKER_NAME' }); - const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue(); + const putWorkflowSpy = jest.spyOn(worker.client.admin, 'putWorkflow').mockResolvedValue(); const getActionEventSpy = jest.spyOn(worker, 'getStepActionEvent'); diff --git a/src/clients/worker/worker.ts b/src/clients/worker/worker.ts index 65ee8f1..29eb441 100644 --- a/src/clients/worker/worker.ts +++ b/src/clients/worker/worker.ts @@ -56,12 +56,14 @@ export class Worker { this.logger = new Logger(`Worker/${this.name}`, this.client.config.log_level); } - // @deprecated - async registerWorkflow(initWorkflow: Workflow) { - return this.register_workflow(initWorkflow); + /** + * @deprecated use registerWorkflow instead + */ + async register_workflow(initWorkflow: Workflow) { + return this.registerWorkflow(initWorkflow); } - async register_workflow(initWorkflow: Workflow) { + async registerWorkflow(initWorkflow: Workflow) { const workflow: Workflow = { ...initWorkflow, id: this.client.config.namespace + initWorkflow.id, @@ -95,7 +97,7 @@ export class Worker { } : undefined; - const registeredWorkflow = this.client.admin.put_workflow({ + const registeredWorkflow = this.client.admin.putWorkflow({ name: workflow.id, description: workflow.description, version: workflow.version || '', diff --git a/src/protoc/dispatcher/dispatcher.ts b/src/protoc/dispatcher/dispatcher.ts index 57b9793..db0f105 100644 --- a/src/protoc/dispatcher/dispatcher.ts +++ b/src/protoc/dispatcher/dispatcher.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: dispatcher/dispatcher.proto diff --git a/src/protoc/events/events.ts b/src/protoc/events/events.ts index c56d89d..bd71b3d 100644 --- a/src/protoc/events/events.ts +++ b/src/protoc/events/events.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: events/events.proto diff --git a/src/protoc/google/protobuf/timestamp.ts b/src/protoc/google/protobuf/timestamp.ts index a2f5af3..4b7823c 100644 --- a/src/protoc/google/protobuf/timestamp.ts +++ b/src/protoc/google/protobuf/timestamp.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: google/protobuf/timestamp.proto diff --git a/src/protoc/workflows/workflows.ts b/src/protoc/workflows/workflows.ts index 8b5e5cf..703d8f4 100644 --- a/src/protoc/workflows/workflows.ts +++ b/src/protoc/workflows/workflows.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: workflows/workflows.proto diff --git a/src/step.ts b/src/step.ts index 05c7524..b1ee899 100644 --- a/src/step.ts +++ b/src/step.ts @@ -232,7 +232,7 @@ export class Context { const name = this.client.config.namespace + workflowName; - const childWorkflowRunIdPromise = this.client.admin.run_workflow(name, input, { + const childWorkflowRunIdPromise = this.client.admin.runWorkflow(name, input, { parentId: workflowRunId, parentStepRunId: stepRunId, childKey: key,