@resonatehq/sdk 0.3.3 → 0.3.4

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 (79) hide show
  1. package/dist/async.d.ts +135 -0
  2. package/dist/async.d.ts.map +1 -0
  3. package/dist/async.js +205 -0
  4. package/dist/core/encoder.d.ts +5 -0
  5. package/dist/core/encoder.d.ts.map +1 -0
  6. package/dist/core/encoder.js +1 -0
  7. package/dist/core/encoders/base64.d.ts +6 -0
  8. package/dist/core/encoders/base64.d.ts.map +1 -0
  9. package/dist/core/encoders/base64.js +8 -0
  10. package/dist/core/encoders/json.d.ts +6 -0
  11. package/dist/core/encoders/json.d.ts.map +1 -0
  12. package/dist/core/encoders/json.js +60 -0
  13. package/dist/core/errors.d.ts +21 -0
  14. package/dist/core/errors.d.ts.map +1 -0
  15. package/dist/core/errors.js +33 -0
  16. package/dist/core/execution.d.ts +44 -0
  17. package/dist/core/execution.d.ts.map +1 -0
  18. package/dist/core/execution.js +195 -0
  19. package/dist/core/future.d.ts +54 -0
  20. package/dist/core/future.d.ts.map +1 -0
  21. package/dist/core/future.js +95 -0
  22. package/dist/core/invocation.d.ts +43 -0
  23. package/dist/core/invocation.d.ts.map +1 -0
  24. package/dist/core/invocation.js +72 -0
  25. package/dist/core/logger.d.ts +10 -0
  26. package/dist/core/logger.d.ts.map +1 -0
  27. package/dist/core/logger.js +1 -0
  28. package/dist/core/loggers/logger.d.ts +13 -0
  29. package/dist/core/loggers/logger.d.ts.map +1 -0
  30. package/dist/core/loggers/logger.js +43 -0
  31. package/dist/core/options.d.ts +79 -0
  32. package/dist/core/options.d.ts.map +1 -0
  33. package/dist/core/options.js +3 -0
  34. package/dist/core/promises/promises.d.ts +47 -0
  35. package/dist/core/promises/promises.d.ts.map +1 -0
  36. package/dist/core/promises/promises.js +128 -0
  37. package/dist/core/promises/types.d.ts +99 -0
  38. package/dist/core/promises/types.d.ts.map +1 -0
  39. package/dist/core/promises/types.js +29 -0
  40. package/dist/core/retries/retry.d.ts +20 -0
  41. package/dist/core/retries/retry.d.ts.map +1 -0
  42. package/dist/core/retries/retry.js +36 -0
  43. package/dist/core/retry.d.ts +27 -0
  44. package/dist/core/retry.d.ts.map +1 -0
  45. package/dist/core/retry.js +17 -0
  46. package/dist/core/schedules/types.d.ts +19 -0
  47. package/dist/core/schedules/types.d.ts.map +1 -0
  48. package/dist/core/schedules/types.js +3 -0
  49. package/dist/core/storage.d.ts +6 -0
  50. package/dist/core/storage.d.ts.map +1 -0
  51. package/dist/core/storage.js +1 -0
  52. package/dist/core/storages/memory.d.ts +8 -0
  53. package/dist/core/storages/memory.d.ts.map +1 -0
  54. package/dist/core/storages/memory.js +22 -0
  55. package/dist/core/storages/withTimeout.d.ts +10 -0
  56. package/dist/core/storages/withTimeout.d.ts.map +1 -0
  57. package/dist/core/storages/withTimeout.js +38 -0
  58. package/dist/core/store.d.ts +139 -0
  59. package/dist/core/store.d.ts.map +1 -0
  60. package/dist/core/store.js +1 -0
  61. package/dist/core/stores/local.d.ts +54 -0
  62. package/dist/core/stores/local.d.ts.map +1 -0
  63. package/dist/core/stores/local.js +368 -0
  64. package/dist/core/stores/remote.d.ts +48 -0
  65. package/dist/core/stores/remote.d.ts.map +1 -0
  66. package/dist/core/stores/remote.js +399 -0
  67. package/dist/core/utils.d.ts +3 -0
  68. package/dist/core/utils.d.ts.map +1 -0
  69. package/dist/core/utils.js +13 -0
  70. package/dist/generator.d.ts +187 -0
  71. package/dist/generator.d.ts.map +1 -0
  72. package/dist/generator.js +396 -0
  73. package/dist/index.d.ts +4 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +3 -0
  76. package/dist/resonate.d.ts +73 -0
  77. package/dist/resonate.d.ts.map +1 -0
  78. package/dist/resonate.js +142 -0
  79. package/package.json +1 -1
@@ -0,0 +1,399 @@
1
+ import { Base64Encoder } from "../encoders/base64";
2
+ import { ErrorCodes, ResonateError } from "../errors";
3
+ import { Logger } from "../loggers/logger";
4
+ import { isDurablePromise, isCompletedPromise, } from "../promises/types";
5
+ import { isSchedule } from "../schedules/types";
6
+ export class RemoteStore {
7
+ promises;
8
+ schedules;
9
+ locks;
10
+ constructor(url, pid, logger = new Logger(), encoder = new Base64Encoder()) {
11
+ this.promises = new RemotePromiseStore(url, logger, encoder);
12
+ this.schedules = new RemoteScheduleStore(url, logger, encoder);
13
+ this.locks = new RemoteLockStore(url, pid, logger);
14
+ }
15
+ }
16
+ export class RemotePromiseStore {
17
+ url;
18
+ logger;
19
+ encoder;
20
+ constructor(url, logger = new Logger(), encoder = new Base64Encoder()) {
21
+ this.url = url;
22
+ this.logger = logger;
23
+ this.encoder = encoder;
24
+ }
25
+ async create(id, ikey, strict, headers, data, timeout, tags) {
26
+ const reqHeaders = {
27
+ Accept: "application/json",
28
+ "Content-Type": "application/json",
29
+ Strict: JSON.stringify(strict),
30
+ };
31
+ if (ikey !== undefined) {
32
+ reqHeaders["Idempotency-Key"] = ikey;
33
+ }
34
+ const promise = await call(`${this.url}/promises`, isDurablePromise, {
35
+ method: "POST",
36
+ headers: reqHeaders,
37
+ body: JSON.stringify({
38
+ id: id,
39
+ param: {
40
+ headers: headers,
41
+ data: data ? encode(data, this.encoder) : undefined,
42
+ },
43
+ timeout: timeout,
44
+ tags: tags,
45
+ }),
46
+ }, this.logger);
47
+ return decode(promise, this.encoder);
48
+ }
49
+ async cancel(id, ikey, strict, headers, data) {
50
+ const reqHeaders = {
51
+ Accept: "application/json",
52
+ "Content-Type": "application/json",
53
+ Strict: JSON.stringify(strict),
54
+ };
55
+ if (ikey !== undefined) {
56
+ reqHeaders["Idempotency-Key"] = ikey;
57
+ }
58
+ const promise = await call(`${this.url}/promises/${id}`, isCompletedPromise, {
59
+ method: "PATCH",
60
+ headers: reqHeaders,
61
+ body: JSON.stringify({
62
+ state: "REJECTED_CANCELED",
63
+ value: {
64
+ headers: headers,
65
+ data: data ? encode(data, this.encoder) : undefined,
66
+ },
67
+ }),
68
+ }, this.logger);
69
+ return decode(promise, this.encoder);
70
+ }
71
+ async resolve(id, ikey, strict, headers, data) {
72
+ const reqHeaders = {
73
+ Accept: "application/json",
74
+ "Content-Type": "application/json",
75
+ Strict: JSON.stringify(strict),
76
+ };
77
+ if (ikey !== undefined) {
78
+ reqHeaders["Idempotency-Key"] = ikey;
79
+ }
80
+ const promise = await call(`${this.url}/promises/${id}`, isCompletedPromise, {
81
+ method: "PATCH",
82
+ headers: reqHeaders,
83
+ body: JSON.stringify({
84
+ state: "RESOLVED",
85
+ value: {
86
+ headers: headers,
87
+ data: data ? encode(data, this.encoder) : undefined,
88
+ },
89
+ }),
90
+ }, this.logger);
91
+ return decode(promise, this.encoder);
92
+ }
93
+ async reject(id, ikey, strict, headers, data) {
94
+ const reqHeaders = {
95
+ Accept: "application/json",
96
+ "Content-Type": "application/json",
97
+ Strict: JSON.stringify(strict),
98
+ };
99
+ if (ikey !== undefined) {
100
+ reqHeaders["Idempotency-Key"] = ikey;
101
+ }
102
+ const promise = await call(`${this.url}/promises/${id}`, isCompletedPromise, {
103
+ method: "PATCH",
104
+ headers: reqHeaders,
105
+ body: JSON.stringify({
106
+ state: "REJECTED",
107
+ value: {
108
+ headers: headers,
109
+ data: data ? encode(data, this.encoder) : undefined,
110
+ },
111
+ }),
112
+ }, this.logger);
113
+ return decode(promise, this.encoder);
114
+ }
115
+ async get(id) {
116
+ const promise = await call(`${this.url}/promises/${id}`, isDurablePromise, {
117
+ method: "GET",
118
+ headers: {
119
+ Accept: "application/json",
120
+ "Content-Type": "application/json",
121
+ },
122
+ }, this.logger);
123
+ return decode(promise, this.encoder);
124
+ }
125
+ async *search(id, state, tags, limit) {
126
+ let cursor = undefined;
127
+ while (cursor !== null) {
128
+ const params = new URLSearchParams({ id });
129
+ if (state !== undefined) {
130
+ params.append("state", state);
131
+ }
132
+ for (const [k, v] of Object.entries(tags ?? {})) {
133
+ params.append(`tags[${k}]`, v);
134
+ }
135
+ if (limit !== undefined) {
136
+ params.append("limit", limit.toString());
137
+ }
138
+ if (cursor !== undefined) {
139
+ params.append("cursor", cursor);
140
+ }
141
+ const url = new URL(`${this.url}/promises`);
142
+ url.search = params.toString();
143
+ const res = await call(url.toString(), isSearchPromiseResult, {
144
+ method: "GET",
145
+ headers: {
146
+ Accept: "application/json",
147
+ "Content-Type": "application/json",
148
+ },
149
+ }, this.logger);
150
+ cursor = res.cursor;
151
+ yield res.promises.map((p) => decode(p, this.encoder));
152
+ }
153
+ }
154
+ }
155
+ export class RemoteScheduleStore {
156
+ url;
157
+ logger;
158
+ encoder;
159
+ constructor(url, logger = new Logger(), encoder = new Base64Encoder()) {
160
+ this.url = url;
161
+ this.logger = logger;
162
+ this.encoder = encoder;
163
+ }
164
+ async create(id, ikey, description, cron, tags, promiseId, promiseTimeout, promiseHeaders, promiseData, promiseTags) {
165
+ const reqHeaders = {
166
+ Accept: "application/json",
167
+ "Content-Type": "application/json",
168
+ };
169
+ if (ikey !== undefined) {
170
+ reqHeaders["Idempotency-Key"] = ikey;
171
+ }
172
+ const schedule = call(`${this.url}/schedules`, isSchedule, {
173
+ method: "POST",
174
+ headers: reqHeaders,
175
+ body: JSON.stringify({
176
+ id,
177
+ description,
178
+ cron,
179
+ tags,
180
+ promiseId,
181
+ promiseTimeout,
182
+ promiseParam: {
183
+ headers: promiseHeaders,
184
+ data: promiseData ? encode(promiseData, this.encoder) : undefined,
185
+ },
186
+ promiseTags,
187
+ }),
188
+ }, this.logger);
189
+ return schedule;
190
+ }
191
+ async get(id) {
192
+ const schedule = call(`${this.url}/schedules/${id}`, isSchedule, {
193
+ method: "GET",
194
+ headers: {
195
+ Accept: "application/json",
196
+ "Content-Type": "application/json",
197
+ },
198
+ }, this.logger);
199
+ return schedule;
200
+ }
201
+ async delete(id) {
202
+ await call(`${this.url}/schedules/${id}`, (b) => true, {
203
+ method: "DELETE",
204
+ headers: {
205
+ Accept: "application/json",
206
+ "Content-Type": "application/json",
207
+ },
208
+ }, this.logger);
209
+ }
210
+ async *search(id, tags, limit) {
211
+ let cursor = undefined;
212
+ while (cursor !== null) {
213
+ const params = new URLSearchParams({ id });
214
+ for (const [k, v] of Object.entries(tags ?? {})) {
215
+ params.append(`tags[${k}]`, v);
216
+ }
217
+ if (limit !== undefined) {
218
+ params.append("limit", limit.toString());
219
+ }
220
+ if (cursor !== undefined) {
221
+ params.append("cursor", cursor);
222
+ }
223
+ const url = new URL(`${this.url}/schedules`);
224
+ url.search = params.toString();
225
+ const res = await call(url.toString(), isSearchSchedulesResult, {
226
+ method: "GET",
227
+ headers: {
228
+ Accept: "application/json",
229
+ "Content-Type": "application/json",
230
+ },
231
+ }, this.logger);
232
+ cursor = res.cursor;
233
+ yield res.schedules;
234
+ }
235
+ }
236
+ }
237
+ export class RemoteLockStore {
238
+ url;
239
+ pid;
240
+ logger;
241
+ lockTimeout;
242
+ heartbeatDelay;
243
+ hearbeatInterval = null;
244
+ constructor(url, pid, logger = new Logger(), lockTimeout = 60000) {
245
+ this.url = url;
246
+ this.pid = pid;
247
+ this.logger = logger;
248
+ this.lockTimeout = lockTimeout;
249
+ this.heartbeatDelay = this.lockTimeout / 4;
250
+ }
251
+ async tryAcquire(resourceId, executionId) {
252
+ const acquired = call(`${this.url}/locks/acquire`, (b) => true, {
253
+ method: "POST",
254
+ body: JSON.stringify({
255
+ resourceId: resourceId,
256
+ processId: this.pid,
257
+ executionId: executionId,
258
+ expiryInSeconds: this.lockTimeout / 1000,
259
+ }),
260
+ }, this.logger);
261
+ // lazily start the heartbeat
262
+ this.startHeartbeat();
263
+ if (await acquired) {
264
+ return true;
265
+ }
266
+ return false;
267
+ }
268
+ async release(resourceId, executionId) {
269
+ return call(`${this.url}/locks/release`, (b) => b === undefined, {
270
+ method: "POST",
271
+ headers: {
272
+ "Content-Type": "application/json",
273
+ },
274
+ body: JSON.stringify({
275
+ resourceId,
276
+ executionId,
277
+ }),
278
+ }, this.logger);
279
+ }
280
+ startHeartbeat() {
281
+ if (this.hearbeatInterval === null) {
282
+ // the + converts to a number
283
+ this.hearbeatInterval = +setInterval(() => this.heartbeat(), this.heartbeatDelay);
284
+ }
285
+ }
286
+ stopHeartbeat() {
287
+ if (this.hearbeatInterval !== null) {
288
+ clearInterval(this.hearbeatInterval);
289
+ this.hearbeatInterval = null;
290
+ }
291
+ }
292
+ async heartbeat() {
293
+ const res = await call(`${this.url}/locks/heartbeat`, (b) => typeof b === "object" && b !== null && "locksAffected" in b && typeof b.locksAffected === "number", {
294
+ method: "POST",
295
+ headers: {
296
+ "Content-Type": "application/json",
297
+ },
298
+ body: JSON.stringify({
299
+ processId: this.pid,
300
+ }),
301
+ }, this.logger);
302
+ if (res.locksAffected === 0) {
303
+ this.stopHeartbeat();
304
+ }
305
+ return res.locksAffected;
306
+ }
307
+ }
308
+ // Utils
309
+ async function call(url, guard, options, logger, retries = 3) {
310
+ let error;
311
+ for (let i = 0; i < retries; i++) {
312
+ try {
313
+ logger.debug("store:req", {
314
+ method: options.method,
315
+ url: url,
316
+ headers: options.headers,
317
+ body: options.body,
318
+ });
319
+ const r = await fetch(url, options);
320
+ const body = r.status !== 204 ? await r.json() : undefined;
321
+ logger.debug("store:res", {
322
+ status: r.status,
323
+ body: body,
324
+ });
325
+ if (!r.ok) {
326
+ switch (r.status) {
327
+ case 400:
328
+ throw new ResonateError("Invalid request", ErrorCodes.STORE_PAYLOAD, body);
329
+ case 403:
330
+ throw new ResonateError("Forbidden request", ErrorCodes.STORE_FORBIDDEN, body);
331
+ case 404:
332
+ throw new ResonateError("Not found", ErrorCodes.STORE_NOT_FOUND, body);
333
+ case 409:
334
+ throw new ResonateError("Already exists", ErrorCodes.STORE_ALREADY_EXISTS, body);
335
+ default:
336
+ throw new ResonateError("Server error", ErrorCodes.STORE, body, true);
337
+ }
338
+ }
339
+ if (!guard(body)) {
340
+ throw new ResonateError("Invalid response", ErrorCodes.STORE_PAYLOAD, body);
341
+ }
342
+ return body;
343
+ }
344
+ catch (e) {
345
+ if (e instanceof ResonateError && !e.retriable) {
346
+ throw e;
347
+ }
348
+ else {
349
+ error = e;
350
+ }
351
+ }
352
+ }
353
+ throw ResonateError.fromError(error);
354
+ }
355
+ function encode(value, encoder) {
356
+ try {
357
+ return encoder.encode(value);
358
+ }
359
+ catch (e) {
360
+ throw new ResonateError("Encoder error", ErrorCodes.STORE_ENCODER, e);
361
+ }
362
+ }
363
+ function decode(promise, encoder) {
364
+ try {
365
+ if (promise.param?.data) {
366
+ promise.param.data = encoder.decode(promise.param.data);
367
+ }
368
+ if (promise.value?.data) {
369
+ promise.value.data = encoder.decode(promise.value.data);
370
+ }
371
+ return promise;
372
+ }
373
+ catch (e) {
374
+ throw new ResonateError("Decoder error", ErrorCodes.STORE_ENCODER, e);
375
+ }
376
+ }
377
+ // Type guards
378
+ function isSearchPromiseResult(obj) {
379
+ return (typeof obj === "object" &&
380
+ obj !== null &&
381
+ "cursor" in obj &&
382
+ obj.cursor !== undefined &&
383
+ (obj.cursor === null || typeof obj.cursor === "string") &&
384
+ "promises" in obj &&
385
+ obj.promises !== undefined &&
386
+ Array.isArray(obj.promises) &&
387
+ obj.promises.every(isDurablePromise));
388
+ }
389
+ function isSearchSchedulesResult(obj) {
390
+ return (typeof obj === "object" &&
391
+ obj !== null &&
392
+ "cursor" in obj &&
393
+ obj.cursor !== undefined &&
394
+ (obj.cursor === null || typeof obj.cursor === "string") &&
395
+ "schedules" in obj &&
396
+ obj.schedules !== undefined &&
397
+ Array.isArray(obj.schedules) &&
398
+ obj.schedules.every(isSchedule));
399
+ }
@@ -0,0 +1,3 @@
1
+ export declare function randomId(): string;
2
+ export declare function hash(s: string): string;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/core/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,IAAI,MAAM,CAEjC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAUtC"}
@@ -0,0 +1,13 @@
1
+ export function randomId() {
2
+ return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16);
3
+ }
4
+ export function hash(s) {
5
+ let h = 0;
6
+ for (let i = 0; i < s.length; i++) {
7
+ h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;
8
+ }
9
+ // Generate fixed length hexadecimal hash
10
+ const hashString = (Math.abs(h) >>> 0).toString(16); // Convert to unsigned int and then to hexadecimal
11
+ const maxLength = 8;
12
+ return "0".repeat(Math.max(0, maxLength - hashString.length)) + hashString;
13
+ }
@@ -0,0 +1,187 @@
1
+ import { Future, ResonatePromise } from "./core/future";
2
+ import { Invocation } from "./core/invocation";
3
+ import { ResonateOptions, Options, PartialOptions } from "./core/options";
4
+ import { ResonateBase } from "./resonate";
5
+ export type GFunc = (ctx: Context, ...args: any[]) => Generator<Yieldable>;
6
+ export type IFunc = (info: Info, ...args: any[]) => any;
7
+ export type Params<F> = F extends (ctx: any, ...args: infer P) => any ? P : never;
8
+ export type Return<F> = F extends (...args: any[]) => Generator<any, infer T> ? T : never;
9
+ export type Yieldable = Call | Future<any>;
10
+ export type Call = {
11
+ kind: "call";
12
+ value: ResonateFunction | OrdinaryFunction | DeferredFunction;
13
+ yieldFuture: boolean;
14
+ };
15
+ type ResonateFunction = {
16
+ kind: "resonate";
17
+ func: GFunc;
18
+ args: any[];
19
+ opts: Options;
20
+ };
21
+ type OrdinaryFunction = {
22
+ kind: "ordinary";
23
+ func: IFunc;
24
+ args: any[];
25
+ opts: Options;
26
+ };
27
+ type DeferredFunction = {
28
+ kind: "deferred";
29
+ func: string;
30
+ args: any;
31
+ opts: Options;
32
+ };
33
+ export declare class Resonate extends ResonateBase {
34
+ private scheduler;
35
+ /**
36
+ * Creates a Resonate instance. This is the starting point for using Resonate.
37
+ *
38
+ * @constructor
39
+ * @param opts - A partial {@link ResonateOptions} object.
40
+ */
41
+ constructor(opts?: Partial<ResonateOptions>);
42
+ /**
43
+ * Register a function with Resonate. Registered functions can be invoked by calling {@link run}, or by the returned function.
44
+ *
45
+ * @template F The type of the generator function.
46
+ * @param name A unique name to identify the function.
47
+ * @param func The generator function to register with Resonate.
48
+ * @param opts Resonate options, can be constructed by calling {@link options}.
49
+ * @returns Resonate function
50
+ */
51
+ register<F extends GFunc>(name: string, func: F, opts?: Partial<Options>): (id: string, ...args: any) => ResonatePromise<Return<F>>;
52
+ /**
53
+ * Register a function with Resonate. Registered functions can be invoked by calling {@link run}, or by the returned function.
54
+ *
55
+ * @template F The type of the generator function.
56
+ * @param name A unique name to identify the function.
57
+ * @param version Version of the function.
58
+ * @param func The generator function to register with Resonate.
59
+ * @param opts Resonate options, can be constructed by calling {@link options}.
60
+ * @returns Resonate function
61
+ */
62
+ register<F extends GFunc>(name: string, version: number, func: F, opts?: Partial<Options>): (id: string, ...args: any) => ResonatePromise<Return<F>>;
63
+ /**
64
+ * Register a module with Resonate. Registered functions can be invoked by calling {@link run}.
65
+ *
66
+ * @template F The type of the generator function.
67
+ * @param module The module to register with Resonate.
68
+ * @param opts Resonate options, can be constructed by calling {@link options}.
69
+ * @returns Resonate function
70
+ */
71
+ registerModule<F extends GFunc>(module: Record<string, F>, opts?: Partial<Options>): void;
72
+ protected execute<F extends GFunc>(name: string, version: number, id: string, func: F, args: Params<F>, opts: Options): ResonatePromise<Return<F>>;
73
+ }
74
+ export declare class Info {
75
+ private invocation;
76
+ constructor(invocation: Invocation<any>);
77
+ /**
78
+ * The running count of function execution attempts.
79
+ */
80
+ get attempt(): number;
81
+ /**
82
+ * Uniquely identifies the function invocation.
83
+ */
84
+ get id(): string;
85
+ /**
86
+ * Deduplicates function invocations with the same id.
87
+ */
88
+ get idempotencyKey(): string | undefined;
89
+ /**
90
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
91
+ */
92
+ get timeout(): number;
93
+ /**
94
+ * The resonate function version.
95
+ */
96
+ get version(): number;
97
+ }
98
+ export declare class Context {
99
+ private invocation;
100
+ constructor(invocation: Invocation<any>);
101
+ /**
102
+ * The running count of child function invocations.
103
+ */
104
+ get counter(): number;
105
+ /**
106
+ * Uniquely identifies the function invocation.
107
+ */
108
+ get id(): string;
109
+ /**
110
+ * Deduplicates function invocations with the same id.
111
+ */
112
+ get idempotencyKey(): string | undefined;
113
+ /**
114
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
115
+ */
116
+ get timeout(): number;
117
+ /**
118
+ * The resonate function version.
119
+ */
120
+ get version(): number;
121
+ /**
122
+ * Invoke a generator function.
123
+ *
124
+ * @template F The type of the generator function.
125
+ * @param func The function to invoke.
126
+ * @param args The function arguments, optionally followed by {@link options}.
127
+ * @returns A {@link Call} that can be yielded for a value.
128
+ */
129
+ run<F extends GFunc>(func: F, ...args: [...Params<F>, PartialOptions?]): Call;
130
+ /**
131
+ * Invoke a function.
132
+ *
133
+ * @template F The type of the function.
134
+ * @param func The function to invoke.
135
+ * @param args The function arguments, optionally followed by {@link options}.
136
+ * @returns A {@link Call} that can be yielded for a value.
137
+ */
138
+ run<F extends IFunc>(func: F, ...args: [...Params<F>, PartialOptions?]): Call;
139
+ /**
140
+ * Invoke a remote function.
141
+ *
142
+ * @param func The id of the remote function.
143
+ * @param args The arguments to pass to the remote function.
144
+ * @param opts Optional {@link options}.
145
+ * @returns A {@link Call} that can be yielded for a value.
146
+ */
147
+ run(func: string, args?: any, opts?: PartialOptions): Call;
148
+ /**
149
+ * Invoke a generator function.
150
+ *
151
+ * @template F The type of the generator function.
152
+ * @param func The function to invoke.
153
+ * @param args The function arguments, optionally followed by {@link options}.
154
+ * @returns A {@link Call} that can be yielded for a {@link Future}.
155
+ */
156
+ call<F extends GFunc>(func: F, ...args: [...Params<F>, PartialOptions?]): Call;
157
+ /**
158
+ * Invoke a function.
159
+ *
160
+ * @template F The type of the function.
161
+ * @param func The function to invoke.
162
+ * @param args The function arguments, optionally followed by {@link options}.
163
+ * @returns A {@link Call} that can be yielded for a {@link Future}.
164
+ */
165
+ call<F extends IFunc>(func: F, ...args: [...Params<F>, PartialOptions?]): Call;
166
+ /**
167
+ * Invoke a remote function.
168
+ *
169
+ * @param func The id of the remote function.
170
+ * @param args The arguments to pass to the remote function.
171
+ * @param opts Optional {@link options}.
172
+ * @returns A {@link Call} that can be yielded for a {@link Future}.
173
+ */
174
+ call(func: string, args?: any, opts?: PartialOptions): Call;
175
+ private _call;
176
+ /**
177
+ * Construct options.
178
+ *
179
+ * @param opts A partial {@link Options} object.
180
+ * @returns Options with the __resonate flag set.
181
+ */
182
+ options(opts?: Partial<Options>): Partial<Options> & {
183
+ __resonate: true;
184
+ };
185
+ }
186
+ export {};
187
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../lib/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM1C,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,SAAS,CAAC,SAAS,CAAC,CAAC;AAE3E,MAAM,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAExD,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;AAElF,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAA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