Get maxSatisfying version including pre-release with node semver - node.js

How can i get the latest version (including the pre-releases) from an array of versions using node/semver.
For example:
var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];
console.log(semver.maxSatisfying(versions, "*"));
Returns null, but i want to get the 1.0.0-rc.11 back.
Kind Regards and have a nice day!

You need to add the includePrerelease option to your maxSatisfying method as described here: https://github.com/npm/node-semver#functions
In your example:
var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];
console.log(semver.maxSatisfying(versions, "*", {
includePrerelease: true
}));

Okay i've found a solution.
The node module semver-extra adds some nice extra functions to the semver library, also one for getting the max version including the pre-releases.
https://www.npmjs.com/package/semver-extra

Related

Can't load Features.Diagnostics

I'm creating a web client for joining Teams meetings with the ACS Calling SDK.
I'm having trouble loading the diagnostics API. Microsoft provides this page:
https://learn.microsoft.com/en-us/azure/communication-services/concepts/voice-video-calling/call-diagnostics
You are supposed to get the diagnostics this way:
const callDiagnostics = call.api(Features.Diagnostics);
This does not work.
I am loading the Features like this:
import { Features } from '#azure/communication-calling'
A statement console.log(Features) shows only these four features:
DominantSpeakers: (...)
Recording: (...)
Transcription: (...)
Transfer: (...)
Where are the Diagnostics??
User Facing Diagnostics
For anyone, like me, looking now...
ATOW, using the latest version of #azure/communication-calling SDK, the documented solution, still doesn't work:
const callDiagnostics = call.api(Features.Diagnostics);
call.api is undefined.
TL;DR
However, once the call is instantiated, this allows you to subscribe to changes:
const call = callAgent.join(/** your settings **/);
const userFacingDiagnostics = call.feature(Features.UserFacingDiagnostics);
userFacingDiagnostics.media.on("diagnosticChanged", (diagnosticInfo) => {
console.log(diagnosticInfo);
});
userFacingDiagnostics.network.on("diagnosticChanged", (diagnosticInfo) => {
console.log(diagnosticInfo);
});
This isn't documented in the latest version, but is under this alpha version.
Whether this will continue to work is anyone's guess ¯\(ツ)/¯
Accessing Pre-Call APIs
Confusingly, this doesn't currently work using the specified version, despite the docs saying it will...
Features.PreCallDiagnostics is undefined.
This is actually what I was looking for, but I can get what I want by setting up a test call asking for the latest values, like this:
const call = callAgent.join(/** your settings **/);
const userFacingDiagnostics = call.feature(Features.UserFacingDiagnostics);
console.log(userFacingDiagnostics.media.getLatest())
console.log(userFacingDiagnostics.network.getLatest())
Hope this helps :)
Currently the User Facing Diagnostics API is only available in the Public Preview and npm beta packages right now. I confirmed this with a quick test comparing the 1.1.0 and beta packages.
Check the following link:
https://github.com/Azure-Samples/communication-services-web-calling-tutorial/
Features are imported from the #azure/communication-calling,
for example:
const {
Features
} = require('#azure/communication-calling');

Validate email with JOI Library

I already use JOI to validate many different things. Now I need to validate an email as well.
Validation logic looks like this:
const emailSchema = Joi.string().email({ minDomainSegments: 2 }).lowercase().required();
const resource = Joi.validate(email, emailSchema);
if (resource.error !== null) {
return true;
}
The thing is it fails to validate the following format:
const email = 6AEFE056-485C-42C0-9059-AF4D614C8FBE#anon
It sees it as a regular email, but it is not.
It does work with regular emails.
What am I doing wrong? I would really want to use JOI for this.
Joi version that I have used is 14.3.1
And coincidentally that is the last version on NPM. Joi moved under Hapi
And while being with Hapi, they release several new versions. The way I was using a version was designed for a newer release, but not mine. Therefore, I used older version notation.
When I find time, I will also switch to newer version.
This is the sample that works with older version.
const emailSchema = Joi.string().email({ minDomainAtoms: 2 });

ag-grid-community vs ag-grid-enterprise new Grid

I have a Node client-side application with the latest ag-grid version.
I was using ag-grid-community without any issues with this require line
const {Grid} = require('ag-grid-community');
and this new
new Grid(agGridDiv, agGridOptions);
but if I change the require to
const {Grid} = require('ag-grid-enterprise');
the new fails with exception 'Grid is not a constructor'
How can I fix this? I have tried various changes such as new Grid.Grid etc but nothing seems to work.
For latest 23.1.1 version this page:
// ECMA 5 - using nodes require() method
const AgGrid = require('ag-grid-enterprise');
Another way to follow this guide, it all depends on which repository you download the dependencies from.
import {Grid, GridOptions} from '#ag-grid-community/core';
import {LicenseManager} from '#ag-grid-enterprise/core';
// or
const {Grid, GridOptions} = require('#ag-grid-community/core');
I used core and it worked for import.
For old version:
Grid, like everything else, needs to be imported from ag-grid-community.
1) ag-grid-enterprise is pure additive functionality for ag-grid-community.
2) You will use ag-grid-enterprise via the ag-grid-community api not explicit. Use ag-grid-enterprise for LicenseManager only.
Off-topic:
I would recommend starting with the old version, since the source code of the new version is minified and it will be more difficult for you to understand many nontrivial nuances.

Replacement for req.param() that is deprecated in Express 4

We are migrating from ExpressJS 3 to ExpressJS 4, and we noted that the following APIs are being deprecated:
req.param(fieldName)
req.param(fieldName, defaultValue)
Is there a middleware that brings these APIs back, like other APIs that were 'externalized' from express to independent modules ?
EDITED:
Clarification - The need is an API that provides an abstracted generic access to a parameter, regardless to if it is a path-parameter, a query-string parameter, or a body field.
Based on Express Documentation, we should use like this
On express 3
req.param(fieldName)
On express 4
req.params.fieldName
Personally i prefer req.params.fieldName instead req.param(fieldName)
Why would you want to bring it back? There's a reason that it's been deprecated and as such you should probably move away from it.
The discussion on why they are deprecating the API is available at their issue tracker as #2440.
The function is a quick and dirty way to get a parameter value from either req.params, req.body or req.query. This could of course cause trouble in some cases, which is why they are removing it. See the function for yourself here.
If you are just using the function for url parameters, you can just replace it with this a check for req.query['smth'] or 'default':
var param_old = req.param('test', 'default');
var param_new = req.query['test'] || 'default';
(Please note that an empty string is evaluated to false, so they are not actually 100% equal. What you want is of course up to you, but for the most part it shouldn't matter.)
Ok, after reading the threads given in references by #Ineentho, we decided to come up with the following answer:
https://github.com/osher/request-param
A connect/express middleware to enable back the req.param(name,default) API deprecated in express 4
The middleware does not only brings back the goo'old functionality.
It also lets you customize the order of collections from which params are retrieved , both as default rule, and as per-call :-)
Have fun!

how about node.js change its api?

I'm using node.js to make a http request to a host. I found the latest version of node.js of 0.6.7 that make a request is like this
var http = require('http');
var req = http.request(options, function(res) {
var result ='';
res.on('data', function (chunk) {
//console.log('BODY: ' + chunk);
result += chunk;
});
res.on('end', function () {
console.log('end:' + result);
});
});
But I also found that the 0.3 version of node.js that make a request like this
http.createClient(80, 'api.t.sina.com.cn')
.request('GET', '/statuses/public_timeline.json?source=3243248798', {'host': 'api.t.sina.com.cn'})
.addListener('response', function(response){
var result = ''
response.addListener('data',function(data){
result += data
})
.addListener('end',function(){
tweets = JSON.parse(result)
})
})
But the 0.3 version of 'createClient' api is deprecated in 0.6.7. And I don't find any docs that describe this.
I'm worrying about the api will change in the future. That will make my code not run in the future.
Can anyone give me some advice? Thanks!
The API has and will change. That's the caveat for using bleeding-edge tech, like Node. The only advice I can give is to update your code to use the latest API, after all it's not changing that often, or just stick to a working version if you don't have the resources to keep upgrading your code base.. I personally keep my Node projects pretty small, that way upgrading is easier.
Also the use of NPM modules and generally modular code is encouraged. That way some API changes are easy update. Hope this helps. :)
Node 0.3 is astonishingly ancient, and Node moves remarkably fast.
The Node API will change, you need to constantly keep your platform up to date. While this can be annoying, it's also one of the best parts of Node. It keeps people in the habit of upgrading, allowing the Node platform and ecosystem to continually improve without the stifling hassles of backwards compatibility.
If you want a less frequently changing API, perhaps PHP or Java is more suitable for you. There's also nothing stopping you from continuing to use the older versions of Node. :D

Resources