```ts
export function parseDuration(input: string): number {
  if (typeof input !== 'string' || input === '') {
    throw new Error('Invalid input');
  }

  const units = ['d', 'h', 'm', 's'];
  const regex = /^(\d+)([dhms])$/;
  let totalSeconds = 0;

  input.split('').forEach(char => {
    if (!units.includes(char)) {
      throw new Error('Unknown unit');
    }
  });

  while (input.length > 0) {
    const match = input.match(regex);
    if (!match) {
      throw new Error('Invalid format');
    }

    const value = parseInt(match[1], 10);
    const unit = match[2];
    const index = units.indexOf(unit);

    if (index === -1 || index < units.length - 1) {
      throw new Error('Units out of order or repeated');
    }

    totalSeconds += value * Math.pow(60, units.length - index - 1);
    input = input.replace(match[0], '');
  }

  return totalSeconds;
}
```