I am getting this error in console everytime I try to run the following code
$('#autcomplete_search').typeahead({
highlight: true
},
{
name: 'apple_game',
remote: "/search/autocomplete?keyword=make"
});
Typeahead: Uncaught Error Missing source
If fetching remote, you need to specify the engine. Here is an example from the docs
var bestPictures = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: '../data/films/post_1960.json',
remote: '../data/films/queries/%QUERY.json'
});
bestPictures.initialize();
$('#remote .typeahead').typeahead(null, {
name: 'best-pictures',
displayKey: 'value',
source: bestPictures.ttAdapter()
});
in this example, var bestPictures is your engine
bloodhound documentation
Related
I am trying to create a document, on an existing collection, using MongoDB + async..await programming + session/transaction control (in order to be able to rollback to a previous state if anything goes wrong). The relevant code is shown below:
exports.campaign_totalize = async (campaign, start_date, end_date, now) => {
var session = await mongoose.startSession();
session.startTransaction();
try {
// ...
let commission = await commissionModel.create({
datetime: Date.now(),
value: 10,
status: 'issued',
affiliate: affiliate_id,
campaign: campaign_id
}, { session: session });
// ...
}
// ...
} catch (err) {
console.log("Error totalizing commissions:", err);
await session.abortTransaction();
session.endSession();
throw err;
}
}
Executing code above I get ValidationError on ALL fields (even being sure they are all OK). If I remove the session parameter, however, everything works fine! The collections exists for sure.
Below information about my environment:
"dependencies": {
"express": "^4.16.4",
"mongoose": "^5.3.9",
"mongoose-bcrypt": "^1.6.0",
"validator": "^10.9.0"
}
$ node --version
v10.14.0
$ mongod --version
db version (v3.6.3) -> v4.0.4
Thank you very much.
Update:
As Shivam Pandey pointed out in the comments, mongoDB version starts supporting transactions on version 4.0. I just updated it to 4.0.4 and it is returning the same errors, though.
Update 2:
Stack trace:
Trace: error
at Object.exports.campaign_totalize (/home/luiz/magalabs/magafilio/magafilio-server/logic/commission_calc.js:147:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
Error totalizing commissions: { ValidationError: Commission validation failed: campaign: All commissions must be associated to a campaign, affiliate: All commissions must be associated to an affiliate, status: Commission needs a status associated, value: Commission needs a value - use 0 for no valued commissions, datetime: Commission needs date/time info
at ValidationError.inspect (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validation.js:59:24)
at formatValue (internal/util/inspect.js:453:31)
at inspect (internal/util/inspect.js:193:10)
at Object.formatWithOptions (util.js:165:18)
at Console.(anonymous function) (console.js:188:15)
at Console.log (console.js:199:31)
at Object.exports.campaign_totalize (/home/luiz/magalabs/magafilio/magafilio-server/logic/commission_calc.js:148:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
errors:
{ campaign:
{ ValidatorError: All commissions must be associated to a campaign
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at ObjectId.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'All commissions must be associated to a campaign',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'campaign',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
affiliate:
{ ValidatorError: All commissions must be associated to an affiliate
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at ObjectId.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'All commissions must be associated to an affiliate',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'affiliate',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
status:
{ ValidatorError: Commission needs a status associated
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at SchemaString.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'Commission needs a status associated',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'status',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
value:
{ ValidatorError: Commission needs a value - use 0 for no valued commissions
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at SchemaNumber.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'Commission needs a value - use 0 for no valued commissions',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'value',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
datetime:
{ ValidatorError: Commission needs date/time info
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at SchemaDate.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'Commission needs date/time info',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'datetime',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true } },
_message: 'Commission validation failed',
name: 'ValidationError' }
I think there's an issue with how you're using the create, or at least that's my first guess.
To specify options, docs must be an array, not a spread.
https://mongoosejs.com/docs/api.html#model_Model.create
Has to be in this form
Model.create([doc], options)
you have
Model.create(doc, options)
This might be what you want
let [commission] = await commissionModel.create([{datetime: Date.now(),
...}], {session})
let [commission] = await commissionModel.create([doc], options})
When you pass an array into Model.create(), Model.create() will return an array with the documents you created/saved so that's why I used "let [commission]" which will set variable commission to the first item in the array that gets returned.
I'm getting the error
Invalid exit definition ("success"). Must be a dictionary-- i.e. plain JavaScript object like `{}`.
Invalid exit definition ("error"). Must be a dictionary-- i.e. plain JavaScript object like `{}`.
when doing sails lift. The error is on getRole.js
module.exports = {
friendlyName: 'Get Role',
description: '',
inputs: {
user_id: {
friendlyName: 'User Id',
description: 'The ID of the user to check role',
type: 'string',
required: true
}
},
exits: {
success: function (role){
return role;
},
error: function (message) {
return message;
}
},
fn: function (inputs, exits) {
User.findOne({ id: inputs.user_id } , function (err, user) {
if (err) return exits.err(err);
return exits.success(user.role);
});
}
};
This is a new error, and looking at my git, nothing has changed in my code since it successfully compiled. I understand the Sails version (v1.0) I'm using in beta, so I'm taking that into account.
Exits cannot be defined as functions. There is a special syntax (Machine Spec) to define exits. In your example this should work:
exits: {
error: {
description: 'Unexpected error occurred.',
},
success: {
description: 'Role was succesffuly fetched'
}
},
You can read more info about helper exits here: https://next.sailsjs.com/documentation/concepts/helpers
May changes occur on the last release 1.0.0-38. I've not checked underneath yet, but the way to execute helpers changed: on .exec() I get errors. Now, use .switch();
I was using traceur and es6 loader, but I change to systemjs and when I try to use System.paths['jquery'], I had the message:
Error: Cannot set SystemJS.paths["jquery"] directly. Use SystemJS.config({ paths: { "jquery": ... } }) rather
So I change to:
System.config({
paths: {
"jquery": "./node_modules/jquery/dist/jquery.js"
}
});
System.import('jquery');
System.import('src/app.js');
Show this error:
system.js:4 Uncaught (in promise) Error: Fetch error: 404 Not Found
system.js:4 Uncaught (in promise) Error: Unable to dynamically transpile ES module
A loader plugin needs to be configured via `SystemJS.config({ transpiler: 'transpiler-module' })`.
I tried, but didn't work:
System.config({
transpiler: "babel",
map: {
"babel": "./node_modules/babel-core/lib/api/browser.js",
"jquery": "./node_modules/jquery/dist/jquery.js"
}
})
Error
system.js:4 Uncaught (in promise) Error: Fetch error: 404 Not Found
Instantiating localhost:3000/node_modules/babel-core/lib/api/node
Loading localhost:3000/node_modules/babel-core/lib/api/browser.js
Loading babel
Unable to load transpiler to transpile localhost:3000/src/app.js
I think you need to inform systemjs that jquery should be added as a global script so it doesn't try to transpile it. Try the following:
System.config({
paths: {
"jquery": "./node_modules/jquery/dist/jquery.js"
},
meta: {
"jquery": { "format": "global" }
}
});
I have two Bloodhound datasets, a local and a remote. The local data will always be duplicated in the remote results. I've found the dupDetector method mentioned in Typeahead documentation, but it seems this method only works if both my local and remote datasets are built within the same Bloodhound object.
Here's my code. Is there a way to filter duplicates across multiple Bloodhound datasets?
var local_props = new Bloodhound({
datumTokenizer: function (p) {
return Bloodhound.tokenizers.whitespace(p.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: portfolio_props,
limit: 100
});
var remote_props = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'properties/searchPropertiesLike?substr=%QUERY',
dupDetector: function(remoteMatch, localMatch) {
return remoteMatch.name === localMatch.name;
},
limit: 100
});
local_props.initialize();
remote_props.initialize();
$('#typeahead-property').typeahead({
hint: true,
highlight: true,
minLength: 2
},
{
name: 'port_properties',
displayKey: 'name',
source: local_props.ttAdapter(),
templates: {
header: '<h3>Your Portfolio Properties</h3>'
}
},
{
name: 'dir_properties',
displayKey: 'name',
source: remote_props.ttAdapter(),
templates: {
header: '<h3>Properties Directory</h3>'
}
});
I'm trying to set up a local testing environment for my Dojo project. I've decided on Karma as the test runner and Jasmine as the suite. I've found a few example karma.config files on how to set it up and that works fine.
But when I try to set up the dojo.config in main test file to point to a local version of dojo it just breaks.
This works:
var dojoConfig = {
packages: [
{
name: 'dojo',
location: 'http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo'
}, {
name: 'dojox',
location: 'http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojox'
}, {
name: 'dijit',
location: 'http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit'
}
],
async: true
};
But as soon as I do something like this:
var dojoConfig = {
packages: [
{
name: 'dojo',
location: 'base/lib/dojo'
}, {
name: 'dojox',
location: 'base/lib/dojox'
}, {
name: 'dijit',
location: 'base/lib/dijit'
}
],
async: true
};
This is the error log:
ERROR: 'There is no timestamp for /base/lib/dojo/domReady.js!'
ERROR: 'There is no timestamp for /base/lib/dojo/_base/array.js!'
WARN [web-server]: 404: /base/lib/dojo/domReady.js
Then it runs through and outputs the same for all dojo modules.
That's an odd error... I can't give you much more than a Google search (You did google your error right?), but have you seen these questions?
test not running on karma/jasmine/require.js 'There is no timestamp for *lib*!' error
karma error 'There is no timestamp for'