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

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.
@@ -5476,45 +5476,55 @@ var __publicField = (obj, key, value) => {
5476
5476
  throw err;
5477
5477
  });
5478
5478
  }
5479
- addBulk(assetsToCreate, workspaceId, assetTypeId) {
5479
+ // TODO: payload does not require asset_type
5480
+ bulkAdd(assetsToCreate, workspaceId, assetTypeId) {
5480
5481
  const { store } = this.client;
5481
- const fullAssets = assetsToCreate.map((asset) => {
5482
- return { ...offline(asset), submitted_at: (/* @__PURE__ */ new Date()).toISOString() };
5483
- });
5484
- const assetBatches = chunkArray(fullAssets, BULK_ADD_ASSET_BATCH_SIZE).map((assetBatch) => {
5485
- return {
5486
- batchId: uuid.v4(),
5487
- payload: {
5488
- assets: assetBatch
5489
- }
5490
- };
5491
- });
5492
- store.dispatch(addAssetsInBatches(fullAssets));
5493
- let prevBatchId = null;
5494
- const batchPromises = Promise.all(
5495
- assetBatches.map((assetBatch) => {
5496
- const { batchId, payload } = assetBatch;
5497
- const promise = this.client.enqueueRequest({
5498
- description: "Batch create assets",
5499
- method: HttpMethod.POST,
5500
- url: `/assets/types/${assetTypeId}/add-assets/`,
5501
- queryParams: {
5502
- workspace_id: workspaceId.toString()
5503
- },
5504
- payload,
5505
- blockers: prevBatchId ? [assetTypeId, prevBatchId] : [assetTypeId],
5506
- blocks: assetBatch.payload.assets.map((c) => c.offline_id).concat([batchId])
5507
- });
5508
- promise.then((result) => {
5509
- store.dispatch(updateAssets(Object.values(result)));
5510
- }).catch(() => {
5511
- store.dispatch(removeAssets(assetBatch.payload.assets.map((c) => c.offline_id)));
5482
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5483
+ const assetBatches = chunkArray(assetsToCreate, BULK_ADD_ASSET_BATCH_SIZE).map(
5484
+ (assetBatch) => {
5485
+ const assetPayloads = assetBatch.map((assetPayload) => {
5486
+ return offline({
5487
+ ...assetPayload,
5488
+ submitted_at: submittedAt
5489
+ });
5512
5490
  });
5513
- prevBatchId = assetBatch.batchId;
5514
- return promise;
5515
- })
5491
+ return {
5492
+ batchId: uuid.v4(),
5493
+ payload: {
5494
+ assets: assetPayloads
5495
+ }
5496
+ };
5497
+ }
5516
5498
  );
5517
- return [fullAssets, batchPromises.then((result) => result)];
5499
+ const batchPromises = [];
5500
+ let prevBatchId = null;
5501
+ for (const assetBatch of assetBatches) {
5502
+ const { batchId, payload } = assetBatch;
5503
+ const batchAssetOfflineIds = payload.assets.map((c) => c.offline_id);
5504
+ const blockers = [assetTypeId];
5505
+ if (prevBatchId)
5506
+ blockers.push(prevBatchId);
5507
+ const blocks2 = batchAssetOfflineIds;
5508
+ blocks2.push(batchId);
5509
+ const promise = this.client.enqueueRequest({
5510
+ description: "Batch create assets",
5511
+ method: HttpMethod.POST,
5512
+ url: `/assets/types/${assetTypeId}/add-assets/`,
5513
+ queryParams: {
5514
+ workspace_id: workspaceId.toString()
5515
+ },
5516
+ payload,
5517
+ blockers,
5518
+ blocks: blocks2
5519
+ });
5520
+ prevBatchId = assetBatch.batchId;
5521
+ batchPromises.push(promise);
5522
+ }
5523
+ void Promise.all(batchPromises).then((result) => {
5524
+ const allCreatedAssets = result.flat();
5525
+ store.dispatch(addAssetsInBatches(allCreatedAssets));
5526
+ });
5527
+ return batchPromises;
5518
5528
  }
5519
5529
  async refreshStore() {
5520
5530
  const { store } = this.client;
@@ -7382,62 +7392,37 @@ var __publicField = (obj, key, value) => {
7382
7392
  // Note currently the bulkAdd method is specific to form submissions for assets
7383
7393
  // TODO: adapt the support bulk adding to any model type
7384
7394
  async bulkAdd(args) {
7385
- const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
7386
7395
  const { store } = this.client;
7387
- const offlineSubmissions = [];
7388
- const offlineAttachments = [];
7389
- const submissionOfflineIds = [];
7396
+ const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
7390
7397
  const allFilesRecord = {};
7391
7398
  const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
7392
7399
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7393
- const createdBy = store.getState().userReducer.currentUser.id;
7394
7400
  const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), MAX_BULK_ADD_SUBMISSIONS);
7395
7401
  const bulkAddBatches = await Promise.all(
7396
7402
  assetIdBatches.map(async (assetIdBatch) => {
7397
7403
  const batchId = uuid.v4();
7398
- const submissionsPayload = [];
7399
- const attachmentsPayload = [];
7400
- let files = { ...commonFiles };
7404
+ const submissionPayloads = [];
7405
+ const attachmentPayloads = [];
7406
+ const files = { ...commonFiles };
7401
7407
  for (const assetId of assetIdBatch) {
7402
7408
  const { values: fileSeperatedSubmissionSpecificValues, files: submissionSpecificFiles } = separateFilesFromValues(fieldValuesByAsset[assetId] ?? {});
7403
- files = Object.assign(files, submissionSpecificFiles);
7404
- const submissionValues = {
7405
- ...fileSeperatedCommonFieldValues,
7406
- ...fileSeperatedSubmissionSpecificValues
7407
- };
7408
- const submission = offline({
7409
- form_revision: formRevision,
7410
- values: submissionValues,
7411
- created_by: createdBy,
7412
- submitted_at: submittedAt,
7413
- asset: assetId
7414
- });
7415
- submissionOfflineIds.push(submission.offline_id);
7416
- submissionsPayload.push({
7417
- offline_id: submission.offline_id,
7409
+ Object.assign(files, submissionSpecificFiles);
7410
+ const submissionPayload = offline({
7418
7411
  asset_id: assetId,
7419
7412
  form_data: fileSeperatedSubmissionSpecificValues
7420
7413
  });
7421
- offlineSubmissions.push(submission);
7414
+ submissionPayloads.push(submissionPayload);
7422
7415
  for (const [fieldIdentifier, fileArray] of Object.entries(files)) {
7423
7416
  for (const file of fileArray) {
7424
7417
  const sha1 = await hashFile(file);
7425
7418
  await this.client.files.addCache(file, sha1);
7426
- const offlineAttachment = offline({
7427
- file_name: file.name,
7428
- file_sha1: sha1,
7429
- file: URL.createObjectURL(file),
7430
- submission: submission.offline_id,
7431
- field_identifier: fieldIdentifier
7432
- });
7433
- offlineAttachments.push(offlineAttachment);
7434
- attachmentsPayload.push({
7435
- offline_id: offlineAttachment.offline_id,
7436
- submission_id: submission.offline_id,
7419
+ const attachmentPayload = offline({
7420
+ submission_id: submissionPayload.offline_id,
7437
7421
  sha1,
7438
7422
  name: file.name,
7439
7423
  field_identifier: fieldIdentifier
7440
7424
  });
7425
+ attachmentPayloads.push(attachmentPayload);
7441
7426
  }
7442
7427
  }
7443
7428
  }
@@ -7458,58 +7443,66 @@ var __publicField = (obj, key, value) => {
7458
7443
  payload: {
7459
7444
  form_data: fileSeperatedCommonFieldValues,
7460
7445
  submitted_at: submittedAt,
7461
- submissions: submissionsPayload,
7462
- attachments: attachmentsPayload,
7446
+ submissions: submissionPayloads,
7447
+ attachments: attachmentPayloads,
7463
7448
  files: filePaylods
7464
7449
  }
7465
7450
  };
7466
7451
  })
7467
7452
  );
7468
- store.dispatch(addFormSubmissions(offlineSubmissions));
7469
- store.dispatch(addFormSubmissionAttachments(offlineAttachments));
7453
+ const batchPromises = [];
7470
7454
  let prevBatchId = null;
7471
- const batchPromises = Promise.all(
7472
- bulkAddBatches.map((batch) => {
7473
- const { payload, batchId } = batch;
7474
- const batchAssetIds = payload.submissions.map((x) => x.asset_id);
7475
- const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
7476
- const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
7477
- const promise = this.client.enqueueRequest({
7478
- description: "Bulk add form submissions",
7479
- method: HttpMethod.POST,
7480
- url: `/forms/revisions/${formRevision}/bulk-respond/`,
7481
- payload,
7482
- blockers: prevBatchId ? batchAssetIds.concat([prevBatchId]) : batchAssetIds,
7483
- blocks: batchSubmissionOfflineIds.concat([batchId])
7484
- });
7485
- promise.then(({ submissions, attachments, presigned_urls }) => {
7486
- store.dispatch(updateFormSubmissions(submissions));
7487
- store.dispatch(updateFormSubmissionAttachments(attachments));
7488
- for (const [sha1, presigned_url] of Object.entries(presigned_urls)) {
7489
- const file = allFilesRecord[sha1];
7490
- if (!file)
7491
- continue;
7492
- void this.client.enqueueRequest({
7493
- url: presigned_url.url,
7494
- description: "Upload file",
7495
- method: HttpMethod.POST,
7496
- isExternalUrl: true,
7497
- isAuthNeeded: false,
7498
- attachmentHash: sha1,
7499
- blockers: [`s3-${file.sha1}.${file.extension}`],
7500
- blocks: [sha1],
7501
- s3url: presigned_url
7502
- });
7503
- }
7504
- }).catch(() => {
7505
- store.dispatch(deleteFormSubmissions(batchSubmissionOfflineIds));
7506
- store.dispatch(deleteFormSubmissionAttachments(batchAttachmentsOfflineIds));
7507
- });
7508
- prevBatchId = batchId;
7509
- return promise;
7510
- })
7511
- );
7512
- return [offlineSubmissions, batchPromises.then((results) => results.map(({ submissions }) => submissions))];
7455
+ for (const batch of bulkAddBatches) {
7456
+ const { payload, batchId } = batch;
7457
+ const batchAssetIds = payload.submissions.map((x) => x.asset_id);
7458
+ const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
7459
+ const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
7460
+ const blockers = batchAssetIds;
7461
+ if (prevBatchId)
7462
+ blockers.push(prevBatchId);
7463
+ const blocks2 = [...batchSubmissionOfflineIds, ...batchAttachmentsOfflineIds, batchId];
7464
+ const promise = this.client.enqueueRequest({
7465
+ description: "Bulk add form submissions",
7466
+ method: HttpMethod.POST,
7467
+ url: `/forms/revisions/${formRevision}/bulk-respond/`,
7468
+ payload,
7469
+ blockers,
7470
+ blocks: blocks2
7471
+ });
7472
+ void promise.then(({ presigned_urls }) => {
7473
+ for (const [sha1, presignedUrl] of Object.entries(presigned_urls)) {
7474
+ const file = allFilesRecord[sha1];
7475
+ if (!file)
7476
+ continue;
7477
+ void this.client.enqueueRequest({
7478
+ url: presignedUrl.url,
7479
+ description: "Upload file",
7480
+ method: HttpMethod.POST,
7481
+ isExternalUrl: true,
7482
+ isAuthNeeded: false,
7483
+ attachmentHash: sha1,
7484
+ blockers: [`s3-${file.sha1}.${file.extension}`],
7485
+ blocks: [sha1],
7486
+ s3url: presignedUrl
7487
+ });
7488
+ }
7489
+ });
7490
+ prevBatchId = batchId;
7491
+ batchPromises.push(promise);
7492
+ }
7493
+ void Promise.all(batchPromises).then((results) => {
7494
+ const createdSubmissions = [];
7495
+ const createdAttachments = [];
7496
+ for (const result of results) {
7497
+ for (const createdSubmission of result.submissions)
7498
+ createdSubmissions.push(createdSubmission);
7499
+ for (const createdAttachment of result.attachments)
7500
+ createdAttachments.push(createdAttachment);
7501
+ }
7502
+ store.dispatch(addFormSubmissions(createdSubmissions));
7503
+ store.dispatch(addFormSubmissionAttachments(createdAttachments));
7504
+ });
7505
+ return batchPromises;
7513
7506
  }
7514
7507
  update(submission) {
7515
7508
  const { store } = this.client;
@@ -13123,10 +13116,7 @@ var __publicField = (obj, key, value) => {
13123
13116
  helpText = showInputOnly ? null : helpText;
13124
13117
  label = showInputOnly ? "" : label;
13125
13118
  const color = blocks.useSeverityColor(severity);
13126
- const value = React.useMemo(
13127
- () => Array.isArray(fieldProps.value) ? fieldProps.value : [],
13128
- [fieldProps.value]
13129
- );
13119
+ const value = React.useMemo(() => Array.isArray(fieldProps.value) ? fieldProps.value : [], [fieldProps.value]);
13130
13120
  const { onChange, onBlur } = fieldProps;
13131
13121
  const droppableId = `${inputId}-droppable`;
13132
13122
  const { disabled } = rest;
@@ -14942,39 +14932,37 @@ var __publicField = (obj, key, value) => {
14942
14932
  meta: { readonly }
14943
14933
  };
14944
14934
  }
14945
- function decodeFormValues(schema, values) {
14946
- let allFields = [];
14935
+ function flattenFields(schema) {
14936
+ const allFields = [];
14947
14937
  for (const field of schema.fields) {
14948
14938
  if (field instanceof FieldSection) {
14949
- allFields = allFields.concat(field.fields);
14939
+ for (const subField of field.fields) {
14940
+ allFields.push(subField);
14941
+ }
14950
14942
  } else {
14951
14943
  if (!(field instanceof BaseField)) {
14952
- throw new Error("Invalid field type");
14944
+ throw new Error(`Invalid field type: ${field.type}`);
14953
14945
  }
14954
14946
  allFields.push(field);
14955
14947
  }
14956
14948
  }
14949
+ return allFields;
14950
+ }
14951
+ function decodeFormValues(schema, values) {
14952
+ const allFields = flattenFields(schema);
14957
14953
  const result = {};
14958
14954
  for (const field of allFields) {
14959
- if (!(field.identifier in values))
14960
- ;
14961
- const value = values[field.identifier];
14962
- result[field.identifier] = field.decodeJsonToValue(value);
14955
+ const value = values[field.identifier] ?? null;
14956
+ if (value !== null) {
14957
+ result[field.identifier] = field.decodeJsonToValue(value);
14958
+ } else {
14959
+ result[field.identifier] = value;
14960
+ }
14963
14961
  }
14964
14962
  return result;
14965
14963
  }
14966
14964
  function encodeFormValues(schema, values) {
14967
- let allFields = [];
14968
- for (const field of schema.fields) {
14969
- if (field instanceof FieldSection) {
14970
- allFields = allFields.concat(field.fields);
14971
- } else {
14972
- if (!(field instanceof BaseField)) {
14973
- throw new Error("Invalid field type");
14974
- }
14975
- allFields.push(field);
14976
- }
14977
- }
14965
+ const allFields = flattenFields(schema);
14978
14966
  const result = {};
14979
14967
  for (const field of allFields) {
14980
14968
  const value = values[field.identifier];
@@ -16777,6 +16765,7 @@ var __publicField = (obj, key, value) => {
16777
16765
  emptyStringField,
16778
16766
  emptyTextField,
16779
16767
  encodeFormValues,
16768
+ flattenFields,
16780
16769
  formRevisionToSchema,
16781
16770
  initialFormValues,
16782
16771
  isConditionMet,
@@ -17018,6 +17007,7 @@ var __publicField = (obj, key, value) => {
17018
17007
  exports2.fileReducer = fileReducer;
17019
17008
  exports2.fileSlice = fileSlice;
17020
17009
  exports2.fileToBlob = fileToBlob;
17010
+ exports2.flattenFields = flattenFields;
17021
17011
  exports2.flipCoordinates = flipCoordinates;
17022
17012
  exports2.formReducer = formReducer;
17023
17013
  exports2.formRevisionReducer = formRevisionReducer;