@anzusystems/common-admin 2.0.0-rc.28 → 2.0.0-rc.29
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/domains/dam/api/damAssetApi.d.ts +12 -1
- package/dist/domains/dam/api/damAssetApi.js +151 -95
- package/dist/domains/dam/api/damAssetApi.js.map +1 -1
- package/dist/domains/dam/api/damMetadataOnServer.d.ts +35 -0
- package/dist/domains/dam/api/damMetadataOnServer.js +28 -0
- package/dist/domains/dam/api/damMetadataOnServer.js.map +1 -0
- package/dist/domains/dam/assetDetail/components/AssetDetailSidebarMetadata.vue.js +26 -25
- package/dist/domains/dam/assetDetail/components/AssetDetailSidebarMetadata.vue.js.map +1 -1
- package/dist/domains/dam/assetDetail/store/assetDetailStore.js +40 -39
- package/dist/domains/dam/assetDetail/store/assetDetailStore.js.map +1 -1
- package/dist/domains/dam/cropper/components/ACropper.vue.d.ts +1 -1
- package/dist/domains/dam/cropper/components/ACropper.vue.js +153 -136
- package/dist/domains/dam/cropper/components/ACropper.vue.js.map +1 -1
- package/dist/domains/dam/imageWidget/components/AImageMediaWidget.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/AImagePublicInput.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/AImageWidget.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/AImageWidgetMultiple.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/ImageMediaWidgetInner.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/ImageWidgetInner.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/ImageWidgetMultipleInner.vue.d.ts +1 -1
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialog.vue.js +106 -106
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialog.vue.js.map +1 -1
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialogSingle.vue.js +13 -13
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialogSingle.vue.js.map +1 -1
- package/dist/domains/dam/uploadQueue/settlement/uploadSettle.js +115 -114
- package/dist/domains/dam/uploadQueue/settlement/uploadSettle.js.map +1 -1
- package/dist/domains/dam/uploadQueue/store/uploadQueuesStore.js +147 -143
- package/dist/domains/dam/uploadQueue/store/uploadQueuesStore.js.map +1 -1
- package/dist/domains/filters/components/FiltersSelected.vue.js +5 -5
- package/dist/domains/filters/components/FiltersSelected.vue.js.map +1 -1
- package/dist/domains/filters/composables/filterFactory.js +41 -38
- package/dist/domains/filters/composables/filterFactory.js.map +1 -1
- package/dist/domains/remoteAutocomplete/components/AFormRemoteAutocomplete.vue.js +46 -38
- package/dist/domains/remoteAutocomplete/components/AFormRemoteAutocomplete.vue.js.map +1 -1
- package/dist/domains/system/composables/alerts.js +8 -2
- package/dist/domains/system/composables/alerts.js.map +1 -1
- package/dist/domains/system/systemBar/utils/appReload.d.ts +9 -1
- package/dist/domains/system/systemBar/utils/appReload.js +3 -3
- package/dist/domains/system/systemBar/utils/appReload.js.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadSettle.js","names":["toRaw","DamAssetType","AssetFileFailReasonDefault","AssetFileProcessStatus","UploadQueueItemStatus","useAssetSuggestions","UploadRowRole","isArray","isNull","isObject","isUndefined","createUploadSettleMemory","isFinalFileStatus","status","resolveReadStatus","asset","target","intent","readStatus","clearRowError","row","isEmptyMetadataValue","value","mergeLoadedMetadata","queue","caches","updateNewNames","getAuthorConflicts","customData","key","authorSuggestions","decorateRow","mainFile","role","hadMetadata","markAsDuplicate","createUploadSettle","profile","memory","options","policyOf","concerns","queueKey","purpose","byConfiguration","names","name","namedQueues","cachesOf","ids","fetchNames","queueKeys","rows","all","isStopped","isLive","raw","item","isMarkedDuplicate","isDisposed","decorate","revisionOf","bump","mark","isStale","startedAt","startRead","trackStateOf","untrack","state","setRefreshMayHelp","mayHelp","noticeOf","notice","dropNotice","showsOwnText","syncNotice","clear","wants","text","loadMetadata","settleProcessed","wasFailed","settleFailed","failReason","settleKnownFailed","entry","settleProcessedByEvent","announceProcessed","duplicateRows","policy","eligible","markDuplicates","originFileId","assetType","marked","file","error","becomeOriginals","candidates","untouched","original","leftWithout","mightHelp","failsHere","settleDuplicate","targets","one","left","settleKnownDuplicate","tryLoadMetadata","applyAssetRead","duplicateSettled","maySettle","candidate","awaitsMetadata","withoutMetadata"],"sources":["../../../../../src/domains/dam/uploadQueue/settlement/uploadSettle.ts"],"sourcesContent":["import { toRaw } from 'vue'\nimport type { DocIdNullable } from '@/shared/types/common'\nimport { type AssetDetailItemDto, DamAssetType, type DamAssetTypeType } from '@/domains/dam/types/Asset'\nimport {\n type AssetFile,\n AssetFileFailReasonDefault,\n type AssetFileFailReasonType,\n type AssetFileNullable,\n AssetFileProcessStatus,\n type AssetFileProcessStatusType,\n} from '@/domains/dam/types/AssetFile'\nimport {\n type UploadQueue,\n type UploadQueueItem,\n UploadQueueItemStatus,\n type UploadQueueKey,\n} from '@/domains/dam/types/UploadQueue'\nimport { useAssetSuggestions } from '@/domains/dam/uploadQueue/composables/assetSuggestions'\nimport {\n UploadRowRole,\n type UploadRowRoleType,\n type UploadSettlementProfile,\n type UploadSettlementTarget,\n} from '@/domains/dam/uploadQueue/settlement/uploadSettlementTypes'\nimport { isArray, isNull, isObject, isUndefined } from '@/shared/utils/common'\n\nexport interface UploadTrackState {\n queueKey: UploadQueueKey\n /** When the row started waiting for the server, in scheduler time. */\n eligibleSince: number\n /** The client failed the row on its finish request. The server may still have finished the file. */\n clientFailed: boolean\n /** Consecutive successful reads that did not include the row's asset, or its file among the slots. */\n misses: number\n readFailures: number\n /**\n * A failed read or a missing asset was already reported, and no read has found the asset since.\n * Further failures are not reported.\n */\n reported: boolean\n}\n\nexport interface UploadRowNotice {\n /** The row has waited longer than processing should take. */\n slow: boolean\n readWarning: boolean\n /** Which of the two notices the settlement wrote into `row.error`. */\n shown: 'slow' | 'readWarning' | null\n /** The text written then. If the row's message differs now, the error belongs to someone else. */\n text: string | null\n}\n\n/** What a read should do for one target. */\nexport interface UploadReadIntent {\n /** State carried by the event. It applies when the read shows no final state. */\n hint: 'processed' | null\n /** When the row settles as processed, load its metadata as well. */\n metadata: boolean\n /** Set by the metadata notification. Metadata may arrive before the final state. */\n early: boolean\n /** The read tells a row with `settleOn: 'never'` that its file is processed. */\n seen: boolean\n}\n\n/** What the settlement remembers about rows. Every key is `toRaw(row)`. */\nexport interface UploadSettleMemory {\n tracked: WeakMap<UploadQueueItem, UploadTrackState>\n /** The last write an event made into the row. A read started before it is stale. Never cleared. */\n revision: WeakMap<UploadQueueItem, number>\n metadataLoaded: WeakSet<UploadQueueItem>\n /** Failed rows revived by an event. Their next read loads the metadata. */\n reviveWithMetadata: WeakSet<UploadQueueItem>\n /** Failed rows a refresh may still change: given up by the client, or left without their duplicate's original. */\n refreshMayHelp: WeakSet<UploadQueueItem>\n /** Rows failed because too many reads found no asset, while the server settles them by nothing else. */\n givenUpMissing: WeakSet<UploadQueueItem>\n notices: WeakMap<UploadQueueItem, UploadRowNotice>\n /** Shared counter for revisions and read starts. */\n clock: number\n}\n\nexport const createUploadSettleMemory = (): UploadSettleMemory => ({\n tracked: new WeakMap(),\n revision: new WeakMap(),\n metadataLoaded: new WeakSet(),\n reviveWithMetadata: new WeakSet(),\n refreshMayHelp: new WeakSet(),\n givenUpMissing: new WeakSet(),\n notices: new WeakMap(),\n clock: 0,\n})\n\nexport interface UploadSettleRow {\n queueKey: UploadQueueKey\n queue: UploadQueue\n row: UploadQueueItem\n}\n\nexport interface UploadSettleOptions {\n /** A row stopped being tracked, by a settlement write or by the store. */\n onUntrack?(queueKey: UploadQueueKey): void\n /** The settlement was disposed. Results of an original read that arrive later are not written. */\n isDisposed?(): boolean\n}\n\nexport const isFinalFileStatus = (\n status: AssetFileProcessStatusType | null | undefined\n): status is 'processed' | 'duplicate' | 'failed' =>\n status === AssetFileProcessStatus.Processed ||\n status === AssetFileProcessStatus.Duplicate ||\n status === AssetFileProcessStatus.Failed\n\n/**\n * The file state a read gives the target.\n * An asset reports only its main file state. A final state from the asset wins, otherwise the event state applies.\n * For another file (a slot) the asset says nothing, so only the event state applies.\n */\nexport const resolveReadStatus = (\n asset: AssetDetailItemDto,\n target: Pick<UploadSettlementTarget, 'fileId'>,\n intent: Pick<UploadReadIntent, 'hint'>\n): AssetFileProcessStatusType | undefined => {\n if (!isNull(target.fileId) && target.fileId !== asset.mainFile?.id) return intent.hint ?? undefined\n const readStatus = asset.mainFile?.fileAttributes?.status\n return isFinalFileStatus(readStatus) ? readStatus : (intent.hint ?? readStatus)\n}\n\nexport const clearRowError = (row: UploadQueueItem) => {\n row.error = { hasError: false, message: '', assetFileFailReason: AssetFileFailReasonDefault }\n}\n\n// \"Empty\" as the queue's mass operations define it.\nexport const isEmptyMetadataValue = (value: unknown) =>\n isUndefined(value) || isNull(value) || value === '' || (isArray(value) && !value.length)\n\n/**\n * First metadata load of a row. Values the user set earlier (via a queue mass operation) stay.\n * Only empty lists and empty custom fields are filled.\n */\nexport function mergeLoadedMetadata(\n queue: UploadQueue,\n row: UploadQueueItem,\n asset: AssetDetailItemDto,\n caches: Pick<UploadSettlementProfile['caches'], 'addAuthors' | 'addKeywords'>\n) {\n const { updateNewNames, getAuthorConflicts } = useAssetSuggestions()\n if (isEmptyMetadataValue(row.keywords)) row.keywords = [...(asset.keywords ?? [])]\n if (isEmptyMetadataValue(row.authors)) row.authors = [...(asset.authors ?? [])]\n if (isEmptyMetadataValue(row.sources)) row.sources = [...(asset.sources ?? [])]\n const customData: Record<string, unknown> = isObject(asset.metadata.customData)\n ? { ...asset.metadata.customData }\n : {}\n if (isObject(row.customData)) {\n for (const [key, value] of Object.entries(row.customData)) {\n if (!isEmptyMetadataValue(value)) customData[key] = value\n }\n }\n row.customData = customData\n // Not mass-operation fields. These come from the server.\n row.mainFileSingleUse = asset.mainFileSingleUse\n row.mainFileInternal = asset.mainFileInternal\n const authorSuggestions = asset.metadata.authorSuggestions ?? {}\n updateNewNames(authorSuggestions, queue.suggestions.newAuthorNames)\n updateNewNames(asset.metadata.keywordSuggestions ?? {}, queue.suggestions.newKeywordNames)\n row.authorConflicts = getAuthorConflicts(authorSuggestions)\n caches.addKeywords(row.keywords)\n caches.addAuthors([...row.authors, ...(row.sources ?? [])])\n caches.addAuthors(row.authorConflicts)\n}\n\n/**\n * Applies a read asset to a row without changing its state.\n * `hadMetadata`: the row's metadata was loaded once, whether or not the form is shown now.\n */\nexport function decorateRow(\n row: UploadQueueItem,\n asset: AssetDetailItemDto,\n mainFile: AssetFile,\n role: UploadRowRoleType,\n hadMetadata: boolean\n) {\n row.assetStatus = asset.attributes.assetStatus\n // Only for the main-file row. A slot row would get a preview of another file.\n if (!isNull(row.fileId) && row.fileId !== mainFile.id) return\n if (mainFile.links?.image_detail) row.imagePreview = mainFile.links.image_detail\n // Skip mass-edit rows and rows that have or had metadata. There these switches are form fields the user may have set.\n // This includes a row that lost its form on failure and gets it back.\n if (!row.canEditMetadata && !hadMetadata && role !== UploadRowRole.MassEdit) {\n row.mainFileSingleUse = asset.mainFileSingleUse\n row.mainFileInternal = asset.mainFileInternal\n }\n}\n\n// Both duplicate policies mark the row through here.\nconst markAsDuplicate = (row: UploadQueueItem) => {\n row.isDuplicate = true\n // Set once, before anything can overwrite `assetId` with the original.\n row.uploadedAssetId ??= row.assetId\n}\n\n/**\n * Settlement writes: a read asset or a known state into queue rows.\n * No timers and no reads of its own, except reading a duplicate's original.\n */\nexport function createUploadSettle(\n profile: UploadSettlementProfile,\n memory: UploadSettleMemory = createUploadSettleMemory(),\n options: UploadSettleOptions = {}\n) {\n const policyOf = (row: UploadQueueItem) => profile.policyFor(profile.roleOf(row))\n\n /**\n * Whether the target concerns a row of queue `queueKey`, by the profile's `matches`.\n * When the profile provides `configOf`, only queues of a configuration the target names match.\n */\n const concerns = (\n queueKey: UploadQueueKey,\n row: UploadQueueItem,\n target: UploadSettlementTarget,\n purpose: 'settle' | 'decorate' | 'metadata'\n ) =>\n (!profile.configOf || !target.configNames?.length || target.configNames.includes(profile.configOf(queueKey))) &&\n profile.matches(row, target, purpose)\n\n /**\n * Splits the target per named configuration when it names several and the profile provides `configOf`.\n * Each copy is read separately, by a queue of that configuration, and written only into its rows.\n * Otherwise returns the target itself.\n */\n const byConfiguration = (target: UploadSettlementTarget): UploadSettlementTarget[] => {\n const names = profile.configOf ? [...new Set(target.configNames ?? [])] : []\n return names.length > 1 ? names.map((name) => ({ ...target, configNames: [name] })) : [target]\n }\n\n // Queues whose rows got names since the caches last fetched.\n const namedQueues = new Set<UploadQueueKey>()\n /** Where the row names go. A profile with `configOf` is given the queue key, one without is not. */\n const cachesOf = (\n queueKey: UploadQueueKey\n ): Pick<UploadSettlementProfile['caches'], 'addAuthors' | 'addKeywords'> => {\n namedQueues.add(queueKey)\n if (!profile.configOf) {\n return {\n addAuthors: (ids) => profile.caches.addAuthors(ids),\n addKeywords: (ids) => profile.caches.addKeywords(ids),\n }\n }\n return {\n addAuthors: (ids) => profile.caches.addAuthors(ids, queueKey),\n addKeywords: (ids) => profile.caches.addKeywords(ids, queueKey),\n }\n }\n /** Fetches caches for each queue that got names, or once without a queue for a profile without `configOf`. */\n const fetchNames = () => {\n const queueKeys = [...namedQueues]\n namedQueues.clear()\n if (!profile.configOf) {\n profile.caches.fetchAuthors()\n profile.caches.fetchKeywords()\n return\n }\n for (const queueKey of queueKeys) {\n profile.caches.fetchAuthors(queueKey)\n profile.caches.fetchKeywords(queueKey)\n }\n }\n\n /** All queue rows at this moment. */\n const rows = (): UploadSettleRow[] => {\n const all: UploadSettleRow[] = []\n for (const [queueKey, queue] of profile.queues()) {\n for (const row of queue.items) all.push({ queueKey, queue, row })\n }\n return all\n }\n\n // Nothing writes into a stopped row. Check again after every await: the row may have been stopped meanwhile.\n const isStopped = (row: UploadQueueItem) => row.status === UploadQueueItemStatus.Stop\n\n const isLive = (row: UploadQueueItem) => {\n const raw = toRaw(row)\n for (const [, queue] of profile.queues()) {\n if (toRaw(queue.items).some((item) => toRaw(item) === raw)) return true\n }\n return false\n }\n\n // A row marked as a duplicate is settled and read-only.\n // A row that became its original is a normal editable row.\n const isMarkedDuplicate = (row: UploadQueueItem) => row.isDuplicate && policyOf(row).duplicate === 'markDuplicate'\n const isDisposed = () => options.isDisposed?.() === true\n\n const decorate = (row: UploadQueueItem, asset: AssetDetailItemDto, mainFile: AssetFile) =>\n decorateRow(row, asset, mainFile, profile.roleOf(row), memory.metadataLoaded.has(toRaw(row)))\n\n const revisionOf = (row: UploadQueueItem) => memory.revision.get(toRaw(row)) ?? 0\n /** An event wrote into the row. Reads started before this are stale for it. */\n const bump = (row: UploadQueueItem) => {\n const mark = ++memory.clock\n memory.revision.set(toRaw(row), mark)\n return mark\n }\n const isStale = (row: UploadQueueItem, startedAt: number) => startedAt <= revisionOf(row)\n /** Mark of a read starting now. */\n const startRead = () => ++memory.clock\n\n const trackStateOf = (row: UploadQueueItem) => memory.tracked.get(toRaw(row))\n const untrack = (row: UploadQueueItem) => {\n const raw = toRaw(row)\n const state = memory.tracked.get(raw)\n if (!state) return\n memory.tracked.delete(raw)\n options.onUntrack?.(state.queueKey)\n }\n\n /** Whether a refresh may still change a failed row. The store is notified on change. */\n const setRefreshMayHelp = (queueKey: UploadQueueKey, row: UploadQueueItem, mayHelp: boolean) => {\n const raw = toRaw(row)\n if (memory.refreshMayHelp.has(raw) === mayHelp) return\n if (mayHelp) memory.refreshMayHelp.add(raw)\n else memory.refreshMayHelp.delete(raw)\n profile.hooks.onRefreshMayHelp?.(queueKey, row, mayHelp)\n }\n\n const noticeOf = (row: UploadQueueItem) => {\n const raw = toRaw(row)\n let notice = memory.notices.get(raw)\n if (!notice) {\n notice = { slow: false, readWarning: false, shown: null, text: null }\n memory.notices.set(raw, notice)\n }\n return notice\n }\n const dropNotice = (row: UploadQueueItem) => memory.notices.delete(toRaw(row))\n // Whether the row message is still the text the settlement wrote.\n // The store also writes `row.error` (failed upload), and the settlement must not clear that error.\n const showsOwnText = (row: UploadQueueItem) => {\n const notice = memory.notices.get(toRaw(row))\n return !!notice?.shown && row.error.message === notice.text\n }\n\n /**\n * Writes the applicable settlement text into `row.error`, or removes its own text.\n * Only its own text, and only while the row still shows it.\n * `clear` also removes an error the settlement did not write, because the row settled as processed.\n */\n const syncNotice = (row: UploadQueueItem, { clear = false }: { clear?: boolean } = {}) => {\n const notice = noticeOf(row)\n let wants: UploadRowNotice['shown'] = null\n if (\n notice.readWarning &&\n policyOf(row).metadata === 'load' &&\n !row.canEditMetadata &&\n !isMarkedDuplicate(row) &&\n row.status !== UploadQueueItemStatus.Failed\n ) {\n wants = 'readWarning'\n } else if (notice.slow && row.status === UploadQueueItemStatus.Processing) {\n wants = 'slow'\n }\n if (wants) {\n const text = wants === 'slow' ? profile.messages.processingTooLong(row) : profile.messages.readFailed(row)\n row.error.hasError = true\n row.error.message = text\n notice.shown = wants\n notice.text = text\n return\n }\n if (clear) {\n clearRowError(row)\n } else if (showsOwnText(row)) {\n // Remove the text. Also clear the flag, unless the row has failed since. Then the flag belongs to the failure.\n if (row.status === UploadQueueItemStatus.Failed) row.error = { ...row.error, message: '' }\n else clearRowError(row)\n }\n notice.shown = null\n notice.text = null\n }\n\n const loadMetadata = (\n { queueKey, queue, row }: Pick<UploadSettleRow, 'queueKey' | 'queue' | 'row'>,\n asset: AssetDetailItemDto\n ) => {\n mergeLoadedMetadata(queue, row, asset, cachesOf(queueKey))\n memory.metadataLoaded.add(toRaw(row))\n }\n\n const settleProcessed = (\n { queueKey, queue, row }: UploadSettleRow,\n asset: AssetDetailItemDto,\n mainFile: AssetFile,\n intent: UploadReadIntent\n ) => {\n const raw = toRaw(row)\n // The client marks an upload failed when one of its requests fails, but the server may still finish it.\n // Such a row lost its form on failure and gets it back here, with its metadata.\n const wasFailed = row.status === UploadQueueItemStatus.Failed || memory.reviveWithMetadata.has(raw)\n row.status = UploadQueueItemStatus.Uploaded\n // A licence copy knows only its asset. The image is built from the file id.\n if (isNull(row.fileId)) row.fileId = mainFile.id\n decorate(row, asset, mainFile)\n const notice = noticeOf(row)\n if (policyOf(row).metadata === 'load' && !isMarkedDuplicate(row) && (intent.metadata || wasFailed)) {\n // Loaded once, and never into a row with the form shown, so user input is kept.\n if (!row.canEditMetadata && !memory.metadataLoaded.has(raw)) loadMetadata({ queueKey, queue, row }, asset)\n row.canEditMetadata = true\n notice.readWarning = false\n profile.hooks.afterMetadataLoaded?.(queueKey, row)\n }\n memory.reviveWithMetadata.delete(raw)\n memory.givenUpMissing.delete(raw)\n notice.slow = false\n syncNotice(row, { clear: true })\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n\n const settleFailed = (\n { queueKey, row }: Pick<UploadSettleRow, 'queueKey' | 'row'>,\n failReason: AssetFileFailReasonType\n ) => {\n row.status = UploadQueueItemStatus.Failed\n // Drop the old text. The row shows a message for the reason, and the old text is not the cause.\n row.error = { hasError: true, message: '', assetFileFailReason: failReason }\n row.canEditMetadata = false\n dropNotice(row)\n memory.reviveWithMetadata.delete(toRaw(row))\n memory.givenUpMissing.delete(toRaw(row))\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n\n /** A failure known by the caller, without a read. */\n const settleKnownFailed = (target: UploadSettlementTarget, failReason: AssetFileFailReasonType) => {\n for (const entry of rows()) {\n if (entry.row.status === UploadQueueItemStatus.Stop || !concerns(entry.queueKey, entry.row, target, 'settle')) {\n continue\n }\n settleFailed(entry, failReason)\n bump(entry.row)\n }\n }\n\n /**\n * Applies a `processed` event immediately to rows that settle on the event.\n * A tick also uses it for a slot row whose file the slot list shows processed.\n */\n const settleProcessedByEvent = (target: UploadSettlementTarget) => {\n for (const { queueKey, row } of rows()) {\n if (row.status === UploadQueueItemStatus.Stop || policyOf(row).settleOn !== 'event') continue\n if (!concerns(queueKey, row, target, 'settle')) continue\n const raw = toRaw(row)\n if (row.status === UploadQueueItemStatus.Failed) memory.reviveWithMetadata.add(raw)\n memory.givenUpMissing.delete(raw)\n row.status = UploadQueueItemStatus.Uploaded\n // A row the client gave up on that already had metadata gets its form back as the user left it.\n if (!isMarkedDuplicate(row) && memory.metadataLoaded.has(raw)) row.canEditMetadata = true\n noticeOf(row).slow = false\n syncNotice(row, { clear: true })\n bump(row)\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n }\n\n /** Handles a `processed` event for rows whose state it does not change. */\n const announceProcessed = (target: UploadSettlementTarget) => {\n for (const { queueKey, row } of rows()) {\n if (row.status === UploadQueueItemStatus.Stop || policyOf(row).settleOn !== 'never') continue\n if (concerns(queueKey, row, target, 'decorate')) profile.hooks.onProcessedSeen?.(queueKey, row)\n }\n }\n\n const duplicateRows = (\n target: UploadSettlementTarget,\n policy: 'becomeOriginal' | 'markDuplicate',\n eligible: (row: UploadQueueItem) => boolean\n ) =>\n rows().filter(\n ({ queueKey, row }) =>\n row.status !== UploadQueueItemStatus.Stop &&\n eligible(row) &&\n policyOf(row).duplicate === policy &&\n concerns(queueKey, row, target, 'settle')\n )\n\n // The row stays and is marked. It is settled first and completed from the original file later.\n // This way the wait for that file does not hold an upload slot.\n const markDuplicates = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null,\n eligible: (row: UploadQueueItem) => boolean\n ) => {\n const marked: Array<{ row: UploadQueueItem; mark: number }> = []\n for (const { queueKey, row } of duplicateRows(target, 'markDuplicate', eligible)) {\n markAsDuplicate(row)\n row.status = UploadQueueItemStatus.Uploaded\n row.canEditMetadata = false\n clearRowError(row)\n dropNotice(row)\n memory.reviveWithMetadata.delete(toRaw(row))\n memory.givenUpMissing.delete(toRaw(row))\n marked.push({ row, mark: bump(row) })\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n if (!marked.length || !originFileId || !assetType || !profile.readers.duplicateOriginFile) return\n let file: AssetFileNullable = null\n try {\n file = await profile.readers.duplicateOriginFile(originFileId, assetType)\n } catch (error) {\n console.error('uploadQueue: the duplicated file could not be read', error)\n }\n if (!file || isDisposed()) return\n for (const { row, mark } of marked) {\n // Only rows still present and not written into meanwhile.\n if (!isLive(row) || row.status === UploadQueueItemStatus.Stop || !row.isDuplicate) continue\n if (revisionOf(row) !== mark) continue\n row.fileId = file.id\n row.duplicateAssetId = file.asset\n row.mainFileSingleUse = file.flags.singleUse\n if (file.links?.image_detail) row.imagePreview = file.links.image_detail\n }\n }\n\n // The row becomes the original: its asset and file are replaced and it takes the original's metadata.\n // Returns whether the original could not be read and a row remains that a refresh may still help.\n const becomeOriginals = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null,\n eligible: (row: UploadQueueItem) => boolean\n ): Promise<boolean> => {\n if (!originFileId || assetType !== DamAssetType.Image) return false\n // Recorded before requesting the original. After the await, only rows still in\n // their queue, not stopped and not written by an event meanwhile are written.\n // The caller that reports a duplicate is outside the read\n // ordering, so an earlier answer must not undo a later event.\n const candidates = duplicateRows(target, 'becomeOriginal', eligible).map((entry) => ({\n ...entry,\n mark: revisionOf(entry.row),\n }))\n if (!candidates.length) return false\n const untouched = () =>\n candidates.filter(({ row, mark }) => isLive(row) && !isStopped(row) && revisionOf(row) === mark)\n const { updateNewNames, getAuthorConflicts } = useAssetSuggestions()\n let original: AssetDetailItemDto\n try {\n if (!profile.readers.duplicateOriginAsset) throw new Error('uploadSettlement: no reader of the original asset')\n original = await profile.readers.duplicateOriginAsset(originFileId, { queueKey: candidates[0]!.queueKey })\n } catch {\n if (isDisposed()) return false\n let leftWithout = false\n for (const { queueKey, row } of untouched()) {\n // Read before untracking, so a row the client gave up on keeps its way back.\n const mightHelp = memory.refreshMayHelp.has(toRaw(row))\n // Untrack regardless of state. The next tick would only retry the same read.\n untrack(row)\n // Only a row still waiting for this answer fails: a settled one must not be flipped back to failed.\n const failsHere = row.status === UploadQueueItemStatus.Processing\n if (failsHere) {\n row.status = UploadQueueItemStatus.Failed\n // Drop a text the settlement wrote. It no longer describes what is wrong with the row.\n row.error = { ...row.error, hasError: true, message: showsOwnText(row) ? '' : row.error.message }\n row.canEditMetadata = false\n dropNotice(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n // Failed because a read failed, not the file. A row refresh requests the original again.\n // Not for a row the server had already failed, which no refresh can undo.\n if (failsHere || mightHelp) {\n setRefreshMayHelp(queueKey, row, true)\n leftWithout = true\n }\n }\n return leftWithout\n }\n if (isDisposed()) return false\n for (const { queueKey, queue, row } of untouched()) {\n const authorSuggestions = original.metadata.authorSuggestions ?? {}\n markAsDuplicate(row)\n row.status = UploadQueueItemStatus.Uploaded\n clearRowError(row)\n row.fileId = originFileId\n row.duplicateAssetId = original.id\n row.assetStatus = original.attributes.assetStatus\n if (original.mainFile?.links?.image_detail) row.imagePreview = original.mainFile.links.image_detail\n row.keywords = [...(original.keywords ?? [])]\n row.authors = [...(original.authors ?? [])]\n row.sources = [...(original.sources ?? [])]\n row.customData = isObject(original.metadata.customData) ? { ...original.metadata.customData } : {}\n updateNewNames(authorSuggestions, queue.suggestions.newAuthorNames)\n updateNewNames(original.metadata.keywordSuggestions ?? {}, queue.suggestions.newKeywordNames)\n row.authorConflicts = getAuthorConflicts(authorSuggestions)\n const caches = cachesOf(queueKey)\n caches.addKeywords(row.keywords)\n caches.addAuthors([...row.authors, ...(row.sources ?? [])])\n caches.addAuthors(row.authorConflicts)\n row.assetId = original.id\n row.mainFileSingleUse = original.mainFileSingleUse\n row.mainFileInternal = original.mainFileInternal\n memory.metadataLoaded.add(toRaw(row))\n row.canEditMetadata = true\n dropNotice(row)\n memory.reviveWithMetadata.delete(toRaw(row))\n memory.givenUpMissing.delete(toRaw(row))\n bump(row)\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n fetchNames()\n return false\n }\n\n /**\n * Handles a duplicate file for every row passing `matches(…, 'settle')`, by the policy of its role.\n * `eligible` excludes rows the read is stale for.\n * Returns whether a row is left without its duplicate's original\n * because it could not be read. A refresh may still help it.\n */\n const settleDuplicate = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null,\n eligible: (row: UploadQueueItem) => boolean = () => true\n ) => {\n // Both start at once, not one after the other, so each records its rows now.\n // The original is read once per configuration the target names, by a queue of that configuration.\n const targets = byConfiguration(target)\n const [, leftWithout] = await Promise.all([\n markDuplicates(target, originFileId, assetType, eligible),\n targets.length === 1\n ? becomeOriginals(target, originFileId, assetType, eligible)\n : Promise.all(targets.map((one) => becomeOriginals(one, originFileId, assetType, eligible))).then((left) =>\n left.some(Boolean)\n ),\n ])\n return leftWithout\n }\n\n /** A duplicate known by the caller, without reading its asset. Never rejects. */\n const settleKnownDuplicate = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null\n ) => {\n try {\n await settleDuplicate(target, originFileId, assetType)\n } catch (error) {\n console.error('uploadQueue: the duplicate could not be settled', error)\n }\n }\n\n /** Metadata notification: loads the metadata and the form, regardless of the file state. */\n const tryLoadMetadata = ({ queueKey, queue, row }: UploadSettleRow, asset: AssetDetailItemDto) => {\n if (policyOf(row).metadata !== 'load' || row.canEditMetadata) return\n // A marked duplicate is settled and has no metadata of its own to load.\n if (isMarkedDuplicate(row)) return\n // Skip a row whose file failed, except one that failed for lack of this metadata.\n if (row.status === UploadQueueItemStatus.Failed && profile.metadataGate?.(queueKey, row) !== 'load') return\n if (!memory.metadataLoaded.has(toRaw(row))) loadMetadata({ queueKey, queue, row }, asset)\n row.canEditMetadata = true\n noticeOf(row).readWarning = false\n syncNotice(row)\n profile.hooks.afterMetadataLoaded?.(queueKey, row)\n }\n\n /**\n * Applies one read asset to every row it concerns. `startedAt` is the read mark.\n * A row written by an event since keeps the event's state.\n * Returns like `settleDuplicate`: whether a row is left without its duplicate's original.\n */\n const applyAssetRead = async (\n asset: AssetDetailItemDto,\n target: UploadSettlementTarget,\n intent: UploadReadIntent,\n startedAt: number\n ) => {\n const mainFile = asset.mainFile ?? null\n const status = resolveReadStatus(asset, target, intent)\n let duplicateSettled = false\n let leftWithout = false\n for (const entry of rows()) {\n const { queueKey, row } = entry\n // The duplicate's original read was awaited. The row may have left its queue meanwhile.\n if (duplicateSettled && !isLive(row)) continue\n if (isStopped(row)) continue\n\n // Apply the file state and row details unless an event wrote\n // into the row after this read started. The event is newer.\n if (!isStale(row, startedAt) && mainFile && concerns(queueKey, row, target, 'decorate')) {\n const maySettle = concerns(queueKey, row, target, 'settle')\n if (status === AssetFileProcessStatus.Processed) {\n if (policyOf(row).settleOn === 'never') {\n decorate(row, asset, mainFile)\n if (intent.seen) profile.hooks.onProcessedSeen?.(queueKey, row)\n } else if (maySettle) {\n settleProcessed(entry, asset, mainFile, intent)\n }\n } else if (status === AssetFileProcessStatus.Duplicate && maySettle) {\n // Once for all rows of the target. The original is read only once.\n if (!duplicateSettled) {\n duplicateSettled = true\n leftWithout = await settleDuplicate(\n target,\n mainFile.originAssetFile,\n asset.attributes.assetType,\n (candidate) => !isStale(candidate, startedAt)\n )\n if (isDisposed()) return leftWithout\n if (!isLive(row) || isStopped(row)) continue\n }\n } else if (status === AssetFileProcessStatus.Failed && maySettle) {\n settleFailed(entry, mainFile.fileAttributes.failReason)\n }\n }\n\n // Applied to such a row as well, because metadata is not file state. It loads once, whenever it arrives.\n // Rows the event failed or marked as duplicate are refused there.\n // Otherwise a `processed` event that overtakes the metadata read would leave the row uploaded without its form.\n if (intent.early && concerns(queueKey, row, target, 'metadata')) tryLoadMetadata(entry, asset)\n }\n profile.hooks.onAssetRead?.(asset)\n return leftWithout\n }\n\n /**\n * An uploaded row without its metadata, which a refresh would load.\n * It is no longer tracked, but reads that find no asset are still counted for it.\n */\n const awaitsMetadata = (row: UploadQueueItem) =>\n row.status === UploadQueueItemStatus.Uploaded &&\n !row.canEditMetadata &&\n policyOf(row).metadata === 'load' &&\n !isMarkedDuplicate(row)\n\n /**\n * The row's asset was missing from enough reads, for a tracked row or one a refresh may still help.\n * A processing row fails. An uploaded row without metadata fails with `assetGone`.\n * Any other row (given up by the client, or left without its duplicate's original) is left alone.\n */\n const giveUpOnMissing = ({ queueKey, row }: Pick<UploadSettleRow, 'queueKey' | 'row'>) => {\n // There is no asset a refresh could read.\n setRefreshMayHelp(queueKey, row, false)\n const withoutMetadata = awaitsMetadata(row)\n if (row.status !== UploadQueueItemStatus.Processing && !withoutMetadata) {\n untrack(row)\n return\n }\n row.status = UploadQueueItemStatus.Failed\n row.error.hasError = true\n row.error.message = withoutMetadata\n ? (profile.messages.assetGone?.(row) ?? profile.messages.assetMissing(row))\n : profile.messages.assetMissing(row)\n row.canEditMetadata = false\n memory.givenUpMissing.add(toRaw(row))\n dropNotice(row)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n\n return {\n memory,\n policyOf,\n concerns,\n byConfiguration,\n fetchNames,\n rows,\n isLive,\n bump,\n isStale,\n startRead,\n trackStateOf,\n untrack,\n setRefreshMayHelp,\n noticeOf,\n syncNotice,\n applyAssetRead,\n settleProcessedByEvent,\n announceProcessed,\n settleFailed,\n settleKnownFailed,\n settleDuplicate,\n settleKnownDuplicate,\n awaitsMetadata,\n giveUpOnMissing,\n }\n}\n\nexport type UploadSettle = ReturnType<typeof createUploadSettle>\n"],"mappings":";;;;;;;;AAiFA,IAAaW,WAAsD;CACjE,yBAAS,IAAI,QAAQ;CACrB,0BAAU,IAAI,QAAQ;CACtB,gCAAgB,IAAI,QAAQ;CAC5B,oCAAoB,IAAI,QAAQ;CAChC,gCAAgB,IAAI,QAAQ;CAC5B,gCAAgB,IAAI,QAAQ;CAC5B,yBAAS,IAAI,QAAQ;CACrB,OAAO;AACT,IAeaC,KACXC,MAEAA,MAAWV,EAAuB,aAClCU,MAAWV,EAAuB,aAClCU,MAAWV,EAAuB,QAOvBW,KACXC,GACAC,GACAC,MAC2C;CAC3C,IAAI,CAACT,EA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AI;EACAmC;EACAxB;EACAC;EACAL;EACAE;EACAoB;EACAI;EACAM;EACA,kBA5CuB,EAAEzE,aAAUtB,aAAqD;GAExFkD,EAAkB5B,GAAUtB,GAAK,EAAK;GACtC,IAAMgG,IAAkBD,EAAe/F,CAAG;GACtCA,EAAI,WAAWhB,EAAsB,cAAc,CAACgH,IACtDhD,EAAQhD,CAAG,KAGbA,EAAI,SAAShB,EAAsB,QACnCgB,EAAI,MAAM,WAAW,IACrBA,EAAI,MAAM,UAAUgG,IACf/E,EAAQ,SAAS,YAAYjB,CAAG,KAAKiB,EAAQ,SAAS,aAAajB,CAAG,IACvEiB,EAAQ,SAAS,aAAajB,CAAG,GACrCA,EAAI,kBAAkB,IACtBkB,EAAO,eAAe,IAAItC,EAAMoB,CAAG,CAAC,GACpCsD,EAAWtD,CAAG,GACdgD,EAAQhD,CAAG,GACXiB,EAAQ,MAAM,WAAWK,GAAUtB,CAAG;EACxC;CA2BA;AACF"}
|
|
1
|
+
{"version":3,"file":"uploadSettle.js","names":["toRaw","DamAssetType","AssetFileFailReasonDefault","AssetFileProcessStatus","UploadQueueItemStatus","useAssetSuggestions","UploadRowRole","isArray","isNull","isObject","isUndefined","metadataOfAsset","setMetadataOnServer","createUploadSettleMemory","isFinalFileStatus","status","resolveReadStatus","asset","target","intent","readStatus","clearRowError","row","isEmptyMetadataValue","value","mergeLoadedMetadata","queue","caches","updateNewNames","getAuthorConflicts","customData","key","authorSuggestions","decorateRow","mainFile","role","hadMetadata","markAsDuplicate","createUploadSettle","profile","memory","options","policyOf","concerns","queueKey","purpose","byConfiguration","names","name","namedQueues","cachesOf","ids","fetchNames","queueKeys","rows","all","isStopped","isLive","raw","item","isMarkedDuplicate","isDisposed","decorate","revisionOf","bump","mark","isStale","startedAt","startRead","trackStateOf","untrack","state","setRefreshMayHelp","mayHelp","noticeOf","notice","dropNotice","showsOwnText","syncNotice","clear","wants","text","loadMetadata","settleProcessed","wasFailed","settleFailed","failReason","settleKnownFailed","entry","settleProcessedByEvent","announceProcessed","duplicateRows","policy","eligible","markDuplicates","originFileId","assetType","marked","file","error","becomeOriginals","candidates","untouched","original","leftWithout","mightHelp","failsHere","settleDuplicate","targets","one","left","settleKnownDuplicate","tryLoadMetadata","applyAssetRead","duplicateSettled","maySettle","candidate","awaitsMetadata","withoutMetadata"],"sources":["../../../../../src/domains/dam/uploadQueue/settlement/uploadSettle.ts"],"sourcesContent":["import { toRaw } from 'vue'\nimport type { DocIdNullable } from '@/shared/types/common'\nimport { type AssetDetailItemDto, DamAssetType, type DamAssetTypeType } from '@/domains/dam/types/Asset'\nimport {\n type AssetFile,\n AssetFileFailReasonDefault,\n type AssetFileFailReasonType,\n type AssetFileNullable,\n AssetFileProcessStatus,\n type AssetFileProcessStatusType,\n} from '@/domains/dam/types/AssetFile'\nimport {\n type UploadQueue,\n type UploadQueueItem,\n UploadQueueItemStatus,\n type UploadQueueKey,\n} from '@/domains/dam/types/UploadQueue'\nimport { useAssetSuggestions } from '@/domains/dam/uploadQueue/composables/assetSuggestions'\nimport {\n UploadRowRole,\n type UploadRowRoleType,\n type UploadSettlementProfile,\n type UploadSettlementTarget,\n} from '@/domains/dam/uploadQueue/settlement/uploadSettlementTypes'\nimport { isArray, isNull, isObject, isUndefined } from '@/shared/utils/common'\nimport { metadataOfAsset, setMetadataOnServer } from '@/domains/dam/api/damMetadataOnServer'\n\nexport interface UploadTrackState {\n queueKey: UploadQueueKey\n /** When the row started waiting for the server, in scheduler time. */\n eligibleSince: number\n /** The client failed the row on its finish request. The server may still have finished the file. */\n clientFailed: boolean\n /** Consecutive successful reads that did not include the row's asset, or its file among the slots. */\n misses: number\n readFailures: number\n /**\n * A failed read or a missing asset was already reported, and no read has found the asset since.\n * Further failures are not reported.\n */\n reported: boolean\n}\n\nexport interface UploadRowNotice {\n /** The row has waited longer than processing should take. */\n slow: boolean\n readWarning: boolean\n /** Which of the two notices the settlement wrote into `row.error`. */\n shown: 'slow' | 'readWarning' | null\n /** The text written then. If the row's message differs now, the error belongs to someone else. */\n text: string | null\n}\n\n/** What a read should do for one target. */\nexport interface UploadReadIntent {\n /** State carried by the event. It applies when the read shows no final state. */\n hint: 'processed' | null\n /** When the row settles as processed, load its metadata as well. */\n metadata: boolean\n /** Set by the metadata notification. Metadata may arrive before the final state. */\n early: boolean\n /** The read tells a row with `settleOn: 'never'` that its file is processed. */\n seen: boolean\n}\n\n/** What the settlement remembers about rows. Every key is `toRaw(row)`. */\nexport interface UploadSettleMemory {\n tracked: WeakMap<UploadQueueItem, UploadTrackState>\n /** The last write an event made into the row. A read started before it is stale. Never cleared. */\n revision: WeakMap<UploadQueueItem, number>\n metadataLoaded: WeakSet<UploadQueueItem>\n /** Failed rows revived by an event. Their next read loads the metadata. */\n reviveWithMetadata: WeakSet<UploadQueueItem>\n /** Failed rows a refresh may still change: given up by the client, or left without their duplicate's original. */\n refreshMayHelp: WeakSet<UploadQueueItem>\n /** Rows failed because too many reads found no asset, while the server settles them by nothing else. */\n givenUpMissing: WeakSet<UploadQueueItem>\n notices: WeakMap<UploadQueueItem, UploadRowNotice>\n /** Shared counter for revisions and read starts. */\n clock: number\n}\n\nexport const createUploadSettleMemory = (): UploadSettleMemory => ({\n tracked: new WeakMap(),\n revision: new WeakMap(),\n metadataLoaded: new WeakSet(),\n reviveWithMetadata: new WeakSet(),\n refreshMayHelp: new WeakSet(),\n givenUpMissing: new WeakSet(),\n notices: new WeakMap(),\n clock: 0,\n})\n\nexport interface UploadSettleRow {\n queueKey: UploadQueueKey\n queue: UploadQueue\n row: UploadQueueItem\n}\n\nexport interface UploadSettleOptions {\n /** A row stopped being tracked, by a settlement write or by the store. */\n onUntrack?(queueKey: UploadQueueKey): void\n /** The settlement was disposed. Results of an original read that arrive later are not written. */\n isDisposed?(): boolean\n}\n\nexport const isFinalFileStatus = (\n status: AssetFileProcessStatusType | null | undefined\n): status is 'processed' | 'duplicate' | 'failed' =>\n status === AssetFileProcessStatus.Processed ||\n status === AssetFileProcessStatus.Duplicate ||\n status === AssetFileProcessStatus.Failed\n\n/**\n * The file state a read gives the target.\n * An asset reports only its main file state. A final state from the asset wins, otherwise the event state applies.\n * For another file (a slot) the asset says nothing, so only the event state applies.\n */\nexport const resolveReadStatus = (\n asset: AssetDetailItemDto,\n target: Pick<UploadSettlementTarget, 'fileId'>,\n intent: Pick<UploadReadIntent, 'hint'>\n): AssetFileProcessStatusType | undefined => {\n if (!isNull(target.fileId) && target.fileId !== asset.mainFile?.id) return intent.hint ?? undefined\n const readStatus = asset.mainFile?.fileAttributes?.status\n return isFinalFileStatus(readStatus) ? readStatus : (intent.hint ?? readStatus)\n}\n\nexport const clearRowError = (row: UploadQueueItem) => {\n row.error = { hasError: false, message: '', assetFileFailReason: AssetFileFailReasonDefault }\n}\n\n// \"Empty\" as the queue's mass operations define it.\nexport const isEmptyMetadataValue = (value: unknown) =>\n isUndefined(value) || isNull(value) || value === '' || (isArray(value) && !value.length)\n\n/**\n * First metadata load of a row. Values the user set earlier (via a queue mass operation) stay.\n * Only empty lists and empty custom fields are filled.\n */\nexport function mergeLoadedMetadata(\n queue: UploadQueue,\n row: UploadQueueItem,\n asset: AssetDetailItemDto,\n caches: Pick<UploadSettlementProfile['caches'], 'addAuthors' | 'addKeywords'>\n) {\n const { updateNewNames, getAuthorConflicts } = useAssetSuggestions()\n if (isEmptyMetadataValue(row.keywords)) row.keywords = [...(asset.keywords ?? [])]\n if (isEmptyMetadataValue(row.authors)) row.authors = [...(asset.authors ?? [])]\n if (isEmptyMetadataValue(row.sources)) row.sources = [...(asset.sources ?? [])]\n const customData: Record<string, unknown> = isObject(asset.metadata.customData)\n ? { ...asset.metadata.customData }\n : {}\n if (isObject(row.customData)) {\n for (const [key, value] of Object.entries(row.customData)) {\n if (!isEmptyMetadataValue(value)) customData[key] = value\n }\n }\n row.customData = customData\n // Not mass-operation fields. These come from the server.\n row.mainFileSingleUse = asset.mainFileSingleUse\n row.mainFileInternal = asset.mainFileInternal\n // What the DAM has. The save sends only what differs, such as the values a mass operation filled in.\n setMetadataOnServer(row, metadataOfAsset(asset))\n const authorSuggestions = asset.metadata.authorSuggestions ?? {}\n updateNewNames(authorSuggestions, queue.suggestions.newAuthorNames)\n updateNewNames(asset.metadata.keywordSuggestions ?? {}, queue.suggestions.newKeywordNames)\n row.authorConflicts = getAuthorConflicts(authorSuggestions)\n caches.addKeywords(row.keywords)\n caches.addAuthors([...row.authors, ...(row.sources ?? [])])\n caches.addAuthors(row.authorConflicts)\n}\n\n/**\n * Applies a read asset to a row without changing its state.\n * `hadMetadata`: the row's metadata was loaded once, whether or not the form is shown now.\n */\nexport function decorateRow(\n row: UploadQueueItem,\n asset: AssetDetailItemDto,\n mainFile: AssetFile,\n role: UploadRowRoleType,\n hadMetadata: boolean\n) {\n row.assetStatus = asset.attributes.assetStatus\n // Only for the main-file row. A slot row would get a preview of another file.\n if (!isNull(row.fileId) && row.fileId !== mainFile.id) return\n if (mainFile.links?.image_detail) row.imagePreview = mainFile.links.image_detail\n // Skip mass-edit rows and rows that have or had metadata. There these switches are form fields the user may have set.\n // This includes a row that lost its form on failure and gets it back.\n if (!row.canEditMetadata && !hadMetadata && role !== UploadRowRole.MassEdit) {\n row.mainFileSingleUse = asset.mainFileSingleUse\n row.mainFileInternal = asset.mainFileInternal\n }\n}\n\n// Both duplicate policies mark the row through here.\nconst markAsDuplicate = (row: UploadQueueItem) => {\n row.isDuplicate = true\n // Set once, before anything can overwrite `assetId` with the original.\n row.uploadedAssetId ??= row.assetId\n}\n\n/**\n * Settlement writes: a read asset or a known state into queue rows.\n * No timers and no reads of its own, except reading a duplicate's original.\n */\nexport function createUploadSettle(\n profile: UploadSettlementProfile,\n memory: UploadSettleMemory = createUploadSettleMemory(),\n options: UploadSettleOptions = {}\n) {\n const policyOf = (row: UploadQueueItem) => profile.policyFor(profile.roleOf(row))\n\n /**\n * Whether the target concerns a row of queue `queueKey`, by the profile's `matches`.\n * When the profile provides `configOf`, only queues of a configuration the target names match.\n */\n const concerns = (\n queueKey: UploadQueueKey,\n row: UploadQueueItem,\n target: UploadSettlementTarget,\n purpose: 'settle' | 'decorate' | 'metadata'\n ) =>\n (!profile.configOf || !target.configNames?.length || target.configNames.includes(profile.configOf(queueKey))) &&\n profile.matches(row, target, purpose)\n\n /**\n * Splits the target per named configuration when it names several and the profile provides `configOf`.\n * Each copy is read separately, by a queue of that configuration, and written only into its rows.\n * Otherwise returns the target itself.\n */\n const byConfiguration = (target: UploadSettlementTarget): UploadSettlementTarget[] => {\n const names = profile.configOf ? [...new Set(target.configNames ?? [])] : []\n return names.length > 1 ? names.map((name) => ({ ...target, configNames: [name] })) : [target]\n }\n\n // Queues whose rows got names since the caches last fetched.\n const namedQueues = new Set<UploadQueueKey>()\n /** Where the row names go. A profile with `configOf` is given the queue key, one without is not. */\n const cachesOf = (\n queueKey: UploadQueueKey\n ): Pick<UploadSettlementProfile['caches'], 'addAuthors' | 'addKeywords'> => {\n namedQueues.add(queueKey)\n if (!profile.configOf) {\n return {\n addAuthors: (ids) => profile.caches.addAuthors(ids),\n addKeywords: (ids) => profile.caches.addKeywords(ids),\n }\n }\n return {\n addAuthors: (ids) => profile.caches.addAuthors(ids, queueKey),\n addKeywords: (ids) => profile.caches.addKeywords(ids, queueKey),\n }\n }\n /** Fetches caches for each queue that got names, or once without a queue for a profile without `configOf`. */\n const fetchNames = () => {\n const queueKeys = [...namedQueues]\n namedQueues.clear()\n if (!profile.configOf) {\n profile.caches.fetchAuthors()\n profile.caches.fetchKeywords()\n return\n }\n for (const queueKey of queueKeys) {\n profile.caches.fetchAuthors(queueKey)\n profile.caches.fetchKeywords(queueKey)\n }\n }\n\n /** All queue rows at this moment. */\n const rows = (): UploadSettleRow[] => {\n const all: UploadSettleRow[] = []\n for (const [queueKey, queue] of profile.queues()) {\n for (const row of queue.items) all.push({ queueKey, queue, row })\n }\n return all\n }\n\n // Nothing writes into a stopped row. Check again after every await: the row may have been stopped meanwhile.\n const isStopped = (row: UploadQueueItem) => row.status === UploadQueueItemStatus.Stop\n\n const isLive = (row: UploadQueueItem) => {\n const raw = toRaw(row)\n for (const [, queue] of profile.queues()) {\n if (toRaw(queue.items).some((item) => toRaw(item) === raw)) return true\n }\n return false\n }\n\n // A row marked as a duplicate is settled and read-only.\n // A row that became its original is a normal editable row.\n const isMarkedDuplicate = (row: UploadQueueItem) => row.isDuplicate && policyOf(row).duplicate === 'markDuplicate'\n const isDisposed = () => options.isDisposed?.() === true\n\n const decorate = (row: UploadQueueItem, asset: AssetDetailItemDto, mainFile: AssetFile) =>\n decorateRow(row, asset, mainFile, profile.roleOf(row), memory.metadataLoaded.has(toRaw(row)))\n\n const revisionOf = (row: UploadQueueItem) => memory.revision.get(toRaw(row)) ?? 0\n /** An event wrote into the row. Reads started before this are stale for it. */\n const bump = (row: UploadQueueItem) => {\n const mark = ++memory.clock\n memory.revision.set(toRaw(row), mark)\n return mark\n }\n const isStale = (row: UploadQueueItem, startedAt: number) => startedAt <= revisionOf(row)\n /** Mark of a read starting now. */\n const startRead = () => ++memory.clock\n\n const trackStateOf = (row: UploadQueueItem) => memory.tracked.get(toRaw(row))\n const untrack = (row: UploadQueueItem) => {\n const raw = toRaw(row)\n const state = memory.tracked.get(raw)\n if (!state) return\n memory.tracked.delete(raw)\n options.onUntrack?.(state.queueKey)\n }\n\n /** Whether a refresh may still change a failed row. The store is notified on change. */\n const setRefreshMayHelp = (queueKey: UploadQueueKey, row: UploadQueueItem, mayHelp: boolean) => {\n const raw = toRaw(row)\n if (memory.refreshMayHelp.has(raw) === mayHelp) return\n if (mayHelp) memory.refreshMayHelp.add(raw)\n else memory.refreshMayHelp.delete(raw)\n profile.hooks.onRefreshMayHelp?.(queueKey, row, mayHelp)\n }\n\n const noticeOf = (row: UploadQueueItem) => {\n const raw = toRaw(row)\n let notice = memory.notices.get(raw)\n if (!notice) {\n notice = { slow: false, readWarning: false, shown: null, text: null }\n memory.notices.set(raw, notice)\n }\n return notice\n }\n const dropNotice = (row: UploadQueueItem) => memory.notices.delete(toRaw(row))\n // Whether the row message is still the text the settlement wrote.\n // The store also writes `row.error` (failed upload), and the settlement must not clear that error.\n const showsOwnText = (row: UploadQueueItem) => {\n const notice = memory.notices.get(toRaw(row))\n return !!notice?.shown && row.error.message === notice.text\n }\n\n /**\n * Writes the applicable settlement text into `row.error`, or removes its own text.\n * Only its own text, and only while the row still shows it.\n * `clear` also removes an error the settlement did not write, because the row settled as processed.\n */\n const syncNotice = (row: UploadQueueItem, { clear = false }: { clear?: boolean } = {}) => {\n const notice = noticeOf(row)\n let wants: UploadRowNotice['shown'] = null\n if (\n notice.readWarning &&\n policyOf(row).metadata === 'load' &&\n !row.canEditMetadata &&\n !isMarkedDuplicate(row) &&\n row.status !== UploadQueueItemStatus.Failed\n ) {\n wants = 'readWarning'\n } else if (notice.slow && row.status === UploadQueueItemStatus.Processing) {\n wants = 'slow'\n }\n if (wants) {\n const text = wants === 'slow' ? profile.messages.processingTooLong(row) : profile.messages.readFailed(row)\n row.error.hasError = true\n row.error.message = text\n notice.shown = wants\n notice.text = text\n return\n }\n if (clear) {\n clearRowError(row)\n } else if (showsOwnText(row)) {\n // Remove the text. Also clear the flag, unless the row has failed since. Then the flag belongs to the failure.\n if (row.status === UploadQueueItemStatus.Failed) row.error = { ...row.error, message: '' }\n else clearRowError(row)\n }\n notice.shown = null\n notice.text = null\n }\n\n const loadMetadata = (\n { queueKey, queue, row }: Pick<UploadSettleRow, 'queueKey' | 'queue' | 'row'>,\n asset: AssetDetailItemDto\n ) => {\n mergeLoadedMetadata(queue, row, asset, cachesOf(queueKey))\n memory.metadataLoaded.add(toRaw(row))\n }\n\n const settleProcessed = (\n { queueKey, queue, row }: UploadSettleRow,\n asset: AssetDetailItemDto,\n mainFile: AssetFile,\n intent: UploadReadIntent\n ) => {\n const raw = toRaw(row)\n // The client marks an upload failed when one of its requests fails, but the server may still finish it.\n // Such a row lost its form on failure and gets it back here, with its metadata.\n const wasFailed = row.status === UploadQueueItemStatus.Failed || memory.reviveWithMetadata.has(raw)\n row.status = UploadQueueItemStatus.Uploaded\n // A licence copy knows only its asset. The image is built from the file id.\n if (isNull(row.fileId)) row.fileId = mainFile.id\n decorate(row, asset, mainFile)\n const notice = noticeOf(row)\n if (policyOf(row).metadata === 'load' && !isMarkedDuplicate(row) && (intent.metadata || wasFailed)) {\n // Loaded once, and never into a row with the form shown, so user input is kept.\n if (!row.canEditMetadata && !memory.metadataLoaded.has(raw)) loadMetadata({ queueKey, queue, row }, asset)\n row.canEditMetadata = true\n notice.readWarning = false\n profile.hooks.afterMetadataLoaded?.(queueKey, row)\n }\n memory.reviveWithMetadata.delete(raw)\n memory.givenUpMissing.delete(raw)\n notice.slow = false\n syncNotice(row, { clear: true })\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n\n const settleFailed = (\n { queueKey, row }: Pick<UploadSettleRow, 'queueKey' | 'row'>,\n failReason: AssetFileFailReasonType\n ) => {\n row.status = UploadQueueItemStatus.Failed\n // Drop the old text. The row shows a message for the reason, and the old text is not the cause.\n row.error = { hasError: true, message: '', assetFileFailReason: failReason }\n row.canEditMetadata = false\n dropNotice(row)\n memory.reviveWithMetadata.delete(toRaw(row))\n memory.givenUpMissing.delete(toRaw(row))\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n\n /** A failure known by the caller, without a read. */\n const settleKnownFailed = (target: UploadSettlementTarget, failReason: AssetFileFailReasonType) => {\n for (const entry of rows()) {\n if (entry.row.status === UploadQueueItemStatus.Stop || !concerns(entry.queueKey, entry.row, target, 'settle')) {\n continue\n }\n settleFailed(entry, failReason)\n bump(entry.row)\n }\n }\n\n /**\n * Applies a `processed` event immediately to rows that settle on the event.\n * A tick also uses it for a slot row whose file the slot list shows processed.\n */\n const settleProcessedByEvent = (target: UploadSettlementTarget) => {\n for (const { queueKey, row } of rows()) {\n if (row.status === UploadQueueItemStatus.Stop || policyOf(row).settleOn !== 'event') continue\n if (!concerns(queueKey, row, target, 'settle')) continue\n const raw = toRaw(row)\n if (row.status === UploadQueueItemStatus.Failed) memory.reviveWithMetadata.add(raw)\n memory.givenUpMissing.delete(raw)\n row.status = UploadQueueItemStatus.Uploaded\n // A row the client gave up on that already had metadata gets its form back as the user left it.\n if (!isMarkedDuplicate(row) && memory.metadataLoaded.has(raw)) row.canEditMetadata = true\n noticeOf(row).slow = false\n syncNotice(row, { clear: true })\n bump(row)\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n }\n\n /** Handles a `processed` event for rows whose state it does not change. */\n const announceProcessed = (target: UploadSettlementTarget) => {\n for (const { queueKey, row } of rows()) {\n if (row.status === UploadQueueItemStatus.Stop || policyOf(row).settleOn !== 'never') continue\n if (concerns(queueKey, row, target, 'decorate')) profile.hooks.onProcessedSeen?.(queueKey, row)\n }\n }\n\n const duplicateRows = (\n target: UploadSettlementTarget,\n policy: 'becomeOriginal' | 'markDuplicate',\n eligible: (row: UploadQueueItem) => boolean\n ) =>\n rows().filter(\n ({ queueKey, row }) =>\n row.status !== UploadQueueItemStatus.Stop &&\n eligible(row) &&\n policyOf(row).duplicate === policy &&\n concerns(queueKey, row, target, 'settle')\n )\n\n // The row stays and is marked. It is settled first and completed from the original file later.\n // This way the wait for that file does not hold an upload slot.\n const markDuplicates = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null,\n eligible: (row: UploadQueueItem) => boolean\n ) => {\n const marked: Array<{ row: UploadQueueItem; mark: number }> = []\n for (const { queueKey, row } of duplicateRows(target, 'markDuplicate', eligible)) {\n markAsDuplicate(row)\n row.status = UploadQueueItemStatus.Uploaded\n row.canEditMetadata = false\n clearRowError(row)\n dropNotice(row)\n memory.reviveWithMetadata.delete(toRaw(row))\n memory.givenUpMissing.delete(toRaw(row))\n marked.push({ row, mark: bump(row) })\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n if (!marked.length || !originFileId || !assetType || !profile.readers.duplicateOriginFile) return\n let file: AssetFileNullable = null\n try {\n file = await profile.readers.duplicateOriginFile(originFileId, assetType)\n } catch (error) {\n console.error('uploadQueue: the duplicated file could not be read', error)\n }\n if (!file || isDisposed()) return\n for (const { row, mark } of marked) {\n // Only rows still present and not written into meanwhile.\n if (!isLive(row) || row.status === UploadQueueItemStatus.Stop || !row.isDuplicate) continue\n if (revisionOf(row) !== mark) continue\n row.fileId = file.id\n row.duplicateAssetId = file.asset\n row.mainFileSingleUse = file.flags.singleUse\n if (file.links?.image_detail) row.imagePreview = file.links.image_detail\n }\n }\n\n // The row becomes the original: its asset and file are replaced and it takes the original's metadata.\n // Returns whether the original could not be read and a row remains that a refresh may still help.\n const becomeOriginals = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null,\n eligible: (row: UploadQueueItem) => boolean\n ): Promise<boolean> => {\n if (!originFileId || assetType !== DamAssetType.Image) return false\n // Recorded before requesting the original. After the await, only rows still in\n // their queue, not stopped and not written by an event meanwhile are written.\n // The caller that reports a duplicate is outside the read\n // ordering, so an earlier answer must not undo a later event.\n const candidates = duplicateRows(target, 'becomeOriginal', eligible).map((entry) => ({\n ...entry,\n mark: revisionOf(entry.row),\n }))\n if (!candidates.length) return false\n const untouched = () =>\n candidates.filter(({ row, mark }) => isLive(row) && !isStopped(row) && revisionOf(row) === mark)\n const { updateNewNames, getAuthorConflicts } = useAssetSuggestions()\n let original: AssetDetailItemDto\n try {\n if (!profile.readers.duplicateOriginAsset) throw new Error('uploadSettlement: no reader of the original asset')\n original = await profile.readers.duplicateOriginAsset(originFileId, { queueKey: candidates[0]!.queueKey })\n } catch {\n if (isDisposed()) return false\n let leftWithout = false\n for (const { queueKey, row } of untouched()) {\n // Read before untracking, so a row the client gave up on keeps its way back.\n const mightHelp = memory.refreshMayHelp.has(toRaw(row))\n // Untrack regardless of state. The next tick would only retry the same read.\n untrack(row)\n // Only a row still waiting for this answer fails: a settled one must not be flipped back to failed.\n const failsHere = row.status === UploadQueueItemStatus.Processing\n if (failsHere) {\n row.status = UploadQueueItemStatus.Failed\n // Drop a text the settlement wrote. It no longer describes what is wrong with the row.\n row.error = { ...row.error, hasError: true, message: showsOwnText(row) ? '' : row.error.message }\n row.canEditMetadata = false\n dropNotice(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n // Failed because a read failed, not the file. A row refresh requests the original again.\n // Not for a row the server had already failed, which no refresh can undo.\n if (failsHere || mightHelp) {\n setRefreshMayHelp(queueKey, row, true)\n leftWithout = true\n }\n }\n return leftWithout\n }\n if (isDisposed()) return false\n for (const { queueKey, queue, row } of untouched()) {\n const authorSuggestions = original.metadata.authorSuggestions ?? {}\n markAsDuplicate(row)\n row.status = UploadQueueItemStatus.Uploaded\n clearRowError(row)\n row.fileId = originFileId\n row.duplicateAssetId = original.id\n row.assetStatus = original.attributes.assetStatus\n if (original.mainFile?.links?.image_detail) row.imagePreview = original.mainFile.links.image_detail\n row.keywords = [...(original.keywords ?? [])]\n row.authors = [...(original.authors ?? [])]\n row.sources = [...(original.sources ?? [])]\n row.customData = isObject(original.metadata.customData) ? { ...original.metadata.customData } : {}\n updateNewNames(authorSuggestions, queue.suggestions.newAuthorNames)\n updateNewNames(original.metadata.keywordSuggestions ?? {}, queue.suggestions.newKeywordNames)\n row.authorConflicts = getAuthorConflicts(authorSuggestions)\n const caches = cachesOf(queueKey)\n caches.addKeywords(row.keywords)\n caches.addAuthors([...row.authors, ...(row.sources ?? [])])\n caches.addAuthors(row.authorConflicts)\n row.assetId = original.id\n row.mainFileSingleUse = original.mainFileSingleUse\n row.mainFileInternal = original.mainFileInternal\n // The row shows the original as the DAM has it. Its save sends only what is changed in it.\n setMetadataOnServer(row, metadataOfAsset(original))\n memory.metadataLoaded.add(toRaw(row))\n row.canEditMetadata = true\n dropNotice(row)\n memory.reviveWithMetadata.delete(toRaw(row))\n memory.givenUpMissing.delete(toRaw(row))\n bump(row)\n setRefreshMayHelp(queueKey, row, false)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n fetchNames()\n return false\n }\n\n /**\n * Handles a duplicate file for every row passing `matches(…, 'settle')`, by the policy of its role.\n * `eligible` excludes rows the read is stale for.\n * Returns whether a row is left without its duplicate's original\n * because it could not be read. A refresh may still help it.\n */\n const settleDuplicate = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null,\n eligible: (row: UploadQueueItem) => boolean = () => true\n ) => {\n // Both start at once, not one after the other, so each records its rows now.\n // The original is read once per configuration the target names, by a queue of that configuration.\n const targets = byConfiguration(target)\n const [, leftWithout] = await Promise.all([\n markDuplicates(target, originFileId, assetType, eligible),\n targets.length === 1\n ? becomeOriginals(target, originFileId, assetType, eligible)\n : Promise.all(targets.map((one) => becomeOriginals(one, originFileId, assetType, eligible))).then((left) =>\n left.some(Boolean)\n ),\n ])\n return leftWithout\n }\n\n /** A duplicate known by the caller, without reading its asset. Never rejects. */\n const settleKnownDuplicate = async (\n target: UploadSettlementTarget,\n originFileId: DocIdNullable,\n assetType: DamAssetTypeType | null\n ) => {\n try {\n await settleDuplicate(target, originFileId, assetType)\n } catch (error) {\n console.error('uploadQueue: the duplicate could not be settled', error)\n }\n }\n\n /** Metadata notification: loads the metadata and the form, regardless of the file state. */\n const tryLoadMetadata = ({ queueKey, queue, row }: UploadSettleRow, asset: AssetDetailItemDto) => {\n if (policyOf(row).metadata !== 'load' || row.canEditMetadata) return\n // A marked duplicate is settled and has no metadata of its own to load.\n if (isMarkedDuplicate(row)) return\n // Skip a row whose file failed, except one that failed for lack of this metadata.\n if (row.status === UploadQueueItemStatus.Failed && profile.metadataGate?.(queueKey, row) !== 'load') return\n if (!memory.metadataLoaded.has(toRaw(row))) loadMetadata({ queueKey, queue, row }, asset)\n row.canEditMetadata = true\n noticeOf(row).readWarning = false\n syncNotice(row)\n profile.hooks.afterMetadataLoaded?.(queueKey, row)\n }\n\n /**\n * Applies one read asset to every row it concerns. `startedAt` is the read mark.\n * A row written by an event since keeps the event's state.\n * Returns like `settleDuplicate`: whether a row is left without its duplicate's original.\n */\n const applyAssetRead = async (\n asset: AssetDetailItemDto,\n target: UploadSettlementTarget,\n intent: UploadReadIntent,\n startedAt: number\n ) => {\n const mainFile = asset.mainFile ?? null\n const status = resolveReadStatus(asset, target, intent)\n let duplicateSettled = false\n let leftWithout = false\n for (const entry of rows()) {\n const { queueKey, row } = entry\n // The duplicate's original read was awaited. The row may have left its queue meanwhile.\n if (duplicateSettled && !isLive(row)) continue\n if (isStopped(row)) continue\n\n // Apply the file state and row details unless an event wrote\n // into the row after this read started. The event is newer.\n if (!isStale(row, startedAt) && mainFile && concerns(queueKey, row, target, 'decorate')) {\n const maySettle = concerns(queueKey, row, target, 'settle')\n if (status === AssetFileProcessStatus.Processed) {\n if (policyOf(row).settleOn === 'never') {\n decorate(row, asset, mainFile)\n if (intent.seen) profile.hooks.onProcessedSeen?.(queueKey, row)\n } else if (maySettle) {\n settleProcessed(entry, asset, mainFile, intent)\n }\n } else if (status === AssetFileProcessStatus.Duplicate && maySettle) {\n // Once for all rows of the target. The original is read only once.\n if (!duplicateSettled) {\n duplicateSettled = true\n leftWithout = await settleDuplicate(\n target,\n mainFile.originAssetFile,\n asset.attributes.assetType,\n (candidate) => !isStale(candidate, startedAt)\n )\n if (isDisposed()) return leftWithout\n if (!isLive(row) || isStopped(row)) continue\n }\n } else if (status === AssetFileProcessStatus.Failed && maySettle) {\n settleFailed(entry, mainFile.fileAttributes.failReason)\n }\n }\n\n // Applied to such a row as well, because metadata is not file state. It loads once, whenever it arrives.\n // Rows the event failed or marked as duplicate are refused there.\n // Otherwise a `processed` event that overtakes the metadata read would leave the row uploaded without its form.\n if (intent.early && concerns(queueKey, row, target, 'metadata')) tryLoadMetadata(entry, asset)\n }\n profile.hooks.onAssetRead?.(asset)\n return leftWithout\n }\n\n /**\n * An uploaded row without its metadata, which a refresh would load.\n * It is no longer tracked, but reads that find no asset are still counted for it.\n */\n const awaitsMetadata = (row: UploadQueueItem) =>\n row.status === UploadQueueItemStatus.Uploaded &&\n !row.canEditMetadata &&\n policyOf(row).metadata === 'load' &&\n !isMarkedDuplicate(row)\n\n /**\n * The row's asset was missing from enough reads, for a tracked row or one a refresh may still help.\n * A processing row fails. An uploaded row without metadata fails with `assetGone`.\n * Any other row (given up by the client, or left without its duplicate's original) is left alone.\n */\n const giveUpOnMissing = ({ queueKey, row }: Pick<UploadSettleRow, 'queueKey' | 'row'>) => {\n // There is no asset a refresh could read.\n setRefreshMayHelp(queueKey, row, false)\n const withoutMetadata = awaitsMetadata(row)\n if (row.status !== UploadQueueItemStatus.Processing && !withoutMetadata) {\n untrack(row)\n return\n }\n row.status = UploadQueueItemStatus.Failed\n row.error.hasError = true\n row.error.message = withoutMetadata\n ? (profile.messages.assetGone?.(row) ?? profile.messages.assetMissing(row))\n : profile.messages.assetMissing(row)\n row.canEditMetadata = false\n memory.givenUpMissing.add(toRaw(row))\n dropNotice(row)\n untrack(row)\n profile.hooks.onRowFinal(queueKey, row)\n }\n\n return {\n memory,\n policyOf,\n concerns,\n byConfiguration,\n fetchNames,\n rows,\n isLive,\n bump,\n isStale,\n startRead,\n trackStateOf,\n untrack,\n setRefreshMayHelp,\n noticeOf,\n syncNotice,\n applyAssetRead,\n settleProcessedByEvent,\n announceProcessed,\n settleFailed,\n settleKnownFailed,\n settleDuplicate,\n settleKnownDuplicate,\n awaitsMetadata,\n giveUpOnMissing,\n }\n}\n\nexport type UploadSettle = ReturnType<typeof createUploadSettle>\n"],"mappings":";;;;;;;;;AAkFA,IAAaa,WAAsD;CACjE,yBAAS,IAAI,QAAQ;CACrB,0BAAU,IAAI,QAAQ;CACtB,gCAAgB,IAAI,QAAQ;CAC5B,oCAAoB,IAAI,QAAQ;CAChC,gCAAgB,IAAI,QAAQ;CAC5B,gCAAgB,IAAI,QAAQ;CAC5B,yBAAS,IAAI,QAAQ;CACrB,OAAO;AACT,IAeaC,KACXC,MAEA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