@discomedia/utils 1.0.55 → 1.0.56

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
@@ -1489,8 +1489,18 @@ class Queue {
1489
1489
  }
1490
1490
 
1491
1491
  function pLimit(concurrency) {
1492
+ let rejectOnClear = false;
1493
+
1494
+ if (typeof concurrency === 'object') {
1495
+ ({concurrency, rejectOnClear = false} = concurrency);
1496
+ }
1497
+
1492
1498
  validateConcurrency(concurrency);
1493
1499
 
1500
+ if (typeof rejectOnClear !== 'boolean') {
1501
+ throw new TypeError('Expected `rejectOnClear` to be a boolean');
1502
+ }
1503
+
1494
1504
  const queue = new Queue();
1495
1505
  let activeCount = 0;
1496
1506
 
@@ -1498,7 +1508,7 @@ function pLimit(concurrency) {
1498
1508
  // Process the next queued function if we're under the concurrency limit
1499
1509
  if (activeCount < concurrency && queue.size > 0) {
1500
1510
  activeCount++;
1501
- queue.dequeue()();
1511
+ queue.dequeue().run();
1502
1512
  }
1503
1513
  };
1504
1514
 
@@ -1525,11 +1535,14 @@ function pLimit(concurrency) {
1525
1535
  next();
1526
1536
  };
1527
1537
 
1528
- const enqueue = (function_, resolve, arguments_) => {
1538
+ const enqueue = (function_, resolve, reject, arguments_) => {
1539
+ const queueItem = {reject};
1540
+
1529
1541
  // Queue the internal resolve function instead of the run function
1530
1542
  // to preserve the asynchronous execution context.
1531
1543
  new Promise(internalResolve => { // eslint-disable-line promise/param-names
1532
- queue.enqueue(internalResolve);
1544
+ queueItem.run = internalResolve;
1545
+ queue.enqueue(queueItem);
1533
1546
  }).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then
1534
1547
 
1535
1548
  // Start processing immediately if we haven't reached the concurrency limit
@@ -1538,8 +1551,8 @@ function pLimit(concurrency) {
1538
1551
  }
1539
1552
  };
1540
1553
 
1541
- const generator = (function_, ...arguments_) => new Promise(resolve => {
1542
- enqueue(function_, resolve, arguments_);
1554
+ const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
1555
+ enqueue(function_, resolve, reject, arguments_);
1543
1556
  });
1544
1557
 
1545
1558
  Object.defineProperties(generator, {
@@ -1551,7 +1564,16 @@ function pLimit(concurrency) {
1551
1564
  },
1552
1565
  clearQueue: {
1553
1566
  value() {
1554
- queue.clear();
1567
+ if (!rejectOnClear) {
1568
+ queue.clear();
1569
+ return;
1570
+ }
1571
+
1572
+ const abortError = AbortSignal.abort().reason;
1573
+
1574
+ while (queue.size > 0) {
1575
+ queue.dequeue().reject(abortError);
1576
+ }
1555
1577
  },
1556
1578
  },
1557
1579
  concurrency: {
@@ -2517,7 +2539,7 @@ const safeJSON = (text) => {
2517
2539
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2518
2540
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2519
2541
 
2520
- const VERSION = '6.16.0'; // x-release-please-version
2542
+ const VERSION = '6.17.0'; // x-release-please-version
2521
2543
 
2522
2544
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2523
2545
  const isRunningInBrowser = () => {
@@ -5810,12 +5832,7 @@ class Assistants extends APIResource {
5810
5832
  /**
5811
5833
  * Create an assistant with a model and instructions.
5812
5834
  *
5813
- * @example
5814
- * ```ts
5815
- * const assistant = await client.beta.assistants.create({
5816
- * model: 'gpt-4o',
5817
- * });
5818
- * ```
5835
+ * @deprecated
5819
5836
  */
5820
5837
  create(body, options) {
5821
5838
  return this._client.post('/assistants', {
@@ -5827,12 +5844,7 @@ class Assistants extends APIResource {
5827
5844
  /**
5828
5845
  * Retrieves an assistant.
5829
5846
  *
5830
- * @example
5831
- * ```ts
5832
- * const assistant = await client.beta.assistants.retrieve(
5833
- * 'assistant_id',
5834
- * );
5835
- * ```
5847
+ * @deprecated
5836
5848
  */
5837
5849
  retrieve(assistantID, options) {
5838
5850
  return this._client.get(path `/assistants/${assistantID}`, {
@@ -5843,12 +5855,7 @@ class Assistants extends APIResource {
5843
5855
  /**
5844
5856
  * Modifies an assistant.
5845
5857
  *
5846
- * @example
5847
- * ```ts
5848
- * const assistant = await client.beta.assistants.update(
5849
- * 'assistant_id',
5850
- * );
5851
- * ```
5858
+ * @deprecated
5852
5859
  */
5853
5860
  update(assistantID, body, options) {
5854
5861
  return this._client.post(path `/assistants/${assistantID}`, {
@@ -5860,13 +5867,7 @@ class Assistants extends APIResource {
5860
5867
  /**
5861
5868
  * Returns a list of assistants.
5862
5869
  *
5863
- * @example
5864
- * ```ts
5865
- * // Automatically fetches more pages as needed.
5866
- * for await (const assistant of client.beta.assistants.list()) {
5867
- * // ...
5868
- * }
5869
- * ```
5870
+ * @deprecated
5870
5871
  */
5871
5872
  list(query = {}, options) {
5872
5873
  return this._client.getAPIList('/assistants', (CursorPage), {
@@ -5878,11 +5879,7 @@ class Assistants extends APIResource {
5878
5879
  /**
5879
5880
  * Delete an assistant.
5880
5881
  *
5881
- * @example
5882
- * ```ts
5883
- * const assistantDeleted =
5884
- * await client.beta.assistants.delete('assistant_id');
5885
- * ```
5882
+ * @deprecated
5886
5883
  */
5887
5884
  delete(assistantID, options) {
5888
5885
  return this._client.delete(path `/assistants/${assistantID}`, {
@@ -7356,8 +7353,8 @@ Evals.Runs = Runs;
7356
7353
  let Files$1 = class Files extends APIResource {
7357
7354
  /**
7358
7355
  * Upload a file that can be used across various endpoints. Individual files can be
7359
- * up to 512 MB, and the size of all files uploaded by one organization can be up
7360
- * to 1 TB.
7356
+ * up to 512 MB, and each project can store up to 2.5 TB of files in total. There
7357
+ * is no organization-wide storage limit.
7361
7358
  *
7362
7359
  * - The Assistants API supports files up to 2 million tokens and of specific file
7363
7360
  * types. See the
@@ -18534,22 +18531,28 @@ class AlpacaTradingAPI {
18534
18531
  * @param side (string) - the side of the order
18535
18532
  * @param trailPercent100 (number) - the trail percent of the order (scale 100, i.e. 0.5 = 0.5%)
18536
18533
  * @param position_intent (string) - the position intent of the order
18534
+ * @param client_order_id (string) - optional client order id
18535
+ * @returns The created trailing stop order
18537
18536
  */
18538
- async createTrailingStop(symbol, qty, side, trailPercent100, position_intent) {
18537
+ async createTrailingStop(symbol, qty, side, trailPercent100, position_intent, client_order_id) {
18539
18538
  this.log(`Creating trailing stop ${side.toUpperCase()} ${qty} shares for ${symbol} with trail percent ${trailPercent100}%`, {
18540
18539
  symbol,
18541
18540
  });
18541
+ const body = {
18542
+ symbol,
18543
+ qty: Math.abs(qty),
18544
+ side,
18545
+ position_intent,
18546
+ order_class: 'simple',
18547
+ type: 'trailing_stop',
18548
+ trail_percent: trailPercent100, // Already in decimal form (e.g., 4 for 4%)
18549
+ time_in_force: 'gtc',
18550
+ };
18551
+ if (client_order_id !== undefined) {
18552
+ body.client_order_id = client_order_id;
18553
+ }
18542
18554
  try {
18543
- await this.makeRequest(`/orders`, 'POST', {
18544
- symbol,
18545
- qty: Math.abs(qty),
18546
- side,
18547
- position_intent,
18548
- order_class: 'simple',
18549
- type: 'trailing_stop',
18550
- trail_percent: trailPercent100, // Already in decimal form (e.g., 4 for 4%)
18551
- time_in_force: 'gtc',
18552
- });
18555
+ return await this.makeRequest(`/orders`, 'POST', body);
18553
18556
  }
18554
18557
  catch (error) {
18555
18558
  this.log(`Error creating trailing stop: ${error}`, {