1.17+ Update
As of 1.17, a loot table is no longer required, but the shulker box still is.
Preparation
You'll need to first place down a yellow shulker box, and place a temporary item (like a piece of dirt) in slot 0 (upper-left corner).
Important: Ensure the shulker box is otherwise empty, and always write to it with the NBT path Items[0].
The standard location for this shulker box is (-30000000, 0, 1602).
Commands
With 1.17 out, you can use /item to copy the item to the shulker box.
item replace block -30000000 0 1602 container.0 from entity @s weapon.mainhand
Then, you can modify your item as much as you want inside the shulker box using any commands you like. For example:
data modify block (x) (y) (z) Items[0] merge value {tag:{Enchantments:[{id:"minecraft:sharpness", lvl:1s}]}}
execute store result block (x) (y) (z) Items[0].tag.Enchantments[0].lvl short 1.0 run scoreboard players get FakePlayer myObjective
Finally, replace the item with /item:
item replace entity @s weapon.mainhand from block -30000000 0 1602 container.0