ここにいたとはあなたは幸いでした。
It was fortunate that you were here. (given translation)
This sentence looks like gibberish to me. If it is indeed good Japanese could you please explain what とは is doing, and the seemingly bizarre placement of あなた?
I assume it must be some kind of quotative と. If so, does it go with 幸い or is there an implied phrase that has been omitted (I cannot think of anything)?
Edit:
So the suggested duplicates perfectly answer the とは part of the question but, as you can see from the comment thread below, I'm still struggling with this sentence.
There is no context; it was a stand-alone sentence. I'm envisaging a scenario where person X rescues person Y from some predicament.
Who says this sentence?
Who is the subject of ここにいた?
Does あなたは belong to ここにいた or 幸いでした or both?
I assume あなたは must go with 幸いでした. To move it after the verb in ここにいた seems too improbable. Therefore I read the sentence as "You were fortunate that (someone) was here. This means that X is the one saying the sentence, in contradiction to the given translation. A plausible translation then seems to be for X to be saying:
To think I (X) was here. You (Y) were fortunate.
Another option could be for X to be saying:
To think you (Y) were here. You (Y) were fortunate.
i.e. if you had been anywhere else then I (X) would not have been in the right place to rescue you. This seems much less likely
The remaining options involve Y saying the sentence.
To think you (X) were here. I (Y) was fortunate.
This one doesn't seem to work with the position of あなたは, but does match the given translation.
To think you (X) were here. You (X) were the bringer of good fortune.
This one works with the position of あなたは but relies on a totally different understanding of 幸いでした.