[node-loader] Signature disambiguation for single options objects vs positional parameters

Open
#915 5 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
javascript, node.js, typescript
Domain
tooling

Research direction

Read source/loaders/node_loader and trace its reflection metadata and invocation entry points first. Compare the two call shapes described in the issue; done means the loader consistently distinguishes a single dictionary argument from positional arguments, with behavior validated by the project's relevant loader tests.

Written by the indexing model from the issue text.

Description

Description

In JavaScript / TypeScript, developers frequently define functions that accept a single destructured options object rather than multiple positional arguments. When invoking these functions through MetaCall with an argument dictionary, there is currently ambiguity on how the payload should be passed.

Problem

Consider two common JavaScript patterns:

// Case 1: Single options object (destructuring)
function createUser({ username, email, isAdmin = false }) {
    return db.users.create({ username, email, isAdmin });
}

// Case 2: Positional arguments
function add(a, b) {
    return a + b;
}

When an external client sends a JSON dictionary { "username": "alice", "email": "[email protected]" }:

  1. If the dispatcher unpacks the dictionary positionally (createUser(arg0, arg1)), the function looks for parameter 0 as an object, finds undefined, and throws:
    TypeError: Cannot destructure property 'username' of undefined or null
  2. To work correctly, the entire dictionary must be passed as argument 0 (createUser(obj)), whereas for add(a, b) the values must be extracted into positional parameters add(1, 2).

Without reflection into function arity (fn.length) and parameter structure, callers cannot determine whether a dictionary represents a single options argument or multiple positional parameters.

Proposed Solution

In source/loaders/node_loader:

  1. Enhance reflection metadata to expose function arity and whether parameter 0 expects an object/struct vs primitives.
  2. Allow the invocation layer in the NodeJS loader to automatically detect when a dictionary should be forwarded as a single object argument vs unpacked into positional parameters.
Dominant language
C
Stars
1.8k
Forks
266
Avg merge
2d 16h
Merged PRs (30d)
14

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from metacall/core

All issues in metacall/core

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.