@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.
@@ -10,6 +10,7 @@ export declare const deserializeField: (serializedField: ISerializedOnlyField) =
10
10
  export declare const deserialize: (serialized: ISerializedField) => AnyField | FieldSection;
11
11
  export type PartialFormRevision = Pick<UserFormRevision, "title" | "fields" | "description"> & Partial<UserFormRevision>;
12
12
  export declare function formRevisionToSchema(formRevision: PartialFormRevision, meta?: Partial<SchemaMeta>): ISchema;
13
+ export declare function flattenFields(schema: ISchema): AnyField[];
13
14
  export declare function decodeFormValues(schema: ISchema, values: Record<string, string>): Record<string, FieldValue>;
14
15
  export declare function encodeFormValues(schema: ISchema, values: Record<string, FieldValue>): Record<string, string>;
15
16
  export declare function valueIsFile(v: FieldValue | Promise<File>[] | undefined): v is File[] | Promise<File>[];
@@ -5486,45 +5486,55 @@ class AssetService extends BaseApiService {
5486
5486
  throw err;
5487
5487
  });
5488
5488
  }
5489
- addBulk(assetsToCreate, workspaceId, assetTypeId) {
5489
+ // TODO: payload does not require asset_type
5490
+ bulkAdd(assetsToCreate, workspaceId, assetTypeId) {
5490
5491
  const { store } = this.client;
5491
- const fullAssets = assetsToCreate.map((asset) => {
5492
- return { ...offline(asset), submitted_at: (/* @__PURE__ */ new Date()).toISOString() };
5493
- });
5494
- const assetBatches = chunkArray(fullAssets, BULK_ADD_ASSET_BATCH_SIZE).map((assetBatch) => {
5495
- return {
5496
- batchId: v4(),
5497
- payload: {
5498
- assets: assetBatch
5499
- }
5500
- };
5501
- });
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)));
5492
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5493
+ const assetBatches = chunkArray(assetsToCreate, BULK_ADD_ASSET_BATCH_SIZE).map(
5494
+ (assetBatch) => {
5495
+ const assetPayloads = assetBatch.map((assetPayload) => {
5496
+ return offline({
5497
+ ...assetPayload,
5498
+ submitted_at: submittedAt
5499
+ });
5522
5500
  });
5523
- prevBatchId = assetBatch.batchId;
5524
- return promise;
5525
- })
5501
+ return {
5502
+ batchId: v4(),
5503
+ payload: {
5504
+ assets: assetPayloads
5505
+ }
5506
+ };
5507
+ }
5526
5508
  );
5527
- return [fullAssets, batchPromises.then((result) => result)];
5509
+ const batchPromises = [];
5510
+ let prevBatchId = null;
5511
+ for (const assetBatch of assetBatches) {
5512
+ const { batchId, payload } = assetBatch;
5513
+ const batchAssetOfflineIds = payload.assets.map((c) => c.offline_id);
5514
+ const blockers = [assetTypeId];
5515
+ if (prevBatchId)
5516
+ blockers.push(prevBatchId);
5517
+ const blocks = batchAssetOfflineIds;
5518
+ blocks.push(batchId);
5519
+ const promise = this.client.enqueueRequest({
5520
+ description: "Batch create assets",
5521
+ method: HttpMethod.POST,
5522
+ url: `/assets/types/${assetTypeId}/add-assets/`,
5523
+ queryParams: {
5524
+ workspace_id: workspaceId.toString()
5525
+ },
5526
+ payload,
5527
+ blockers,
5528
+ blocks
5529
+ });
5530
+ prevBatchId = assetBatch.batchId;
5531
+ batchPromises.push(promise);
5532
+ }
5533
+ void Promise.all(batchPromises).then((result) => {
5534
+ const allCreatedAssets = result.flat();
5535
+ store.dispatch(addAssetsInBatches(allCreatedAssets));
5536
+ });
5537
+ return batchPromises;
5528
5538
  }
5529
5539
  async refreshStore() {
5530
5540
  const { store } = this.client;
@@ -7392,62 +7402,37 @@ class UserFormSubmissionService extends BaseApiService {
7392
7402
  // Note currently the bulkAdd method is specific to form submissions for assets
7393
7403
  // TODO: adapt the support bulk adding to any model type
7394
7404
  async bulkAdd(args) {
7395
- const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
7396
7405
  const { store } = this.client;
7397
- const offlineSubmissions = [];
7398
- const offlineAttachments = [];
7399
- const submissionOfflineIds = [];
7406
+ const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
7400
7407
  const allFilesRecord = {};
7401
7408
  const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
7402
7409
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7403
- const createdBy = store.getState().userReducer.currentUser.id;
7404
7410
  const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), MAX_BULK_ADD_SUBMISSIONS);
7405
7411
  const bulkAddBatches = await Promise.all(
7406
7412
  assetIdBatches.map(async (assetIdBatch) => {
7407
7413
  const batchId = v4();
7408
- const submissionsPayload = [];
7409
- const attachmentsPayload = [];
7410
- let files = { ...commonFiles };
7414
+ const submissionPayloads = [];
7415
+ const attachmentPayloads = [];
7416
+ const files = { ...commonFiles };
7411
7417
  for (const assetId of assetIdBatch) {
7412
7418
  const { values: fileSeperatedSubmissionSpecificValues, files: submissionSpecificFiles } = separateFilesFromValues(fieldValuesByAsset[assetId] ?? {});
7413
- files = Object.assign(files, submissionSpecificFiles);
7414
- const submissionValues = {
7415
- ...fileSeperatedCommonFieldValues,
7416
- ...fileSeperatedSubmissionSpecificValues
7417
- };
7418
- const submission = offline({
7419
- form_revision: formRevision,
7420
- values: submissionValues,
7421
- created_by: createdBy,
7422
- submitted_at: submittedAt,
7423
- asset: assetId
7424
- });
7425
- submissionOfflineIds.push(submission.offline_id);
7426
- submissionsPayload.push({
7427
- offline_id: submission.offline_id,
7419
+ Object.assign(files, submissionSpecificFiles);
7420
+ const submissionPayload = offline({
7428
7421
  asset_id: assetId,
7429
7422
  form_data: fileSeperatedSubmissionSpecificValues
7430
7423
  });
7431
- offlineSubmissions.push(submission);
7424
+ submissionPayloads.push(submissionPayload);
7432
7425
  for (const [fieldIdentifier, fileArray] of Object.entries(files)) {
7433
7426
  for (const file of fileArray) {
7434
7427
  const sha1 = await hashFile(file);
7435
7428
  await this.client.files.addCache(file, sha1);
7436
- const offlineAttachment = offline({
7437
- file_name: file.name,
7438
- file_sha1: sha1,
7439
- file: URL.createObjectURL(file),
7440
- submission: submission.offline_id,
7441
- field_identifier: fieldIdentifier
7442
- });
7443
- offlineAttachments.push(offlineAttachment);
7444
- attachmentsPayload.push({
7445
- offline_id: offlineAttachment.offline_id,
7446
- submission_id: submission.offline_id,
7429
+ const attachmentPayload = offline({
7430
+ submission_id: submissionPayload.offline_id,
7447
7431
  sha1,
7448
7432
  name: file.name,
7449
7433
  field_identifier: fieldIdentifier
7450
7434
  });
7435
+ attachmentPayloads.push(attachmentPayload);
7451
7436
  }
7452
7437
  }
7453
7438
  }
@@ -7468,58 +7453,66 @@ class UserFormSubmissionService extends BaseApiService {
7468
7453
  payload: {
7469
7454
  form_data: fileSeperatedCommonFieldValues,
7470
7455
  submitted_at: submittedAt,
7471
- submissions: submissionsPayload,
7472
- attachments: attachmentsPayload,
7456
+ submissions: submissionPayloads,
7457
+ attachments: attachmentPayloads,
7473
7458
  files: filePaylods
7474
7459
  }
7475
7460
  };
7476
7461
  })
7477
7462
  );
7478
- store.dispatch(addFormSubmissions(offlineSubmissions));
7479
- store.dispatch(addFormSubmissionAttachments(offlineAttachments));
7463
+ const batchPromises = [];
7480
7464
  let prevBatchId = null;
7481
- const batchPromises = Promise.all(
7482
- bulkAddBatches.map((batch) => {
7483
- const { payload, batchId } = batch;
7484
- const batchAssetIds = payload.submissions.map((x) => x.asset_id);
7485
- const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
7486
- const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
7487
- const promise = this.client.enqueueRequest({
7488
- description: "Bulk add form submissions",
7489
- method: HttpMethod.POST,
7490
- url: `/forms/revisions/${formRevision}/bulk-respond/`,
7491
- payload,
7492
- blockers: prevBatchId ? batchAssetIds.concat([prevBatchId]) : batchAssetIds,
7493
- blocks: batchSubmissionOfflineIds.concat([batchId])
7494
- });
7495
- promise.then(({ submissions, attachments, presigned_urls }) => {
7496
- store.dispatch(updateFormSubmissions(submissions));
7497
- store.dispatch(updateFormSubmissionAttachments(attachments));
7498
- for (const [sha1, presigned_url] of Object.entries(presigned_urls)) {
7499
- const file = allFilesRecord[sha1];
7500
- if (!file)
7501
- continue;
7502
- void this.client.enqueueRequest({
7503
- url: presigned_url.url,
7504
- description: "Upload file",
7505
- method: HttpMethod.POST,
7506
- isExternalUrl: true,
7507
- isAuthNeeded: false,
7508
- attachmentHash: sha1,
7509
- blockers: [`s3-${file.sha1}.${file.extension}`],
7510
- blocks: [sha1],
7511
- s3url: presigned_url
7512
- });
7513
- }
7514
- }).catch(() => {
7515
- store.dispatch(deleteFormSubmissions(batchSubmissionOfflineIds));
7516
- store.dispatch(deleteFormSubmissionAttachments(batchAttachmentsOfflineIds));
7517
- });
7518
- prevBatchId = batchId;
7519
- return promise;
7520
- })
7521
- );
7522
- return [offlineSubmissions, batchPromises.then((results) => results.map(({ submissions }) => submissions))];
7465
+ for (const batch of bulkAddBatches) {
7466
+ const { payload, batchId } = batch;
7467
+ const batchAssetIds = payload.submissions.map((x) => x.asset_id);
7468
+ const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
7469
+ const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
7470
+ const blockers = batchAssetIds;
7471
+ if (prevBatchId)
7472
+ blockers.push(prevBatchId);
7473
+ const blocks = [...batchSubmissionOfflineIds, ...batchAttachmentsOfflineIds, batchId];
7474
+ const promise = this.client.enqueueRequest({
7475
+ description: "Bulk add form submissions",
7476
+ method: HttpMethod.POST,
7477
+ url: `/forms/revisions/${formRevision}/bulk-respond/`,
7478
+ payload,
7479
+ blockers,
7480
+ blocks
7481
+ });
7482
+ void promise.then(({ presigned_urls }) => {
7483
+ for (const [sha1, presignedUrl] of Object.entries(presigned_urls)) {
7484
+ const file = allFilesRecord[sha1];
7485
+ if (!file)
7486
+ continue;
7487
+ void this.client.enqueueRequest({
7488
+ url: presignedUrl.url,
7489
+ description: "Upload file",
7490
+ method: HttpMethod.POST,
7491
+ isExternalUrl: true,
7492
+ isAuthNeeded: false,
7493
+ attachmentHash: sha1,
7494
+ blockers: [`s3-${file.sha1}.${file.extension}`],
7495
+ blocks: [sha1],
7496
+ s3url: presignedUrl
7497
+ });
7498
+ }
7499
+ });
7500
+ prevBatchId = batchId;
7501
+ batchPromises.push(promise);
7502
+ }
7503
+ void Promise.all(batchPromises).then((results) => {
7504
+ const createdSubmissions = [];
7505
+ const createdAttachments = [];
7506
+ for (const result of results) {
7507
+ for (const createdSubmission of result.submissions)
7508
+ createdSubmissions.push(createdSubmission);
7509
+ for (const createdAttachment of result.attachments)
7510
+ createdAttachments.push(createdAttachment);
7511
+ }
7512
+ store.dispatch(addFormSubmissions(createdSubmissions));
7513
+ store.dispatch(addFormSubmissionAttachments(createdAttachments));
7514
+ });
7515
+ return batchPromises;
7523
7516
  }
7524
7517
  update(submission) {
7525
7518
  const { store } = this.client;
@@ -13133,10 +13126,7 @@ const MultiStringInput = memo((props) => {
13133
13126
  helpText = showInputOnly ? null : helpText;
13134
13127
  label = showInputOnly ? "" : label;
13135
13128
  const color = useSeverityColor(severity);
13136
- const value = useMemo(
13137
- () => Array.isArray(fieldProps.value) ? fieldProps.value : [],
13138
- [fieldProps.value]
13139
- );
13129
+ const value = useMemo(() => Array.isArray(fieldProps.value) ? fieldProps.value : [], [fieldProps.value]);
13140
13130
  const { onChange, onBlur } = fieldProps;
13141
13131
  const droppableId = `${inputId}-droppable`;
13142
13132
  const { disabled } = rest;
@@ -14952,39 +14942,37 @@ function formRevisionToSchema(formRevision, meta = {}) {
14952
14942
  meta: { readonly }
14953
14943
  };
14954
14944
  }
14955
- function decodeFormValues(schema, values) {
14956
- let allFields = [];
14945
+ function flattenFields(schema) {
14946
+ const allFields = [];
14957
14947
  for (const field of schema.fields) {
14958
14948
  if (field instanceof FieldSection) {
14959
- allFields = allFields.concat(field.fields);
14949
+ for (const subField of field.fields) {
14950
+ allFields.push(subField);
14951
+ }
14960
14952
  } else {
14961
14953
  if (!(field instanceof BaseField)) {
14962
- throw new Error("Invalid field type");
14954
+ throw new Error(`Invalid field type: ${field.type}`);
14963
14955
  }
14964
14956
  allFields.push(field);
14965
14957
  }
14966
14958
  }
14959
+ return allFields;
14960
+ }
14961
+ function decodeFormValues(schema, values) {
14962
+ const allFields = flattenFields(schema);
14967
14963
  const result = {};
14968
14964
  for (const field of allFields) {
14969
- if (!(field.identifier in values))
14970
- ;
14971
- const value = values[field.identifier];
14972
- result[field.identifier] = field.decodeJsonToValue(value);
14965
+ const value = values[field.identifier] ?? null;
14966
+ if (value !== null) {
14967
+ result[field.identifier] = field.decodeJsonToValue(value);
14968
+ } else {
14969
+ result[field.identifier] = value;
14970
+ }
14973
14971
  }
14974
14972
  return result;
14975
14973
  }
14976
14974
  function encodeFormValues(schema, values) {
14977
- let allFields = [];
14978
- for (const field of schema.fields) {
14979
- if (field instanceof FieldSection) {
14980
- allFields = allFields.concat(field.fields);
14981
- } else {
14982
- if (!(field instanceof BaseField)) {
14983
- throw new Error("Invalid field type");
14984
- }
14985
- allFields.push(field);
14986
- }
14987
- }
14975
+ const allFields = flattenFields(schema);
14988
14976
  const result = {};
14989
14977
  for (const field of allFields) {
14990
14978
  const value = values[field.identifier];
@@ -16787,6 +16775,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
16787
16775
  emptyStringField,
16788
16776
  emptyTextField,
16789
16777
  encodeFormValues,
16778
+ flattenFields,
16790
16779
  formRevisionToSchema,
16791
16780
  initialFormValues,
16792
16781
  isConditionMet,
@@ -17029,6 +17018,7 @@ export {
17029
17018
  fileReducer,
17030
17019
  fileSlice,
17031
17020
  fileToBlob,
17021
+ flattenFields,
17032
17022
  flipCoordinates,
17033
17023
  formReducer,
17034
17024
  formRevisionReducer,