@pooflabs/core 0.0.40 → 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/README.md CHANGED
@@ -39,6 +39,15 @@ export interface User {
39
39
  address: string;
40
40
  provider: AuthProvider;
41
41
  }
42
+
43
+ export interface GetManyResult {
44
+ path: string;
45
+ data: any | null;
46
+ error?: {
47
+ code: 'NOT_FOUND' | 'UNAUTHORIZED' | 'INVALID_PATH';
48
+ message: string;
49
+ };
50
+ }
42
51
  ```
43
52
 
44
53
  ### Core Operations
@@ -52,6 +61,7 @@ function getConfig(): Promise<ClientConfig>;
52
61
 
53
62
  // Data operations
54
63
  function get(path: string): Promise<any>;
64
+ function getMany(paths: string[], options?: { bypassCache?: boolean }): Promise<GetManyResult[]>;
55
65
  function set(path: string, data: any, options?: SetOptions): Promise<any>;
56
66
  function setMany(paths: { [key: string]: any }, options?: SetOptions): Promise<any>;
57
67
  function setFile(path: string, file: File, metadata?: any): Promise<any>;
@@ -113,6 +113,20 @@ export declare function count(path: string, opts?: CountOptions): Promise<Aggreg
113
113
  */
114
114
  export declare function aggregate(path: string, operation: AggregateOperation, opts?: AggregateOptions): Promise<AggregateResult>;
115
115
  export declare function get(path: string, opts?: GetOptions): Promise<any>;
116
+ export type GetManyResult = {
117
+ path: string;
118
+ data: any | null;
119
+ error?: {
120
+ code: 'NOT_FOUND' | 'UNAUTHORIZED' | 'INVALID_PATH';
121
+ message: string;
122
+ };
123
+ };
124
+ export declare function getMany(paths: string[], opts?: {
125
+ bypassCache?: boolean;
126
+ _overrides?: {
127
+ headers?: Record<string, string>;
128
+ };
129
+ }): Promise<GetManyResult[]>;
116
130
  export type RunExpressionOptions = {
117
131
  returnType?: 'Bool' | 'String' | 'Int' | 'UInt';
118
132
  _overrides?: RequestOverrides;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { init } from './client/config';
2
2
  export { getConfig, ClientConfig } from './client/config';
3
- export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany, runExpression, runExpressionMany, signMessage, signTransaction, signAndSubmitTransaction, count, aggregate, RequestOverrides, SetOptions, GetOptions, RunQueryOptions, CountOptions, AggregateOptions, AggregateOperation, AggregateResult, RunExpressionOptions, RunExpressionResult, InsufficientBalanceError } from './client/operations';
3
+ export { get, getMany, set, setMany, setFile, getFiles, runQuery, runQueryMany, runExpression, runExpressionMany, signMessage, signTransaction, signAndSubmitTransaction, count, aggregate, RequestOverrides, SetOptions, GetOptions, RunQueryOptions, CountOptions, AggregateOptions, AggregateOperation, AggregateResult, RunExpressionOptions, RunExpressionResult, InsufficientBalanceError, GetManyResult } from './client/operations';
4
4
  export { subscribe, closeAllSubscriptions, clearCache, getCachedData, reconnectWithNewAuth } from './client/subscription';
5
5
  export * from './types';
6
6
  export { getIdToken } from './utils/utils';
package/dist/index.js CHANGED
@@ -2977,7 +2977,7 @@ function convertRemainingAccounts(remainingAccounts) {
2977
2977
  // ─────────────────────────────────────────────────────────────
2978
2978
  // Updated Transaction Builder: It now accepts a PublicKey for the payer
2979
2979
  // ─────────────────────────────────────────────────────────────
2980
- async function buildSetDocumentsTransaction(connection, idl, anchorProvider, payerPublicKey, args, remainingAccounts, lutKey, preInstructions, simulate) {
2980
+ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, payerPublicKey, args, remainingAccounts, lutKey, preInstructions, simulate, additionalLutAddresses) {
2981
2981
  const computeBudgetIx = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
2982
2982
  units: 1400000,
2983
2983
  });
@@ -3018,8 +3018,25 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
3018
3018
  tx.feePayer = payerPublicKey;
3019
3019
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
3020
3020
  tx.recentBlockhash = blockhash;
3021
- if (lutKey == null) {
3022
- const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
3021
+ // Resolve LUTs: additionalLutAddresses (when present) is the authoritative set.
3022
+ // Falls back to lutKey alone for backwards compatibility.
3023
+ const lookupTables = [];
3024
+ const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
3025
+ if (additionalLutAddresses && additionalLutAddresses.length > 0) {
3026
+ const results = await Promise.all(additionalLutAddresses.map(addr => connection.getAddressLookupTable(new web3_js.PublicKey(addr)).catch(() => null)));
3027
+ for (const result of results) {
3028
+ if (result === null || result === void 0 ? void 0 : result.value) {
3029
+ lookupTables.push(result.value);
3030
+ }
3031
+ }
3032
+ }
3033
+ else if (lutKey != null) {
3034
+ const { value: table } = await connection.getAddressLookupTable(new web3_js.PublicKey(lutKey));
3035
+ if (!table)
3036
+ throw new Error('LUT not found after creation/extend');
3037
+ lookupTables.push(table);
3038
+ }
3039
+ if (lookupTables.length === 0) {
3023
3040
  const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
3024
3041
  const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
3025
3042
  units: computeUnits ? computeUnits * 1.2 : 1400000,
@@ -3027,11 +3044,7 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
3027
3044
  tx.instructions[0] = computeBudgetIxOptimized;
3028
3045
  return { tx, blockhash, lastValidBlockHeight };
3029
3046
  }
3030
- const { value: table } = await connection.getAddressLookupTable(new web3_js.PublicKey(lutKey));
3031
- if (!table)
3032
- throw new Error('LUT not found after creation/extend');
3033
- const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
3034
- const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
3047
+ const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, lookupTables);
3035
3048
  const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
3036
3049
  units: computeUnits ? computeUnits * 1.2 : 1400000,
3037
3050
  }); // 20% buffer
@@ -3040,7 +3053,7 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
3040
3053
  payerKey: payerPublicKey,
3041
3054
  recentBlockhash: blockhash,
3042
3055
  instructions: tx.instructions,
3043
- }).compileToV0Message([table]);
3056
+ }).compileToV0Message(lookupTables);
3044
3057
  const vTx = new anchor__namespace.web3.VersionedTransaction(msgV0);
3045
3058
  return { tx: vTx, blockhash, lastValidBlockHeight };
3046
3059
  }
@@ -3735,6 +3748,90 @@ function cleanupExpiredCache() {
3735
3748
  });
3736
3749
  lastCacheCleanup = now;
3737
3750
  }
3751
+ async function getMany(paths, opts = {}) {
3752
+ if (paths.length === 0) {
3753
+ return [];
3754
+ }
3755
+ if (paths.length > 30) {
3756
+ throw new Error('Cannot fetch more than 30 documents at once');
3757
+ }
3758
+ const normalizedPaths = [];
3759
+ for (const path of paths) {
3760
+ let normalizedPath = path.startsWith("/") ? path.slice(1) : path;
3761
+ if (normalizedPath.endsWith("*") && normalizedPath.length > 1) {
3762
+ normalizedPath = normalizedPath.slice(0, -1);
3763
+ }
3764
+ if (!normalizedPath || normalizedPath.length === 0) {
3765
+ throw new Error(`Invalid path provided: ${path}`);
3766
+ }
3767
+ const pathIsDocument = normalizedPath.split("/").length % 2 === 0;
3768
+ if (!pathIsDocument) {
3769
+ throw new Error(`Path must point to a document (even number of segments): ${path}`);
3770
+ }
3771
+ normalizedPaths.push(normalizedPath);
3772
+ }
3773
+ const now = Date.now();
3774
+ const results = new Array(paths.length);
3775
+ const uncachedIndices = [];
3776
+ const uncachedPaths = [];
3777
+ for (let i = 0; i < normalizedPaths.length; i++) {
3778
+ const normalizedPath = normalizedPaths[i];
3779
+ const cacheKey = `${normalizedPath}:`;
3780
+ if (!opts.bypassCache && getCache[cacheKey] && now < getCache[cacheKey].expiresAt) {
3781
+ results[i] = { path: normalizedPath, data: getCache[cacheKey].data };
3782
+ }
3783
+ else {
3784
+ uncachedIndices.push(i);
3785
+ uncachedPaths.push(normalizedPath);
3786
+ }
3787
+ }
3788
+ if (uncachedPaths.length > 0) {
3789
+ try {
3790
+ const response = await makeApiRequest('POST', 'items/batch', { paths: uncachedPaths }, opts._overrides);
3791
+ const serverResults = response.data.results;
3792
+ const serverResultsMap = new Map();
3793
+ for (const result of serverResults) {
3794
+ serverResultsMap.set(result.path, result);
3795
+ }
3796
+ for (let i = 0; i < uncachedIndices.length; i++) {
3797
+ const originalIndex = uncachedIndices[i];
3798
+ const normalizedPath = uncachedPaths[i];
3799
+ const serverResult = serverResultsMap.get(normalizedPath);
3800
+ if (serverResult) {
3801
+ results[originalIndex] = serverResult;
3802
+ if (!serverResult.error && !opts.bypassCache) {
3803
+ const cacheKey = `${normalizedPath}:`;
3804
+ getCache[cacheKey] = {
3805
+ data: serverResult.data,
3806
+ expiresAt: now + GET_CACHE_TTL
3807
+ };
3808
+ }
3809
+ }
3810
+ else {
3811
+ results[originalIndex] = {
3812
+ path: normalizedPath,
3813
+ data: null,
3814
+ error: { code: 'NOT_FOUND', message: `No result returned for path ${normalizedPath}` }
3815
+ };
3816
+ }
3817
+ }
3818
+ if (now - lastCacheCleanup > 5000) {
3819
+ cleanupExpiredCache();
3820
+ lastCacheCleanup = now;
3821
+ }
3822
+ }
3823
+ catch (error) {
3824
+ for (const originalIndex of uncachedIndices) {
3825
+ results[originalIndex] = {
3826
+ path: normalizedPaths[originalIndex],
3827
+ data: null,
3828
+ error: { code: 'NOT_FOUND', message: error instanceof Error ? error.message : 'Unknown error' }
3829
+ };
3830
+ }
3831
+ }
3832
+ }
3833
+ return results;
3834
+ }
3738
3835
  async function runQuery(absolutePath, queryName, queryArgs, opts) {
3739
3836
  const result = await runQueryMany([{ absolutePath, queryName, queryArgs }], opts);
3740
3837
  return result[0];
@@ -3924,6 +4021,7 @@ async function setMany(many, options) {
3924
4021
  appId: config.appId,
3925
4022
  txArgs: [solTransactionData],
3926
4023
  lutKey: (_c = tx.lutAddress) !== null && _c !== void 0 ? _c : null,
4024
+ additionalLutAddresses: tx.additionalLutAddresses,
3927
4025
  network: tx.network,
3928
4026
  preInstructions: (_e = (_d = tx.preInstructions) === null || _d === void 0 ? void 0 : _d.map((ix) => {
3929
4027
  var _a;
@@ -4993,6 +5091,7 @@ exports.getCachedData = getCachedData;
4993
5091
  exports.getConfig = getConfig;
4994
5092
  exports.getFiles = getFiles;
4995
5093
  exports.getIdToken = getIdToken;
5094
+ exports.getMany = getMany;
4996
5095
  exports.init = init;
4997
5096
  exports.reconnectWithNewAuth = reconnectWithNewAuth;
4998
5097
  exports.refreshSession = refreshSession;