Can you please explain the meaning and use of validateAsync function of strongloop.enter link description here
It's used to validate the name property on the User model in the example. It checks if the provided name is equal to "bad" and returns an error if it is. The example also shows you how to validate using the async and sync styles.
Related
I have a Copy Data task which is obtaining data from an API
The API is a GET call to a method and requires 2 parameters
_token
Symbols
I have defined these as parameters
What is the syntax that allows me to use the values of my parameters as the values that are in the query string? So in the screenshot above Symbols is hard coded, but I want the value to be the value of the parameters
I need a screen solution rather than code please as I am not comfortable with ADF yet and I dont know how to get to the code/ARM views
Paul
Using a feature called string interpolation where expressions are wrapped in #{ ... }
Click on the Base URL field. Add Parameters. Using Concat expression function,
Example:
#{Concat('https://stackoverflow.com/questions/GetRealTimeRates?',linkedService().Symbols,'=',linkedService()._token)}
Add first parameter:
Add second parameter:
Test connection. If you see any error, it would provide a description as to debug further.
What's the difference between using : and ? in a URL? For example /products/:id and /products?id=1? I am trying to get the values from the URL like this Product.findById (req.params.id) but I was wondering which one is most suitable. I know using : do I have to use req.params and ? req.query but I don't understand the difference between them, are they the same?
in my point of view, it is totally different if you are using RESTFUL API pattern
/products/:id called path parameters
The path parameters determine the resource you’re requesting for. Think of it like an automatic answering machine that asks you to press 1 for service, press 2 for another service, 3 for yet another service and so on.
Path parameters are part of the endpoint itself and are not optional
but query parameters
Technically, query parameters are not part of the REST architecture, and they used to help you completely understand how to read and use API’s Query parameters give you the option to modify your request with key-value pairs.
Having your parameters in the query is conceptually optional to the router, query parameters are more of properties and descriptions of the request itself, like when saying GET /users?sort=asc, in this case, the sort attribute was more of a description to the request and the request could complete the fetch without it, that might not always be the case, but a query parameter still describes its request even if it was mandatory.
On the other hand, URL parameters are part of the request itself, the URL without the parameter doesn't make sense, like GET /users/:userID, in this case, not supplying userID will supply unexpected data (A list of users for example) if it didn't break the router completely. URL parameters play part in defining the request rather than just describing it, and they can't be optional.
I am trying to query the CLIENTPROCESSID of the msiexec.exe process using the MSIGetProperty() API. The third parameter of this API should get the value of the property being passed as per Microsoft Docs. After calling,his API returns 0, which I think means ERROR_SUCCESS. However there is blank value or nothing within the szValueBuf parameter.
I have followed the exact method of getting the value as per https://learn.microsoft.com/en-us/windows/desktop/api/msiquery/nf-msiquery-msigetpropertya. I tried going through various Microsoft Docs but was not able to get satisfying answers.
return_value = MsiGetProperty(msihandle, _T("CLIENTPROCESSID"), msiPID, &size);
I would expect the process ID of msi process to be present within the msiPID but the string doesn't have any value at all.
Your question doesn't include quite enough to be certain about this, but I suspect your custom action is deferred, and thus CLIENTPROCESSID is unavailable. Unavailable properties are treated just like any other unset property, and thus are equivalent to an empty string, hence the successful return code with an empty output. Note that MsiGetProperty...
Supports a limited set of properties when used with deferred execution custom actions: the CustomActionData property, ProductCode property, and UserSID property.Commit custom actions cannot use the MsiGetProperty function to obtain the ProductCode property. Commit custom actions can use the CustomActionData property to obtain the product code.
Typically one must populate the CustomActionData property (by populating with an immediate action sequenced before the deferred action, a property with the same name as the deferred custom action) for any properties beyond those listed in the excerpt above.
The Express MDN tutorial here uses the following code to do a validation step
// Validate that the name field is not empty.
body('name', 'Genre name required').isLength({ min: 1 }).trim(),
What I don't get is why trim() is chained after the isLength() validation. Shouldn't it be the other way around, or is it the same semantics either way?
I did try looking around in the express-validator doc for a mention of something like this, but was unsuccessful.
UPDATE
In response to gustavohenke's answer, I think what was confusing me, was that I was seeing two sanitization points as shown in the MDN express tutorial screenshot below:
so when I read the validation doc for express-validator "If you use any of the sanitizers together with validators, the validated value is the sanitized one", I was wondering which sanitization point?
From what I've characterized, however, is that the documentation in the express tutorial (that says sanitizers in the validation step only apply to that validation step and don't mutate the request, and so another sanitizer is needed) is not true anymore. In other words, I think you can do all sanitization and validation in one chain.
To get it clear first: trim is a sanitizer, not a validator, like isLength.
Currently (as of v5.x.x), when you specify both sanitizers and validators in the same chain, sanitizers will always run before validators. If you specify more sanitizers, they will run in the order specified.
It's documented behaviour, but it's quite easy to not see it:
If you use any of the sanitizers together with validators, the validated value is the sanitized one.
This is a point of astonishment for users, as you might have guessed, and it's planned to change on an upcoming major version.
I have question regarding session.evaluate in SSJS. In a keyword document I have some #formula stored which does some conversion of data. Lets say this is would be:
#left(fieldname;2)
If the fieldname contained 'hello' this would result in 'he'. Nothing to fancy here. Now I would like to use this in an xpage.
I wrote a function called executeFormula(doc). I call this function from an action on a xpage. This xpage contains 1 notes document datasource. The function call is
executeFormula(datasource.getDocument(true))
Now for some reason the #formula is never calculated correctly. Do I need to save the document first before I can use session.evaluate(kwFormula,doc) or is the #formula wrong in some way?
p.s. I forgot to mention that this code is working inside a customvalidator
Without seeing the code for the executeFormula(doc) function it is very difficult to know exactly how session.evaluate is being called.
I would suggest taking the function out of the equasion for the moment and create a simple test page with the document source and a simple computed field with the session.evaluate in it so that you can see the result. Given your examples above the computed field would be something along the lines of
session.evaluate("#Left(fieldname;2)",xspDoc.getDocument(true));
Once you get acceptable results back then you can move it into your function and verify that it is working there also.
Don't forget that session.evaluate returns a vector so you may beed to do a .getFirstElement() on the returned value if it is not null.
If you're using it in a custom validator, the values posted from the browser/client haven't updated the data model (in your case, the document) yet. This happens after validation is successful.
I imagine it might work for some fields (e.g. fields that are updated after a successful refresh, or stored fields in an existing document).
Actually no need of mentioning the document, eg:- session.evaluate("#username") is enough.
For yours session.evaluate("#left('hello';2)") will work.,