@resonatehq/sdk 0.8.2 → 0.8.3
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/dist/dev/network.d.ts +3 -3
- package/dist/dev/network.d.ts.map +1 -1
- package/dist/dev/network.js +3 -3
- package/dist/dev/network.js.map +1 -1
- package/dist/dev/server.d.ts +1 -0
- package/dist/dev/server.d.ts.map +1 -1
- package/dist/dev/server.js +26 -23
- package/dist/dev/server.js.map +1 -1
- package/dist/sim/example-1.js +3 -3
- package/dist/sim/example-1.js.map +1 -1
- package/dist/sim/example-2.js +3 -3
- package/dist/sim/example-2.js.map +1 -1
- package/dist/sim/example-3.js +3 -3
- package/dist/sim/example-3.js.map +1 -1
- package/dist/sim/src/server.d.ts.map +1 -1
- package/dist/sim/src/worker.d.ts.map +1 -1
- package/dist/sim/src/worker.js +2 -1
- package/dist/sim/src/worker.js.map +1 -1
- package/dist/src/computation.d.ts.map +1 -1
- package/dist/src/computation.js +30 -10
- package/dist/src/computation.js.map +1 -1
- package/dist/src/context.d.ts +14 -3
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +20 -8
- package/dist/src/context.js.map +1 -1
- package/dist/src/core.d.ts +5 -5
- package/dist/src/core.d.ts.map +1 -1
- package/dist/src/core.js +11 -11
- package/dist/src/core.js.map +1 -1
- package/dist/src/coroutine.d.ts.map +1 -1
- package/dist/src/coroutine.js +22 -14
- package/dist/src/coroutine.js.map +1 -1
- package/dist/src/decorator.d.ts.map +1 -1
- package/dist/src/exceptions.d.ts +35 -0
- package/dist/src/exceptions.d.ts.map +1 -0
- package/dist/src/exceptions.js +75 -0
- package/dist/src/exceptions.js.map +1 -0
- package/dist/src/handler.d.ts +11 -11
- package/dist/src/handler.d.ts.map +1 -1
- package/dist/src/handler.js +50 -50
- package/dist/src/handler.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/network/network.d.ts +17 -4
- package/dist/src/network/network.d.ts.map +1 -1
- package/dist/src/network/remote.d.ts +3 -2
- package/dist/src/network/remote.d.ts.map +1 -1
- package/dist/src/network/remote.js +42 -17
- package/dist/src/network/remote.js.map +1 -1
- package/dist/src/processor/processor.d.ts.map +1 -1
- package/dist/src/processor/processor.js +2 -3
- package/dist/src/processor/processor.js.map +1 -1
- package/dist/src/promises.d.ts +4 -0
- package/dist/src/promises.d.ts.map +1 -1
- package/dist/src/promises.js +28 -16
- package/dist/src/promises.js.map +1 -1
- package/dist/src/registry.d.ts +2 -2
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +25 -49
- package/dist/src/registry.js.map +1 -1
- package/dist/src/resonate.d.ts +207 -14
- package/dist/src/resonate.d.ts.map +1 -1
- package/dist/src/resonate.js +138 -47
- package/dist/src/resonate.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/src/resonate.d.ts
CHANGED
|
@@ -45,11 +45,61 @@ export declare class Resonate {
|
|
|
45
45
|
};
|
|
46
46
|
});
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Initializes a Resonate client instance for local development.
|
|
49
|
+
*
|
|
50
|
+
* Creates and returns a Resonate client configured for **local-only execution**
|
|
51
|
+
* with zero external dependencies. All state is stored in local memory — no
|
|
52
|
+
* network or external persistence is required. This mode is ideal for rapid
|
|
53
|
+
* testing, debugging, and experimentation before connecting to a Resonate server.
|
|
54
|
+
*
|
|
55
|
+
* The client runs with a `"default"` worker group, a `"default"` process ID,
|
|
56
|
+
* and an effectively infinite TTL (`Number.MAX_SAFE_INTEGER`) for tasks.
|
|
57
|
+
*
|
|
58
|
+
* @returns A {@link Resonate} client instance configured for local development.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const resonate = Resonate.local();
|
|
63
|
+
* resonate.register(foo);
|
|
64
|
+
* const result = await resonate.run("foo.1", foo, { data: "test" });
|
|
65
|
+
* console.log(result);
|
|
66
|
+
* ```
|
|
49
67
|
*/
|
|
50
68
|
static local(): Resonate;
|
|
51
69
|
/**
|
|
52
|
-
*
|
|
70
|
+
* Initializes a Resonate client instance with remote configuration.
|
|
71
|
+
*
|
|
72
|
+
* Creates and returns a Resonate client that connects to a **Resonate Server**
|
|
73
|
+
* and optional remote message sources. This configuration enables distributed,
|
|
74
|
+
* durable workers to cooperate and execute functions via **durable RPCs**.
|
|
75
|
+
*
|
|
76
|
+
* By default, the client connects to a Resonate Server running locally
|
|
77
|
+
* (`http://localhost:8001`) and joins the `"default"` worker group.
|
|
78
|
+
*
|
|
79
|
+
* The client is identified by a unique process ID (`pid`) and maintains
|
|
80
|
+
* claimed task leases for the duration specified by `ttl`.
|
|
81
|
+
*
|
|
82
|
+
* @param options - Configuration options for the remote client.
|
|
83
|
+
* @param options.url - The base URL of the remote Resonate Server. Defaults to `"http://localhost:8001"`.
|
|
84
|
+
* @param options.group - The worker group name. Defaults to `"default"`.
|
|
85
|
+
* @param options.pid - Optional process identifier for the client. Defaults to a randomly generated UUID.
|
|
86
|
+
* @param options.ttl - Time-to-live (in seconds) for claimed tasks. Defaults to `1 * util.MIN`.
|
|
87
|
+
* @param options.auth - Optional authentication credentials for connecting to the remote server.
|
|
88
|
+
*
|
|
89
|
+
* @returns A {@link Resonate} client instance configured for remote operation.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const resonate = Resonate.remote({
|
|
94
|
+
* url: "https://resonate.example.com",
|
|
95
|
+
* group: "analytics",
|
|
96
|
+
* ttl: 30,
|
|
97
|
+
* auth: { username: "user", password: "secret" },
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* const result = await resonate.run("task-42", "processData", { input: "dataset.csv" });
|
|
101
|
+
* console.log(result);
|
|
102
|
+
* ```
|
|
53
103
|
*/
|
|
54
104
|
static remote({ url, group, pid, ttl, auth, }?: {
|
|
55
105
|
url?: string;
|
|
@@ -66,7 +116,34 @@ export declare class Resonate {
|
|
|
66
116
|
};
|
|
67
117
|
}): Resonate;
|
|
68
118
|
/**
|
|
69
|
-
*
|
|
119
|
+
* Registers a function with Resonate for execution and version control.
|
|
120
|
+
*
|
|
121
|
+
* This method makes a function available for distributed or top-level execution
|
|
122
|
+
* under a specific name and version.
|
|
123
|
+
*
|
|
124
|
+
* Providing explicit `name` or `version` options allows precise control over
|
|
125
|
+
* function identification and versioning, enabling repeatable, distributed
|
|
126
|
+
* invocation and backward-compatible deployments.
|
|
127
|
+
*
|
|
128
|
+
* @param nameOrFunc - Either the function name (string) or the function itself.
|
|
129
|
+
* When passing a name, provide the function and optional options as additional parameters.
|
|
130
|
+
* @param funcOrOptions - The function to register, or an optional configuration object
|
|
131
|
+
* with versioning information when the first argument is a name.
|
|
132
|
+
* @param maybeOptions - Optional configuration object when both name and function are provided.
|
|
133
|
+
* Supports a `version` field to specify the registered function version.
|
|
134
|
+
*
|
|
135
|
+
* @returns A {@link ResonateFunc} wrapper for the registered function.
|
|
136
|
+
* When used as a decorator, returns a decorator that registers the target function
|
|
137
|
+
* upon definition.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* function greet(ctx: Context, name: string): string {
|
|
142
|
+
* return `Hello, ${name}!`;
|
|
143
|
+
* }
|
|
144
|
+
*
|
|
145
|
+
* resonate.register("greet_user", greet, { version: 2 });
|
|
146
|
+
* ```
|
|
70
147
|
*/
|
|
71
148
|
register<F extends Func>(name: string, func: F, options?: {
|
|
72
149
|
version?: number;
|
|
@@ -75,25 +152,131 @@ export declare class Resonate {
|
|
|
75
152
|
version?: number;
|
|
76
153
|
}): ResonateFunc<F>;
|
|
77
154
|
/**
|
|
78
|
-
*
|
|
155
|
+
* Runs a registered function with Resonate and waits for the result.
|
|
156
|
+
*
|
|
157
|
+
* This method executes the specified function under a **durable promise**
|
|
158
|
+
* identified by the provided `id`. If a promise with the same `id` already exists,
|
|
159
|
+
* Resonate subscribes to its result or returns it immediately if it has already completed.
|
|
160
|
+
*
|
|
161
|
+
* Duplicate executions for the same `id` are automatically prevented, ensuring
|
|
162
|
+
* idempotent and consistent behavior across distributed runs.
|
|
163
|
+
*
|
|
164
|
+
* This is a **blocking operation** — execution will not continue until the
|
|
165
|
+
* function result is available.
|
|
166
|
+
*
|
|
167
|
+
* @param id - The unique identifier of the durable promise. Reusing an ID ensures
|
|
168
|
+
* idempotent execution.
|
|
169
|
+
* @param funcOrName - Either the registered function reference or its string name
|
|
170
|
+
* to execute.
|
|
171
|
+
* @param args - Positional arguments passed to the function.
|
|
172
|
+
*
|
|
173
|
+
* @returns A promise resolving to the final result returned from the function execution.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const result = await client.run("job-123", "processData", { input: "records.csv" });
|
|
178
|
+
* console.log("Result:", result);
|
|
179
|
+
* ```
|
|
79
180
|
*/
|
|
80
181
|
run<F extends Func>(id: string, func: F, ...args: ParamsWithOptions<F>): Promise<Return<F>>;
|
|
81
182
|
run<T>(id: string, name: string, ...args: any[]): Promise<T>;
|
|
82
183
|
run<T>(id: string, funcOrName: Func | string, ...args: any[]): Promise<T>;
|
|
83
184
|
/**
|
|
84
|
-
*
|
|
185
|
+
* Runs a registered function asynchronously with Resonate.
|
|
186
|
+
*
|
|
187
|
+
* This method schedules the specified function for execution under a **durable promise**
|
|
188
|
+
* identified by the provided `id`. If a promise with the same `id` already exists,
|
|
189
|
+
* Resonate subscribes to its result or returns it immediately if it has already completed.
|
|
190
|
+
*
|
|
191
|
+
* Unlike {@link run}, this method is **non-blocking** and immediately returns a
|
|
192
|
+
* {@link ResonateHandle} that can be awaited or queried later to retrieve the final result
|
|
193
|
+
* once execution completes.
|
|
194
|
+
*
|
|
195
|
+
* Duplicate executions for the same `id` are automatically prevented, ensuring idempotent
|
|
196
|
+
* and consistent behavior across distributed runs.
|
|
197
|
+
*
|
|
198
|
+
* @param id - The unique identifier of the durable promise. Reusing an ID ensures
|
|
199
|
+
* idempotent execution.
|
|
200
|
+
* @param funcOrName - Either the registered function reference or its string name
|
|
201
|
+
* to execute.
|
|
202
|
+
* @param argsWithOpts - Positional arguments and optional configuration parameters
|
|
203
|
+
* passed to the function.
|
|
204
|
+
*
|
|
205
|
+
* @returns A {@link ResonateHandle} representing the asynchronous execution.
|
|
206
|
+
* The handle can be awaited or inspected for status and results.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* const handle = await client.beginRun("run-001", "generateReport", { period: "Q3" });
|
|
211
|
+
* const result = await handle.getResult();
|
|
212
|
+
* console.log(result);
|
|
213
|
+
* ```
|
|
85
214
|
*/
|
|
86
215
|
beginRun<F extends Func>(id: string, func: F, ...args: ParamsWithOptions<F>): Promise<ResonateHandle<Return<F>>>;
|
|
87
216
|
beginRun<T>(id: string, func: string, ...args: any[]): Promise<ResonateHandle<T>>;
|
|
88
217
|
beginRun(id: string, funcOrName: Func | string, ...args: any[]): Promise<ResonateHandle<any>>;
|
|
89
218
|
/**
|
|
90
|
-
*
|
|
219
|
+
* Executes a registered function remotely with Resonate and waits for the result.
|
|
220
|
+
*
|
|
221
|
+
* This method runs the specified function on a remote worker or process under a
|
|
222
|
+
* **durable promise** identified by the provided `id`. If a promise with the same
|
|
223
|
+
* `id` already exists, Resonate subscribes to its result or returns it immediately
|
|
224
|
+
* if it has already completed.
|
|
225
|
+
*
|
|
226
|
+
* Unlike {@link beginRpc}, this method is **blocking** — it waits for the remote
|
|
227
|
+
* function to complete and returns the final result before continuing execution.
|
|
228
|
+
*
|
|
229
|
+
* Duplicate executions for the same `id` are automatically prevented, ensuring
|
|
230
|
+
* idempotent and consistent behavior across distributed runs.
|
|
231
|
+
*
|
|
232
|
+
* @param id - The unique identifier of the durable promise. Reusing an ID ensures
|
|
233
|
+
* idempotent remote execution.
|
|
234
|
+
* @param funcOrName - Either the registered function reference or its string name
|
|
235
|
+
* to execute remotely.
|
|
236
|
+
* @param args - Positional arguments passed to the remote function.
|
|
237
|
+
*
|
|
238
|
+
* @returns A promise resolving to the final result returned from the remote
|
|
239
|
+
* function execution.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* const result = await client.rpc("job-42", "analyzeData", { file: "input.csv" });
|
|
244
|
+
* console.log("Remote result:", result);
|
|
245
|
+
* ```
|
|
91
246
|
*/
|
|
92
247
|
rpc<F extends Func>(id: string, func: F, ...args: ParamsWithOptions<F>): Promise<Return<F>>;
|
|
93
248
|
rpc<T>(id: string, name: string, ...args: any[]): Promise<T>;
|
|
94
249
|
rpc<T>(id: string, funcOrName: Func | string, ...args: any[]): Promise<T>;
|
|
95
250
|
/**
|
|
96
|
-
*
|
|
251
|
+
* Initiates a remote procedure call (RPC) with Resonate and returns a handle to the execution.
|
|
252
|
+
*
|
|
253
|
+
* This method schedules a registered function for **remote execution** under a durable promise
|
|
254
|
+
* identified by the provided `id`. The function runs on a remote worker or process as part of
|
|
255
|
+
* Resonate’s distributed execution environment.
|
|
256
|
+
*
|
|
257
|
+
* Unlike {@link rpc}, this method is **non-blocking** and immediately returns a
|
|
258
|
+
* {@link ResonateHandle} that can be awaited or queried later to retrieve the final result once
|
|
259
|
+
* remote execution completes.
|
|
260
|
+
*
|
|
261
|
+
* If a durable promise with the same `id` already exists, Resonate subscribes to its result or
|
|
262
|
+
* returns it immediately if it has already completed. Duplicate executions for the same `id`
|
|
263
|
+
* are automatically prevented, ensuring idempotent and consistent behavior.
|
|
264
|
+
*
|
|
265
|
+
* @param id - The unique identifier of the durable promise. Reusing an ID ensures
|
|
266
|
+
* idempotent remote execution.
|
|
267
|
+
* @param funcOrName - Either the registered function reference or its string name to execute remotely.
|
|
268
|
+
* @param argsWithOpts - Positional arguments and optional configuration parameters
|
|
269
|
+
* passed to the remote function.
|
|
270
|
+
*
|
|
271
|
+
* @returns A {@link ResonateHandle} representing the asynchronous remote execution.
|
|
272
|
+
* The handle can be awaited or inspected for completion and results.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* const handle = await client.beginRpc("task-123", "processData", { input: "hello" });
|
|
277
|
+
* const result = await handle.getResult();
|
|
278
|
+
* console.log(result);
|
|
279
|
+
* ```
|
|
97
280
|
*/
|
|
98
281
|
beginRpc<F extends Func>(id: string, func: F, ...args: ParamsWithOptions<F>): Promise<ResonateHandle<Return<F>>>;
|
|
99
282
|
beginRpc<T>(id: string, func: string, ...args: any[]): Promise<ResonateHandle<T>>;
|
|
@@ -101,16 +284,26 @@ export declare class Resonate {
|
|
|
101
284
|
schedule<F extends Func>(name: string, cron: string, func: F, ...args: ParamsWithOptions<F>): Promise<ResonateSchedule>;
|
|
102
285
|
schedule(name: string, cron: string, func: string, ...args: any[]): Promise<ResonateSchedule>;
|
|
103
286
|
/**
|
|
104
|
-
*
|
|
287
|
+
* Retrieves or subscribes to an existing execution by its unique ID.
|
|
288
|
+
*
|
|
289
|
+
* This method attaches to an existing **durable promise** identified by `id`.
|
|
290
|
+
* If the associated execution is still in progress, it returns a {@link ResonateHandle}
|
|
291
|
+
* that can be awaited or observed until completion. If the execution has already
|
|
292
|
+
* finished, the handle is immediately resolved with the stored result.
|
|
293
|
+
*
|
|
294
|
+
* Notes:
|
|
295
|
+
* - A durable promise with the given `id` must already exist.
|
|
296
|
+
* - This operation is **non-blocking**; awaiting the returned handle will block
|
|
297
|
+
* only if the execution is still running.
|
|
298
|
+
*
|
|
299
|
+
* @param id - Unique identifier of the target execution or durable promise.
|
|
300
|
+
*
|
|
301
|
+
* @returns A {@link ResonateHandle} representing the existing execution.
|
|
302
|
+
* The handle can be awaited or queried to retrieve the final result.
|
|
105
303
|
*/
|
|
106
304
|
get<T = any>(id: string): Promise<ResonateHandle<T>>;
|
|
107
305
|
options(opts?: Partial<Options>): Options;
|
|
108
|
-
|
|
109
|
-
* The dependency is made available to all functions via
|
|
110
|
-
* their execution `Context`.
|
|
111
|
-
* Setting a dependency for a name that already exists will
|
|
112
|
-
* overwrite the previously set dependency.
|
|
113
|
-
*/
|
|
306
|
+
private getArgsAndOpts;
|
|
114
307
|
setDependency(name: string, obj: any): void;
|
|
115
308
|
stop(): void;
|
|
116
309
|
private createPromiseAndTask;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resonate.d.ts","sourceRoot":"","sources":["../../src/resonate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resonate.d.ts","sourceRoot":"","sources":["../../src/resonate.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAG/D,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,IAAI;IAC1C,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,OAAO,CAA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O,CAAC,OAAO,CAAM,GAAG,OAAO;IAKpD,OAAO,CAAC,cAAc;IAIf,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI;IAI3C,IAAI;IAMX,OAAO,CAAC,oBAAoB;IAmB5B,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,SAAS;YA8BH,SAAS;IA4BvB,OAAO,CAAC,MAAM;CAcf"}
|
package/dist/src/resonate.js
CHANGED
|
@@ -32,6 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.Resonate = void 0;
|
|
37
40
|
const network_1 = require("../dev/network");
|
|
@@ -39,6 +42,7 @@ const handler_1 = require("../src/handler");
|
|
|
39
42
|
const registry_1 = require("../src/registry");
|
|
40
43
|
const clock_1 = require("./clock");
|
|
41
44
|
const encoder_1 = require("./encoder");
|
|
45
|
+
const exceptions_1 = __importDefault(require("./exceptions"));
|
|
42
46
|
const heartbeat_1 = require("./heartbeat");
|
|
43
47
|
const remote_1 = require("./network/remote");
|
|
44
48
|
const options_1 = require("./options");
|
|
@@ -70,15 +74,39 @@ class Resonate {
|
|
|
70
74
|
this.pid = pid;
|
|
71
75
|
this.ttl = ttl;
|
|
72
76
|
this.encoder = new encoder_1.JsonEncoder();
|
|
73
|
-
|
|
77
|
+
// Determine the URL based on priority: url arg > RESONATE_URL > RESONATE_HOST+PORT
|
|
78
|
+
let resolvedUrl = url;
|
|
79
|
+
if (!resolvedUrl) {
|
|
80
|
+
if (process.env.RESONATE_URL) {
|
|
81
|
+
resolvedUrl = process.env.RESONATE_URL;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const resonateScheme = process.env.RESONATE_SCHEME ?? "http";
|
|
85
|
+
const resonateHost = process.env.RESONATE_HOST;
|
|
86
|
+
const resonatePort = process.env.RESONATE_PORT ?? "8001";
|
|
87
|
+
if (resonateHost) {
|
|
88
|
+
resolvedUrl = `${resonateScheme}://${resonateHost}:${resonatePort}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Determine the auth based on priority: auth arg > RESONATE_USERNAME+RESONATE_PASSWORD
|
|
93
|
+
let resolvedAuth = auth;
|
|
94
|
+
if (!resolvedAuth) {
|
|
95
|
+
const resonateUsername = process.env.RESONATE_USERNAME;
|
|
96
|
+
const resonatePassword = process.env.RESONATE_PASSWORD ?? "";
|
|
97
|
+
if (resonateUsername) {
|
|
98
|
+
resolvedAuth = { username: resonateUsername, password: resonatePassword };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!resolvedUrl) {
|
|
74
102
|
const localNetwork = new network_1.LocalNetwork();
|
|
75
103
|
this.network = localNetwork;
|
|
76
104
|
this.messageSource = localNetwork.getMessageSource();
|
|
77
105
|
this.heartbeat = new heartbeat_1.NoopHeartbeat();
|
|
78
106
|
}
|
|
79
107
|
else {
|
|
80
|
-
this.network = new remote_1.HttpNetwork({ url, auth, timeout: 1 * util.MIN, headers: {} });
|
|
81
|
-
this.messageSource = new remote_1.HttpMessageSource({ url, pid, group, auth });
|
|
108
|
+
this.network = new remote_1.HttpNetwork({ url: resolvedUrl, auth: resolvedAuth, timeout: 1 * util.MIN, headers: {} });
|
|
109
|
+
this.messageSource = new remote_1.HttpMessageSource({ url: resolvedUrl, pid, group, auth: resolvedAuth });
|
|
82
110
|
this.heartbeat = new heartbeat_1.AsyncHeartbeat(pid, ttl / 2, this.network);
|
|
83
111
|
}
|
|
84
112
|
this.handler = new handler_1.Handler(this.network, this.encoder);
|
|
@@ -104,7 +132,25 @@ class Resonate {
|
|
|
104
132
|
this.messageSource.subscribe("notify", this.onMessage.bind(this));
|
|
105
133
|
}
|
|
106
134
|
/**
|
|
107
|
-
*
|
|
135
|
+
* Initializes a Resonate client instance for local development.
|
|
136
|
+
*
|
|
137
|
+
* Creates and returns a Resonate client configured for **local-only execution**
|
|
138
|
+
* with zero external dependencies. All state is stored in local memory — no
|
|
139
|
+
* network or external persistence is required. This mode is ideal for rapid
|
|
140
|
+
* testing, debugging, and experimentation before connecting to a Resonate server.
|
|
141
|
+
*
|
|
142
|
+
* The client runs with a `"default"` worker group, a `"default"` process ID,
|
|
143
|
+
* and an effectively infinite TTL (`Number.MAX_SAFE_INTEGER`) for tasks.
|
|
144
|
+
*
|
|
145
|
+
* @returns A {@link Resonate} client instance configured for local development.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* const resonate = Resonate.local();
|
|
150
|
+
* resonate.register(foo);
|
|
151
|
+
* const result = await resonate.run("foo.1", foo, { data: "test" });
|
|
152
|
+
* console.log(result);
|
|
153
|
+
* ```
|
|
108
154
|
*/
|
|
109
155
|
static local() {
|
|
110
156
|
return new Resonate({
|
|
@@ -114,7 +160,39 @@ class Resonate {
|
|
|
114
160
|
});
|
|
115
161
|
}
|
|
116
162
|
/**
|
|
117
|
-
*
|
|
163
|
+
* Initializes a Resonate client instance with remote configuration.
|
|
164
|
+
*
|
|
165
|
+
* Creates and returns a Resonate client that connects to a **Resonate Server**
|
|
166
|
+
* and optional remote message sources. This configuration enables distributed,
|
|
167
|
+
* durable workers to cooperate and execute functions via **durable RPCs**.
|
|
168
|
+
*
|
|
169
|
+
* By default, the client connects to a Resonate Server running locally
|
|
170
|
+
* (`http://localhost:8001`) and joins the `"default"` worker group.
|
|
171
|
+
*
|
|
172
|
+
* The client is identified by a unique process ID (`pid`) and maintains
|
|
173
|
+
* claimed task leases for the duration specified by `ttl`.
|
|
174
|
+
*
|
|
175
|
+
* @param options - Configuration options for the remote client.
|
|
176
|
+
* @param options.url - The base URL of the remote Resonate Server. Defaults to `"http://localhost:8001"`.
|
|
177
|
+
* @param options.group - The worker group name. Defaults to `"default"`.
|
|
178
|
+
* @param options.pid - Optional process identifier for the client. Defaults to a randomly generated UUID.
|
|
179
|
+
* @param options.ttl - Time-to-live (in seconds) for claimed tasks. Defaults to `1 * util.MIN`.
|
|
180
|
+
* @param options.auth - Optional authentication credentials for connecting to the remote server.
|
|
181
|
+
*
|
|
182
|
+
* @returns A {@link Resonate} client instance configured for remote operation.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const resonate = Resonate.remote({
|
|
187
|
+
* url: "https://resonate.example.com",
|
|
188
|
+
* group: "analytics",
|
|
189
|
+
* ttl: 30,
|
|
190
|
+
* auth: { username: "user", password: "secret" },
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* const result = await resonate.run("task-42", "processData", { input: "dataset.csv" });
|
|
194
|
+
* console.log(result);
|
|
195
|
+
* ```
|
|
118
196
|
*/
|
|
119
197
|
static remote({ url = "http://localhost:8001", group = "default", pid = crypto.randomUUID().replace(/-/g, ""), ttl = 1 * util.MIN, auth = undefined, } = {}) {
|
|
120
198
|
return new Resonate({ url, group, pid, ttl, auth });
|
|
@@ -122,13 +200,13 @@ class Resonate {
|
|
|
122
200
|
register(nameOrFunc, funcOrOptions, maybeOptions = {}) {
|
|
123
201
|
const { version = 1 } = (typeof funcOrOptions === "object" ? funcOrOptions : maybeOptions) ?? {};
|
|
124
202
|
const func = typeof nameOrFunc === "function" ? nameOrFunc : funcOrOptions;
|
|
125
|
-
const name = typeof nameOrFunc === "string" ? nameOrFunc :
|
|
203
|
+
const name = typeof nameOrFunc === "string" ? nameOrFunc : func.name;
|
|
126
204
|
this.registry.add(func, name, version);
|
|
127
205
|
return {
|
|
128
|
-
run: (id, ...args) => this.run(id, func, ...
|
|
129
|
-
rpc: (id, ...args) => this.rpc(id, func, ...
|
|
130
|
-
beginRun: (id, ...args) => this.beginRun(id, func, ...
|
|
131
|
-
beginRpc: (id, ...args) => this.beginRpc(id, func, ...
|
|
206
|
+
run: (id, ...args) => this.run(id, func, ...this.getArgsAndOpts(args, version)),
|
|
207
|
+
rpc: (id, ...args) => this.rpc(id, func, ...this.getArgsAndOpts(args, version)),
|
|
208
|
+
beginRun: (id, ...args) => this.beginRun(id, func, ...this.getArgsAndOpts(args, version)),
|
|
209
|
+
beginRpc: (id, ...args) => this.beginRpc(id, func, ...this.getArgsAndOpts(args, version)),
|
|
132
210
|
options: this.options,
|
|
133
211
|
};
|
|
134
212
|
}
|
|
@@ -136,8 +214,13 @@ class Resonate {
|
|
|
136
214
|
return (await this.beginRun(id, funcOrName, ...args)).result();
|
|
137
215
|
}
|
|
138
216
|
async beginRun(id, funcOrName, ...argsWithOpts) {
|
|
139
|
-
const [args, opts] =
|
|
217
|
+
const [args, opts] = this.getArgsAndOpts(argsWithOpts);
|
|
140
218
|
const registered = this.registry.get(funcOrName, opts.version);
|
|
219
|
+
// function must be registered
|
|
220
|
+
if (!registered) {
|
|
221
|
+
throw exceptions_1.default.REGISTRY_FUNCTION_NOT_REGISTERED(typeof funcOrName === "string" ? funcOrName : funcOrName.name, opts.version);
|
|
222
|
+
}
|
|
223
|
+
util.assert(registered.version > 0, "function version must be greater than zero");
|
|
141
224
|
const { promise, task } = await this.createPromiseAndTask({
|
|
142
225
|
kind: "createPromiseAndTask",
|
|
143
226
|
promise: {
|
|
@@ -147,7 +230,7 @@ class Resonate {
|
|
|
147
230
|
data: {
|
|
148
231
|
func: registered.name,
|
|
149
232
|
args: args,
|
|
150
|
-
version:
|
|
233
|
+
version: registered.version,
|
|
151
234
|
},
|
|
152
235
|
},
|
|
153
236
|
tags: {
|
|
@@ -172,13 +255,11 @@ class Resonate {
|
|
|
172
255
|
return (await this.beginRpc(id, funcOrName, ...args)).result();
|
|
173
256
|
}
|
|
174
257
|
async beginRpc(id, funcOrName, ...argsWithOpts) {
|
|
175
|
-
const [args, opts] =
|
|
176
|
-
|
|
177
|
-
if
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
else {
|
|
181
|
-
name = this.registry.get(funcOrName, opts.version).name;
|
|
258
|
+
const [args, opts] = this.getArgsAndOpts(argsWithOpts);
|
|
259
|
+
const registered = this.registry.get(funcOrName, opts.version);
|
|
260
|
+
// function must be registered if function pointer is provided
|
|
261
|
+
if (typeof funcOrName === "function" && !registered) {
|
|
262
|
+
throw exceptions_1.default.REGISTRY_FUNCTION_NOT_REGISTERED(funcOrName.name, opts.version);
|
|
182
263
|
}
|
|
183
264
|
const promise = await this.createPromise({
|
|
184
265
|
kind: "createPromise",
|
|
@@ -186,9 +267,9 @@ class Resonate {
|
|
|
186
267
|
timeout: Date.now() + opts.timeout,
|
|
187
268
|
param: {
|
|
188
269
|
data: {
|
|
189
|
-
func: name,
|
|
270
|
+
func: registered ? registered.name : funcOrName,
|
|
190
271
|
args: args,
|
|
191
|
-
version: opts.version,
|
|
272
|
+
version: registered ? registered.version : opts.version || 1,
|
|
192
273
|
},
|
|
193
274
|
},
|
|
194
275
|
tags: { ...opts.tags, "resonate:invoke": opts.target, "resonate:scope": "global" },
|
|
@@ -197,17 +278,19 @@ class Resonate {
|
|
|
197
278
|
});
|
|
198
279
|
return this.createHandle(promise);
|
|
199
280
|
}
|
|
200
|
-
async schedule(name, cron,
|
|
201
|
-
const [args, opts] =
|
|
202
|
-
|
|
203
|
-
if
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
else {
|
|
207
|
-
funcName = this.registry.get(func, opts.version).name;
|
|
281
|
+
async schedule(name, cron, funcOrName, ...argsWithOpts) {
|
|
282
|
+
const [args, opts] = this.getArgsAndOpts(argsWithOpts);
|
|
283
|
+
const registered = this.registry.get(funcOrName, opts.version);
|
|
284
|
+
// function must be registered if function pointer is provided
|
|
285
|
+
if (typeof funcOrName === "function" && !registered) {
|
|
286
|
+
throw exceptions_1.default.REGISTRY_FUNCTION_NOT_REGISTERED(funcOrName.name, opts.version);
|
|
208
287
|
}
|
|
209
288
|
// TODO: move this into the handler?
|
|
210
|
-
const { headers, data } = this.encoder.encode({
|
|
289
|
+
const { headers, data } = this.encoder.encode({
|
|
290
|
+
func: registered ? registered.name : funcOrName,
|
|
291
|
+
args: args,
|
|
292
|
+
version: registered ? registered.version : opts.version || 1,
|
|
293
|
+
});
|
|
211
294
|
await this.schedules.create(name, cron, "{{.id}}.{{.timestamp}}", opts.timeout, {
|
|
212
295
|
ikey: name,
|
|
213
296
|
promiseHeaders: headers,
|
|
@@ -219,7 +302,22 @@ class Resonate {
|
|
|
219
302
|
};
|
|
220
303
|
}
|
|
221
304
|
/**
|
|
222
|
-
*
|
|
305
|
+
* Retrieves or subscribes to an existing execution by its unique ID.
|
|
306
|
+
*
|
|
307
|
+
* This method attaches to an existing **durable promise** identified by `id`.
|
|
308
|
+
* If the associated execution is still in progress, it returns a {@link ResonateHandle}
|
|
309
|
+
* that can be awaited or observed until completion. If the execution has already
|
|
310
|
+
* finished, the handle is immediately resolved with the stored result.
|
|
311
|
+
*
|
|
312
|
+
* Notes:
|
|
313
|
+
* - A durable promise with the given `id` must already exist.
|
|
314
|
+
* - This operation is **non-blocking**; awaiting the returned handle will block
|
|
315
|
+
* only if the execution is still running.
|
|
316
|
+
*
|
|
317
|
+
* @param id - Unique identifier of the target execution or durable promise.
|
|
318
|
+
*
|
|
319
|
+
* @returns A {@link ResonateHandle} representing the existing execution.
|
|
320
|
+
* The handle can be awaited or queried to retrieve the final result.
|
|
223
321
|
*/
|
|
224
322
|
async get(id) {
|
|
225
323
|
const promise = await this.readPromise({
|
|
@@ -232,12 +330,9 @@ class Resonate {
|
|
|
232
330
|
const target = opts.target ?? this.anycastNoPreference;
|
|
233
331
|
return new options_1.Options({ target, ...opts });
|
|
234
332
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
* Setting a dependency for a name that already exists will
|
|
239
|
-
* overwrite the previously set dependency.
|
|
240
|
-
*/
|
|
333
|
+
getArgsAndOpts(args, version) {
|
|
334
|
+
return util.splitArgsAndOpts(args, this.options({ version }));
|
|
335
|
+
}
|
|
241
336
|
setDependency(name, obj) {
|
|
242
337
|
this.dependencies.set(name, obj);
|
|
243
338
|
}
|
|
@@ -249,30 +344,27 @@ class Resonate {
|
|
|
249
344
|
createPromiseAndTask(req) {
|
|
250
345
|
return new Promise((resolve, reject) => this.handler.createPromiseAndTask(req, (err, res) => {
|
|
251
346
|
if (err) {
|
|
252
|
-
|
|
253
|
-
reject(new Error(`Promise '${req.promise.id}' could not be created`));
|
|
347
|
+
reject(err);
|
|
254
348
|
}
|
|
255
349
|
else {
|
|
256
350
|
resolve({ promise: res.promise, task: res.task });
|
|
257
351
|
}
|
|
258
|
-
}, true));
|
|
352
|
+
}, undefined, true));
|
|
259
353
|
}
|
|
260
354
|
createPromise(req) {
|
|
261
355
|
return new Promise((resolve, reject) => this.handler.createPromise(req, (err, res) => {
|
|
262
356
|
if (err) {
|
|
263
|
-
|
|
264
|
-
reject(new Error(`Promise '${req.id}' could not be created`));
|
|
357
|
+
reject(err);
|
|
265
358
|
}
|
|
266
359
|
else {
|
|
267
360
|
resolve(res);
|
|
268
361
|
}
|
|
269
|
-
}, true));
|
|
362
|
+
}, undefined, true));
|
|
270
363
|
}
|
|
271
364
|
createSubscription(req) {
|
|
272
365
|
return new Promise((resolve, reject) => this.handler.createSubscription(req, (err, res) => {
|
|
273
366
|
if (err) {
|
|
274
|
-
|
|
275
|
-
reject(new Error(`Subscription for promise '${req.promiseId}' could not be created`));
|
|
367
|
+
reject(err);
|
|
276
368
|
}
|
|
277
369
|
else {
|
|
278
370
|
resolve(res);
|
|
@@ -282,8 +374,7 @@ class Resonate {
|
|
|
282
374
|
readPromise(req) {
|
|
283
375
|
return new Promise((resolve, reject) => this.handler.readPromise(req, (err, res) => {
|
|
284
376
|
if (err) {
|
|
285
|
-
|
|
286
|
-
reject(new Error(`Promise '${req.id}' not found`));
|
|
377
|
+
reject(err);
|
|
287
378
|
}
|
|
288
379
|
else {
|
|
289
380
|
resolve(res);
|