@bounded-sh/core 0.0.12 → 0.0.14
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/index.js +6 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4771,39 +4771,8 @@ async function get(path, opts = {}) {
|
|
|
4771
4771
|
}
|
|
4772
4772
|
// Create a new request promise and store it
|
|
4773
4773
|
const requestPromise = (async () => {
|
|
4774
|
-
var _a;
|
|
4775
4774
|
try {
|
|
4776
|
-
// For realtime chains, prefer WebSocket reads (lower latency, already connected)
|
|
4777
|
-
const config = await getConfig();
|
|
4778
4775
|
const pathIsDocument = normalizedPath.split("/").length % 2 === 0;
|
|
4779
|
-
if (((_a = config.chain) === null || _a === void 0 ? void 0 : _a.startsWith('realtime_')) && !config.isServer && !opts.prompt && !opts.shape && !opts.cursor && !opts.includeSubPaths && !opts.filter && !opts.sort) {
|
|
4780
|
-
try {
|
|
4781
|
-
const { wsGet, wsQuery, hasActiveConnection } = await Promise.resolve().then(function () { return subscriptionV2; });
|
|
4782
|
-
if (hasActiveConnection()) {
|
|
4783
|
-
if (pathIsDocument) {
|
|
4784
|
-
const wsResult = await wsGet(normalizedPath);
|
|
4785
|
-
const responseData = normalizeReadResult(wsResult, true);
|
|
4786
|
-
if (!opts.bypassCache) {
|
|
4787
|
-
getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
|
|
4788
|
-
}
|
|
4789
|
-
return responseData;
|
|
4790
|
-
}
|
|
4791
|
-
else if (!opts.limit) {
|
|
4792
|
-
const wsResult = await wsQuery(normalizedPath, {
|
|
4793
|
-
filter: undefined,
|
|
4794
|
-
sort: undefined,
|
|
4795
|
-
includeSubPaths: opts.includeSubPaths,
|
|
4796
|
-
});
|
|
4797
|
-
const responseData = normalizeReadResult(wsResult, false);
|
|
4798
|
-
if (!opts.bypassCache) {
|
|
4799
|
-
getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
|
|
4800
|
-
}
|
|
4801
|
-
return responseData;
|
|
4802
|
-
}
|
|
4803
|
-
}
|
|
4804
|
-
}
|
|
4805
|
-
catch ( /* fall through to HTTP */_b) { /* fall through to HTTP */ }
|
|
4806
|
-
}
|
|
4807
4776
|
// Cache miss or bypass - proceed with HTTP API request
|
|
4808
4777
|
let response;
|
|
4809
4778
|
// Build common query params
|
|
@@ -5056,7 +5025,7 @@ async function set(path, document, options) {
|
|
|
5056
5025
|
return result;
|
|
5057
5026
|
}
|
|
5058
5027
|
async function setMany(many, options) {
|
|
5059
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
5028
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
5060
5029
|
// Returns the data that was set, or undefined if the document was already set.
|
|
5061
5030
|
try {
|
|
5062
5031
|
const config = await getConfig();
|
|
@@ -5093,40 +5062,13 @@ async function setMany(many, options) {
|
|
|
5093
5062
|
}
|
|
5094
5063
|
let setResponse;
|
|
5095
5064
|
try {
|
|
5096
|
-
|
|
5097
|
-
const useWs = ((_c = config.chain) === null || _c === void 0 ? void 0 : _c.startsWith('realtime_')) && !config.isServer;
|
|
5098
|
-
if (useWs) {
|
|
5099
|
-
try {
|
|
5100
|
-
const { wsSet, hasActiveConnection } = await Promise.resolve().then(function () { return subscriptionV2; });
|
|
5101
|
-
if (hasActiveConnection()) {
|
|
5102
|
-
// Connection is active — send via WS. If this throws, the write
|
|
5103
|
-
// may have been applied server-side (ack lost). Do NOT fall through
|
|
5104
|
-
// to HTTP, as that would double-apply non-idempotent ops (Increment).
|
|
5105
|
-
const wsResult = await wsSet(documents);
|
|
5106
|
-
setResponse = { data: wsResult, status: 200 };
|
|
5107
|
-
}
|
|
5108
|
-
}
|
|
5109
|
-
catch (wsError) {
|
|
5110
|
-
// Only fall through to HTTP if the request was never sent (connection not available).
|
|
5111
|
-
// If the request was sent and ack was lost (timeout), the server may have
|
|
5112
|
-
// applied it — re-sending via HTTP risks double-write for non-idempotent ops.
|
|
5113
|
-
const msg = (_d = wsError === null || wsError === void 0 ? void 0 : wsError.message) !== null && _d !== void 0 ? _d : '';
|
|
5114
|
-
const neverSent = msg.includes('not available') || msg.includes('connection timeout');
|
|
5115
|
-
if (!neverSent) {
|
|
5116
|
-
throw wsError;
|
|
5117
|
-
}
|
|
5118
|
-
// Safe to retry via HTTP — request was never sent
|
|
5119
|
-
}
|
|
5120
|
-
}
|
|
5121
|
-
if (!setResponse) {
|
|
5122
|
-
setResponse = await makeApiRequest('PUT', `items`, { documents }, options === null || options === void 0 ? void 0 : options._overrides);
|
|
5123
|
-
}
|
|
5065
|
+
setResponse = await makeApiRequest('PUT', `items`, { documents }, options === null || options === void 0 ? void 0 : options._overrides);
|
|
5124
5066
|
}
|
|
5125
5067
|
catch (error) {
|
|
5126
5068
|
if ((error === null || error === void 0 ? void 0 : error.statusCode) === 402 && (error === null || error === void 0 ? void 0 : error.error) === 'INSUFFICIENT_BALANCE') {
|
|
5127
|
-
const deficitLamports = Number((
|
|
5128
|
-
const deficitSol = Number((
|
|
5129
|
-
throw new InsufficientBalanceError(String((
|
|
5069
|
+
const deficitLamports = Number((_c = error.deficitLamports) !== null && _c !== void 0 ? _c : 0);
|
|
5070
|
+
const deficitSol = Number((_d = error.deficitSol) !== null && _d !== void 0 ? _d : deficitLamports / 1000000000);
|
|
5071
|
+
throw new InsufficientBalanceError(String((_e = error.address) !== null && _e !== void 0 ? _e : ''), Number((_f = error.balanceLamports) !== null && _f !== void 0 ? _f : 0), Number((_g = error.estimatedCostLamports) !== null && _g !== void 0 ? _g : 0), deficitLamports, deficitSol);
|
|
5130
5072
|
}
|
|
5131
5073
|
throw error;
|
|
5132
5074
|
}
|
|
@@ -5173,7 +5115,7 @@ async function setMany(many, options) {
|
|
|
5173
5115
|
else if (setResponse.data &&
|
|
5174
5116
|
typeof setResponse.data === 'object' &&
|
|
5175
5117
|
setResponse.data.success === true) {
|
|
5176
|
-
const
|
|
5118
|
+
const _h = setResponse.data, { success: _success } = _h, rest = __rest$1(_h, ["success"]);
|
|
5177
5119
|
return Object.assign(Object.assign(Object.assign({}, documents.map(d => d.document)), rest), { transactionId: null });
|
|
5178
5120
|
}
|
|
5179
5121
|
else {
|
|
@@ -6701,23 +6643,6 @@ async function wsGetMany(paths) {
|
|
|
6701
6643
|
}));
|
|
6702
6644
|
}
|
|
6703
6645
|
|
|
6704
|
-
var subscriptionV2 = /*#__PURE__*/Object.freeze({
|
|
6705
|
-
__proto__: null,
|
|
6706
|
-
clearCacheV2: clearCacheV2,
|
|
6707
|
-
closeAllSubscriptionsV2: closeAllSubscriptionsV2,
|
|
6708
|
-
getCachedDataV2: getCachedDataV2,
|
|
6709
|
-
hasActiveConnection: hasActiveConnection,
|
|
6710
|
-
reconnectWithNewAuthV2: reconnectWithNewAuthV2,
|
|
6711
|
-
subscribeV2: subscribeV2,
|
|
6712
|
-
wsDelete: wsDelete,
|
|
6713
|
-
wsGet: wsGet,
|
|
6714
|
-
wsGetMany: wsGetMany,
|
|
6715
|
-
wsIntent: wsIntent,
|
|
6716
|
-
wsIntentReliable: wsIntentReliable,
|
|
6717
|
-
wsQuery: wsQuery,
|
|
6718
|
-
wsSet: wsSet
|
|
6719
|
-
});
|
|
6720
|
-
|
|
6721
6646
|
/**
|
|
6722
6647
|
* WebSocket Subscription Module
|
|
6723
6648
|
*
|