JSDoc how to document array of arrays and boolean or other types for returns? - jsdoc

I have a function that returns a array like this: [ [true, true], true] where index 0 is an array of boolean and second a boolean. How can I document this in JSDoc return type.
I have tried: #returns {[boolean[], boolean]} which produces "unable to parse.."..."invalid type expression.." error.

You have complex type to return and perhaps #typedef will be better option to set the type of return. But if you want to leave it as is, the following should work for you ...
#return {Array<Array<Boolean>, Boolean>}

Related

Data Factory aggregate function array within array not allowed

Is it possible to do something like this in Data Factory (data flow expression builder)? I am trying to create an array within an array but with a filter so it doesn't create an array with an empty item.
When I do this, it works however produces an array that looks like fooBar: [{ }] note the array contains a single item.
collect(#(
optionNumber=OptionNo,
price=OptionPrice,
salePricePeriods=array(#(
salePrice=OptionSalePrice,
priceActiveFrom=toString(OptionSaleFrom),
priceActiveTo=toString(OptionSaleTo)))))
Ideally, I want to filter this data by using an expression:
collect(#(
optionNumber=OptionNo,
price=OptionPrice,
salePricePeriods=
filter(
collect(#(
salePrice=OptionSalePrice,
priceActiveFrom=toString(OptionSaleFrom),
priceActiveTo=toString(OptionSaleTo))),
and(not(isNull(#item.salePrice)), and(not(isNull(#item.priceActiveFrom)), not(isNull(#item.priceActiveTo)))))))
When I do the above I get an error stating
Job failed due to reason: It is not allowed to use an aggregate function in the argument of another aggregate function. Please use the inner aggregate function in a sub-query.;;
Aggregate [958abb16-5236-430c-9af6-497495d60469#23243], [958abb16-5236-430c-9af6-497495d60469#23243, first(DataSet#22183, false) AS DataSet#23295, first(Realm#22184, false) AS Realm#23297, first(Territory#22185, false) AS Territory#23299, first(ItemNo#22186, false) AS ItemNo#23301, first(PriceGroupCode#22187, false) AS PriceGroupCode#23303, first(MinOptionPrice#22196, false) AS MinOptionPrice#23305, first(MaxOptionPrice#22197, false) AS MaxOptionPrice#23307, min(MinOptionSalePriceForPeriod#22198) AS MinOptionSalePrice#23309, max(MaxOptionSalePriceForPeriod#22199) AS MaxOptionSalePrice#23311, first(OldestDatePointMinPrice#22203, false) AS OldestDatePointMinPrice#23313, first(OldestDatePointMaxPrice#22204, false) AS OldestDatePointMaxPrice#23315, collect_list(named_struct(optionNumber, OptionNo#22189, price, OptionPrice#22191, salePrice
Figured it out, annoyingly the filter should have been on the incoming field so like so. The filter expression seems to get evaluated first before adding it to the array.
collect(#(
optionNumber=OptionNo,
price=OptionPrice,
salePricePeriods=
filter(
array(#(
salePrice=OptionSalePrice,
priceActiveFrom=toString(OptionSaleFrom),
priceActiveTo=toString(OptionSaleTo))),
not(isNull(toString(OptionSaleFrom))))))

Add jsonb property of type boolean

I'm trying to add a property to an existing jsonb column (column "data").
I want have my jsonb document to log like this
{
// ... existing properties
"Filed": false // new property
}
I tried
UPDATE "doc" SET "data" = jsonb_set("data"::jsonb, 'Filed', false, true)
I get this error:
[42883] ERROR: function jsonb_set(jsonb, unknown, boolean, boolean) does not exist
Hint: No function matches the given name and argument types.
You might need to add explicit type casts. Position: 46
It should be
jsonb_set("data"::jsonb, '{Filed}', 'false', TRUE)
The second parameter is an array denoting the path to the appropriate key, and 'false' is the string representation of a JSON boolean.
Better use the || operator.
UPDATE "doc" SET "data" = "data" || '{"Filed": false}';
This one is equivalent but more suitable for parameterization:
UPDATE "doc" SET "data" = "data" || jsonb_build_object('Filed', false);

Model.find() returnes an object or array of objects? [mongodb]

const tours = await Tour.find()
when i use console.log(typeof tours) it shows object in console log.
but when i use console.log(tours) it shows an array of objects.
so i'm bit confused about what it actually returns back?
In JavaScript the value of typeof when used on an array is "object". The correct way to check if a variable is an array is Array.isArray() - it will return true or false depending if the argument passed is an array.

Entity Framework Core PostgreSQL EF.Functions.JsonTypeof

.Where(e => EF.Functions.JsonTypeof(e.Customer.GetProperty("Age")))
This syntax in https://www.npgsql.org/efcore/mapping/json.html?tabs=data-annotations%2Cjsondocument not works!! show this error: cannot implicitly convert "string" to "bool"
The sample syntax from the link is simply incomplete. JsonTypeof returns string an according to the link is mapped to jsonb_typeof which
Returns the type of the outermost JSON value as a text string. Possible types are object, array, string, number, boolean, and null.
So the correct sample usage in Where clause would compare the return value of the method to a string containing one of the aforementioned values, for instance
.Where(e => EF.Functions.JsonTypeof(e.Customer.GetProperty("Age")) == "number")

Dereference a ReferenceField in Mongoengine

I am trying to dereference a reference field on my Flask backend and return the complete object with that certain field dereferenced.
The field I am trying to dereference is defined like this:
vouches_received = db.ListField(db.ReferenceField('Vouch'))
The way I am trying to dereference it is like this:
unverified_vouches = []
for vouch in usr.vouches_received:
unverified_vouches.append(vouch.to_mongo())
usr.vouches_received = unverified_vouches
However, when I then do:
usr.to_json()
On the object, then I get a ValidationError like so:
ValidationError: u'{...}' is not a valid ObjectId, it must be a
12-byte input of type 'str' or a 24-character hex string
The 3 dots (...) is basically the document dereferenced, it has mostly Strings, a Date Field, and some other reference fields I do not wish to dereference.
I am aware this is a valid error, as it is expecting an ObjectID for the reference field, but then arises the question, how do I succeed at dereferencing that field and return the document.
Thanks
The ListField is expecting elements of ObjectId and because you've de-referenced them it throws that error. I'm not sure this is the most elegant way but could you convert the usr.to_json() to a dict and then replace the vouches_received list with a deferenced list afterwards - I can't test it but something like?
user_dict = json.loads(usr.to_json())
unverified_vouches = []
for vouch in usr.vouches_received:
user_dict['vouches_received'].append(vouch.to_mongo())
usr_json = json.dumps(user_dict)
A better solution may be to use an EmbededDocument.