FeathersJS Inserts 2 records into MySql from 1 REST call - feathersjs

When I use the .create(item) method to do an INSERT from the client (within the browser) I see 1 call via websocket or REST go to feathersjs. I see one request go into Feathersjs. For an unknown reason I see 2 rows created in MySql and 2 lines in the log that say: {"message":"after: name_of_service - Method: create","level":"info"}
Using sequelize 4.42.0 and feathers-sequelize 6.0.1
I do not have the issue when running create() from within the server code, only from client.
I found https://github.com/feathersjs-ecosystem/feathers-rethinkdb/issues/80 that looked simular but is for a different DB and the explanation did not fit with MySql.
I switched to MariaDB for other reasons but obviously nothing changed.
I was using FeathersJS v3.x and upgrading to v4.x to see if that would fix it. Nope. As I work around I have been making my own insert methods but it would be nice to use the built in ones.
I tried switching between REST and websocket.
My Hooks:
const { authenticate } = require('#feathersjs/authentication').hooks;
module.exports = {
before: {
all: [ ], // authenticate('jwt') normally use, but deactivated to debug
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
Service:
const createService = require('feathers-sequelize');
const createModel = require('../../models/name_of_service.model');
const hooks = require('./name_of_service.hooks');
module.exports = function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');
const options = {
Model,
paginate: {
default: 100,
max: 2000
}
};
app.use('/name_of_service', createService(options));
const service = app.service('name_of_service');
service.hooks(hooks);
};
I expected it to insert 1 row in MySql table. But got 2. I expected one row in the log for the after hook, but see 2. This has been happening for a couple of months and was thinking, hey, maybe I am not the only one.

Thank you everyone for your help. I found the issue.
I fixed my rooky mistake by changing:
app.configure(socketio());
app.configure(socketio(function(io) {io.sockets.setMaxListeners(555);}));
To:
app.configure(socketio(function(io) {io.sockets.setMaxListeners(555);}));

Related

Is there any way of conecting atoti cube with ActiveUI frontend?

We are trying to connect an atoti cube the same way that is on env.js on the Active UI frontend.
window.env = {
contentServerVersion: "5.11.x",
contentServerUrl: "https://activepivot-ranch.activeviam.com:5110",
// WARNING: Changing the keys of activePivotServers will break previously saved widgets and dashboards.
// If you must do it, then you also need to update each one's serverKey attribute on your content server.
activePivotServers: {
// You can connect to as many servers as needed.
// In practice most projects only need one.
"Ranch 5.11": {
url: "https://activepivot-ranch.activeviam.com:5110",
version: "5.11.1",
},
"Ranch 5.10": {
url: "https://activepivot-ranch.activeviam.com:5100",
version: "5.10.0",
},
"Ranch 5.9": {
url: "https://activepivot-ranch.activeviam.com:5900",
version: "5.9.4",
},
"my-server": {
url: "https://localhost:9090",
version: "5.10.x",
}
},
};
but when we launch the frontend we are just give this error: 404: The resource at http://localhost:9090/atoti/pivot/rest/v5/ping was not found.
The URL in your env.js is probably not correct. You can find the correct one by running the following in your notebook:
session.link()
Let's call what it returns my-url.
Then your env.js should look like this:
window.env = {
contentServerVersion: "5.10",
contentServerUrl: my-url,
activePivotServers: {
"my-server": {
url: my-url,
version: "5.10",
},
},
};
You might also have to change your version attribute. It depends on your atoti version, as follows:
atoti 0.6.x => version = "5.11.0"
atoti 0.5.x => version = "5.10.0"
atoti 0.2.x, 0.3.x, 0.4.x => version = "5.9.0"
earlier => version = "5.8.0"

Adding time based scheduling via ElasticBeanstalk Node JS SDK

I have been trying to add time-based scheduling via AWS SDK. Here is sample code snippet
const {ElasticBeanstalkClient ,
UpdateConfigurationTemplateCommand } = require('#aws-sdk/client-elastic-beanstalk');
const abortEnvironmentUpdateCommand = new
UpdateConfigurationTemplateCommand({ApplicationName:'Admin Portal',EnvironmentName:'xxxx-xxxx-v2',
"OptionSettings.member.1.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.1.OptionName": "MinSize",
"OptionSettings.member.1.Value": "1",
"Operation": "UpdateConfigurationTemplate",
"OptionSettings.member.2.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.2.OptionName": "MaxSize",
"OptionSettings.member.2.Value": "1",
"OptionSettings.member.3.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.3.OptionName": "DesiredCapacity",
"OptionSettings.member.3.Value": "1",
"OptionSettings.member.4.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.4.OptionName": "StartTime",
"OptionSettings.member.4.Value": "2022-08-18T00:00:00Z",
"TemplateName":'xxxxxTestConfiguration'});
elasticbeanstalktemp
.send(abortEnvironmentUpdateCommand)
.then(data => {
console.log("Data",data);
// do something
})
.catch(error => {
console.log("Error",error);
// error handling
});
In response, I am getting 200 status codes but when I am applying updated configuration to the environment, it doesn't add time-based scheduling action.
Can anyone help me pointing what I am doing wrong ?

Rest-spread not being transpiled when targeting edge with NextJS

I am trying to transpile my ES6 code via Babel, I am using the next/babel preset along with preset-env and I'm using the browsers: defaults target.
The NextJS preset comes with #babel/plugin-proposal-object-rest-spread in its plugins array, I'm wondering why I am getting an error when testing on edge that says Expected identifier, string or number, and when looking in the compiled JS for the error, I see it happens when {...t} occurs.
Here is my babel.config.js:
module.exports = {
presets: [
[
'next/babel',
{
'#babel/preset-env': {
targets: {
browsers: 'defaults'
},
useBuiltIns: 'usage'
}
}
]
],
plugins: [
'#babel/plugin-proposal-optional-chaining',
'#babel/plugin-proposal-nullish-coalescing-operator',
['styled-components', { ssr: true, displayName: true, preprocess: false }],
[
'module-resolver',
{
root: ['.', './src']
}
]
],
env: {
development: {
compact: false
}
}
};
Any help on this would be greatly appreciated!
In the end my problem was related to a package that was not being transpiled by babel. My solution was to use NextJS' next-transpile-modules plugin to get babel to transpile the package code into something that would work on the browsers I need.
Here's an example of my NextJS webpack config with the package I need transpiled specified:
const withTM = require('next-transpile-modules');
module.exports = withTM({
transpileModules: ['swipe-listener']
});
SCRIPT1028: Expected identifier, string or number error can occur in 2 situations.
(1) This error get trigger if you are using trailing comma after your last property in a JavaScript object.
Example:
var message = {
title: 'Login Unsuccessful',
};
(2) This error get trigger if you are using a JavaScript reserved word as a property name.
Example:
var message = {
class: 'error'
};
solution is to pass the class property value as a string. You will need to use bracket notation, however, to call the property in your script.
Reference:
ERROR : SCRIPT1028: Expected identifier, string or number

How to update a response through LimeSurvey's Remote Control (JSON)

I'm trying to modify a single response through Remote Control using request promise native with a Node Server, so far all API calls have been successful, unfortunately "update_response" has not.
this is what I've got:
var options = {
uri: "http://localhost/admin/remotecontrol",
method: "POST",
body: {
method:'update_response',
params:[sessionkey,surveyid,{ id: 5, token: "aValidToken", aValidColumnName: "a perfectly normal string" }],
id:1
},
json: true
};
request(options).then((body) => {
console.log(body.result);
}).catch((err) => {
res.send(err);
});
The LimeSurvey API docummentation is not quite clear as to what structure the third parameter should have (https://api.limesurvey.org/classes/remotecontrol_handle.html#method_update_response), funnily enough if I only pass { id: 5, token: "aValidToken" } it does work (outputs "true"), with a key value pair though I'm getting:
Error: Invalid Column names supplied: aValidColumnName
Has anyone had success with this?
The column names are the question or sub-question IDs - https://manual.limesurvey.org/SGQA_identifier/en
I would think that the third parameter is an array of question/sub-question IDs and answers.
{'123':'A1', '124':'A3', '128':'Some text input...'}

How can I set the correct order of files to be concatenated with gulp-bundle-assets

I use gulp-bundle-assets for processing my static resources. I have the next configuration in my bundle.config.js:
module.exports = {
bundle: {
...
vendor: {
scripts: [
'./bower_components/angular/angular.js',
'./bower_components/angular-aria/angular-aria.js',
'./bower_components/angular-material/angular-material.js',
'./bower_components/angular-translate/angular-translate.js',
'./bower_components/angular-animate/angular-animate.js'
]
options: {
uglify: false,
order: {
scripts: [
'angular.js',
'*.js'
]
}
}
}
},
...
};
Thus, the first script to be concatenated must be angular.js, but "options.order" doesn't work correct - the first concatenated file in the final script is angular-animate.js. So, my question is how to achieve the correct order?
I'm the author of gulp-bundle-assets. The problem is with your glob syntax. Under the covers, gulp-bundle-assets uses gulp-order, which itself uses minimatch. The docs for each give lots of examples but for your particular use-case, this minimatch example shows your problem:
var minimatch = require("minimatch")
minimatch("./bower_components/angular/angular.js", "angular.js") // false
minimatch("./bower_components/angular/angular.js", "./**/angular.js") // true
Unfortunately the ./ at the beginning is throwing off minimatch. The following should fix your problem:
options: {
order: {
scripts: [
'./**/angular.js',
'./**/*.js'
]
}
}
Hope that helps.