@overmap-ai/core 1.0.58-asset-description.6 → 1.0.58-asset-description.8

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.
@@ -1738,6 +1738,16 @@ const assetSlice = createSlice({
1738
1738
  }
1739
1739
  prevAssets = null;
1740
1740
  },
1741
+ updateAssets: (state, action) => {
1742
+ for (const asset of action.payload) {
1743
+ if (asset.offline_id in state.assets) {
1744
+ state.assets[asset.offline_id] = asset;
1745
+ } else {
1746
+ throw new Error(`Tried to update asset with ID that doesn't exist: ${asset.offline_id}`);
1747
+ }
1748
+ }
1749
+ prevAssets = null;
1750
+ },
1741
1751
  removeAsset: (state, action) => {
1742
1752
  if (action.payload in state.assets) {
1743
1753
  delete state.assets[action.payload];
@@ -1746,6 +1756,16 @@ const assetSlice = createSlice({
1746
1756
  }
1747
1757
  prevAssets = null;
1748
1758
  },
1759
+ removeAssets: (state, action) => {
1760
+ for (const assetId of action.payload) {
1761
+ if (assetId in state.assets) {
1762
+ delete state.assets[assetId];
1763
+ } else {
1764
+ throw new Error(`Failed to remove asset because ID doesn't exist: ${assetId}`);
1765
+ }
1766
+ }
1767
+ prevAssets = null;
1768
+ },
1749
1769
  removeAllAssetsOfType: (state, action) => {
1750
1770
  var _a2;
1751
1771
  for (const componentId in state.assets) {
@@ -1769,7 +1789,9 @@ const assetSlice = createSlice({
1769
1789
  const {
1770
1790
  addAsset,
1771
1791
  updateAsset,
1792
+ updateAssets,
1772
1793
  removeAsset,
1794
+ removeAssets,
1773
1795
  addAssetsInBatches,
1774
1796
  setAssets,
1775
1797
  removeAllAssetsOfType,
@@ -5378,6 +5400,16 @@ class CategoryService extends BaseApiService {
5378
5400
  store.dispatch(setCategories(result));
5379
5401
  }
5380
5402
  }
5403
+ function chunkArray(arr, chunkSize) {
5404
+ const chunks = [];
5405
+ let index2 = 0;
5406
+ const arrLength = arr.length;
5407
+ while (index2 < arrLength) {
5408
+ chunks.push(arr.slice(index2, index2 += chunkSize));
5409
+ }
5410
+ return chunks;
5411
+ }
5412
+ const BULK_ADD_ASSET_BATCH_SIZE = 1e3;
5381
5413
  class AssetService extends BaseApiService {
5382
5414
  // Basic CRUD functions
5383
5415
  add(asset, workspaceId) {
@@ -5454,36 +5486,45 @@ class AssetService extends BaseApiService {
5454
5486
  throw err;
5455
5487
  });
5456
5488
  }
5457
- async addBatch(assetsToCreate, workspaceId, assetTypeId) {
5489
+ addBulk(assetsToCreate, workspaceId, assetTypeId) {
5490
+ const { store } = this.client;
5458
5491
  const fullAssets = assetsToCreate.map((asset) => {
5459
5492
  return { ...offline(asset), submitted_at: (/* @__PURE__ */ new Date()).toISOString() };
5460
5493
  });
5461
- const { store } = this.client;
5462
- store.dispatch(addAssetsInBatches(fullAssets));
5463
- const promise = this.client.enqueueRequest({
5464
- description: "Batch create assets",
5465
- method: HttpMethod.POST,
5466
- url: `/assets/types/${assetTypeId}/add-assets/`,
5467
- queryParams: {
5468
- workspace_id: workspaceId.toString()
5469
- },
5470
- payload: {
5471
- assets: fullAssets
5472
- },
5473
- blockers: [assetTypeId],
5474
- blocks: fullAssets.map((c) => c.offline_id)
5475
- });
5476
- void promise.then((result) => {
5477
- for (const assets of Object.values(result)) {
5478
- store.dispatch(updateAsset(assets));
5479
- }
5480
- }).catch((e) => {
5481
- for (const asset of fullAssets) {
5482
- store.dispatch(removeAsset(asset.offline_id));
5483
- }
5484
- throw e;
5494
+ const assetBatches = chunkArray(fullAssets, BULK_ADD_ASSET_BATCH_SIZE).map((assetBatch) => {
5495
+ return {
5496
+ batchId: v4(),
5497
+ payload: {
5498
+ assets: assetBatch
5499
+ }
5500
+ };
5485
5501
  });
5486
- return promise;
5502
+ store.dispatch(addAssetsInBatches(fullAssets));
5503
+ let prevBatchId = null;
5504
+ const batchPromises = Promise.all(
5505
+ assetBatches.map((assetBatch) => {
5506
+ const { batchId, payload } = assetBatch;
5507
+ const promise = this.client.enqueueRequest({
5508
+ description: "Batch create assets",
5509
+ method: HttpMethod.POST,
5510
+ url: `/assets/types/${assetTypeId}/add-assets/`,
5511
+ queryParams: {
5512
+ workspace_id: workspaceId.toString()
5513
+ },
5514
+ payload,
5515
+ blockers: prevBatchId ? [assetTypeId, prevBatchId] : [assetTypeId],
5516
+ blocks: assetBatch.payload.assets.map((c) => c.offline_id).concat([batchId])
5517
+ });
5518
+ promise.then((result) => {
5519
+ store.dispatch(updateAssets(Object.values(result)));
5520
+ }).catch(() => {
5521
+ store.dispatch(removeAssets(assetBatch.payload.assets.map((c) => c.offline_id)));
5522
+ });
5523
+ prevBatchId = assetBatch.batchId;
5524
+ return promise;
5525
+ })
5526
+ );
5527
+ return [fullAssets, batchPromises.then((result) => result)];
5487
5528
  }
5488
5529
  async refreshStore() {
5489
5530
  const { store } = this.client;
@@ -7249,15 +7290,6 @@ class UserFormService extends BaseApiService {
7249
7290
  store.dispatch(setFormRevisionAttachments(Object.values(result.attachments)));
7250
7291
  }
7251
7292
  }
7252
- function chunkArray(arr, chunkSize) {
7253
- const chunks = [];
7254
- let index2 = 0;
7255
- const arrLength = arr.length;
7256
- while (index2 < arrLength) {
7257
- chunks.push(arr.slice(index2, index2 += chunkSize));
7258
- }
7259
- return chunks;
7260
- }
7261
7293
  const isArrayOfFiles = (value) => {
7262
7294
  return Array.isArray(value) && value[0] instanceof File;
7263
7295
  };
@@ -17074,6 +17106,7 @@ export {
17074
17106
  removeAssetAttachments,
17075
17107
  removeAssetTypeAttachment,
17076
17108
  removeAssetTypeAttachments,
17109
+ removeAssets,
17077
17110
  removeAttachmentsOfIssue,
17078
17111
  removeCategory,
17079
17112
  removeColor,
@@ -17391,6 +17424,7 @@ export {
17391
17424
  updateAssetAttachments,
17392
17425
  updateAssetTypeAttachment,
17393
17426
  updateAssetTypeAttachments,
17427
+ updateAssets,
17394
17428
  updateConversation,
17395
17429
  updateDocumentAttachment,
17396
17430
  updateDocumentAttachments,