@pooflabs/core 0.0.1 → 0.0.3

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.
@@ -11,12 +11,36 @@ export declare function get(path: string, opts?: {
11
11
  headers?: Record<string, string>;
12
12
  };
13
13
  }): Promise<any>;
14
+ export type RunExpressionOptions = {
15
+ returnType?: 'Bool' | 'String' | 'Int' | 'UInt';
16
+ _overrides?: {
17
+ headers?: Record<string, string>;
18
+ };
19
+ };
20
+ export type RunExpressionResult = {
21
+ result: any;
22
+ trace?: {
23
+ variable: string;
24
+ resolvedValue: any;
25
+ operation?: string;
26
+ result?: any;
27
+ }[];
28
+ };
14
29
  export declare function runQuery(absolutePath: string, queryName: string, queryArgs: any): Promise<any>;
15
30
  export declare function runQueryMany(many: {
16
31
  absolutePath: string;
17
32
  queryName: string;
18
33
  queryArgs: any;
19
34
  }[]): Promise<any>;
35
+ export declare function runExpression(expression: string, queryArgs: any, options?: RunExpressionOptions): Promise<RunExpressionResult>;
36
+ export declare function runExpressionMany(many: {
37
+ expression: string;
38
+ queryArgs: any;
39
+ returnType?: 'Bool' | 'String' | 'Int' | 'UInt';
40
+ _overrides?: {
41
+ headers?: Record<string, string>;
42
+ };
43
+ }[]): Promise<RunExpressionResult[]>;
20
44
  export declare function set(path: string, document: any, options?: SetOptions): Promise<any>;
21
45
  export declare function setMany(many: {
22
46
  path: string;
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, SetOptions } from './client/operations';
3
+ export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany, runExpression, runExpressionMany, SetOptions, RunExpressionOptions, RunExpressionResult } from './client/operations';
4
4
  export { subscribe } from './client/subscription';
5
5
  export * from './types';
6
6
  export { getIdToken } from './utils/utils';
package/dist/index.js CHANGED
@@ -108,7 +108,6 @@ class WebSessionManager {
108
108
  /* ---------- validate app-id ---------- */
109
109
  const config = await getConfig();
110
110
  if (sessionObj.appId && sessionObj.appId !== config.appId) {
111
- console.warn("Session appId mismatch. Stored session belongs to a different app. Logging out.");
112
111
  this.clearSession();
113
112
  return null;
114
113
  }
@@ -133,7 +132,6 @@ class WebSessionManager {
133
132
  }
134
133
  }
135
134
  catch (err) {
136
- console.error("Error decoding access token:", err);
137
135
  return null;
138
136
  }
139
137
  return { address: sessionObj.address, session: sessionObj };
@@ -184,7 +182,6 @@ class WebSessionManager {
184
182
  /* ---------- app-id guard ---------- */
185
183
  const config = await getConfig();
186
184
  if (sessionObj.appId && sessionObj.appId !== config.appId) {
187
- console.warn("Session appId mismatch during token refresh. Logging out.");
188
185
  this.clearSession();
189
186
  return;
190
187
  }
@@ -6277,7 +6274,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
6277
6274
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
6278
6275
  tx.recentBlockhash = blockhash;
6279
6276
  if (lutKey == null) {
6280
- const computeUnits = await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
6277
+ const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
6278
+ const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
6281
6279
  const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
6282
6280
  units: computeUnits ? computeUnits * 1.2 : 1400000,
6283
6281
  }); // 20% buffer
@@ -6287,7 +6285,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
6287
6285
  const { value: table } = await connection.getAddressLookupTable(new web3_js.PublicKey(lutKey));
6288
6286
  if (!table)
6289
6287
  throw new Error('LUT not found after creation/extend');
6290
- const computeUnits = await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
6288
+ const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
6289
+ const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
6291
6290
  const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
6292
6291
  units: computeUnits ? computeUnits * 1.2 : 1400000,
6293
6292
  }); // 20% buffer
@@ -6424,7 +6423,7 @@ function updateIdTokenAndAccessToken(idToken, accessToken) {
6424
6423
  }
6425
6424
 
6426
6425
  async function makeApiRequest(method, urlPath, data, _overrides) {
6427
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
6426
+ var _a, _b, _c, _d, _e, _f;
6428
6427
  const config = await getConfig();
6429
6428
  async function executeRequest() {
6430
6429
  const authHeader = await createAuthHeader(config.isServer);
@@ -6474,8 +6473,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
6474
6473
  return { data: null, status: 404 };
6475
6474
  }
6476
6475
  if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) {
6477
- console.error(`Error in set call with code ${(_e = error.response) === null || _e === void 0 ? void 0 : _e.status} and message ${(_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.message}`);
6478
- throw new Error((_j = (_h = error.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.message);
6476
+ throw new Error((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message);
6479
6477
  }
6480
6478
  throw error;
6481
6479
  }
@@ -6516,8 +6514,6 @@ function init(newConfig) {
6516
6514
  isInitialized = true;
6517
6515
  resolve();
6518
6516
  }).catch((error) => {
6519
- console.error('Failed to authenticate with API key or fetch config for this app:', error);
6520
- console.error('Please check your API key and try again.');
6521
6517
  reject(new Error("Failed to initialize Tarobase app."));
6522
6518
  });
6523
6519
  });
@@ -6621,16 +6617,11 @@ async function get(path, opts = {}) {
6621
6617
  // Helper to clean up expired cache entries
6622
6618
  function cleanupExpiredCache() {
6623
6619
  const now = Date.now();
6624
- let removedCount = 0;
6625
6620
  Object.keys(getCache).forEach(key => {
6626
6621
  if (getCache[key] && getCache[key].expiresAt < now) {
6627
6622
  delete getCache[key];
6628
- removedCount++;
6629
6623
  }
6630
6624
  });
6631
- if (removedCount > 0) {
6632
- console.debug(`Cleaned up ${removedCount} expired cache entries`);
6633
- }
6634
6625
  lastCacheCleanup = now;
6635
6626
  }
6636
6627
  async function runQuery(absolutePath, queryName, queryArgs) {
@@ -6655,6 +6646,37 @@ async function runQueryMany(many) {
6655
6646
  throw error;
6656
6647
  }
6657
6648
  }
6649
+ // NEW: Ad-hoc expression execution - first-class feature
6650
+ async function runExpression(expression, queryArgs, options) {
6651
+ const results = await runExpressionMany([Object.assign({ expression, queryArgs }, options)]);
6652
+ return results[0];
6653
+ }
6654
+ async function runExpressionMany(many) {
6655
+ try {
6656
+ let queries = [];
6657
+ let overrides = undefined;
6658
+ for (const { expression, queryArgs, returnType, _overrides } of many) {
6659
+ // Collect overrides from first query that has them (all queries share same request)
6660
+ if (_overrides && !overrides) {
6661
+ overrides = _overrides;
6662
+ }
6663
+ queries.push({ queryArgs, expression, returnType });
6664
+ }
6665
+ const response = await makeApiRequest('POST', 'queries', { queries }, overrides);
6666
+ // Map results - trace is automatically included by server for non-mainnet networks
6667
+ return response.data.queries.map((queryResult) => {
6668
+ const result = { result: queryResult.result };
6669
+ // Include trace if present (server includes it for non-mainnet networks)
6670
+ if (queryResult.trace) {
6671
+ result.trace = queryResult.trace;
6672
+ }
6673
+ return result;
6674
+ });
6675
+ }
6676
+ catch (error) {
6677
+ throw error;
6678
+ }
6679
+ }
6658
6680
  async function set(path, document, options) {
6659
6681
  const result = await setMany([{ path, document }], options);
6660
6682
  // Clear cache entries that might be affected by this update
@@ -6733,7 +6755,6 @@ async function setMany(many, options) {
6733
6755
  }
6734
6756
  }
6735
6757
  catch (error) {
6736
- console.error("Error setting data", error);
6737
6758
  throw error;
6738
6759
  }
6739
6760
  async function handleSolanaTransaction(tx, authProvider, options) {
@@ -6850,9 +6871,7 @@ async function setFile(path, file) {
6850
6871
  });
6851
6872
  // 3) Check if the upload was successful
6852
6873
  if (!uploadResponse.ok) {
6853
- console.error(uploadResponse);
6854
- const errorText = await uploadResponse.text();
6855
- console.error('S3 Error Body:', errorText);
6874
+ await uploadResponse.text();
6856
6875
  throw new Error(`Upload failed with status: ${uploadResponse.status}`);
6857
6876
  }
6858
6877
  // Optionally return the file's public URL or some confirmation
@@ -7540,10 +7559,9 @@ async function subscribe(path, subscriptionOptions) {
7540
7559
  }
7541
7560
  });
7542
7561
  ws.addEventListener('error', (event) => {
7543
- console.error(`WebSocket error for path: ${connectionKey}`, event);
7544
7562
  notifyError(connectionKey, event);
7545
7563
  });
7546
- ws.addEventListener('close', (event) => {
7564
+ ws.addEventListener('close', () => {
7547
7565
  // Connection will be recreated on next subscription if needed
7548
7566
  });
7549
7567
  return async () => await removeSubscription(connectionKey, subscriptionOptions);
@@ -7584,8 +7602,7 @@ async function removeSubscription(connectionKey, subscription) {
7584
7602
  ws.addEventListener('close', () => {
7585
7603
  resolve();
7586
7604
  });
7587
- ws.addEventListener('error', (err) => {
7588
- console.error(`WebSocket closure error for connection: ${connectionKey}`, err);
7605
+ ws.addEventListener('error', () => {
7589
7606
  resolve(); // Resolve even on error to avoid hanging
7590
7607
  });
7591
7608
  ws.close();
@@ -7607,6 +7624,8 @@ exports.getFiles = getFiles;
7607
7624
  exports.getIdToken = getIdToken;
7608
7625
  exports.init = init;
7609
7626
  exports.refreshSession = refreshSession;
7627
+ exports.runExpression = runExpression;
7628
+ exports.runExpressionMany = runExpressionMany;
7610
7629
  exports.runQuery = runQuery;
7611
7630
  exports.runQueryMany = runQueryMany;
7612
7631
  exports.set = set;