@hatchet-dev/typescript-sdk 0.16.0-alpha.3 → 0.16.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 (58) hide show
  1. package/clients/dispatcher/dispatcher-client.d.ts +2 -1
  2. package/clients/dispatcher/dispatcher-client.js +10 -1
  3. package/clients/event/event-client.js +13 -8
  4. package/clients/hatchet-client/client-config.d.ts +0 -6
  5. package/clients/hatchet-client/client-config.js +0 -2
  6. package/clients/hatchet-client/features/cron-client.d.ts +79 -0
  7. package/clients/hatchet-client/features/cron-client.js +127 -0
  8. package/clients/hatchet-client/features/schedule-client.d.ts +76 -0
  9. package/clients/hatchet-client/features/schedule-client.js +120 -0
  10. package/clients/hatchet-client/hatchet-client.d.ts +4 -2
  11. package/clients/hatchet-client/hatchet-client.js +6 -25
  12. package/clients/listener/child-listener-client.js +16 -13
  13. package/clients/rest/api.d.ts +0 -3
  14. package/clients/rest/api.js +0 -10
  15. package/clients/rest/generated/Api.d.ts +152 -2
  16. package/clients/rest/generated/Api.js +81 -1
  17. package/clients/rest/generated/data-contracts.d.ts +86 -0
  18. package/clients/rest/generated/data-contracts.js +27 -1
  19. package/clients/rest/index.d.ts +2 -2
  20. package/clients/rest/index.js +21 -10
  21. package/clients/worker/handler.js +16 -11
  22. package/clients/worker/worker.d.ts +2 -10
  23. package/clients/worker/worker.js +21 -37
  24. package/examples/crons/cron-worker.d.ts +2 -0
  25. package/examples/crons/cron-worker.js +48 -0
  26. package/examples/crons/programatic-crons.js +55 -0
  27. package/examples/on-failure.js +15 -10
  28. package/examples/scheduled-runs/programatic-schedules.d.ts +1 -0
  29. package/examples/scheduled-runs/programatic-schedules.js +54 -0
  30. package/examples/simple-worker.d.ts +2 -1
  31. package/examples/simple-worker.js +6 -3
  32. package/package.json +7 -8
  33. package/protoc/dispatcher/dispatcher.js +1 -1
  34. package/protoc/events/events.js +1 -1
  35. package/protoc/google/protobuf/timestamp.js +1 -1
  36. package/protoc/google/protobuf/wrappers.js +17 -7
  37. package/protoc/workflows/workflows.d.ts +13 -0
  38. package/protoc/workflows/workflows.js +160 -7
  39. package/step.d.ts +0 -117
  40. package/step.js +17 -9
  41. package/util/config-loader/config-loader.js +18 -26
  42. package/util/retrier.js +8 -3
  43. package/version.d.ts +1 -0
  44. package/version.js +4 -0
  45. package/workflow.d.ts +0 -443
  46. package/workflow.js +17 -7
  47. package/clients/rest/generated/cloud/Api.d.ts +0 -377
  48. package/clients/rest/generated/cloud/Api.js +0 -326
  49. package/clients/rest/generated/cloud/data-contracts.d.ts +0 -468
  50. package/clients/rest/generated/cloud/data-contracts.js +0 -68
  51. package/clients/rest/generated/cloud/http-client.d.ts +0 -41
  52. package/clients/rest/generated/cloud/http-client.js +0 -102
  53. package/clients/worker/compute/compute-config.d.ts +0 -150
  54. package/clients/worker/compute/compute-config.js +0 -76
  55. package/clients/worker/compute/managed-compute.d.ts +0 -15
  56. package/clients/worker/compute/managed-compute.js +0 -102
  57. package/examples/managed-worker.js +0 -65
  58. /package/examples/{managed-worker.d.ts → crons/programatic-crons.d.ts} +0 -0
@@ -1,150 +0,0 @@
1
- import { ManagedWorkerRegion } from '../../rest/generated/cloud/data-contracts';
2
- import { z } from 'zod';
3
- export declare const SharedCPUComputeSchema: z.ZodObject<z.objectUtil.extendShape<{
4
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
5
- numReplicas: z.ZodDefault<z.ZodNumber>;
6
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">>;
7
- cpus: z.ZodNumber;
8
- }, {
9
- cpuKind: z.ZodLiteral<"shared">;
10
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
11
- }>, "strip", z.ZodTypeAny, {
12
- numReplicas: number;
13
- cpus: number;
14
- cpuKind: "shared";
15
- memoryMb: number;
16
- pool?: string | undefined;
17
- regions?: ManagedWorkerRegion[] | undefined;
18
- }, {
19
- cpus: number;
20
- cpuKind: "shared";
21
- memoryMb: number;
22
- pool?: string | undefined;
23
- numReplicas?: number | undefined;
24
- regions?: ManagedWorkerRegion[] | undefined;
25
- }>;
26
- export type SharedCPUCompute = z.infer<typeof SharedCPUComputeSchema>;
27
- export declare const PerformanceCPUComputeSchema: z.ZodObject<z.objectUtil.extendShape<{
28
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
29
- numReplicas: z.ZodDefault<z.ZodNumber>;
30
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">>;
31
- cpus: z.ZodNumber;
32
- }, {
33
- cpuKind: z.ZodLiteral<"performance">;
34
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
35
- }>, "strip", z.ZodTypeAny, {
36
- numReplicas: number;
37
- cpus: number;
38
- cpuKind: "performance";
39
- memoryMb: number;
40
- pool?: string | undefined;
41
- regions?: ManagedWorkerRegion[] | undefined;
42
- }, {
43
- cpus: number;
44
- cpuKind: "performance";
45
- memoryMb: number;
46
- pool?: string | undefined;
47
- numReplicas?: number | undefined;
48
- regions?: ManagedWorkerRegion[] | undefined;
49
- }>;
50
- export type PerformanceCPUCompute = z.infer<typeof PerformanceCPUComputeSchema>;
51
- export declare const GPUComputeSchema: z.ZodObject<z.objectUtil.extendShape<{
52
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
53
- numReplicas: z.ZodDefault<z.ZodNumber>;
54
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">>;
55
- cpus: z.ZodNumber;
56
- }, {
57
- cpuKind: z.ZodLiteral<"shared">;
58
- gpuKind: z.ZodEnum<["a10", "l40s", "a100-40gb", "a100-80gb"]>;
59
- regions: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">, ManagedWorkerRegion[], ManagedWorkerRegion[]>>;
60
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
61
- }>, "strip", z.ZodTypeAny, {
62
- numReplicas: number;
63
- cpus: number;
64
- cpuKind: "shared";
65
- memoryMb: number;
66
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
67
- pool?: string | undefined;
68
- regions?: ManagedWorkerRegion[] | undefined;
69
- }, {
70
- cpus: number;
71
- cpuKind: "shared";
72
- memoryMb: number;
73
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
74
- pool?: string | undefined;
75
- numReplicas?: number | undefined;
76
- regions?: ManagedWorkerRegion[] | undefined;
77
- }>;
78
- export type GPUCompute = z.infer<typeof GPUComputeSchema>;
79
- export declare const ComputeSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
80
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
81
- numReplicas: z.ZodDefault<z.ZodNumber>;
82
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">>;
83
- cpus: z.ZodNumber;
84
- }, {
85
- cpuKind: z.ZodLiteral<"shared">;
86
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
87
- }>, "strip", z.ZodTypeAny, {
88
- numReplicas: number;
89
- cpus: number;
90
- cpuKind: "shared";
91
- memoryMb: number;
92
- pool?: string | undefined;
93
- regions?: ManagedWorkerRegion[] | undefined;
94
- }, {
95
- cpus: number;
96
- cpuKind: "shared";
97
- memoryMb: number;
98
- pool?: string | undefined;
99
- numReplicas?: number | undefined;
100
- regions?: ManagedWorkerRegion[] | undefined;
101
- }>, z.ZodObject<z.objectUtil.extendShape<{
102
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
103
- numReplicas: z.ZodDefault<z.ZodNumber>;
104
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">>;
105
- cpus: z.ZodNumber;
106
- }, {
107
- cpuKind: z.ZodLiteral<"performance">;
108
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
109
- }>, "strip", z.ZodTypeAny, {
110
- numReplicas: number;
111
- cpus: number;
112
- cpuKind: "performance";
113
- memoryMb: number;
114
- pool?: string | undefined;
115
- regions?: ManagedWorkerRegion[] | undefined;
116
- }, {
117
- cpus: number;
118
- cpuKind: "performance";
119
- memoryMb: number;
120
- pool?: string | undefined;
121
- numReplicas?: number | undefined;
122
- regions?: ManagedWorkerRegion[] | undefined;
123
- }>, z.ZodObject<z.objectUtil.extendShape<{
124
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
125
- numReplicas: z.ZodDefault<z.ZodNumber>;
126
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">>;
127
- cpus: z.ZodNumber;
128
- }, {
129
- cpuKind: z.ZodLiteral<"shared">;
130
- gpuKind: z.ZodEnum<["a10", "l40s", "a100-40gb", "a100-80gb"]>;
131
- regions: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNativeEnum<typeof ManagedWorkerRegion>, "many">, ManagedWorkerRegion[], ManagedWorkerRegion[]>>;
132
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
133
- }>, "strip", z.ZodTypeAny, {
134
- numReplicas: number;
135
- cpus: number;
136
- cpuKind: "shared";
137
- memoryMb: number;
138
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
139
- pool?: string | undefined;
140
- regions?: ManagedWorkerRegion[] | undefined;
141
- }, {
142
- cpus: number;
143
- cpuKind: "shared";
144
- memoryMb: number;
145
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
146
- pool?: string | undefined;
147
- numReplicas?: number | undefined;
148
- regions?: ManagedWorkerRegion[] | undefined;
149
- }>]>;
150
- export declare const computeHash: (compute: z.infer<typeof ComputeSchema>) => string;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computeHash = exports.ComputeSchema = exports.GPUComputeSchema = exports.PerformanceCPUComputeSchema = exports.SharedCPUComputeSchema = void 0;
4
- const data_contracts_1 = require("../../rest/generated/cloud/data-contracts");
5
- const crypto_1 = require("crypto");
6
- const zod_1 = require("zod");
7
- const BaseComputeSchema = zod_1.z.object({
8
- pool: zod_1.z.string().default('default').optional().describe('The name of the compute pool to use'),
9
- numReplicas: zod_1.z
10
- .number()
11
- .int()
12
- .min(0, { message: 'Must be at least 0' })
13
- .max(1000, { message: 'Must be at most 1000' })
14
- .default(1)
15
- .describe('The number of replicas'),
16
- regions: zod_1.z
17
- .array(zod_1.z.nativeEnum(data_contracts_1.ManagedWorkerRegion))
18
- .optional()
19
- .describe('The regions to deploy the worker to'),
20
- cpus: zod_1.z
21
- .number()
22
- .int()
23
- .min(1, { message: 'Must be at least 1' })
24
- .max(64, { message: 'Must be at most 64' })
25
- .describe('The number of CPUs to use for the worker'),
26
- });
27
- exports.SharedCPUComputeSchema = BaseComputeSchema.extend({
28
- cpuKind: zod_1.z.literal('shared'),
29
- memoryMb: zod_1.z
30
- .number()
31
- .int()
32
- .min(256, { message: 'Must be at least 256 MB' })
33
- .max(65536, { message: 'Must be at most 65536 MB' })
34
- .refine((val) => val % 256 === 0, { message: 'Must be divisible by 256 MB' })
35
- .describe('The amount of memory in MB to use for the worker'),
36
- });
37
- exports.PerformanceCPUComputeSchema = BaseComputeSchema.extend({
38
- cpuKind: zod_1.z.literal('performance'),
39
- memoryMb: zod_1.z
40
- .number()
41
- .int()
42
- .min(2048, { message: 'Must be at least 1024 MB' })
43
- .max(65536, { message: 'Must be at most 65536 MB' })
44
- .refine((val) => val % 256 === 0, { message: 'Must be divisible by 256 MB' })
45
- .describe('The amount of memory in MB to use for the worker'),
46
- });
47
- // eslint-disable-next-line no-shadow
48
- const AllowedGPUManagedWorkerRegions = [data_contracts_1.ManagedWorkerRegion.Ord];
49
- exports.GPUComputeSchema = BaseComputeSchema.extend({
50
- cpuKind: zod_1.z.literal('shared'),
51
- gpuKind: zod_1.z.enum(['a10', 'l40s', 'a100-40gb', 'a100-80gb']),
52
- regions: zod_1.z
53
- .array(zod_1.z.nativeEnum(data_contracts_1.ManagedWorkerRegion))
54
- .refine((val) => val.every((region) => AllowedGPUManagedWorkerRegions.includes(region)), {
55
- message: 'Invalid GPU region',
56
- })
57
- .optional()
58
- .describe('The regions to deploy the worker to'),
59
- memoryMb: zod_1.z
60
- .number()
61
- .int()
62
- .min(2048, { message: 'Must be at least 1024 MB' })
63
- .max(65536, { message: 'Must be at most 65536 MB' })
64
- .refine((val) => val % 256 === 0, { message: 'Must be divisible by 256 MB' })
65
- .describe('The amount of memory in MB to use for the worker'),
66
- });
67
- exports.ComputeSchema = zod_1.z.union([
68
- exports.SharedCPUComputeSchema,
69
- exports.PerformanceCPUComputeSchema,
70
- exports.GPUComputeSchema,
71
- ]);
72
- const computeHash = (compute) => {
73
- const str = JSON.stringify(compute);
74
- return (0, crypto_1.createHash)('sha256').update(str).digest('hex');
75
- };
76
- exports.computeHash = computeHash;
@@ -1,15 +0,0 @@
1
- import { HatchetClient } from '../../hatchet-client';
2
- import { CreateManagedWorkerRuntimeConfigRequest } from '../../rest/generated/cloud/data-contracts';
3
- import { Logger } from '../../../util/logger';
4
- import { ActionRegistry } from '../worker';
5
- export declare class ManagedCompute {
6
- actions: ActionRegistry;
7
- client: HatchetClient;
8
- maxRuns: number;
9
- configs: CreateManagedWorkerRuntimeConfigRequest[];
10
- cloudRegisterId: string | undefined;
11
- logger: Logger;
12
- constructor(actions: ActionRegistry, client: HatchetClient, maxRuns?: number);
13
- getComputeConfigs(actions: ActionRegistry): CreateManagedWorkerRuntimeConfigRequest[];
14
- cloudRegister(): Promise<void>;
15
- }
@@ -1,102 +0,0 @@
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
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ManagedCompute = void 0;
13
- const logger_1 = require("../../../util/logger");
14
- const compute_config_1 = require("./compute-config");
15
- class ManagedCompute {
16
- constructor(actions, client, maxRuns = 1) {
17
- this.actions = actions;
18
- this.client = client;
19
- this.maxRuns = maxRuns;
20
- this.configs = this.getComputeConfigs(this.actions);
21
- this.cloudRegisterId = this.client.config.cloud_register_id;
22
- this.logger = new logger_1.Logger(`Compute`, this.client.config.log_level);
23
- if (this.configs.length === 0) {
24
- this.logger.debug('No compute configs found, skipping cloud registration and running all actions locally.');
25
- return;
26
- }
27
- if (!this.cloudRegisterId) {
28
- this.logger.warn('Managed cloud compute plan:');
29
- this.configs.forEach((compute) => {
30
- var _a;
31
- this.logger.warn(' ----------------------------');
32
- this.logger.warn(` actions: ${(_a = compute.actions) === null || _a === void 0 ? void 0 : _a.join(', ')}`);
33
- this.logger.warn(` num replicas: ${compute.numReplicas}`);
34
- this.logger.warn(` cpu kind: ${compute.cpuKind}`);
35
- this.logger.warn(` cpus: ${compute.cpus}`);
36
- this.logger.warn(` memory mb: ${compute.memoryMb}`);
37
- // this.logger.warn(` regions: ${compute.regions?.join(', ')}`);
38
- });
39
- this.logger.warn('NOTICE: local mode detected, skipping cloud registration and running all actions locally.');
40
- }
41
- }
42
- getComputeConfigs(actions) {
43
- /**
44
- * Builds a map of compute hashes to compute configs and lists of actions that correspond to each compute hash.
45
- */
46
- const computeMap = {};
47
- try {
48
- Object.entries(actions).forEach(([action, { compute }]) => {
49
- if (!compute) {
50
- return;
51
- }
52
- const key = (0, compute_config_1.computeHash)(compute);
53
- const gpuKind = 'gpuKind' in compute ? compute.gpuKind : undefined;
54
- if (!computeMap[key]) {
55
- computeMap[key] = {
56
- actions: [],
57
- numReplicas: compute.numReplicas,
58
- cpuKind: compute.cpuKind,
59
- cpus: compute.cpus,
60
- memoryMb: compute.memoryMb,
61
- regions: compute.regions,
62
- slots: this.maxRuns,
63
- gpuKind,
64
- };
65
- }
66
- computeMap[key].actions.push(action);
67
- });
68
- return Object.values(computeMap);
69
- }
70
- catch (e) {
71
- this.logger.error(`Error getting compute configs: ${e}`);
72
- return [];
73
- }
74
- }
75
- cloudRegister() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- /**
78
- * Registers the compute plan with the cloud if the environment variable is set.
79
- * Exits the process upon completion.
80
- */
81
- if (this.cloudRegisterId) {
82
- this.logger.info(`Registering cloud compute plan with ID: ${this.cloudRegisterId}`);
83
- try {
84
- if (this.configs.length === 0) {
85
- this.logger.warn('No actions to register, skipping cloud registration.');
86
- process.exit(0);
87
- }
88
- const req = {
89
- runtimeConfigs: this.configs,
90
- };
91
- yield this.client.cloudApi.infraAsCodeCreate(this.cloudRegisterId, req);
92
- process.exit(0);
93
- }
94
- catch (e) {
95
- this.logger.error(`ERROR: ${e}`);
96
- process.exit(1);
97
- }
98
- }
99
- });
100
- }
101
- }
102
- exports.ManagedCompute = ManagedCompute;
@@ -1,65 +0,0 @@
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
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const data_contracts_1 = require("../clients/rest/generated/cloud/data-contracts");
16
- const sdk_1 = __importDefault(require("../sdk"));
17
- const hatchet = sdk_1.default.init();
18
- const oneCpuWorkerConfig = {
19
- cpuKind: 'shared',
20
- memoryMb: 1024,
21
- numReplicas: 1,
22
- cpus: 1,
23
- regions: [data_contracts_1.ManagedWorkerRegion.Ewr],
24
- };
25
- const twoCpuWorkerConfig = {
26
- cpuKind: 'shared',
27
- memoryMb: 1024,
28
- numReplicas: 1,
29
- cpus: 2,
30
- regions: [data_contracts_1.ManagedWorkerRegion.Ewr],
31
- };
32
- const workflow = {
33
- id: 'simple-workflow',
34
- description: 'test',
35
- on: {
36
- event: 'user:create',
37
- },
38
- steps: [
39
- {
40
- name: 'step1',
41
- compute: oneCpuWorkerConfig,
42
- run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
43
- console.log('executed step1!');
44
- return { step1: 'step1 results!' };
45
- }),
46
- },
47
- {
48
- name: 'step2',
49
- parents: ['step1'],
50
- compute: twoCpuWorkerConfig,
51
- run: (ctx) => {
52
- console.log('executed step2 after step1 returned ', ctx.stepOutput('step1'));
53
- return { step2: 'step2 results!' };
54
- },
55
- },
56
- ],
57
- };
58
- function main() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const worker = yield hatchet.worker('managed-worker');
61
- yield worker.registerWorkflow(workflow);
62
- worker.start();
63
- });
64
- }
65
- main();