@pooflabs/core 0.0.41 → 0.0.42

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.mjs CHANGED
@@ -3728,6 +3728,90 @@ function cleanupExpiredCache() {
3728
3728
  });
3729
3729
  lastCacheCleanup = now;
3730
3730
  }
3731
+ async function getMany(paths, opts = {}) {
3732
+ if (paths.length === 0) {
3733
+ return [];
3734
+ }
3735
+ if (paths.length > 30) {
3736
+ throw new Error('Cannot fetch more than 30 documents at once');
3737
+ }
3738
+ const normalizedPaths = [];
3739
+ for (const path of paths) {
3740
+ let normalizedPath = path.startsWith("/") ? path.slice(1) : path;
3741
+ if (normalizedPath.endsWith("*") && normalizedPath.length > 1) {
3742
+ normalizedPath = normalizedPath.slice(0, -1);
3743
+ }
3744
+ if (!normalizedPath || normalizedPath.length === 0) {
3745
+ throw new Error(`Invalid path provided: ${path}`);
3746
+ }
3747
+ const pathIsDocument = normalizedPath.split("/").length % 2 === 0;
3748
+ if (!pathIsDocument) {
3749
+ throw new Error(`Path must point to a document (even number of segments): ${path}`);
3750
+ }
3751
+ normalizedPaths.push(normalizedPath);
3752
+ }
3753
+ const now = Date.now();
3754
+ const results = new Array(paths.length);
3755
+ const uncachedIndices = [];
3756
+ const uncachedPaths = [];
3757
+ for (let i = 0; i < normalizedPaths.length; i++) {
3758
+ const normalizedPath = normalizedPaths[i];
3759
+ const cacheKey = `${normalizedPath}:`;
3760
+ if (!opts.bypassCache && getCache[cacheKey] && now < getCache[cacheKey].expiresAt) {
3761
+ results[i] = { path: normalizedPath, data: getCache[cacheKey].data };
3762
+ }
3763
+ else {
3764
+ uncachedIndices.push(i);
3765
+ uncachedPaths.push(normalizedPath);
3766
+ }
3767
+ }
3768
+ if (uncachedPaths.length > 0) {
3769
+ try {
3770
+ const response = await makeApiRequest('POST', 'items/batch', { paths: uncachedPaths }, opts._overrides);
3771
+ const serverResults = response.data.results;
3772
+ const serverResultsMap = new Map();
3773
+ for (const result of serverResults) {
3774
+ serverResultsMap.set(result.path, result);
3775
+ }
3776
+ for (let i = 0; i < uncachedIndices.length; i++) {
3777
+ const originalIndex = uncachedIndices[i];
3778
+ const normalizedPath = uncachedPaths[i];
3779
+ const serverResult = serverResultsMap.get(normalizedPath);
3780
+ if (serverResult) {
3781
+ results[originalIndex] = serverResult;
3782
+ if (!serverResult.error && !opts.bypassCache) {
3783
+ const cacheKey = `${normalizedPath}:`;
3784
+ getCache[cacheKey] = {
3785
+ data: serverResult.data,
3786
+ expiresAt: now + GET_CACHE_TTL
3787
+ };
3788
+ }
3789
+ }
3790
+ else {
3791
+ results[originalIndex] = {
3792
+ path: normalizedPath,
3793
+ data: null,
3794
+ error: { code: 'NOT_FOUND', message: `No result returned for path ${normalizedPath}` }
3795
+ };
3796
+ }
3797
+ }
3798
+ if (now - lastCacheCleanup > 5000) {
3799
+ cleanupExpiredCache();
3800
+ lastCacheCleanup = now;
3801
+ }
3802
+ }
3803
+ catch (error) {
3804
+ for (const originalIndex of uncachedIndices) {
3805
+ results[originalIndex] = {
3806
+ path: normalizedPaths[originalIndex],
3807
+ data: null,
3808
+ error: { code: 'NOT_FOUND', message: error instanceof Error ? error.message : 'Unknown error' }
3809
+ };
3810
+ }
3811
+ }
3812
+ }
3813
+ return results;
3814
+ }
3731
3815
  async function runQuery(absolutePath, queryName, queryArgs, opts) {
3732
3816
  const result = await runQueryMany([{ absolutePath, queryName, queryArgs }], opts);
3733
3817
  return result[0];
@@ -4968,5 +5052,5 @@ class ReactNativeSessionManager {
4968
5052
  }
4969
5053
  ReactNativeSessionManager.TAROBASE_SESSION_STORAGE_KEY = "tarobase_session_storage";
4970
5054
 
4971
- export { InsufficientBalanceError, ReactNativeSessionManager, ServerSessionManager, WebSessionManager, aggregate, buildSetDocumentsTransaction, clearCache, closeAllSubscriptions, convertRemainingAccounts, count, createSessionWithPrivy, createSessionWithSignature, genAuthNonce, genSolanaMessage, get, getCachedData, getConfig, getFiles, getIdToken, init, reconnectWithNewAuth, refreshSession, runExpression, runExpressionMany, runQuery, runQueryMany, set, setFile, setMany, signAndSubmitTransaction, signMessage, signSessionCreateMessage, signTransaction, subscribe };
5055
+ export { InsufficientBalanceError, ReactNativeSessionManager, ServerSessionManager, WebSessionManager, aggregate, buildSetDocumentsTransaction, clearCache, closeAllSubscriptions, convertRemainingAccounts, count, createSessionWithPrivy, createSessionWithSignature, genAuthNonce, genSolanaMessage, get, getCachedData, getConfig, getFiles, getIdToken, getMany, init, reconnectWithNewAuth, refreshSession, runExpression, runExpressionMany, runQuery, runQueryMany, set, setFile, setMany, signAndSubmitTransaction, signMessage, signSessionCreateMessage, signTransaction, subscribe };
4972
5056
  //# sourceMappingURL=index.mjs.map