adzejs/adze

The Namespace Modifier Should Allow for Restof Operator

Closed this issue · 3 comments

Currently when applying namespaces to a log via the namespace or ns methods you must pass in an array of strings if you want to apply multiple namespaces. This API could be simplified to allow a restof args operator to collect the multiple namespaces.

// Current API
adze().ns(['namespace-1', 'namespace-2']);

// Proposed API
adze().ns('namespace-1', 'namespace-2');

Hey! Do you have any plans for this?

I thought we could overload the namespace method. With these signatures, namespace accepts either an array of strings or strings passed as a rest parameter.

function namespace(...ns: string[]): this
function namespace(ns: string | string[]): this
function namespace(ns: string | string[]): this {
  //...
}

Instead of overloads we could also use a single signature for the rest param and include the tuple [string[]] to allow an array of strings aswell.

function namespace(...args: [string[]] | string[]):this {
  const ns = args.flat();
  //...
}

The only drawback with this is we need to flat the array, otherwise, when the client tries a call with an Array the argument will be [ ['namespace-1', 'namespace-2'] ].

Let me know what you think, and if I can make a PR ✌

Hey @andersonjoseph,

Thank you for taking the opportunity to contribute! I think my preference would be to go the overload route as it wouldn't require any logic changes. I'd be happy to review and merge a PR for this.

Also, this is my fault, but I still need to create a contributing.md document for contributing processes. However, please be sure to create a unit test for this and add a log demonstrating it to the demo_funcs.js file. Thank you!

Closed in PR #115