thosakwe / feathers-seeder Goto Github PK
View Code? Open in Web Editor NEWStraightforward data seeder for Feathers.js services. Promise-based.
Home Page: https://docs.feathersjs.com/guides/seeding-services.html
License: MIT License
Straightforward data seeder for Feathers.js services. Promise-based.
Home Page: https://docs.feathersjs.com/guides/seeding-services.html
License: MIT License
Hey, great project!
Given the following dataset:
export default
[
{ 'name': '50l bag' },
{ 'name': 'holdall' },
{ 'name': 'bumbag (fannypack)' },
]
It would be great to be able to import this data 1:1 with the original dataset - no randomization or duplication. Any ideas how I could accomplish this?
So far I've tried
import data from './data/items'
let options = {
path: 'items',
count: data.length,
template: [
...data
]
}
module.exports = options
But obvious problems are obvious xD
Cheers @thosakwe!
So, I have this scenario (using Postgres/sequelize):
1 insert predefined users
2 insert predefined roles
3 insert predefined users-roles
I'm stuck at the 3rd step, it requires users and roles to exist so that it can insert correctly.
if I use a callback after each template, the seeder tries to execute each following template the same number of times, but if I don't use a callback, then each service is executed asynchronously and it doesn't work because users and/or roles do not exist yet.
How can I do this?
Thanks!
configuration file:
module.exports = {
services: [
{
delete: true,
randomize: false,
path: 'users',
templates: [
{
user_id: '22d5362c-efdc-11e6-bc64-92361f002671',
username: 'sss',
email: '[email protected]',
password: '1234'
}
],
callback(user, seed) {
return seed({
delete: true,
randomize: false,
path: 'roles',
templates: [
{
role_id: '5abec6e0-efda-11e6-bfc0-4979bfeeb47e',
name: 'admin'
},
{
role_id: '79e7c441-efda-11e6-a9dc-5364a8fb9f30',
name: 'user'
},
{
role_id: 'a18da632-efdb-11e6-a946-afdca6ae2a45',
name: 'guest',
status: 'inactive'
}
],
callback(role, seed) {
return seed({
delete: true,
randomize: false,
path: 'user_roles',
templates: [
{
user_id: '22d5362c-efdc-11e6-bc64-92361f002671',
role_id: '5abec6e0-efda-11e6-bfc0-4979bfeeb47e'
}
]
});
}
});
}
}
]
};
When I increase the number of 'users' I seed I get:
{ GeneralError: ResourceRequest timed out
at new GeneralError (/home/usr/api_server/node_modules/feathers-errors/lib/index.js:177:17)
at /home/usr/api_server/node_modules/feathers-seeder/lib/index.js:45:15
type: 'FeathersError',
name: 'GeneralError',
message: 'ResourceRequest timed out',
code: 500,
className: 'general-error',
data: undefined,
errors: {} } +0ms
With just 10 users it gets through without error, but some more and the error will come.
I have seeder setup with markets
service:
{
path: 'markets',
count: 2,
template: {
name: '{{lorem.words(3)}}',
slug: '{{lorem.words(1)}}'
}
}
With result:
info: after: markets - Method: remove
info: after: markets - Method: create
info: after: markets - Method: create
But I see nothing show up in database (postgres). However, if I use REST api, I get it in the database.
info: after: markets - Method: create
App is otherwise working fine. Example:
I have the need to load a set of static user data from a predefined JSON file (they are actual users from an external OAuth provider), rather than generating from a template.
The configuration allows an array of templates that are selected randomly, but that won't guarantee all users are loaded.
What do you recommend?
Would you be willing to make the feathers-seeder library MIT license?
I am getting:
info: Feathers application started on http://localhost:8089
error: Unhandled Rejection at: Promise Promise {
<rejected> { GeneralError: Cannot read property 'remove' of undefined
at new GeneralError (/home/usr/api_server/node_modules/feathers-errors/lib/index.js:177:17)
at /home/usr/api_server/node_modules/feathers-seeder/lib/index.js:45:15
at <anonymous>
at runMicrotasksCallback (internal/process/next_tick.js:121:5)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:684:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3
type: 'FeathersError',
name: 'GeneralError',
message: 'Cannot read property \'remove\' of undefined',
code: 500,
className: 'general-error',
data: undefined,
errors: {} } } GeneralError: Cannot read property 'remove' of undefined
at new GeneralError (/home/usr/api_server/node_modules/feathers-errors/lib/index.js:177:17)
at /home/usr/api_server/node_modules/feathers-seeder/lib/index.js:45:15
at <anonymous>
at runMicrotasksCallback (internal/process/next_tick.js:121:5)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:684:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3
my config:
const moment = require('moment');
module.exports = {
count: 10,
// delete: true,
disabled: false,
params: {seeder: 'true'},
services: [
{
path: 'users.service.js',
template: {
name: '{{name.firstName}} {{name.lastName}}',
password: '{{internet.password}}',
username: '{{internet.userName}}',
email: '{{internet.email}}',
created_at: () => moment().subtract(7, 'days').format()
}
}
]
};
Template:
const services = [{
path: 'dummy',
template: {
name: '{{name.firstName}} {{name.lastName}}',
age: 99
}
}];
produces
Seeding app...
Params seeding 'dummy': {}
Creating 1 instance(s)
Running 1 seeder(s)...
Deleted from 'dummy:' []
About to compile this template: { name: '{{name.firstName}} {{name.lastName}}', age: 99 }
Populating name from this value: {{name.firstName}} {{name.lastName}}
This is a string.
Populating age from this value: 99
This is a number
About to compile this template: 99
Compiled template: { name: 'Jaden Abshire', age: {} }
Created: { name: 'Jaden Abshire', age: {}, id: 0 }
Created 1 total items: [ [ { name: 'Jaden Abshire', age: {}, id: 0 } ] ]
1 dummy: { name: 'Jaden Abshire', age: {}, id: 0 }
Hello,
I am not able to install feathers-seed, here is the log:
> [email protected] postinstall /Users/.../backend/node_modules/feathers-seeder
> npm run compile
> [email protected] compile /Users/.../backend/node_modules/feathers-seeder
> rimraf lib/ && babel -d lib/ src/
ReferenceError: Unknown plugin "add-module-exports" specified in "/Users/.../backend/node_modules/feathers-seeder/.babelrc" at 0, attempted to resolve relative to "/Users/.../backend/node_modules/feathers-seeder"
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:177:17
at Array.map (native)
at Function.normalisePlugins (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:153:20)
at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:245:36)
at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:383:12)
at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:223:65)
at new File (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:140:24)
at Pipeline.transform (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transform (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:52:22)
at Object.compile (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:61:12)
Thanks in advance !
Let's say i want to generate [email protected] to [email protected]. It would be nice to be able to specify the following template:
template: {
email: 'user_{{index}}@myservice.com',
password: 'test123'
}
hi , I want to use custom locale with the faker but it is not pussible to do this . can you add option to change locale in service options level or seeder options level . and when there is no config for locale default back to english ?
thank you
I get the following output when running npm audit
:
=== npm audit security report ===
Manual Review
Some vulnerabilities require your attention to resolve
Visit https://go.npm.me/audit-guide for additional guidance
Low Regular Expression Denial of Service
Package braces
Patched in >=2.3.1
Dependency of feathers-seeder
Path feathers-seeder > @feathersjs/cli > @feathersjs/tools >
@feathersjs/jscodeshift > micromatch > braces
More info https://nodesecurity.io/advisories/786
Low Regular Expression Denial of Service
Package braces
Patched in >=2.3.1
Dependency of feathers-seeder
Path feathers-seeder > @feathersjs/cli > generator-feathers >
@feathersjs/jscodeshift > micromatch > braces
More info https://nodesecurity.io/advisories/786
Low Regular Expression Denial of Service
Package braces
Patched in >=2.3.1
Dependency of feathers-seeder
Path feathers-seeder > @feathersjs/cli > generator-feathers >
@feathersjs/tools > @feathersjs/jscodeshift > micromatch >
braces
More info https://nodesecurity.io/advisories/786
found 3 low severity vulnerabilities in 877366 scanned packages
3 vulnerabilities require manual review. See the full report for details.
Kindly update the affected package.
The primary field auto increment value is not resetted on delete operation, thus when seeding the app the first time and creating 1 user he will have the id 1. After restarting node.js and seeding again, the database is clean but the id of the user is 2.
Currently with the callback one can store the ids of entities to dynamically set the correct relationships in later services(e.g. if i want to relate an item to the first user i created i need to know the userId). But to make life simpler, it would be great if the auto increment value is resetted, because one can then easier prototype the config, without having to make sure to not use hard-coded ids.
Seeders should work on models for a variety of reasons.
Another question/possible improvement.
Currently it seems that the execution order of service array is not guaranteed to be like stated in the config file right?
e.g. i have the following pseudocode:
service: [
{path: 'users',template:{...}},
{path: 'panels',template:{...}},
{path: 'studies',template:{...}}
]
It seems that he is first inserting the panels, then the studies and presumbly the users at last. Could it be alphabetical ordered? Anyway i first need users to be created, otherwise my relation constraints(sequelize-adapter) are not fullfiled.
Any idea why this is? Or how one can fix that? It would be totally fine if he is just respecting the order of the array.
Hi,
great package! Is there an easy way to enable all the URLs to use https
instead?
Thanks!
Is there any way to get a date such as {{date.future}} converted into ISO format? It seems when I use that I get a Date.toString() version of it such as Wed Jul 25 2018 18:42:57 GMT-0400 (Eastern Daylight Time) instead of ISO like 2018-01-27T11:59:18.201Z (these dates aren't equivalent, just examples). I've tried creating a new Date object from the string and using toISOString() but it's giving me errors. I'm probably just not doing it right.
The reason I'm asking is that I'm using Moment to display the dates and I'm getting a warning now about dates and I'd like to clear it up.
From Moment
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release.
Any help would be appreciated. Thanks.
Because of the latest change in the package.json (ffdaee9#diff-b9cfc7f2cdf78a7f4b91a753d10865a2L5) i get
Error: Cannot find module 'feathers-seeder'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
However when reverting the change(renaming back to .js) it works. I'm using latest nodeJS and intellij via:
"C:\Program Files\nodejs\node.exe" C:\Users\xxxx\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js -x "node --harmony-async-await" --debug=3001 D:\yyyyyyy\src\index.js
I think it was just a typo, or there is something special about .jsnpm file format that i wasn't aware of :P
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.