@discomedia/utils 1.0.40 → 1.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
@@ -1502,8 +1502,8 @@ function pLimit(concurrency) {
1502
1502
  },
1503
1503
  },
1504
1504
  map: {
1505
- async value(array, function_) {
1506
- const promises = array.map((value, index) => this(function_, value, index));
1505
+ async value(iterable, function_) {
1506
+ const promises = Array.from(iterable, (value, index) => this(function_, value, index));
1507
1507
  return Promise.all(promises);
1508
1508
  },
1509
1509
  },
@@ -2449,7 +2449,7 @@ const safeJSON = (text) => {
2449
2449
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2450
2450
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2451
2451
 
2452
- const VERSION = '6.2.0'; // x-release-please-version
2452
+ const VERSION = '6.5.0'; // x-release-please-version
2453
2453
 
2454
2454
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2455
2455
  const isRunningInBrowser = () => {
@@ -6004,19 +6004,6 @@ class ChatKit extends APIResource {
6004
6004
  this.sessions = new Sessions(this._client);
6005
6005
  this.threads = new Threads$1(this._client);
6006
6006
  }
6007
- /**
6008
- * Upload a ChatKit file
6009
- *
6010
- * @example
6011
- * ```ts
6012
- * const response = await client.beta.chatkit.uploadFile({
6013
- * file: fs.createReadStream('path/to/file'),
6014
- * });
6015
- * ```
6016
- */
6017
- uploadFile(body, options) {
6018
- return this._client.post('/chatkit/files', maybeMultipartFormRequestOptions({ body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) }, this._client));
6019
- }
6020
6007
  }
6021
6008
  ChatKit.Sessions = Sessions;
6022
6009
  ChatKit.Threads = Threads$1;
@@ -7338,7 +7325,7 @@ let Files$1 = class Files extends APIResource {
7338
7325
  return this._client.getAPIList('/files', (CursorPage), { query, ...options });
7339
7326
  }
7340
7327
  /**
7341
- * Delete a file.
7328
+ * Delete a file and remove it from all vector stores.
7342
7329
  */
7343
7330
  delete(fileID, options) {
7344
7331
  return this._client.delete(path `/files/${fileID}`, options);
@@ -16708,7 +16695,11 @@ function requireConfig () {
16708
16695
 
16709
16696
  requireConfig();
16710
16697
 
16698
+ const DEBUG_LOGGING = process.env['DEBUG'] === 'true' || false;
16711
16699
  const log = (message, options = { type: 'info' }) => {
16700
+ if (!DEBUG_LOGGING && options.type === 'debug') {
16701
+ return;
16702
+ }
16712
16703
  log$1(message, { ...options, source: 'AlpacaMarketDataAPI' });
16713
16704
  };
16714
16705
  // Default settings for market data API
@@ -16798,7 +16789,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
16798
16789
  this.optionWs = ws;
16799
16790
  }
16800
16791
  ws.on('open', () => {
16801
- log(`${streamType} stream connected`, { type: 'info' });
16792
+ log(`${streamType} stream connected`);
16802
16793
  const authMessage = {
16803
16794
  action: 'auth',
16804
16795
  key: process.env.ALPACA_API_KEY,
@@ -16811,7 +16802,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
16811
16802
  const messages = JSON.parse(data.toString());
16812
16803
  for (const message of messages) {
16813
16804
  if (message.T === 'success' && message.msg === 'authenticated') {
16814
- log(`${streamType} stream authenticated`, { type: 'info' });
16805
+ log(`${streamType} stream authenticated`);
16815
16806
  this.sendSubscription(streamType);
16816
16807
  }
16817
16808
  else if (message.T === 'error') {
@@ -16961,9 +16952,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
16961
16952
  symbols.forEach((symbol) => {
16962
16953
  allBars[symbol] = [];
16963
16954
  });
16964
- log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
16965
- type: 'info',
16966
- });
16955
+ log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
16967
16956
  while (hasMorePages) {
16968
16957
  pageCount++;
16969
16958
  const requestParams = {
@@ -17008,7 +16997,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17008
16997
  const dateRangeStr = earliestTimestamp && latestTimestamp
17009
16998
  ? `${new Date(earliestTimestamp).toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${new Date(latestTimestamp).toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17010
16999
  : 'unknown range';
17011
- log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`);
17000
+ log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17012
17001
  // Prevent infinite loops
17013
17002
  if (pageCount > 1000) {
17014
17003
  log(`Stopping pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
@@ -17019,7 +17008,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17019
17008
  const symbolsJoined = Object.entries(allBars)
17020
17009
  .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
17021
17010
  .join(', ');
17022
- log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
17011
+ log(`Bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
17023
17012
  return {
17024
17013
  bars: allBars,
17025
17014
  next_page_token: null, // Always null since we fetch all pages
@@ -17214,14 +17203,25 @@ class AlpacaMarketDataAPI extends EventEmitter {
17214
17203
  `Avg Volume: ${avgVolume.toLocaleString()}`);
17215
17204
  }
17216
17205
  /**
17217
- * Get all assets available for trade and data consumption from Alpaca
17218
- * @param params Optional query params: status (e.g. 'active'), asset_class (e.g. 'us_equity', 'crypto')
17206
+ * Get assets available for trade and data consumption from Alpaca
17207
+ * @param params Optional query params
17208
+ * - status: 'active' | 'inactive' (default 'active')
17209
+ * - asset_class: 'us_equity' | 'us_option' | 'crypto' (default 'us_equity')
17210
+ * - shortable: if true (default), filters to assets with shortable=true and easy_to_borrow=true
17219
17211
  * @returns Array of AlpacaAsset objects
17220
17212
  * @see https://docs.alpaca.markets/reference/get-v2-assets-1
17221
17213
  */
17222
17214
  async getAssets(params) {
17223
17215
  // Endpoint: GET /v2/assets
17224
- return this.makeRequest('/assets', 'GET', params, 'api'); // use apiURL
17216
+ const { status = 'active', asset_class = 'us_equity', shortable = true, } = {
17217
+ status: params?.status ?? 'active',
17218
+ asset_class: params?.asset_class ?? 'us_equity',
17219
+ shortable: params?.shortable ?? true,
17220
+ };
17221
+ const assets = await this.makeRequest('/assets', 'GET', { status, asset_class }, 'api');
17222
+ if (!shortable)
17223
+ return assets;
17224
+ return assets.filter((a) => a.shortable === true && a.easy_to_borrow === true);
17225
17225
  }
17226
17226
  /**
17227
17227
  * Get a single asset by symbol or asset_id
@@ -17289,9 +17289,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17289
17289
  symbols.forEach((symbol) => {
17290
17290
  allBars[symbol] = [];
17291
17291
  });
17292
- log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
17293
- type: 'info',
17294
- });
17292
+ log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
17295
17293
  while (hasMorePages) {
17296
17294
  pageCount++;
17297
17295
  const requestParams = {
@@ -17331,7 +17329,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17331
17329
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17332
17330
  : 'unknown range';
17333
17331
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
17334
- type: 'info',
17332
+ type: 'debug',
17335
17333
  });
17336
17334
  // Prevent infinite loops
17337
17335
  if (pageCount > 1000) {
@@ -17343,9 +17341,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17343
17341
  const symbolCounts = Object.entries(allBars)
17344
17342
  .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
17345
17343
  .join(', ');
17346
- log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
17347
- type: 'info',
17348
- });
17344
+ log(`Options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`);
17349
17345
  return {
17350
17346
  bars: allBars,
17351
17347
  next_page_token: undefined, // Always undefined since we fetch all pages
@@ -17371,9 +17367,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17371
17367
  symbols.forEach((symbol) => {
17372
17368
  allTrades[symbol] = [];
17373
17369
  });
17374
- log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
17375
- type: 'info',
17376
- });
17370
+ log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17377
17371
  while (hasMorePages) {
17378
17372
  pageCount++;
17379
17373
  const requestParams = {
@@ -17413,7 +17407,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17413
17407
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17414
17408
  : 'unknown range';
17415
17409
  log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
17416
- type: 'info',
17410
+ type: 'debug',
17417
17411
  });
17418
17412
  // Prevent infinite loops
17419
17413
  if (pageCount > 1000) {
@@ -17425,9 +17419,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17425
17419
  const symbolCounts = Object.entries(allTrades)
17426
17420
  .map(([symbol, trades]) => `${symbol}: ${trades.length}`)
17427
17421
  .join(', ');
17428
- log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
17429
- type: 'info',
17430
- });
17422
+ log(`Options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`);
17431
17423
  return {
17432
17424
  trades: allTrades,
17433
17425
  next_page_token: undefined, // Always undefined since we fetch all pages
@@ -17635,7 +17627,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17635
17627
  symbols.forEach((symbol) => {
17636
17628
  allBars[symbol] = [];
17637
17629
  });
17638
- log(`Starting crypto historical bars fetch for ${symbols.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17630
+ log(`Starting crypto historical bars fetch for ${symbols.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
17639
17631
  while (hasMorePages) {
17640
17632
  pageCount++;
17641
17633
  const requestParams = {
@@ -17659,14 +17651,14 @@ class AlpacaMarketDataAPI extends EventEmitter {
17659
17651
  totalBarsCount += pageBarsCount;
17660
17652
  pageToken = response.next_page_token || null;
17661
17653
  hasMorePages = !!pageToken;
17662
- log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} crypto bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17654
+ log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} crypto bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17663
17655
  // Prevent infinite loops
17664
17656
  if (pageCount > 1000) {
17665
17657
  log(`Stopping crypto bars pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17666
17658
  break;
17667
17659
  }
17668
17660
  }
17669
- log(`Crypto historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages`, { type: 'info' });
17661
+ log(`Crypto historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages`);
17670
17662
  return {
17671
17663
  bars: allBars,
17672
17664
  next_page_token: null, // Always null since we fetch all pages
@@ -17698,7 +17690,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17698
17690
  symbols.forEach((symbol) => {
17699
17691
  allQuotes[symbol] = [];
17700
17692
  });
17701
- log(`Starting crypto historical quotes fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17693
+ log(`Starting crypto historical quotes fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17702
17694
  while (hasMorePages) {
17703
17695
  pageCount++;
17704
17696
  const requestParams = {
@@ -17722,14 +17714,14 @@ class AlpacaMarketDataAPI extends EventEmitter {
17722
17714
  totalQuotesCount += pageQuotesCount;
17723
17715
  pageToken = response.next_page_token || null;
17724
17716
  hasMorePages = !!pageToken;
17725
- log(`Page ${pageCount}: Fetched ${pageQuotesCount.toLocaleString()} crypto quotes (total: ${totalQuotesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17717
+ log(`Page ${pageCount}: Fetched ${pageQuotesCount.toLocaleString()} crypto quotes (total: ${totalQuotesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17726
17718
  // Prevent infinite loops
17727
17719
  if (pageCount > 1000) {
17728
17720
  log(`Stopping crypto quotes pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17729
17721
  break;
17730
17722
  }
17731
17723
  }
17732
- log(`Crypto historical quotes fetch complete: ${totalQuotesCount.toLocaleString()} total quotes across ${pageCount} pages`, { type: 'info' });
17724
+ log(`Crypto historical quotes fetch complete: ${totalQuotesCount.toLocaleString()} total quotes across ${pageCount} pages`);
17733
17725
  return {
17734
17726
  quotes: allQuotes,
17735
17727
  next_page_token: null, // Always null since we fetch all pages
@@ -17765,7 +17757,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
17765
17757
  symbols.forEach((symbol) => {
17766
17758
  allTrades[symbol] = [];
17767
17759
  });
17768
- log(`Starting crypto historical trades fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17760
+ log(`Starting crypto historical trades fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17769
17761
  while (hasMorePages) {
17770
17762
  pageCount++;
17771
17763
  const requestParams = {
@@ -17789,14 +17781,14 @@ class AlpacaMarketDataAPI extends EventEmitter {
17789
17781
  totalTradesCount += pageTradesCount;
17790
17782
  pageToken = response.next_page_token || null;
17791
17783
  hasMorePages = !!pageToken;
17792
- log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} crypto trades (total: ${totalTradesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17784
+ log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} crypto trades (total: ${totalTradesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17793
17785
  // Prevent infinite loops
17794
17786
  if (pageCount > 1000) {
17795
17787
  log(`Stopping crypto trades pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17796
17788
  break;
17797
17789
  }
17798
17790
  }
17799
- log(`Crypto historical trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages`, { type: 'info' });
17791
+ log(`Crypto historical trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages`);
17800
17792
  return {
17801
17793
  trades: allTrades,
17802
17794
  next_page_token: null, // Always null since we fetch all pages