@overmap-ai/core 1.0.58-asset-description.8 → 1.0.58-asset-description.10
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/forms/fields/utils.d.ts +1 -0
- package/dist/overmap-core.js +125 -139
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +125 -139
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/services/AssetService.d.ts +2 -2
- package/dist/sdk/services/UserFormSubmissionService.d.ts +9 -2
- package/package.json +1 -1
|
@@ -5399,7 +5399,6 @@ var __publicField = (obj, key, value) => {
|
|
|
5399
5399
|
}
|
|
5400
5400
|
return chunks;
|
|
5401
5401
|
}
|
|
5402
|
-
const BULK_ADD_ASSET_BATCH_SIZE = 1e3;
|
|
5403
5402
|
class AssetService extends BaseApiService {
|
|
5404
5403
|
// Basic CRUD functions
|
|
5405
5404
|
add(asset, workspaceId) {
|
|
@@ -5476,45 +5475,53 @@ var __publicField = (obj, key, value) => {
|
|
|
5476
5475
|
throw err;
|
|
5477
5476
|
});
|
|
5478
5477
|
}
|
|
5479
|
-
|
|
5478
|
+
// TODO: payload does not require asset_type
|
|
5479
|
+
bulkAdd(assetsToCreate, workspaceId, assetTypeId, batchSize) {
|
|
5480
5480
|
const { store } = this.client;
|
|
5481
|
-
const
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5481
|
+
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5482
|
+
const assetBatches = chunkArray(assetsToCreate, batchSize).map((assetBatch) => {
|
|
5483
|
+
const assetPayloads = assetBatch.map((assetPayload) => {
|
|
5484
|
+
return offline({
|
|
5485
|
+
...assetPayload,
|
|
5486
|
+
submitted_at: submittedAt
|
|
5487
|
+
});
|
|
5488
|
+
});
|
|
5485
5489
|
return {
|
|
5486
5490
|
batchId: uuid.v4(),
|
|
5487
5491
|
payload: {
|
|
5488
|
-
assets:
|
|
5492
|
+
assets: assetPayloads
|
|
5489
5493
|
}
|
|
5490
5494
|
};
|
|
5491
5495
|
});
|
|
5492
|
-
|
|
5496
|
+
const batchPromises = [];
|
|
5493
5497
|
let prevBatchId = null;
|
|
5494
|
-
const
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
)
|
|
5517
|
-
|
|
5498
|
+
for (const assetBatch of assetBatches) {
|
|
5499
|
+
const { batchId, payload } = assetBatch;
|
|
5500
|
+
const batchAssetOfflineIds = payload.assets.map((c) => c.offline_id);
|
|
5501
|
+
const blockers = [assetTypeId];
|
|
5502
|
+
if (prevBatchId)
|
|
5503
|
+
blockers.push(prevBatchId);
|
|
5504
|
+
const blocks2 = batchAssetOfflineIds;
|
|
5505
|
+
blocks2.push(batchId);
|
|
5506
|
+
const promise = this.client.enqueueRequest({
|
|
5507
|
+
description: "Batch create assets",
|
|
5508
|
+
method: HttpMethod.POST,
|
|
5509
|
+
url: `/assets/types/${assetTypeId}/add-assets/`,
|
|
5510
|
+
queryParams: {
|
|
5511
|
+
workspace_id: workspaceId.toString()
|
|
5512
|
+
},
|
|
5513
|
+
payload,
|
|
5514
|
+
blockers,
|
|
5515
|
+
blocks: blocks2
|
|
5516
|
+
});
|
|
5517
|
+
prevBatchId = assetBatch.batchId;
|
|
5518
|
+
batchPromises.push(promise);
|
|
5519
|
+
}
|
|
5520
|
+
void Promise.all(batchPromises).then((result) => {
|
|
5521
|
+
const allCreatedAssets = result.flat();
|
|
5522
|
+
store.dispatch(addAssetsInBatches(allCreatedAssets));
|
|
5523
|
+
});
|
|
5524
|
+
return batchPromises;
|
|
5518
5525
|
}
|
|
5519
5526
|
async refreshStore() {
|
|
5520
5527
|
const { store } = this.client;
|
|
@@ -7300,7 +7307,6 @@ var __publicField = (obj, key, value) => {
|
|
|
7300
7307
|
}
|
|
7301
7308
|
return { values: newValues, files };
|
|
7302
7309
|
};
|
|
7303
|
-
const MAX_BULK_ADD_SUBMISSIONS = 1e3;
|
|
7304
7310
|
class UserFormSubmissionService extends BaseApiService {
|
|
7305
7311
|
constructor() {
|
|
7306
7312
|
super(...arguments);
|
|
@@ -7381,63 +7387,38 @@ var __publicField = (obj, key, value) => {
|
|
|
7381
7387
|
}
|
|
7382
7388
|
// Note currently the bulkAdd method is specific to form submissions for assets
|
|
7383
7389
|
// TODO: adapt the support bulk adding to any model type
|
|
7384
|
-
async bulkAdd(args) {
|
|
7385
|
-
const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
|
|
7390
|
+
async bulkAdd(args, batchSize) {
|
|
7386
7391
|
const { store } = this.client;
|
|
7387
|
-
const
|
|
7388
|
-
const offlineAttachments = [];
|
|
7389
|
-
const submissionOfflineIds = [];
|
|
7392
|
+
const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
|
|
7390
7393
|
const allFilesRecord = {};
|
|
7391
7394
|
const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
|
|
7392
7395
|
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7393
|
-
const
|
|
7394
|
-
const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), MAX_BULK_ADD_SUBMISSIONS);
|
|
7396
|
+
const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), batchSize);
|
|
7395
7397
|
const bulkAddBatches = await Promise.all(
|
|
7396
7398
|
assetIdBatches.map(async (assetIdBatch) => {
|
|
7397
7399
|
const batchId = uuid.v4();
|
|
7398
|
-
const
|
|
7399
|
-
const
|
|
7400
|
-
|
|
7400
|
+
const submissionPayloads = [];
|
|
7401
|
+
const attachmentPayloads = [];
|
|
7402
|
+
const files = { ...commonFiles };
|
|
7401
7403
|
for (const assetId of assetIdBatch) {
|
|
7402
7404
|
const { values: fileSeperatedSubmissionSpecificValues, files: submissionSpecificFiles } = separateFilesFromValues(fieldValuesByAsset[assetId] ?? {});
|
|
7403
|
-
|
|
7404
|
-
const
|
|
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,
|
|
7405
|
+
Object.assign(files, submissionSpecificFiles);
|
|
7406
|
+
const submissionPayload = offline({
|
|
7418
7407
|
asset_id: assetId,
|
|
7419
7408
|
form_data: fileSeperatedSubmissionSpecificValues
|
|
7420
7409
|
});
|
|
7421
|
-
|
|
7410
|
+
submissionPayloads.push(submissionPayload);
|
|
7422
7411
|
for (const [fieldIdentifier, fileArray] of Object.entries(files)) {
|
|
7423
7412
|
for (const file of fileArray) {
|
|
7424
7413
|
const sha1 = await hashFile(file);
|
|
7425
7414
|
await this.client.files.addCache(file, sha1);
|
|
7426
|
-
const
|
|
7427
|
-
|
|
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,
|
|
7415
|
+
const attachmentPayload = offline({
|
|
7416
|
+
submission_id: submissionPayload.offline_id,
|
|
7437
7417
|
sha1,
|
|
7438
7418
|
name: file.name,
|
|
7439
7419
|
field_identifier: fieldIdentifier
|
|
7440
7420
|
});
|
|
7421
|
+
attachmentPayloads.push(attachmentPayload);
|
|
7441
7422
|
}
|
|
7442
7423
|
}
|
|
7443
7424
|
}
|
|
@@ -7458,58 +7439,66 @@ var __publicField = (obj, key, value) => {
|
|
|
7458
7439
|
payload: {
|
|
7459
7440
|
form_data: fileSeperatedCommonFieldValues,
|
|
7460
7441
|
submitted_at: submittedAt,
|
|
7461
|
-
submissions:
|
|
7462
|
-
attachments:
|
|
7442
|
+
submissions: submissionPayloads,
|
|
7443
|
+
attachments: attachmentPayloads,
|
|
7463
7444
|
files: filePaylods
|
|
7464
7445
|
}
|
|
7465
7446
|
};
|
|
7466
7447
|
})
|
|
7467
7448
|
);
|
|
7468
|
-
|
|
7469
|
-
store.dispatch(addFormSubmissionAttachments(offlineAttachments));
|
|
7449
|
+
const batchPromises = [];
|
|
7470
7450
|
let prevBatchId = null;
|
|
7471
|
-
const
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
}
|
|
7504
|
-
}
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7451
|
+
for (const batch of bulkAddBatches) {
|
|
7452
|
+
const { payload, batchId } = batch;
|
|
7453
|
+
const batchAssetIds = payload.submissions.map((x) => x.asset_id);
|
|
7454
|
+
const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
|
|
7455
|
+
const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
|
|
7456
|
+
const blockers = batchAssetIds;
|
|
7457
|
+
if (prevBatchId)
|
|
7458
|
+
blockers.push(prevBatchId);
|
|
7459
|
+
const blocks2 = [...batchSubmissionOfflineIds, ...batchAttachmentsOfflineIds, batchId];
|
|
7460
|
+
const promise = this.client.enqueueRequest({
|
|
7461
|
+
description: "Bulk add form submissions",
|
|
7462
|
+
method: HttpMethod.POST,
|
|
7463
|
+
url: `/forms/revisions/${formRevision}/bulk-respond/`,
|
|
7464
|
+
payload,
|
|
7465
|
+
blockers,
|
|
7466
|
+
blocks: blocks2
|
|
7467
|
+
});
|
|
7468
|
+
void promise.then(({ presigned_urls }) => {
|
|
7469
|
+
for (const [sha1, presignedUrl] of Object.entries(presigned_urls)) {
|
|
7470
|
+
const file = allFilesRecord[sha1];
|
|
7471
|
+
if (!file)
|
|
7472
|
+
continue;
|
|
7473
|
+
void this.client.enqueueRequest({
|
|
7474
|
+
url: presignedUrl.url,
|
|
7475
|
+
description: "Upload file",
|
|
7476
|
+
method: HttpMethod.POST,
|
|
7477
|
+
isExternalUrl: true,
|
|
7478
|
+
isAuthNeeded: false,
|
|
7479
|
+
attachmentHash: sha1,
|
|
7480
|
+
blockers: [`s3-${file.sha1}.${file.extension}`],
|
|
7481
|
+
blocks: [sha1],
|
|
7482
|
+
s3url: presignedUrl
|
|
7483
|
+
});
|
|
7484
|
+
}
|
|
7485
|
+
});
|
|
7486
|
+
prevBatchId = batchId;
|
|
7487
|
+
batchPromises.push(promise);
|
|
7488
|
+
}
|
|
7489
|
+
void Promise.all(batchPromises).then((results) => {
|
|
7490
|
+
const createdSubmissions = [];
|
|
7491
|
+
const createdAttachments = [];
|
|
7492
|
+
for (const result of results) {
|
|
7493
|
+
for (const createdSubmission of result.submissions)
|
|
7494
|
+
createdSubmissions.push(createdSubmission);
|
|
7495
|
+
for (const createdAttachment of result.attachments)
|
|
7496
|
+
createdAttachments.push(createdAttachment);
|
|
7497
|
+
}
|
|
7498
|
+
store.dispatch(addFormSubmissions(createdSubmissions));
|
|
7499
|
+
store.dispatch(addFormSubmissionAttachments(createdAttachments));
|
|
7500
|
+
});
|
|
7501
|
+
return batchPromises;
|
|
7513
7502
|
}
|
|
7514
7503
|
update(submission) {
|
|
7515
7504
|
const { store } = this.client;
|
|
@@ -13123,10 +13112,7 @@ var __publicField = (obj, key, value) => {
|
|
|
13123
13112
|
helpText = showInputOnly ? null : helpText;
|
|
13124
13113
|
label = showInputOnly ? "" : label;
|
|
13125
13114
|
const color = blocks.useSeverityColor(severity);
|
|
13126
|
-
const value = React.useMemo(
|
|
13127
|
-
() => Array.isArray(fieldProps.value) ? fieldProps.value : [],
|
|
13128
|
-
[fieldProps.value]
|
|
13129
|
-
);
|
|
13115
|
+
const value = React.useMemo(() => Array.isArray(fieldProps.value) ? fieldProps.value : [], [fieldProps.value]);
|
|
13130
13116
|
const { onChange, onBlur } = fieldProps;
|
|
13131
13117
|
const droppableId = `${inputId}-droppable`;
|
|
13132
13118
|
const { disabled } = rest;
|
|
@@ -14942,39 +14928,37 @@ var __publicField = (obj, key, value) => {
|
|
|
14942
14928
|
meta: { readonly }
|
|
14943
14929
|
};
|
|
14944
14930
|
}
|
|
14945
|
-
function
|
|
14946
|
-
|
|
14931
|
+
function flattenFields(schema) {
|
|
14932
|
+
const allFields = [];
|
|
14947
14933
|
for (const field of schema.fields) {
|
|
14948
14934
|
if (field instanceof FieldSection) {
|
|
14949
|
-
|
|
14935
|
+
for (const subField of field.fields) {
|
|
14936
|
+
allFields.push(subField);
|
|
14937
|
+
}
|
|
14950
14938
|
} else {
|
|
14951
14939
|
if (!(field instanceof BaseField)) {
|
|
14952
|
-
throw new Error(
|
|
14940
|
+
throw new Error(`Invalid field type: ${field.type}`);
|
|
14953
14941
|
}
|
|
14954
14942
|
allFields.push(field);
|
|
14955
14943
|
}
|
|
14956
14944
|
}
|
|
14945
|
+
return allFields;
|
|
14946
|
+
}
|
|
14947
|
+
function decodeFormValues(schema, values) {
|
|
14948
|
+
const allFields = flattenFields(schema);
|
|
14957
14949
|
const result = {};
|
|
14958
14950
|
for (const field of allFields) {
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14951
|
+
const value = values[field.identifier] ?? null;
|
|
14952
|
+
if (value !== null) {
|
|
14953
|
+
result[field.identifier] = field.decodeJsonToValue(value);
|
|
14954
|
+
} else {
|
|
14955
|
+
result[field.identifier] = value;
|
|
14956
|
+
}
|
|
14963
14957
|
}
|
|
14964
14958
|
return result;
|
|
14965
14959
|
}
|
|
14966
14960
|
function encodeFormValues(schema, values) {
|
|
14967
|
-
|
|
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
|
-
}
|
|
14961
|
+
const allFields = flattenFields(schema);
|
|
14978
14962
|
const result = {};
|
|
14979
14963
|
for (const field of allFields) {
|
|
14980
14964
|
const value = values[field.identifier];
|
|
@@ -16777,6 +16761,7 @@ var __publicField = (obj, key, value) => {
|
|
|
16777
16761
|
emptyStringField,
|
|
16778
16762
|
emptyTextField,
|
|
16779
16763
|
encodeFormValues,
|
|
16764
|
+
flattenFields,
|
|
16780
16765
|
formRevisionToSchema,
|
|
16781
16766
|
initialFormValues,
|
|
16782
16767
|
isConditionMet,
|
|
@@ -17018,6 +17003,7 @@ var __publicField = (obj, key, value) => {
|
|
|
17018
17003
|
exports2.fileReducer = fileReducer;
|
|
17019
17004
|
exports2.fileSlice = fileSlice;
|
|
17020
17005
|
exports2.fileToBlob = fileToBlob;
|
|
17006
|
+
exports2.flattenFields = flattenFields;
|
|
17021
17007
|
exports2.flipCoordinates = flipCoordinates;
|
|
17022
17008
|
exports2.formReducer = formReducer;
|
|
17023
17009
|
exports2.formRevisionReducer = formRevisionReducer;
|