rivetkit 0.0.0-pr.4792.8c20f1a → 0.0.0-pr.4794.efd07f2
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/browser/client.d.ts +1 -1
- package/dist/browser/client.js +117 -55
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -1
- package/dist/tsup/agent-os/index.d.ts +1 -1
- package/dist/tsup/{chunk-B27LED27.cjs → chunk-3RQL5CY6.cjs} +2 -2
- package/dist/tsup/{chunk-B27LED27.cjs.map → chunk-3RQL5CY6.cjs.map} +1 -1
- package/dist/tsup/{chunk-UIUKHW3C.js → chunk-AJRPETMD.js} +2 -2
- package/dist/tsup/{chunk-GARDRY7K.cjs → chunk-BXJG65HV.cjs} +5 -5
- package/dist/tsup/{chunk-GARDRY7K.cjs.map → chunk-BXJG65HV.cjs.map} +1 -1
- package/dist/tsup/{chunk-447NZOHH.cjs → chunk-DBWR3TER.cjs} +4 -4
- package/dist/tsup/{chunk-447NZOHH.cjs.map → chunk-DBWR3TER.cjs.map} +1 -1
- package/dist/tsup/{chunk-3PNGQBFA.cjs → chunk-DH2GWJ53.cjs} +3 -3
- package/dist/tsup/{chunk-3PNGQBFA.cjs.map → chunk-DH2GWJ53.cjs.map} +1 -1
- package/dist/tsup/{chunk-PGRQHKJE.cjs → chunk-ESZUORA3.cjs} +8 -8
- package/dist/tsup/{chunk-PGRQHKJE.cjs.map → chunk-ESZUORA3.cjs.map} +1 -1
- package/dist/tsup/{chunk-HWLHLSEJ.js → chunk-I2IT5KXZ.js} +98 -60
- package/dist/tsup/chunk-I2IT5KXZ.js.map +1 -0
- package/dist/tsup/{chunk-NZZJVDFU.js → chunk-JGUNJ346.js} +2 -2
- package/dist/tsup/{chunk-NZZJVDFU.js.map → chunk-JGUNJ346.js.map} +1 -1
- package/dist/tsup/{chunk-PE2G7JKJ.cjs → chunk-JZY5WHVY.cjs} +226 -188
- package/dist/tsup/chunk-JZY5WHVY.cjs.map +1 -0
- package/dist/tsup/{chunk-7P4DYJJZ.js → chunk-KK7ZNG4Y.js} +3 -3
- package/dist/tsup/{chunk-AADUJZB3.cjs → chunk-RDDR6XZY.cjs} +10 -10
- package/dist/tsup/{chunk-AADUJZB3.cjs.map → chunk-RDDR6XZY.cjs.map} +1 -1
- package/dist/tsup/{chunk-BUXV6MUA.js → chunk-SPHDBXZ3.js} +2 -2
- package/dist/tsup/{chunk-TOK4N5SS.js → chunk-V3GGCE6Q.js} +4 -4
- package/dist/tsup/{chunk-7AFPF5YA.js → chunk-YLSP3HLS.js} +2 -2
- package/dist/tsup/client/mod.cjs +7 -6
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +6 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-dkj-A9c_.d.ts → config-CW4vcJ_f.d.ts} +1 -1
- package/dist/tsup/{config-BtPoYx1C.d.cts → config-hcAotIdp.d.cts} +1 -1
- package/dist/tsup/{context-C3kimvYw.d.ts → context-BxJlKoEv.d.ts} +1 -1
- package/dist/tsup/{context-uvYekFi7.d.cts → context-DAOAwyGn.d.cts} +1 -1
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/mod.cjs +46 -46
- package/dist/tsup/mod.d.cts +3 -3
- package/dist/tsup/mod.d.ts +3 -3
- package/dist/tsup/mod.js +5 -5
- package/dist/tsup/test/mod.cjs +10 -9
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +6 -5
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +7 -7
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +4 -4
- package/package.json +7 -7
- package/src/client/actor-conn.ts +4 -0
- package/src/client/actor-handle.ts +121 -61
- package/src/client/actor-query.ts +2 -0
- package/dist/tsup/chunk-HWLHLSEJ.js.map +0 -1
- package/dist/tsup/chunk-PE2G7JKJ.cjs.map +0 -1
- /package/dist/tsup/{chunk-UIUKHW3C.js.map → chunk-AJRPETMD.js.map} +0 -0
- /package/dist/tsup/{chunk-7P4DYJJZ.js.map → chunk-KK7ZNG4Y.js.map} +0 -0
- /package/dist/tsup/{chunk-BUXV6MUA.js.map → chunk-SPHDBXZ3.js.map} +0 -0
- /package/dist/tsup/{chunk-TOK4N5SS.js.map → chunk-V3GGCE6Q.js.map} +0 -0
- /package/dist/tsup/{chunk-7AFPF5YA.js.map → chunk-YLSP3HLS.js.map} +0 -0
package/dist/browser/client.d.ts
CHANGED
|
@@ -451,7 +451,7 @@ declare class ActorConnRaw {
|
|
|
451
451
|
*
|
|
452
452
|
* @protected
|
|
453
453
|
*/
|
|
454
|
-
constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState);
|
|
454
|
+
constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, onResolvedActorId?: (actorId: string) => void);
|
|
455
455
|
send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
|
|
456
456
|
send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
|
|
457
457
|
/**
|
package/dist/browser/client.js
CHANGED
|
@@ -225,7 +225,7 @@ function noopNext() {
|
|
|
225
225
|
// package.json
|
|
226
226
|
var package_default = {
|
|
227
227
|
name: "rivetkit",
|
|
228
|
-
version: "0.0.0-pr.
|
|
228
|
+
version: "0.0.0-pr.4794.efd07f2",
|
|
229
229
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
230
230
|
license: "Apache-2.0",
|
|
231
231
|
keywords: [
|
|
@@ -3700,7 +3700,7 @@ function getGatewayTarget(state) {
|
|
|
3700
3700
|
return state;
|
|
3701
3701
|
}
|
|
3702
3702
|
function isStaleResolvedActorError(group, code) {
|
|
3703
|
-
return group === "actor" && (code === "not_found" || code === "starting" || code === "stopping" || code.startsWith("destroyed_"));
|
|
3703
|
+
return group === "actor" && (code === "not_found" || code === "starting" || code === "stopping" || code === "not_configured" || code === "dropped_reply" || code.startsWith("destroyed_"));
|
|
3704
3704
|
}
|
|
3705
3705
|
async function checkForSchedulingError(group, code, actorId, query, driver) {
|
|
3706
3706
|
const name = getActorNameFromQuery(query);
|
|
@@ -3824,6 +3824,7 @@ var ActorConnRaw = class {
|
|
|
3824
3824
|
#getParams;
|
|
3825
3825
|
#encoding;
|
|
3826
3826
|
#actorResolutionState;
|
|
3827
|
+
#onResolvedActorId;
|
|
3827
3828
|
// TODO: ws message queue
|
|
3828
3829
|
/**
|
|
3829
3830
|
* Do not call this directly.
|
|
@@ -3832,13 +3833,14 @@ var ActorConnRaw = class {
|
|
|
3832
3833
|
*
|
|
3833
3834
|
* @protected
|
|
3834
3835
|
*/
|
|
3835
|
-
constructor(client, driver, params, getParams, encoding, actorResolutionState) {
|
|
3836
|
+
constructor(client, driver, params, getParams, encoding, actorResolutionState, onResolvedActorId) {
|
|
3836
3837
|
this.#client = client;
|
|
3837
3838
|
this.#driver = driver;
|
|
3838
3839
|
this.#params = params;
|
|
3839
3840
|
this.#getParams = getParams;
|
|
3840
3841
|
this.#encoding = encoding;
|
|
3841
3842
|
this.#actorResolutionState = actorResolutionState;
|
|
3843
|
+
this.#onResolvedActorId = onResolvedActorId;
|
|
3842
3844
|
this.#queueSender = createQueueSender({
|
|
3843
3845
|
encoding: this.#encoding,
|
|
3844
3846
|
params: this.#params,
|
|
@@ -4175,6 +4177,7 @@ var ActorConnRaw = class {
|
|
|
4175
4177
|
if (response.body.tag === "Init") {
|
|
4176
4178
|
this.#actorId = response.body.val.actorId;
|
|
4177
4179
|
this.#connId = response.body.val.connectionId;
|
|
4180
|
+
this.#onResolvedActorId?.(this.#actorId);
|
|
4178
4181
|
logger2().trace({
|
|
4179
4182
|
msg: "received init message",
|
|
4180
4183
|
actorId: this.#actorId,
|
|
@@ -4798,6 +4801,33 @@ var ActorConnRaw = class {
|
|
|
4798
4801
|
}
|
|
4799
4802
|
};
|
|
4800
4803
|
|
|
4804
|
+
// src/common/database/shared.ts
|
|
4805
|
+
var AsyncMutex = class {
|
|
4806
|
+
#locked = false;
|
|
4807
|
+
#waiting = [];
|
|
4808
|
+
async acquire() {
|
|
4809
|
+
while (this.#locked) {
|
|
4810
|
+
await new Promise((resolve) => this.#waiting.push(resolve));
|
|
4811
|
+
}
|
|
4812
|
+
this.#locked = true;
|
|
4813
|
+
}
|
|
4814
|
+
release() {
|
|
4815
|
+
this.#locked = false;
|
|
4816
|
+
const next = this.#waiting.shift();
|
|
4817
|
+
if (next) {
|
|
4818
|
+
next();
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
async run(fn) {
|
|
4822
|
+
await this.acquire();
|
|
4823
|
+
try {
|
|
4824
|
+
return await fn();
|
|
4825
|
+
} finally {
|
|
4826
|
+
this.release();
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
4829
|
+
};
|
|
4830
|
+
|
|
4801
4831
|
// src/client/raw-utils.ts
|
|
4802
4832
|
async function rawHttpFetch(driver, target, params, input, init) {
|
|
4803
4833
|
let path;
|
|
@@ -4945,7 +4975,9 @@ var ActorHandleRaw = class {
|
|
|
4945
4975
|
#params;
|
|
4946
4976
|
#getParams;
|
|
4947
4977
|
#resolvedActorId;
|
|
4978
|
+
#resolvedActorIdPinned = false;
|
|
4948
4979
|
#resolvingActorId;
|
|
4980
|
+
#queueSendMutex = new AsyncMutex();
|
|
4949
4981
|
/**
|
|
4950
4982
|
* Do not call this directly.
|
|
4951
4983
|
*
|
|
@@ -4971,61 +5003,73 @@ var ActorHandleRaw = class {
|
|
|
4971
5003
|
return this.#sendQueueMessage(name, body, options);
|
|
4972
5004
|
}
|
|
4973
5005
|
async #sendQueueMessage(name, body, options) {
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
let
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
5006
|
+
return await this.#queueSendMutex.run(async () => {
|
|
5007
|
+
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
5008
|
+
let useQueryTarget = false;
|
|
5009
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
5010
|
+
let actorId;
|
|
5011
|
+
try {
|
|
5012
|
+
const target = await this.#resolveActionTarget(useQueryTarget);
|
|
5013
|
+
actorId = "directId" in target ? target.directId : void 0;
|
|
5014
|
+
return await createQueueSender({
|
|
5015
|
+
encoding: this.#encoding,
|
|
5016
|
+
params: this.#params,
|
|
5017
|
+
customFetch: async (request) => {
|
|
5018
|
+
return await this.#driver.sendRequest(target, request);
|
|
5019
|
+
}
|
|
5020
|
+
}).send(name, body, options);
|
|
5021
|
+
} catch (err) {
|
|
5022
|
+
const { group, code, message, metadata } = deconstructError(
|
|
5023
|
+
err,
|
|
5024
|
+
logger2(),
|
|
5025
|
+
{},
|
|
5026
|
+
true
|
|
5027
|
+
);
|
|
5028
|
+
if (this.#shouldRetryQueueDispatchOverload(
|
|
5029
|
+
group,
|
|
5030
|
+
code,
|
|
5031
|
+
metadata,
|
|
5032
|
+
attempt,
|
|
5033
|
+
maxAttempts
|
|
5034
|
+
)) {
|
|
5035
|
+
await this.#waitForRetryWindow();
|
|
5036
|
+
continue;
|
|
4986
5037
|
}
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
if (await this.#shouldRetrySchedulingError(
|
|
4996
|
-
group,
|
|
4997
|
-
code,
|
|
4998
|
-
actorId,
|
|
4999
|
-
attempt,
|
|
5000
|
-
maxAttempts
|
|
5001
|
-
)) {
|
|
5002
|
-
useQueryTarget = true;
|
|
5003
|
-
await this.#waitForRetryWindow();
|
|
5004
|
-
continue;
|
|
5005
|
-
}
|
|
5006
|
-
if (this.#shouldRetryDynamicLifecycleError(
|
|
5007
|
-
group,
|
|
5008
|
-
code,
|
|
5009
|
-
attempt,
|
|
5010
|
-
maxAttempts
|
|
5011
|
-
)) {
|
|
5012
|
-
this.#clearResolvedActorId();
|
|
5013
|
-
useQueryTarget = true;
|
|
5014
|
-
await this.#waitForRetryWindow();
|
|
5015
|
-
continue;
|
|
5016
|
-
}
|
|
5017
|
-
const invalidated = this.#invalidateResolvedActorId(group, code);
|
|
5018
|
-
if (invalidated && attempt < maxAttempts - 1) {
|
|
5019
|
-
useQueryTarget = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
|
|
5020
|
-
if (useQueryTarget) {
|
|
5038
|
+
if (await this.#shouldRetrySchedulingError(
|
|
5039
|
+
group,
|
|
5040
|
+
code,
|
|
5041
|
+
actorId,
|
|
5042
|
+
attempt,
|
|
5043
|
+
maxAttempts
|
|
5044
|
+
)) {
|
|
5045
|
+
useQueryTarget = true;
|
|
5021
5046
|
await this.#waitForRetryWindow();
|
|
5047
|
+
continue;
|
|
5022
5048
|
}
|
|
5023
|
-
|
|
5049
|
+
if (this.#shouldRetryDynamicLifecycleError(
|
|
5050
|
+
group,
|
|
5051
|
+
code,
|
|
5052
|
+
attempt,
|
|
5053
|
+
maxAttempts
|
|
5054
|
+
)) {
|
|
5055
|
+
this.#clearResolvedActorId();
|
|
5056
|
+
useQueryTarget = true;
|
|
5057
|
+
await this.#waitForRetryWindow();
|
|
5058
|
+
continue;
|
|
5059
|
+
}
|
|
5060
|
+
const invalidated = this.#invalidateResolvedActorId(group, code);
|
|
5061
|
+
if (invalidated && attempt < maxAttempts - 1) {
|
|
5062
|
+
useQueryTarget = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
|
|
5063
|
+
if (useQueryTarget) {
|
|
5064
|
+
await this.#waitForRetryWindow();
|
|
5065
|
+
}
|
|
5066
|
+
continue;
|
|
5067
|
+
}
|
|
5068
|
+
throw new RivetError(group, code, message, metadata);
|
|
5024
5069
|
}
|
|
5025
|
-
throw new RivetError(group, code, message, metadata);
|
|
5026
5070
|
}
|
|
5027
|
-
|
|
5028
|
-
|
|
5071
|
+
throw new Error("unreachable queue retry state");
|
|
5072
|
+
});
|
|
5029
5073
|
}
|
|
5030
5074
|
/**
|
|
5031
5075
|
* Call a raw action. This method sends an HTTP request to invoke the named action.
|
|
@@ -5172,12 +5216,24 @@ var ActorHandleRaw = class {
|
|
|
5172
5216
|
if (!isDynamicActorQuery(this.#actorResolutionState) || attempt >= maxAttempts - 1 || group !== "actor") {
|
|
5173
5217
|
return false;
|
|
5174
5218
|
}
|
|
5175
|
-
return code === "not_found" || code === "starting" || code === "stopping" || code === "destroying" || code.startsWith("destroyed_");
|
|
5219
|
+
return code === "not_found" || code === "starting" || code === "stopping" || code === "not_configured" || code === "dropped_reply" || code === "destroying" || code.startsWith("destroyed_");
|
|
5220
|
+
}
|
|
5221
|
+
#shouldRetryQueueDispatchOverload(group, code, metadata, attempt, maxAttempts) {
|
|
5222
|
+
if (!isDynamicActorQuery(this.#actorResolutionState) || attempt >= maxAttempts - 1 || group !== "actor" || code !== "overloaded" || metadata === null || typeof metadata !== "object") {
|
|
5223
|
+
return false;
|
|
5224
|
+
}
|
|
5225
|
+
const overload = metadata;
|
|
5226
|
+
return overload.channel === "dispatch_inbox" && overload.operation === "dispatch_queue_send";
|
|
5176
5227
|
}
|
|
5177
5228
|
#clearResolvedActorId() {
|
|
5178
5229
|
this.#resolvedActorId = void 0;
|
|
5230
|
+
this.#resolvedActorIdPinned = false;
|
|
5179
5231
|
this.#resolvingActorId = void 0;
|
|
5180
5232
|
}
|
|
5233
|
+
#setResolvedActorIdFromConnection(actorId) {
|
|
5234
|
+
this.#resolvedActorId = actorId;
|
|
5235
|
+
this.#resolvedActorIdPinned = true;
|
|
5236
|
+
}
|
|
5181
5237
|
async #shouldRetrySchedulingError(group, code, actorId, attempt, maxAttempts) {
|
|
5182
5238
|
if (!isDynamicActorQuery(this.#actorResolutionState) || !isSchedulingError(group, code) || attempt >= maxAttempts - 1) {
|
|
5183
5239
|
return false;
|
|
@@ -5219,6 +5275,9 @@ var ActorHandleRaw = class {
|
|
|
5219
5275
|
this.#driver,
|
|
5220
5276
|
this.#actorResolutionState
|
|
5221
5277
|
).then((actorId) => {
|
|
5278
|
+
if (this.#resolvedActorIdPinned && this.#resolvedActorId) {
|
|
5279
|
+
return this.#resolvedActorId;
|
|
5280
|
+
}
|
|
5222
5281
|
this.#resolvedActorId = actorId;
|
|
5223
5282
|
return actorId;
|
|
5224
5283
|
});
|
|
@@ -5248,7 +5307,10 @@ var ActorHandleRaw = class {
|
|
|
5248
5307
|
connParams,
|
|
5249
5308
|
getParams,
|
|
5250
5309
|
this.#encoding,
|
|
5251
|
-
this.#actorResolutionState
|
|
5310
|
+
this.#actorResolutionState,
|
|
5311
|
+
(actorId) => {
|
|
5312
|
+
this.#setResolvedActorIdFromConnection(actorId);
|
|
5313
|
+
}
|
|
5252
5314
|
);
|
|
5253
5315
|
return this.#client[CREATE_ACTOR_CONN_PROXY](
|
|
5254
5316
|
conn
|