ajv-errors plugin with fastify 4 in lerna project gives error that compiler schema error - fastify

my fastify 3 (ajv6) use this settings:
ajv: {
customOptions: {
allErrors: true,
removeAdditional: true,
jsonPointers: true
},
plugins: [require('ajv-errors')],
},
as ajv 8 removed jsonpointers so i delete it.
but it still throw errors that in my project.
the reproduce project is in this repo, please check.
https://github.com/radiorz/fastify-lerna-ajv-error-demo
error message :
Error compiling schema, function code: const schema26 = scope.schema[20];const obj0 = scope.obj[0];return function validate24(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(data && typeof data == "object" && !Array.isArray(data)){if(data.parameters === undefined){const err0 = {instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: "parameters"},message:"must have required property '"+"parameters"+"'"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}for(const key0 in data){if(!(key0 === "parameters")){delete data[key0];}}if(data.parameters !== undefined){let data0 = data.parameters;if(typeof data0 !== "string"){let dataType0 = typeof data0;let coerced0 = undefined;if(dataType0 == 'object' && Array.isArray(data0) && data0.length == 1){data0 = data0[0];dataType0 = typeof data0;if(typeof data0 === "string"){coerced0 = data0;}}if(!(coerced0 !== undefined)){if(dataType0 == "number" || dataType0 == "boolean"){coerced0 = "" + data0;}else if(data0 === null){coerced0 = "";}else {const err1 = {instancePath:instancePath+"/parameters",schemaPath:"#/properties/parameters/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}}if(coerced0 !== undefined){data0 = coerced0;if(data !== undefined){data["parameters"] = coerced0;}}}}}else {const err2 = {instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err2];}else {vErrors.push(err2);}errors++;}if(errors > 0){const emErrors0 = {"required":{"parameters":[]}};let emParamsErrors0;for(const err3 of vErrors){if(((((({"str":"err3"}.keyword !== "errorMessage") && (!{"str":"err3"}.emUsed)) && ({"str":"err3"}.instancePath === instancePath)) && ({"str":"err3"}.keyword in {"str":"emErrors0"})) && ({"str":"err3"}.schemaPath.indexOf("#") === 0)) && (/^/[^/]*$/.test({"str":"err3"}.schemaPath.slice(1)))){emParamsErrors0 = {"str":"emErrors0"}[{"str":"err3"}.keyword][{"str":"err3"}.params[{"str":"emPropParams0"}]];if(emParamsErrors0){{"str":"emParamsErrors0"}.push({"str":"err3"});{"str":"err3"}.emUsed = true;}}}for(const key1 in emErro

having the same error - any solutions?
"fastify": "4.1.0"
"ajv-errors": "^3.0.0"
ajv: {
customOptions: {
allErrors: true,
},
plugins: [AjvErrors],
},
Error: Cannot find module 'ajv'
EDIT: looks like reinstalling node modules fixed this issue - if you're using fasify 4 or above you can use ajv-errors 3 if you're using below fastify version 4 you have to use ajv-errors 1

Related

No fetchJoinCollection in subresource

I'm using api platform 2.6
I'm trying to use "pagination_fetch_join_collection" with SubresourceOperations.
But, it seems that there is no support for FetchJoinCollection (https://www.doctrine-project.org/projects/doctrine-orm/en/current/tutorials/pagination.html)
https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Extension/PaginationExtension.php#L128
if (null !== $resourceClass) {
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if (isset($context['collection_operation_name']) && null !== $fetchJoinCollection = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_fetch_join_collection', null, true)) {
return $fetchJoinCollection;
}
if (isset($context['graphql_operation_name']) && null !== $fetchJoinCollection = $resourceMetadata->getGraphqlAttribute($operationName, 'pagination_fetch_join_collection', null, true)) {
return $fetchJoinCollection;
}
}
//[...]
Only support for collection_operation_name & graphql_operation_name
There is any reason for that ?
And, Have you a solution for use fetchJoinCollection properly ?
Thank you.

Why am I getting Undefined instead of Null from a Form drop down list when I haven't selected anything?

So, I have a basic page where I find() data from a collection in my Database and I created it using Node.js, express, MongoDB and ejs. I created a Form so that I can filter data from the rendered table and send it as filters to mongoDb. The form consists of 3 input types, 2 text types and 1 drop down along with a submit button.
My problem lies in the Drop down. When I select a value from the drop down and submit, I get the filtered result. But whenever I leave the drop down as it is and fill any other input field to filter with only those, I dont get back any Data.
Here is the code for my Drop down:
<div class="col-lg-12">
<select class="form-control" name="searchDept">
<option selected disabled value="">Choose Department</option>
<option value="Computer Science Engineering">Computer Science Engineering</option>
<option value="Information Science Engineering">Information Science Engineering</option>
<option value="Electrical & Electronics Engineering">Electrical & Electronics Engineering</option>
<option value="Electronics and Communication Engineering">Electronics and Communication Engineering</option>
<option value="Mechanical Engineering">Mechanical Engineering</option>
<option value="Civil Engineering">Civil Engineering</option>
<option value="Main Office">Main Office</option>
<option value="Admission Office">Admission Office</option>
<option value="Principal Office">Principal Office</option>
</select>
</div>
And in my app.js file, this is my get method:
const searchName = req.body.searchName;
const searchPhone = req.body.searchPhone;
const searchDept = req.body.searchDept;
if (searchName != "" && searchPhone != "" && searchDept != "") {
var searchParameter = { $and: [{visitorName : searchName}, { $and: [{phone : searchPhone}, {deptOfVisit : searchDept}]}]}
} else if (searchName != "" && searchPhone == "" && searchDept != "") {
var searchParameter = { $and: [{visitorName : searchName}, {deptOfVisit : searchDept}]}
} else if (searchName == "" && searchPhone != "" && searchDept != "") {
var searchParameter = { $and: [{phone : searchPhone}, {deptOfVisit : searchDept}]}
} else if (searchName != "" && searchPhone != "" && searchDept == "") {
var searchParameter = { $and: [{visitorName : searchName}, {phone : searchPhone}]}
} else if (searchName != "" && searchPhone == "" && searchDept == "") {
var searchParameter = {visitorName : searchName}
} else if (searchName == "" && searchPhone == "" && searchDept != "") {
var searchParameter = {deptOfVisit : searchDept}
} else if (searchName == "" && searchPhone != "" && searchDept == "") {
var searchParameter = {phone : searchPhone}
} else {
var searchParameter = {}
}
console.log(searchName);
console.log(searchPhone);
console.log(searchDept);
console.log(searchParameter);
var visitorSearch = Visitor.find(searchParameter);
Everything works fine when I select one of those options from the List and I am able to find the right Data and render it. But If I leave the Drop down without selecting anything, I get back no records.
So I tried console logging everything and when I did, I realised it's passing an "Undefined" value instead of null and is getting in the first if statement instead of the one where it should be null.
Test
12345
undefined
{ '$and': [ { visitorName: 'Test' }, { '$and': [Array] } ] }
What am I doing wrong and what should I be doing?
I haven't really found an answer to this but I found myself a work around. I assigned the 2nd option as Selected as that was working without me having to select it and changed the "Choose Department" option to "None". So as #GarrGodfrey said in the comments, req.body get set on a change. I dont know how it works with the second option without me changing it but anyway, If I dont want to search by Department, I click on the Drop Down and select None whose value is "" or null. And the Search happens perfectly.

Syntax for a nested expression binding [SAPUI5]

i would like to set the visibility based on the tests of two different conditions. it musst fullfill the tests bellow.
Things that i want to test:
name !== ''
and name is not null
AND
nr === 13;
or nr === 14;
Syntax:
<Button visible="{= {${modelExample>name} !== '' &&amp ${modelExample>name} !== null} && {${modelExample>nr} === 13 || ${modelExample>nr} === 14 } ? true: false}"
Issue: It does give out an error.
Question: What would be the appropriate syntax for this conditionals. Is it even possible to test two different things ?
The readability of expression binding is kinda ...
if your condition get's to complex go for a formatter.(IMO better readability)
Expression Binding
JSONModel
this.getView().setModel(new JSONModel({
name: "",
nr: 10
}), "json");
XML
<Button text="test" visible="{= ${json>/name} && (${json>/nr} === 13 || ${json>/nr} === 14) ? true : false}"/>
Formatter
formatter.js
myCond: function (sName, iNumber) {
if (sName && (iNumber === 13 || iNumber === 14)) {
return true;
} else {
return false;
}
}
XML
<Button text="test" visible="{ parts: ['json>/name', 'json>/nr'], formatter: '.formatter.myCond'}"/>

discord.js content: Must be 2000 or fewer in length

I have a message which is lets say about 2k characters so how can i split the message so that it will send the messages in fragments
Example my Help command exceeded 2000 characters
if (!args[0]) {
// Load guild settings (for prefixes and eventually per-guild tweaks)
const settings = message.settings;
// Filter all commands by which are available for the user's level, using the <Collection>.filter() method.
const myCommands = message.guild ? client.commands.filter(cmd => client.levelCache[cmd.conf.permLevel] <= level) : client.commands.filter(cmd => client.levelCache[cmd.conf.permLevel] <= level && cmd.conf.guildOnly !== true);
// Here we have to get the command names only, and we use that array to get the longest name.
// This make the help commands "aligned" in the output.
const commandNames = myCommands.keyArray();
const longest = commandNames.reduce((long, str) => Math.max(long, str.length), 0);
let currentCategory = "";
let output = `= Command List =\n\n[Use ${settings.prefix}help <commandname> for details]\n`;
const sorted = myCommands.array().sort((p, c) => p.help.category > c.help.category ? 1 : p.help.name > c.help.name && p.help.category === c.help.category ? 1 : -1 );
sorted.forEach( c => {
const cat = c.help.category.toProperCase();
if (currentCategory !== cat) {
output += `\n== ${cat} ==\n`;
currentCategory = cat;
}
output += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
});
message.channel.send(output, {code:"asciidoc"});
} else {
// Show individual command's help.
let command = args[0];
if (client.commands.has(command)) {
command = client.commands.get(command);
if (level < client.levelCache[command.conf.permLevel]) return;
message.channel.send(`= ${command.help.name} = \n${command.help.description}\nusage::${command.help.usage}`, {code:"asciidoc"});
}
}
any easy way to split the message
I saw something https://stackoverflow.com/a/52863304/12843955 but didnt get it
I tried
let output = `= Command List =\n\n[Use ${settings.prefix}help <commandname> for details]\n`;
let output1 =`` , output2 = ``;
if (output.length < 1900 ) output += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
else if (output.length > 1900){
output1 += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
}
else if(output1.length >1900 && output.length > 1900 ) output2 += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
message.channel.send(output, {code:"asciidoc"});
if(output1 !== ``) message.channel.send(output1, {code:"asciidoc"});
if(output2 !== ``) message.channel.send(output2, {code:"asciidoc"});
and its working but still any better solution than this ?

how to remove {} empty field in array .. nodejs

i am using below code...but if Status is Empty iss show below result in database...i want to remove if Status is Empty ..
1 Address {}, Status {} save in database.
function CheckStatus(oldJob, newJob) {
var obj = {};
if(newJob && newJob.Status) {
obj.Status= {};
if (oldJob.Status.total !== newJob.Status.total) {
obj.Status.total = newJob.Status.total;
}
if (oldJob.Status.charge_description && oldJob.Status.charge_description !== newJob.Status.charge_description) {
obj.Status.charge_description = newJob.Status.charge_description;
}
}
}
Mongodb
"Job" : {
"_id" : ObjectId("5873b352e7621d08fccc5890"),
"updated_by" : "",
"details" : "{\"current_status\":\"Completed\",\"address\":{},\"Status\":{}}",
"changetype" : "Update",
"datetime" : ISODate("2017-01-09T15:59:14.202Z")
},
please help how what enter in If Condition ( below code not working)
if(obj.address = '{}')
{
console.log('Empty');
}
Setting an object's value to undefined essentially deletes them. You may use the undefined keyword easily as such:
newJob.address = undefined;
How i would check for an empty object and delete its content:
if(Object.keys(newJob.address).length === 0 && obj.constructor === Object){
newJob.address = undefined;
}
Solution is better explained in this question's answers:
How do I test for an empty JavaScript object?

Resources