@hatchet-dev/typescript-sdk 1.37.0 → 1.38.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.37.0",
3
+ "version": "1.38.0",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -47,6 +47,12 @@ export interface StreamTopicMetadata {
47
47
  /** when the newest retained message was stored; unset when none is retained */
48
48
  lastPublishedAt: Date | undefined;
49
49
  }
50
+ export interface ResetStreamTopicRequest {
51
+ namespace: string;
52
+ topic: string;
53
+ }
54
+ export interface ResetStreamTopicResponse {
55
+ }
50
56
  export declare const PublishStreamMessageRequest: MessageFns<PublishStreamMessageRequest>;
51
57
  export declare const PublishStreamMessageResponse: MessageFns<PublishStreamMessageResponse>;
52
58
  export declare const SubscribeStreamRequest: MessageFns<SubscribeStreamRequest>;
@@ -54,6 +60,8 @@ export declare const StreamMessage: MessageFns<StreamMessage>;
54
60
  export declare const StreamEntry: MessageFns<StreamEntry>;
55
61
  export declare const GetStreamTopicMetadataRequest: MessageFns<GetStreamTopicMetadataRequest>;
56
62
  export declare const StreamTopicMetadata: MessageFns<StreamTopicMetadata>;
63
+ export declare const ResetStreamTopicRequest: MessageFns<ResetStreamTopicRequest>;
64
+ export declare const ResetStreamTopicResponse: MessageFns<ResetStreamTopicResponse>;
57
65
  export type V1StreamsDefinition = typeof V1StreamsDefinition;
58
66
  export declare const V1StreamsDefinition: {
59
67
  readonly name: "V1Streams";
@@ -83,17 +91,27 @@ export declare const V1StreamsDefinition: {
83
91
  readonly responseStream: false;
84
92
  readonly options: {};
85
93
  };
94
+ readonly reset: {
95
+ readonly name: "Reset";
96
+ readonly requestType: typeof ResetStreamTopicRequest;
97
+ readonly requestStream: false;
98
+ readonly responseType: typeof ResetStreamTopicResponse;
99
+ readonly responseStream: false;
100
+ readonly options: {};
101
+ };
86
102
  };
87
103
  };
88
104
  export interface V1StreamsServiceImplementation<CallContextExt = {}> {
89
105
  publish(request: PublishStreamMessageRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PublishStreamMessageResponse>>;
90
106
  subscribe(request: SubscribeStreamRequest, context: CallContext & CallContextExt): ServerStreamingMethodResult<DeepPartial<StreamMessage>>;
91
107
  getTopicMetadata(request: GetStreamTopicMetadataRequest, context: CallContext & CallContextExt): Promise<DeepPartial<StreamTopicMetadata>>;
108
+ reset(request: ResetStreamTopicRequest, context: CallContext & CallContextExt): Promise<DeepPartial<ResetStreamTopicResponse>>;
92
109
  }
93
110
  export interface V1StreamsClient<CallOptionsExt = {}> {
94
111
  publish(request: DeepPartial<PublishStreamMessageRequest>, options?: CallOptions & CallOptionsExt): Promise<PublishStreamMessageResponse>;
95
112
  subscribe(request: DeepPartial<SubscribeStreamRequest>, options?: CallOptions & CallOptionsExt): AsyncIterable<StreamMessage>;
96
113
  getTopicMetadata(request: DeepPartial<GetStreamTopicMetadataRequest>, options?: CallOptions & CallOptionsExt): Promise<StreamTopicMetadata>;
114
+ reset(request: DeepPartial<ResetStreamTopicRequest>, options?: CallOptions & CallOptionsExt): Promise<ResetStreamTopicResponse>;
97
115
  }
98
116
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
99
117
  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 {} ? {
@@ -5,7 +5,7 @@
5
5
  // protoc v3.19.1
6
6
  // source: v1/streams.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.V1StreamsDefinition = exports.StreamTopicMetadata = exports.GetStreamTopicMetadataRequest = exports.StreamEntry = exports.StreamMessage = exports.SubscribeStreamRequest = exports.PublishStreamMessageResponse = exports.PublishStreamMessageRequest = exports.protobufPackage = void 0;
8
+ exports.V1StreamsDefinition = exports.ResetStreamTopicResponse = exports.ResetStreamTopicRequest = exports.StreamTopicMetadata = exports.GetStreamTopicMetadataRequest = exports.StreamEntry = exports.StreamMessage = exports.SubscribeStreamRequest = exports.PublishStreamMessageResponse = exports.PublishStreamMessageRequest = exports.protobufPackage = void 0;
9
9
  /* eslint-disable */
10
10
  const wire_1 = require("@bufbuild/protobuf/wire");
11
11
  const timestamp_1 = require("../google/protobuf/timestamp");
@@ -694,6 +694,112 @@ exports.StreamTopicMetadata = {
694
694
  return message;
695
695
  },
696
696
  };
697
+ function createBaseResetStreamTopicRequest() {
698
+ return { namespace: '', topic: '' };
699
+ }
700
+ exports.ResetStreamTopicRequest = {
701
+ encode(message, writer = new wire_1.BinaryWriter()) {
702
+ if (message.namespace !== '') {
703
+ writer.uint32(10).string(message.namespace);
704
+ }
705
+ if (message.topic !== '') {
706
+ writer.uint32(18).string(message.topic);
707
+ }
708
+ return writer;
709
+ },
710
+ decode(input, length) {
711
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
712
+ const end = length === undefined ? reader.len : reader.pos + length;
713
+ const message = createBaseResetStreamTopicRequest();
714
+ while (reader.pos < end) {
715
+ const tag = reader.uint32();
716
+ switch (tag >>> 3) {
717
+ case 1: {
718
+ if (tag !== 10) {
719
+ break;
720
+ }
721
+ message.namespace = reader.string();
722
+ continue;
723
+ }
724
+ case 2: {
725
+ if (tag !== 18) {
726
+ break;
727
+ }
728
+ message.topic = reader.string();
729
+ continue;
730
+ }
731
+ }
732
+ if ((tag & 7) === 4 || tag === 0) {
733
+ break;
734
+ }
735
+ reader.skip(tag & 7);
736
+ }
737
+ return message;
738
+ },
739
+ fromJSON(object) {
740
+ return {
741
+ namespace: isSet(object.namespace) ? globalThis.String(object.namespace) : '',
742
+ topic: isSet(object.topic) ? globalThis.String(object.topic) : '',
743
+ };
744
+ },
745
+ toJSON(message) {
746
+ const obj = {};
747
+ if (message.namespace !== '') {
748
+ obj.namespace = message.namespace;
749
+ }
750
+ if (message.topic !== '') {
751
+ obj.topic = message.topic;
752
+ }
753
+ return obj;
754
+ },
755
+ create(base) {
756
+ return exports.ResetStreamTopicRequest.fromPartial(base !== null && base !== void 0 ? base : {});
757
+ },
758
+ fromPartial(object) {
759
+ var _a, _b;
760
+ const message = createBaseResetStreamTopicRequest();
761
+ message.namespace = (_a = object.namespace) !== null && _a !== void 0 ? _a : '';
762
+ message.topic = (_b = object.topic) !== null && _b !== void 0 ? _b : '';
763
+ return message;
764
+ },
765
+ };
766
+ function createBaseResetStreamTopicResponse() {
767
+ return {};
768
+ }
769
+ exports.ResetStreamTopicResponse = {
770
+ encode(_, writer = new wire_1.BinaryWriter()) {
771
+ return writer;
772
+ },
773
+ decode(input, length) {
774
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
775
+ const end = length === undefined ? reader.len : reader.pos + length;
776
+ const message = createBaseResetStreamTopicResponse();
777
+ while (reader.pos < end) {
778
+ const tag = reader.uint32();
779
+ switch (tag >>> 3) {
780
+ }
781
+ if ((tag & 7) === 4 || tag === 0) {
782
+ break;
783
+ }
784
+ reader.skip(tag & 7);
785
+ }
786
+ return message;
787
+ },
788
+ fromJSON(_) {
789
+ return {};
790
+ },
791
+ toJSON(_) {
792
+ const obj = {};
793
+ return obj;
794
+ },
795
+ create(base) {
796
+ return exports.ResetStreamTopicResponse.fromPartial(base !== null && base !== void 0 ? base : {});
797
+ },
798
+ fromPartial(_) {
799
+ const message = createBaseResetStreamTopicResponse();
800
+ return message;
801
+ },
802
+ };
697
803
  exports.V1StreamsDefinition = {
698
804
  name: 'V1Streams',
699
805
  fullName: 'v1.V1Streams',
@@ -722,6 +828,14 @@ exports.V1StreamsDefinition = {
722
828
  responseStream: false,
723
829
  options: {},
724
830
  },
831
+ reset: {
832
+ name: 'Reset',
833
+ requestType: exports.ResetStreamTopicRequest,
834
+ requestStream: false,
835
+ responseType: exports.ResetStreamTopicResponse,
836
+ responseStream: false,
837
+ options: {},
838
+ },
725
839
  },
726
840
  };
727
841
  function bytesFromBase64(b64) {
@@ -181,6 +181,33 @@ export type StreamTopicMetadata = Message<"v1.StreamTopicMetadata"> & {
181
181
  * Use `create(StreamTopicMetadataSchema)` to create a new message.
182
182
  */
183
183
  export declare const StreamTopicMetadataSchema: GenMessage<StreamTopicMetadata>;
184
+ /**
185
+ * @generated from message v1.ResetStreamTopicRequest
186
+ */
187
+ export type ResetStreamTopicRequest = Message<"v1.ResetStreamTopicRequest"> & {
188
+ /**
189
+ * @generated from field: string namespace = 1;
190
+ */
191
+ namespace: string;
192
+ /**
193
+ * @generated from field: string topic = 2;
194
+ */
195
+ topic: string;
196
+ };
197
+ /**
198
+ * Describes the message v1.ResetStreamTopicRequest.
199
+ * Use `create(ResetStreamTopicRequestSchema)` to create a new message.
200
+ */
201
+ export declare const ResetStreamTopicRequestSchema: GenMessage<ResetStreamTopicRequest>;
202
+ /**
203
+ * @generated from message v1.ResetStreamTopicResponse
204
+ */
205
+ export type ResetStreamTopicResponse = Message<"v1.ResetStreamTopicResponse"> & {};
206
+ /**
207
+ * Describes the message v1.ResetStreamTopicResponse.
208
+ * Use `create(ResetStreamTopicResponseSchema)` to create a new message.
209
+ */
210
+ export declare const ResetStreamTopicResponseSchema: GenMessage<ResetStreamTopicResponse>;
184
211
  /**
185
212
  * @generated from service v1.V1Streams
186
213
  */
@@ -209,4 +236,12 @@ export declare const V1Streams: GenService<{
209
236
  input: typeof GetStreamTopicMetadataRequestSchema;
210
237
  output: typeof StreamTopicMetadataSchema;
211
238
  };
239
+ /**
240
+ * @generated from rpc v1.V1Streams.Reset
241
+ */
242
+ reset: {
243
+ methodKind: "unary";
244
+ input: typeof ResetStreamTopicRequestSchema;
245
+ output: typeof ResetStreamTopicResponseSchema;
246
+ };
212
247
  }>;
@@ -3,13 +3,13 @@
3
3
  // @generated from file v1/streams.proto (package v1, syntax proto3)
4
4
  /* eslint-disable */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.V1Streams = exports.StreamTopicMetadataSchema = exports.GetStreamTopicMetadataRequestSchema = exports.StreamEntrySchema = exports.StreamMessageSchema = exports.SubscribeStreamRequestSchema = exports.PublishStreamMessageResponseSchema = exports.PublishStreamMessageRequestSchema = exports.file_v1_streams = void 0;
6
+ exports.V1Streams = exports.ResetStreamTopicResponseSchema = exports.ResetStreamTopicRequestSchema = exports.StreamTopicMetadataSchema = exports.GetStreamTopicMetadataRequestSchema = exports.StreamEntrySchema = exports.StreamMessageSchema = exports.SubscribeStreamRequestSchema = exports.PublishStreamMessageResponseSchema = exports.PublishStreamMessageRequestSchema = exports.file_v1_streams = void 0;
7
7
  const codegenv2_1 = require("@bufbuild/protobuf/codegenv2");
8
8
  const wkt_1 = require("@bufbuild/protobuf/wkt");
9
9
  /**
10
10
  * Describes the file v1/streams.proto.
11
11
  */
12
- exports.file_v1_streams = (0, codegenv2_1.fileDesc)("ChB2MS9zdHJlYW1zLnByb3RvEgJ2MSKQAQobUHVibGlzaFN0cmVhbU1lc3NhZ2VSZXF1ZXN0EhEKCW5hbWVzcGFjZRgBIAEoCRINCgV0b3BpYxgCIAEoCRIPCgdwYXlsb2FkGAMgASgMEhMKC3Byb2R1Y2VyX2lkGAQgASgJEhQKDHByb2R1Y2VyX3NlcRgFIAEoAxITCgtwYXlsb2FkX3JlZhgGIAEoCSIeChxQdWJsaXNoU3RyZWFtTWVzc2FnZVJlc3BvbnNlIloKFlN1YnNjcmliZVN0cmVhbVJlcXVlc3QSEQoJbmFtZXNwYWNlGAEgASgJEg0KBXRvcGljGAIgASgJEhMKBmN1cnNvchgDIAEoCUgAiAEBQgkKB19jdXJzb3IiUQoNU3RyZWFtTWVzc2FnZRIgCgdlbnRyaWVzGAEgAygLMg8udjEuU3RyZWFtRW50cnkSDgoGaGFuZ3VwGAIgASgIEg4KBmN1cnNvchgDIAEoCSJzCgtTdHJlYW1FbnRyeRIPCgdwYXlsb2FkGAEgASgMEg4KBmN1cnNvchgCIAEoCRIuCgpjcmVhdGVkX2F0GAMgAS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QdWJsaXNoU3RyZWFtTWVzc2FnZVJlc3BvbnNlIgASPgoJU3Vic2NyaWJlEhoudjEuU3Vic2NyaWJlU3RyZWFtUmVxdWVzdBoRLnYxLlN0cmVhbU1lc3NhZ2UiADABElAKEEdldFRvcGljTWV0YWRhdGESIS52MS5HZXRTdHJlYW1Ub3BpY01ldGFkYXRhUmVxdWVzdBoXLnYxLlN0cmVhbVRvcGljTWV0YWRhdGEiABJECgVSZXNldBIbLnYxLlJlc2V0U3RyZWFtVG9waWNSZXF1ZXN0GhwudjEuUmVzZXRTdHJlYW1Ub3BpY1Jlc3BvbnNlIgBCQlpAZ2l0aHViLmNvbS9oYXRjaGV0LWRldi9oYXRjaGV0L2ludGVybmFsL3NlcnZpY2VzL3NoYXJlZC9wcm90by92MWIGcHJvdG8z", [wkt_1.file_google_protobuf_timestamp]);
13
13
  /**
14
14
  * Describes the message v1.PublishStreamMessageRequest.
15
15
  * Use `create(PublishStreamMessageRequestSchema)` to create a new message.
@@ -45,6 +45,16 @@ exports.GetStreamTopicMetadataRequestSchema = (0, codegenv2_1.messageDesc)(expor
45
45
  * Use `create(StreamTopicMetadataSchema)` to create a new message.
46
46
  */
47
47
  exports.StreamTopicMetadataSchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 6);
48
+ /**
49
+ * Describes the message v1.ResetStreamTopicRequest.
50
+ * Use `create(ResetStreamTopicRequestSchema)` to create a new message.
51
+ */
52
+ exports.ResetStreamTopicRequestSchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 7);
53
+ /**
54
+ * Describes the message v1.ResetStreamTopicResponse.
55
+ * Use `create(ResetStreamTopicResponseSchema)` to create a new message.
56
+ */
57
+ exports.ResetStreamTopicResponseSchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 8);
48
58
  /**
49
59
  * @generated from service v1.V1Streams
50
60
  */
@@ -57,7 +57,16 @@ export declare class StreamsClient {
57
57
  */
58
58
  topicMetadata(topic: string, options?: Pick<StreamCallOptions, 'namespace'>): Promise<StreamTopicMetadata>;
59
59
  /**
60
- * Yields topic's messages after options.cursor, or from the oldest retained.
60
+ * Makes events() calls without a cursor start after the topic's latest
61
+ * message. Readers already iterating, and any call with a cursor, are
62
+ * unaffected.
63
+ * @param topic - the topic to reset
64
+ * @param options - optional namespace override
65
+ */
66
+ reset(topic: string, options?: Pick<StreamCallOptions, 'namespace'>): Promise<void>;
67
+ /**
68
+ * Yields topic's messages after options.cursor, or from the oldest retained
69
+ * (or, once the topic is reset, after the reset).
61
70
  * If the connection drops, it resubscribes from the last message yielded, so
62
71
  * nothing is skipped or repeated. Ends when the server hangs up an idle
63
72
  * subscription, options.signal aborts, or the caller stops iterating; throws
@@ -216,7 +216,21 @@ class StreamsClient {
216
216
  });
217
217
  }
218
218
  /**
219
- * Yields topic's messages after options.cursor, or from the oldest retained.
219
+ * Makes events() calls without a cursor start after the topic's latest
220
+ * message. Readers already iterating, and any call with a cursor, are
221
+ * unaffected.
222
+ * @param topic - the topic to reset
223
+ * @param options - optional namespace override
224
+ */
225
+ reset(topic, options) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ var _a;
228
+ yield this.grpc.reset({ namespace: (_a = options === null || options === void 0 ? void 0 : options.namespace) !== null && _a !== void 0 ? _a : '', topic });
229
+ });
230
+ }
231
+ /**
232
+ * Yields topic's messages after options.cursor, or from the oldest retained
233
+ * (or, once the topic is reset, after the reset).
220
234
  * If the connection drops, it resubscribes from the last message yielded, so
221
235
  * nothing is skipped or repeated. Ends when the server hangs up an idle
222
236
  * subscription, options.signal aborts, or the caller stops iterating; throws
@@ -0,0 +1,6 @@
1
+ export declare function consume(): Promise<void>;
2
+ export declare function publishFromAnywhere(): Promise<void>;
3
+ export declare function resumeFromCursor(topic: string): Promise<void>;
4
+ export declare function stopWithSignal(topic: string): Promise<void>;
5
+ export declare function namespaces(): Promise<void>;
6
+ export declare function resetTopic(): Promise<void>;
@@ -0,0 +1,192 @@
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 __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.consume = consume;
20
+ exports.publishFromAnywhere = publishFromAnywhere;
21
+ exports.resumeFromCursor = resumeFromCursor;
22
+ exports.stopWithSignal = stopWithSignal;
23
+ exports.namespaces = namespaces;
24
+ exports.resetTopic = resetTopic;
25
+ const crypto_1 = require("crypto");
26
+ const hatchet_client_1 = require("../hatchet-client");
27
+ const workflow_1 = require("./workflow");
28
+ const decode = (payload) => new TextDecoder().decode(payload);
29
+ function consume() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ var _a, e_1, _b, _c;
32
+ // > Consume
33
+ const topic = `progress-${(0, crypto_1.randomUUID)()}`;
34
+ yield workflow_1.progressTask.runNoWait({ topic });
35
+ try {
36
+ for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events(topic)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
37
+ _c = _f.value;
38
+ _d = false;
39
+ const event = _c;
40
+ const { step, total } = JSON.parse(decode(event.payload));
41
+ console.log(`step ${step} of ${total}`);
42
+ // the stream outlives the run, so the reader decides when it's done
43
+ if (step === total) {
44
+ break;
45
+ }
46
+ }
47
+ }
48
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
49
+ finally {
50
+ try {
51
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
52
+ }
53
+ finally { if (e_1) throw e_1.error; }
54
+ }
55
+ // !!
56
+ });
57
+ }
58
+ function publishFromAnywhere() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ // > Publish from anywhere
61
+ yield hatchet_client_1.hatchet.streams.publish('orders', JSON.stringify({ orderId: 'ord_123', status: 'shipped' }));
62
+ // !!
63
+ });
64
+ }
65
+ function resumeFromCursor(topic) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ var _a, e_2, _b, _c, _d, e_3, _e, _f;
68
+ // > Resume from a cursor
69
+ let cursor;
70
+ try {
71
+ for (var _g = true, _h = __asyncValues(hatchet_client_1.hatchet.streams.events(topic)), _j; _j = yield _h.next(), _a = _j.done, !_a; _g = true) {
72
+ _c = _j.value;
73
+ _g = false;
74
+ const event = _c;
75
+ console.log(decode(event.payload));
76
+ ({ cursor } = event);
77
+ break;
78
+ }
79
+ }
80
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
81
+ finally {
82
+ try {
83
+ if (!_g && !_a && (_b = _h.return)) yield _b.call(_h);
84
+ }
85
+ finally { if (e_2) throw e_2.error; }
86
+ }
87
+ try {
88
+ // picks up right after the last event read, even from another process
89
+ for (var _k = true, _l = __asyncValues(hatchet_client_1.hatchet.streams.events(topic, { cursor })), _m; _m = yield _l.next(), _d = _m.done, !_d; _k = true) {
90
+ _f = _m.value;
91
+ _k = false;
92
+ const event = _f;
93
+ console.log(decode(event.payload));
94
+ }
95
+ }
96
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
97
+ finally {
98
+ try {
99
+ if (!_k && !_d && (_e = _l.return)) yield _e.call(_l);
100
+ }
101
+ finally { if (e_3) throw e_3.error; }
102
+ }
103
+ // !!
104
+ });
105
+ }
106
+ function stopWithSignal(topic) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ var _a, e_4, _b, _c;
109
+ // > Stop reading
110
+ const controller = new AbortController();
111
+ setTimeout(() => controller.abort(), 10000);
112
+ try {
113
+ for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events(topic, { signal: controller.signal })), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
114
+ _c = _f.value;
115
+ _d = false;
116
+ const event = _c;
117
+ console.log(decode(event.payload));
118
+ }
119
+ }
120
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
121
+ finally {
122
+ try {
123
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
124
+ }
125
+ finally { if (e_4) throw e_4.error; }
126
+ }
127
+ // !!
128
+ });
129
+ }
130
+ function namespaces() {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ var _a, e_5, _b, _c;
133
+ // > Namespaces
134
+ yield hatchet_client_1.hatchet.streams.publish('updates', 'hello', { namespace: 'customer-a' });
135
+ try {
136
+ for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events('updates', { namespace: 'customer-a' })), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
137
+ _c = _f.value;
138
+ _d = false;
139
+ const event = _c;
140
+ console.log(decode(event.payload));
141
+ break;
142
+ }
143
+ }
144
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
145
+ finally {
146
+ try {
147
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
148
+ }
149
+ finally { if (e_5) throw e_5.error; }
150
+ }
151
+ // !!
152
+ });
153
+ }
154
+ function resetTopic() {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ var _a, e_6, _b, _c;
157
+ // > Reset a topic
158
+ yield hatchet_client_1.hatchet.streams.reset('orders');
159
+ try {
160
+ // starts after the reset; readers that were already iterating aren't affected
161
+ for (var _d = true, _e = __asyncValues(hatchet_client_1.hatchet.streams.events('orders')), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
162
+ _c = _f.value;
163
+ _d = false;
164
+ const event = _c;
165
+ console.log(decode(event.payload));
166
+ }
167
+ }
168
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
169
+ finally {
170
+ try {
171
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
172
+ }
173
+ finally { if (e_6) throw e_6.error; }
174
+ }
175
+ // !!
176
+ });
177
+ }
178
+ function main() {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ yield consume();
181
+ yield publishFromAnywhere();
182
+ yield stopWithSignal('orders');
183
+ yield namespaces();
184
+ });
185
+ }
186
+ if (require.main === module) {
187
+ main()
188
+ .catch(console.error)
189
+ .finally(() => {
190
+ process.exit(0);
191
+ });
192
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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
+ const hatchet_client_1 = require("../hatchet-client");
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = yield hatchet_client_1.hatchet.worker('durable-streams-worker', {
17
+ workflows: [workflow_1.progressTask, workflow_1.retryingProgressTask],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,9 @@
1
+ export type ProgressInput = {
2
+ topic: string;
3
+ };
4
+ export declare const progressTask: import("../..").TaskWorkflowDeclaration<ProgressInput, {
5
+ steps: number;
6
+ }, {}, {}, {}, {}>;
7
+ export declare const retryingProgressTask: import("../..").TaskWorkflowDeclaration<ProgressInput, {
8
+ chunks: number;
9
+ }, {}, {}, {}, {}>;
@@ -0,0 +1,47 @@
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
+ exports.retryingProgressTask = exports.progressTask = void 0;
16
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const hatchet_client_1 = require("../hatchet-client");
18
+ exports.progressTask = hatchet_client_1.hatchet.task({
19
+ name: 'durable-streams-progress',
20
+ fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const total = 5;
22
+ for (let step = 1; step <= total; step += 1) {
23
+ yield (0, sleep_1.default)(500);
24
+ yield hatchet_client_1.hatchet.streams.publish(input.topic, JSON.stringify({ step, total }));
25
+ }
26
+ return { steps: total };
27
+ }),
28
+ });
29
+ // !!
30
+ // > Reset on retry
31
+ exports.retryingProgressTask = hatchet_client_1.hatchet.task({
32
+ name: 'durable-streams-retrying-progress',
33
+ retries: 1,
34
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
35
+ // readers that subscribe from here on skip a failed attempt's messages
36
+ yield hatchet_client_1.hatchet.streams.reset(input.topic);
37
+ for (let chunk = 0; chunk < 3; chunk += 1) {
38
+ yield hatchet_client_1.hatchet.streams.publish(input.topic, JSON.stringify({ attempt: ctx.retryCount(), chunk }));
39
+ }
40
+ if (ctx.retryCount() === 0) {
41
+ throw new Error('intentional failure before the final message');
42
+ }
43
+ yield hatchet_client_1.hatchet.streams.publish(input.topic, JSON.stringify({ done: true }));
44
+ return { chunks: 3 };
45
+ }),
46
+ });
47
+ // !!
@@ -33,24 +33,25 @@ const workflow_12 = require("./durable_event/workflow");
33
33
  const workflow_13 = require("./durable_eviction/workflow");
34
34
  const workflow_14 = require("./durable_callback_ordering/workflow");
35
35
  const workflow_15 = require("./durable_sleep/workflow");
36
- const workflow_16 = require("./logger/workflow");
37
- const workflow_17 = require("./non_retryable/workflow");
38
- const workflow_18 = require("./retry_after/workflow");
39
- const workflow_19 = require("./on_failure/workflow");
40
- const workflow_20 = require("./idempotency/workflow");
41
- const workflow_21 = require("./on_event/workflow");
42
- const workflow_22 = require("./return_exceptions/workflow");
43
- const workflow_23 = require("./run_details/workflow");
36
+ const workflow_16 = require("./durable-streams/workflow");
37
+ const workflow_17 = require("./logger/workflow");
38
+ const workflow_18 = require("./non_retryable/workflow");
39
+ const workflow_19 = require("./retry_after/workflow");
40
+ const workflow_20 = require("./on_failure/workflow");
41
+ const workflow_21 = require("./idempotency/workflow");
42
+ const workflow_22 = require("./on_event/workflow");
43
+ const workflow_23 = require("./return_exceptions/workflow");
44
+ const workflow_24 = require("./run_details/workflow");
44
45
  const e2e_workflows_1 = require("./simple/e2e-workflows");
45
- const workflow_24 = require("./batch_assign/workflow");
46
- const workflow_25 = require("./streaming/workflow");
47
- const workflow_26 = require("./subscribe_to_stream/workflow");
48
- const workflow_27 = require("./timeout/workflow");
49
- const workflow_28 = require("./webhooks/workflow");
50
- const workflow_29 = require("./child_index/workflow");
51
- const workflow_30 = require("./support_agent/workflow");
52
- const workflow_31 = require("./welcome_email/workflow");
53
- const workflow_32 = require("./pdf_pipeline/workflow");
46
+ const workflow_25 = require("./batch_assign/workflow");
47
+ const workflow_26 = require("./streaming/workflow");
48
+ const workflow_27 = require("./subscribe_to_stream/workflow");
49
+ const workflow_28 = require("./timeout/workflow");
50
+ const workflow_29 = require("./webhooks/workflow");
51
+ const workflow_30 = require("./child_index/workflow");
52
+ const workflow_31 = require("./support_agent/workflow");
53
+ const workflow_32 = require("./welcome_email/workflow");
54
+ const workflow_33 = require("./pdf_pipeline/workflow");
54
55
  const workflows = [
55
56
  workflow_1.bulkChild,
56
57
  workflow_1.bulkParentWorkflow,
@@ -91,6 +92,8 @@ const workflows = [
91
92
  workflow_14.callbackOrderingMid,
92
93
  workflow_14.callbackOrderingRoot,
93
94
  workflow_15.durableSleep,
95
+ workflow_16.progressTask,
96
+ workflow_16.retryingProgressTask,
94
97
  workflow_13.evictableSleep,
95
98
  workflow_13.evictableWaitForEvent,
96
99
  workflow_13.evictableMemoThenWaitForEvent,
@@ -100,47 +103,47 @@ const workflows = [
100
103
  workflow_13.childTask,
101
104
  workflow_13.bulkChildTask,
102
105
  workflow_13.evictableChildBulkSpawn,
103
- (0, workflow_16.createLoggingWorkflow)(hatchet_client_1.hatchet),
104
- workflow_17.nonRetryableWorkflow,
105
- workflow_18.retryAfterUpstreamDelay,
106
- workflow_18.retryAfterExponentialBackoff,
107
- workflow_19.failureWorkflow,
108
- workflow_20.idempotentTask,
109
- workflow_20.idempotentTaskShortWindow,
110
- workflow_21.lower,
111
- workflow_22.returnExceptionsTask,
112
- workflow_23.runDetailTestWorkflow,
106
+ (0, workflow_17.createLoggingWorkflow)(hatchet_client_1.hatchet),
107
+ workflow_18.nonRetryableWorkflow,
108
+ workflow_19.retryAfterUpstreamDelay,
109
+ workflow_19.retryAfterExponentialBackoff,
110
+ workflow_20.failureWorkflow,
111
+ workflow_21.idempotentTask,
112
+ workflow_21.idempotentTaskShortWindow,
113
+ workflow_22.lower,
114
+ workflow_23.returnExceptionsTask,
115
+ workflow_24.runDetailTestWorkflow,
113
116
  e2e_workflows_1.helloWorld,
114
117
  e2e_workflows_1.helloWorldDurable,
115
- workflow_25.streamingTask,
116
- workflow_26.dagStream,
117
- workflow_26.longStream,
118
- workflow_27.timeoutTask,
119
- workflow_27.refreshTimeoutTask,
120
- workflow_28.webhookWorkflow,
121
- workflow_29.childIndexChild,
122
- workflow_29.childIndexParent,
123
- workflow_29.scenarioTask,
124
- workflow_29.orchestratorTask,
125
- workflow_30.supportAgent,
126
- workflow_30.triageTicket,
127
- workflow_30.generateReply,
128
- workflow_30.escalateTicket,
129
- workflow_31.welcomeEmail,
130
- workflow_32.pdfPipeline,
131
- workflow_24.batchSimple,
132
- workflow_24.batchKeyed,
133
- workflow_24.batchKeyedFailable,
134
- workflow_24.batchKeyedInterval,
135
- workflow_24.batchLarge,
136
- workflow_24.batchSingle,
137
- workflow_24.batchOrdered,
138
- workflow_24.batchBroadcast,
139
- workflow_24.batchCancel,
140
- workflow_24.child,
141
- workflow_24.childBatch,
142
- workflow_24.batchChildSpawn,
143
- workflow_24.batchChildBatchSpawn,
118
+ workflow_26.streamingTask,
119
+ workflow_27.dagStream,
120
+ workflow_27.longStream,
121
+ workflow_28.timeoutTask,
122
+ workflow_28.refreshTimeoutTask,
123
+ workflow_29.webhookWorkflow,
124
+ workflow_30.childIndexChild,
125
+ workflow_30.childIndexParent,
126
+ workflow_30.scenarioTask,
127
+ workflow_30.orchestratorTask,
128
+ workflow_31.supportAgent,
129
+ workflow_31.triageTicket,
130
+ workflow_31.generateReply,
131
+ workflow_31.escalateTicket,
132
+ workflow_32.welcomeEmail,
133
+ workflow_33.pdfPipeline,
134
+ workflow_25.batchSimple,
135
+ workflow_25.batchKeyed,
136
+ workflow_25.batchKeyedFailable,
137
+ workflow_25.batchKeyedInterval,
138
+ workflow_25.batchLarge,
139
+ workflow_25.batchSingle,
140
+ workflow_25.batchOrdered,
141
+ workflow_25.batchBroadcast,
142
+ workflow_25.batchCancel,
143
+ workflow_25.child,
144
+ workflow_25.childBatch,
145
+ workflow_25.batchChildSpawn,
146
+ workflow_25.batchChildBatchSpawn,
144
147
  ];
145
148
  function main() {
146
149
  return __awaiter(this, void 0, void 0, function* () {
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.37.0";
1
+ export declare const HATCHET_VERSION = "1.38.0";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.37.0';
4
+ exports.HATCHET_VERSION = '1.38.0';