@instantdb/core
Advanced tools
Comparing version 0.12.30 to 0.12.31
@@ -42,3 +42,12 @@ /** | ||
_initStorage(Storage: any): void; | ||
_finishTransaction(ok: any, status: any, clientId: any, errDetails: any): void; | ||
/** | ||
* @param {'enqueued' | 'pending' | 'synced' | 'timeout' | 'error' } status | ||
* @param string clientId | ||
* @param {{message?: string, hint?: string, error?: Error}} [errDetails] | ||
*/ | ||
_finishTransaction(status: "enqueued" | "pending" | "synced" | "timeout" | "error", clientId: any, errDetails?: { | ||
message?: string; | ||
hint?: string; | ||
error?: Error; | ||
}): void; | ||
_setStatus(status: any, err: any): void; | ||
@@ -64,2 +73,12 @@ /** | ||
_sessionId: any; | ||
/** | ||
* @param {'timeout' | 'error'} status | ||
* @param {string} eventId | ||
* @param {{message?: string, hint?: string, error?: Error}} errDetails | ||
*/ | ||
_handleMutationError(status: "timeout" | "error", eventId: string, errDetails: { | ||
message?: string; | ||
hint?: string; | ||
error?: Error; | ||
}): void; | ||
_handleReceiveError(msg: any): void; | ||
@@ -66,0 +85,0 @@ _setAttrs(attrs: any): void; |
@@ -284,5 +284,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
_finishTransaction(ok, status, clientId, errDetails) { | ||
/** | ||
* @param {'enqueued' | 'pending' | 'synced' | 'timeout' | 'error' } status | ||
* @param string clientId | ||
* @param {{message?: string, hint?: string, error?: Error}} [errDetails] | ||
*/ | ||
_finishTransaction(status, clientId, errDetails) { | ||
const dfd = this.mutationDeferredStore.get(clientId); | ||
this.mutationDeferredStore.delete(clientId); | ||
const ok = status !== "error" && status !== "timeout"; | ||
if (!dfd && !ok) { | ||
@@ -390,3 +396,3 @@ // console.erroring here, as there are no listeners to let know | ||
}); | ||
this._finishTransaction(true, "synced", eventId); | ||
this._finishTransaction("synced", eventId); | ||
const newAttrs = prevMutation["tx-steps"] | ||
@@ -431,2 +437,20 @@ .filter(([action, ..._args]) => action === "add-attr") | ||
} | ||
/** | ||
* @param {'timeout' | 'error'} status | ||
* @param {string} eventId | ||
* @param {{message?: string, hint?: string, error?: Error}} errDetails | ||
*/ | ||
_handleMutationError(status, eventId, errDetails) { | ||
const mut = this.pendingMutations.currentValue.get(eventId); | ||
if (mut && (status !== "timeout" || !mut["tx-id"])) { | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
this.notifyAll(); | ||
this.notifyAttrsSubs(); | ||
this.notifyMutationErrorSubs(errDetails); | ||
this._finishTransaction(status, eventId, errDetails); | ||
} | ||
} | ||
_handleReceiveError(msg) { | ||
@@ -438,9 +462,2 @@ var _a, _b, _c; | ||
// This must be a transaction error | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
this.notifyAll(); | ||
this.notifyAttrsSubs(); | ||
this.notifyMutationErrorSubs(msg); | ||
const errDetails = { | ||
@@ -450,3 +467,3 @@ message: msg.message, | ||
}; | ||
this._finishTransaction(false, "error", eventId, errDetails); | ||
this._handleMutationError("error", eventId, errDetails); | ||
return; | ||
@@ -646,14 +663,10 @@ } | ||
if (mutation.error) { | ||
this._finishTransaction(false, "error", eventId, { | ||
this._handleMutationError("error", eventId, { | ||
error: mutation.error, | ||
message: mutation.error.message, | ||
}); | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
return; | ||
} | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
this._finishTransaction(true, "enqueued", eventId); | ||
this._finishTransaction("enqueued", eventId); | ||
return; | ||
@@ -663,3 +676,3 @@ } | ||
if (!this._isOnline) { | ||
this._finishTransaction(true, "enqueued", eventId); | ||
this._finishTransaction("enqueued", eventId); | ||
} | ||
@@ -672,3 +685,3 @@ else { | ||
setTimeout(() => { | ||
this._finishTransaction(true, "pending", eventId); | ||
this._finishTransaction("pending", eventId); | ||
}, 3000); | ||
@@ -682,11 +695,5 @@ setTimeout(() => { | ||
// so we error with a timeout. | ||
const mut = this.pendingMutations.currentValue.get(eventId); | ||
if (mut && !mut["tx-id"]) { | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
this._finishTransaction(false, "timeout", eventId); | ||
console.error("mutation timed out", mut); | ||
} | ||
this._handleMutationError("timeout", eventId, { | ||
message: "transaction timed out", | ||
}); | ||
}, timeoutMs); | ||
@@ -693,0 +700,0 @@ } |
@@ -42,3 +42,12 @@ /** | ||
_initStorage(Storage: any): void; | ||
_finishTransaction(ok: any, status: any, clientId: any, errDetails: any): void; | ||
/** | ||
* @param {'enqueued' | 'pending' | 'synced' | 'timeout' | 'error' } status | ||
* @param string clientId | ||
* @param {{message?: string, hint?: string, error?: Error}} [errDetails] | ||
*/ | ||
_finishTransaction(status: "enqueued" | "pending" | "synced" | "timeout" | "error", clientId: any, errDetails?: { | ||
message?: string; | ||
hint?: string; | ||
error?: Error; | ||
}): void; | ||
_setStatus(status: any, err: any): void; | ||
@@ -64,2 +73,12 @@ /** | ||
_sessionId: any; | ||
/** | ||
* @param {'timeout' | 'error'} status | ||
* @param {string} eventId | ||
* @param {{message?: string, hint?: string, error?: Error}} errDetails | ||
*/ | ||
_handleMutationError(status: "timeout" | "error", eventId: string, errDetails: { | ||
message?: string; | ||
hint?: string; | ||
error?: Error; | ||
}): void; | ||
_handleReceiveError(msg: any): void; | ||
@@ -66,0 +85,0 @@ _setAttrs(attrs: any): void; |
@@ -312,5 +312,11 @@ "use strict"; | ||
} | ||
_finishTransaction(ok, status, clientId, errDetails) { | ||
/** | ||
* @param {'enqueued' | 'pending' | 'synced' | 'timeout' | 'error' } status | ||
* @param string clientId | ||
* @param {{message?: string, hint?: string, error?: Error}} [errDetails] | ||
*/ | ||
_finishTransaction(status, clientId, errDetails) { | ||
const dfd = this.mutationDeferredStore.get(clientId); | ||
this.mutationDeferredStore.delete(clientId); | ||
const ok = status !== "error" && status !== "timeout"; | ||
if (!dfd && !ok) { | ||
@@ -418,3 +424,3 @@ // console.erroring here, as there are no listeners to let know | ||
}); | ||
this._finishTransaction(true, "synced", eventId); | ||
this._finishTransaction("synced", eventId); | ||
const newAttrs = prevMutation["tx-steps"] | ||
@@ -459,2 +465,20 @@ .filter(([action, ..._args]) => action === "add-attr") | ||
} | ||
/** | ||
* @param {'timeout' | 'error'} status | ||
* @param {string} eventId | ||
* @param {{message?: string, hint?: string, error?: Error}} errDetails | ||
*/ | ||
_handleMutationError(status, eventId, errDetails) { | ||
const mut = this.pendingMutations.currentValue.get(eventId); | ||
if (mut && (status !== "timeout" || !mut["tx-id"])) { | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
this.notifyAll(); | ||
this.notifyAttrsSubs(); | ||
this.notifyMutationErrorSubs(errDetails); | ||
this._finishTransaction(status, eventId, errDetails); | ||
} | ||
} | ||
_handleReceiveError(msg) { | ||
@@ -466,9 +490,2 @@ var _a, _b, _c; | ||
// This must be a transaction error | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
this.notifyAll(); | ||
this.notifyAttrsSubs(); | ||
this.notifyMutationErrorSubs(msg); | ||
const errDetails = { | ||
@@ -478,3 +495,3 @@ message: msg.message, | ||
}; | ||
this._finishTransaction(false, "error", eventId, errDetails); | ||
this._handleMutationError("error", eventId, errDetails); | ||
return; | ||
@@ -674,14 +691,10 @@ } | ||
if (mutation.error) { | ||
this._finishTransaction(false, "error", eventId, { | ||
this._handleMutationError("error", eventId, { | ||
error: mutation.error, | ||
message: mutation.error.message, | ||
}); | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
return; | ||
} | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
this._finishTransaction(true, "enqueued", eventId); | ||
this._finishTransaction("enqueued", eventId); | ||
return; | ||
@@ -691,3 +704,3 @@ } | ||
if (!this._isOnline) { | ||
this._finishTransaction(true, "enqueued", eventId); | ||
this._finishTransaction("enqueued", eventId); | ||
} | ||
@@ -700,3 +713,3 @@ else { | ||
setTimeout(() => { | ||
this._finishTransaction(true, "pending", eventId); | ||
this._finishTransaction("pending", eventId); | ||
}, 3000); | ||
@@ -710,11 +723,5 @@ setTimeout(() => { | ||
// so we error with a timeout. | ||
const mut = this.pendingMutations.currentValue.get(eventId); | ||
if (mut && !mut["tx-id"]) { | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
this._finishTransaction(false, "timeout", eventId); | ||
console.error("mutation timed out", mut); | ||
} | ||
this._handleMutationError("timeout", eventId, { | ||
message: "transaction timed out", | ||
}); | ||
}, timeoutMs); | ||
@@ -721,0 +728,0 @@ } |
{ | ||
"name": "@instantdb/core", | ||
"version": "v0.12.30", | ||
"version": "v0.12.31", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -159,5 +159,12 @@ // @ts-check | ||
_finishTransaction(ok, status, clientId, errDetails) { | ||
/** | ||
* @param {'enqueued' | 'pending' | 'synced' | 'timeout' | 'error' } status | ||
* @param string clientId | ||
* @param {{message?: string, hint?: string, error?: Error}} [errDetails] | ||
*/ | ||
_finishTransaction(status, clientId, errDetails) { | ||
const dfd = this.mutationDeferredStore.get(clientId); | ||
this.mutationDeferredStore.delete(clientId); | ||
const ok = status !== "error" && status !== "timeout"; | ||
if (!dfd && !ok) { | ||
@@ -344,3 +351,3 @@ // console.erroring here, as there are no listeners to let know | ||
this._finishTransaction(true, "synced", eventId); | ||
this._finishTransaction("synced", eventId); | ||
@@ -387,7 +394,11 @@ const newAttrs = prevMutation["tx-steps"] | ||
_handleReceiveError(msg) { | ||
const eventId = msg["client-event-id"]; | ||
const prevMutation = this.pendingMutations.currentValue.get(eventId); | ||
if (prevMutation) { | ||
// This must be a transaction error | ||
/** | ||
* @param {'timeout' | 'error'} status | ||
* @param {string} eventId | ||
* @param {{message?: string, hint?: string, error?: Error}} errDetails | ||
*/ | ||
_handleMutationError(status, eventId, errDetails) { | ||
const mut = this.pendingMutations.currentValue.get(eventId); | ||
if (mut && (status !== "timeout" || !mut["tx-id"])) { | ||
this.pendingMutations.set((prev) => { | ||
@@ -399,3 +410,12 @@ prev.delete(eventId); | ||
this.notifyAttrsSubs(); | ||
this.notifyMutationErrorSubs(msg); | ||
this.notifyMutationErrorSubs(errDetails); | ||
this._finishTransaction(status, eventId, errDetails); | ||
} | ||
} | ||
_handleReceiveError(msg) { | ||
const eventId = msg["client-event-id"]; | ||
const prevMutation = this.pendingMutations.currentValue.get(eventId); | ||
if (prevMutation) { | ||
// This must be a transaction error | ||
const errDetails = { | ||
@@ -405,3 +425,3 @@ message: msg.message, | ||
}; | ||
this._finishTransaction(false, "error", eventId, errDetails); | ||
this._handleMutationError("error", eventId, errDetails); | ||
return; | ||
@@ -712,14 +732,10 @@ } | ||
if (mutation.error) { | ||
this._finishTransaction(false, "error", eventId, { | ||
this._handleMutationError("error", eventId, { | ||
error: mutation.error, | ||
message: mutation.error.message, | ||
}); | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
return; | ||
} | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
this._finishTransaction(true, "enqueued", eventId); | ||
this._finishTransaction("enqueued", eventId); | ||
return; | ||
@@ -733,3 +749,3 @@ } | ||
if (!this._isOnline) { | ||
this._finishTransaction(true, "enqueued", eventId); | ||
this._finishTransaction("enqueued", eventId); | ||
} else { | ||
@@ -742,3 +758,3 @@ this._trySend(eventId, mutation); | ||
setTimeout(() => { | ||
this._finishTransaction(true, "pending", eventId); | ||
this._finishTransaction("pending", eventId); | ||
}, 3_000); | ||
@@ -750,17 +766,8 @@ | ||
} | ||
// If we are here, this means that we have sent this mutation, we are online | ||
// but we have not received a response. If it's this long, something must be wrong, | ||
// so we error with a timeout. | ||
const mut = this.pendingMutations.currentValue.get(eventId); | ||
if (mut && !mut["tx-id"]) { | ||
this.pendingMutations.set((prev) => { | ||
prev.delete(eventId); | ||
return prev; | ||
}); | ||
this._finishTransaction(false, "timeout", eventId); | ||
console.error("mutation timed out", mut); | ||
} | ||
this._handleMutationError("timeout", eventId, { | ||
message: "transaction timed out", | ||
}); | ||
}, timeoutMs); | ||
@@ -767,0 +774,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
1981673
319
40296