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

  const unitValues: { [key: string]: number } = {
    d: 86400,
    h: 3600,
    m: 60,
    s: 1,
  };

  const regex = /(\d+)([dhms])/g;
  let match: RegExpExecArray | null;
  let totalSeconds = 0;
  let lastUnitValue = Infinity;

  while ((match = regex.exec(input)) !== null) {
    const value = parseInt(match[1], 10);
    const unit = match[2];
    const unitValue = unitValues[unit];

    if (isNaN(value) || !unitValue || value < 0) {
      throw new Error('Invalid input');
    }

    if (unitValue >= lastUnitValue) {
      throw new Error('Units must appear in strictly decreasing size');
    }

    totalSeconds += value * unitValue;
    lastUnitValue = unitValue;
  }

  if (regex.lastIndex !== input.length) {
    throw new Error('Invalid input');
  }

  return totalSeconds;
}
```