Skip to content

[Feature] applyDefaults helper for repeated settings.x ?? DEFAULT_X pattern #266

Description

@pathosDev

Size / Priority

  • Size: Trivial (~30+ sites)
  • Category: C.2 Simplifications & DRY.
  • Risk: low.

Affected files

  • Across the codebase — sites using settings.x ?? DEFAULT_X to apply per-call defaults.

Background

The pattern is everywhere:

const timeoutMs = options.timeoutMs ?? DEFAULT_ASK_TIMEOUT_MS;
const batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;
const consistency = options.consistency ?? 'local';

For methods with many optional parameters, this becomes verbose:

async updateAsync(opts) {
  const timeoutMs = opts.timeoutMs ?? 5_000;
  const consistency = opts.consistency ?? 'local';
  const pendingId = opts.pendingId ?? nextPendingId();
  // ... etc
}

Could be:

async updateAsync(opts) {
  const resolved = applyDefaults(opts, UPDATE_DEFAULTS);
  // resolved.timeoutMs, resolved.consistency are guaranteed populated
}

(applyDefaults from #255.)

Target

Same helper as #255 (applyDefaults<S>(partial, defaults)):

  • Returns a fully-populated S from a Partial<S> + a S defaults.
  • TypeScript narrows S correctly.

Cleaner than per-property nullish-coalescing.

Integration / risk

Test plan

  1. Per-site regression: behaviour unchanged.
  2. Edge cases: explicit undefined vs missing field handled consistently.

Acceptance criteria

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority: lowNice-to-have / niche / demand-driven

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions