Merge branch 'master' into heroku-strapi-project-updates

This commit is contained in:
Jim LAURIE 2019-04-22 15:19:36 +02:00 committed by GitHub
commit d06123a677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 370 additions and 139 deletions

View File

@ -31,3 +31,4 @@
- [Migration guide from alpha.22 to alpha.23](migration-guide-alpha.22-to-alpha.23.md)
- [Migration guide from alpha.23 to alpha.24](migration-guide-alpha.23-to-alpha.24.md)
- [Migration guide from alpha.24 to alpha.25](migration-guide-alpha.24-to-alpha.25.md)
- [Migration guide from alpha.25 to alpha.26](migration-guide-alpha.25-to-alpha.26.md)

View File

@ -55,13 +55,13 @@ Then, delete your old `plugins` folder and replace it with the new one.
## Update Mongoose
Update all your API services by following this update https://github.com/strapi/strapi/pull/2812/files#diff-c36b911d1bc2922e1d7cf93ae692e054R132
Update all your API services by following this update [https://github.com/strapi/strapi/pull/2812/files#diff-c36b911d1bc2922e1d7cf93ae692e054R132](https://github.com/strapi/strapi/pull/2812/files#diff-c36b911d1bc2922e1d7cf93ae692e054R132)
## Update Bookshelf
Update all your API services by following this update https://github.com/strapi/strapi/pull/2970/files#diff-61ba361ed6161efcd5f4e583001cc9c9R240 and https://github.com/strapi/strapi/pull/2864/files#diff-61ba361ed6161efcd5f4e583001cc9c9R124
Update all your API services by following this update [https://github.com/strapi/strapi/pull/2970/files#diff-61ba361ed6161efcd5f4e583001cc9c9R240](https://github.com/strapi/strapi/pull/2970/files#diff-61ba361ed6161efcd5f4e583001cc9c9R240) and [https://github.com/strapi/strapi/pull/2864/files#diff-61ba361ed6161efcd5f4e583001cc9c9R124](https://github.com/strapi/strapi/pull/2864/files#diff-61ba361ed6161efcd5f4e583001cc9c9R124)
We update the name of the life cycle for the before/after fetch all https://github.com/strapi/strapi/pull/2965/files
We update the name of the life cycle for the before/after fetch all [https://github.com/strapi/strapi/pull/2965/files](https://github.com/strapi/strapi/pull/2965/files)
You will have to replace `beforeFetchCollection` by `beforeFetchAll` if you added theses functions in you `Model.js` files.
<br>

View File

@ -0,0 +1,185 @@
# Migration guide from alpha.25 to alpha.26
**Here are the major changes:**
- Deep filtering
- Content type builder refactoring
**Useful links:**
- Changelog: [https://github.com/strapi/strapi/releases/tag/v3.0.0-alpha.26](https://github.com/strapi/strapi/releases/tag/v3.0.0-alpha.26)
- GitHub diff: [https://github.com/strapi/strapi/compare/v3.0.0-alpha.25...v3.0.0-alpha.26](https://github.com/strapi/strapi/compare/v3.0.0-alpha.25...v3.0.0-alpha.26)
<br>
::: note
Feel free to [join us on Slack](http://slack.strapi.io) and ask questions about the migration process.
:::
<br>
## Getting started
Install Strapi `alpha.26` globally on your computer. To do so run `npm install strapi@3.0.0-alpha.26 -g`.
When it's done, generate a new empty project `strapi new myNewProject` (don't pay attention to the database configuration).
<br>
## Update node modules
Update the Strapi's dependencies version (move Strapi's dependencies to `3.0.0-alpha.26` version) of your project.
Run `npm install strapi@3.0.0-alpha.26 --save` to update your strapi version.
<br>
## Update the Admin
::: note
If you performed updates in the Admin, you will have to manually migrate your changes.
:::
Delete your old admin folder and replace it with the new one.
<br>
## Update the Plugins
::: note
If you did a custom update on one of the plugins, you will have to manually migrate your update.
:::
Copy the fields and relations you had in your `/plugins/users-permissions/models/User.settings.json` and `/plugins/users-permissions/config/jwt.json` file in the new one.
Then, delete your old `plugins` folder and replace it with the new one.
## Add deep filtering feature
By default your generated API will not have the deep filtering feature provide by this release. You will have to make some updates.
### Updating Mongoose
**Updating your controllers**: [https://github.com/strapi/strapi/pull/2961/files#diff-008d6bf29828238415549d6caf613284](https://github.com/strapi/strapi/pull/2961/files#diff-008d6bf29828238415549d6caf613284)
You will have to add `, next, { populate } = {}` in the arguments of the `find` function.
Before
```js
find: async (ctx) => {
// ...
},
```
After
```js
find: async (ctx, next, { populate } = {}) => {
// ...
},
```
**Updating your services**: [https://github.com/strapi/strapi/pull/2961/files#diff-c36b911d1bc2922e1d7cf93ae692e054](https://github.com/strapi/strapi/pull/2961/files#diff-c36b911d1bc2922e1d7cf93ae692e054)
You will have to add this requirement on the top of you file `const { convertRestQueryParams, buildQuery } = require('strapi-utils');`
Replace the `fetchAll` function by the following code.
```js
fetchAll: (params, populate) => {
const filters = convertRestQueryParams(params);
const populateOpt = populate || <%= globalID %>.associations
.filter(ast => ast.autoPopulate !== false)
.map(ast => ast.alias);
return buildQuery({
model: <%= globalID %>,
filters,
populate: populateOpt,
});
},
```
Replace the `count` function by the following code.
```js
count: (params) => {
const filters = convertRestQueryParams(params);
return buildQuery({
model: <%= globalID %>,
filters: { where: filters.where },
})
.count();
```
And replace `<%= globalID %>` by the Global of your API.
## Updating Bookshelf
**Updating your controllers**: [https://github.com/strapi/strapi/pull/2961/files#diff-a2a09f28ea5f2a78c485c232dd2dbfde](https://github.com/strapi/strapi/pull/2961/files#diff-a2a09f28ea5f2a78c485c232dd2dbfde)
You will have to add `, next, { populate } = {}` in the arguments of the `find` function.
Before
```js
find: async (ctx) => {
// ...
},
```
After
```js
find: async (ctx, next, { populate } = {}) => {
// ...
},
```
Send this new argument in the service function.
Before `return strapi.services.<%= id %>.fetchAll(ctx.query);`
After: `return strapi.services.<%= id %>.fetchAll(ctx.query, populate);`
It will be the same update for the `count` function.
**Updating your services**: [https://github.com/strapi/strapi/pull/2961/files#diff-61ba361ed6161efcd5f4e583001cc9c9](https://github.com/strapi/strapi/pull/2961/files#diff-61ba361ed6161efcd5f4e583001cc9c9)
You will have to add this requirement on the top of you file `const { convertRestQueryParams, buildQuery } = require('strapi-utils');`
Replace the `fetchAll` function by the following code.
```js
fetchAll: (params, populate) => {
// Select field to populate.
const withRelated = populate || <%= globalID %>.associations
.filter(ast => ast.autoPopulate !== false)
.map(ast => ast.alias);
const filters = convertRestQueryParams(params);
return <%= globalID %>.query(buildQuery({ model: <%= globalID %>, filters }))
.fetchAll({ withRelated })
.then(data => data.toJSON());
},
```
Replace the `count` function by the following code.
```js
count: (params) => {
// Convert `params` object to filters compatible with Bookshelf.
const filters = convertRestQueryParams(params);
return <%= globalID %>.query(buildQuery({ model: <%= globalID %>, filters: _.pick(filters, 'where') })).count();
},
```
And replace `<%= globalID %>` by the Global of your API.
<br>
That's all, you have now upgraded to Strapi `alpha.26`.

View File

@ -1,6 +1,6 @@
{
"private": true,
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"dependencies": {},
"devDependencies": {
"assert": "~1.3.0",
@ -43,7 +43,8 @@
"shelljs": "^0.7.7",
"snyk": "^1.99.0",
"strapi-lint": "file:packages/strapi-lint",
"wait-on": "^3.2.0"
"wait-on": "^3.2.0",
"yargs": "^13.2.2"
},
"scripts": {
"clean": "npm run removesymlinkdependencies && npx rimraf package-lock.json && npx rimraf packages/*/package-lock.json",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-admin",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Strapi Admin",
"repository": {
"type": "git",
@ -35,8 +35,8 @@
"devDependencies": {
"cross-env": "^5.0.5",
"sanitize.css": "^4.1.0",
"strapi-helper-plugin": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26",
"strapi-utils": "3.0.0-alpha.26"
},
"author": {
"name": "Strapi",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-admin",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate the default admin panel for a Strapi application.",
"homepage": "http://strapi.io",
"keywords": [
@ -19,8 +19,8 @@
"fs-extra": "^4.0.1",
"lodash": "^4.17.5",
"shelljs": "^0.7.8",
"strapi-admin": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-admin": "3.0.0-alpha.26",
"strapi-utils": "3.0.0-alpha.26"
},
"author": {
"email": "hi@strapi.io",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-api",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate an API for a Strapi application.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-controller",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate a controller for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-model",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate a model for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-new",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate a new Strapi application.",
"homepage": "http://strapi.io",
"keywords": [
@ -22,7 +22,7 @@
"ora": "^2.1.0",
"request": "^2.88.0",
"shelljs": "^0.7.8",
"strapi-utils": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.26",
"uuid": "^3.1.0"
},
"scripts": {

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-plugin",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate an plugin for a Strapi application.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-policy",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate a policy for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-service",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Generate a service for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Master of ceremonies for the Strapi generators.",
"homepage": "http://strapi.io",
"keywords": [
@ -20,7 +20,7 @@
"fs-extra": "^4.0.0",
"lodash": "^4.17.5",
"reportback": "^2.0.1",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-utils": "3.0.0-alpha.26"
},
"author": {
"name": "Strapi team",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-helper-plugin",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Helper for Strapi plugins development",
"engines": {
"node": ">= 10.0.0",

View File

@ -81,17 +81,18 @@ const buildJoinsAndFilter = (qb, model, whereClauses) => {
const buildJoin = (qb, assoc, originInfo, destinationInfo) => {
if (assoc.nature === 'manyToMany') {
const joinTableAlias = generateAlias(assoc.tableCollectionName);
qb.leftJoin(
`${assoc.tableCollectionName} AS ${joinTableAlias}`,
`${joinTableAlias}.${singular(originInfo.model.collectionName)}_${
`${originInfo.model.databaseName}.${assoc.tableCollectionName} AS ${joinTableAlias}`,
`${joinTableAlias}.${singular(originInfo.model.globalId.toLowerCase())}_${
originInfo.model.attributes[assoc.alias].column
}`,
`${originInfo.alias}.${originInfo.model.primaryKey}`
);
qb.leftJoin(
`${destinationInfo.model.collectionName} AS ${destinationInfo.alias}`,
`${joinTableAlias}.${singular(destinationInfo.model.collectionName)}_${
`${destinationInfo.model.databaseName}.${destinationInfo.model.collectionName} AS ${destinationInfo.alias}`,
`${joinTableAlias}.${singular(destinationInfo.model.globalId.toLowerCase())}_${
destinationInfo.model.primaryKey
}`,
`${destinationInfo.alias}.${destinationInfo.model.primaryKey}`
@ -110,7 +111,7 @@ const buildJoinsAndFilter = (qb, model, whereClauses) => {
: `${originInfo.alias}.${assoc.alias}`;
qb.leftJoin(
`${destinationInfo.model.collectionName} AS ${destinationInfo.alias}`,
`${destinationInfo.model.databaseName}.${destinationInfo.model.collectionName} AS ${destinationInfo.alias}`,
externalKey,
internalKey
);

View File

@ -23,6 +23,20 @@ const buildQuery = require('./buildQuery');
const PIVOT_PREFIX = '_pivot_';
const GLOBALS = {};
const getDatabaseName = connection => {
const dbName = _.get(connection.settings, 'database');
switch (_.get(connection.settings, 'client')) {
case 'sqlite3':
return 'main';
case 'pg':
return `${dbName}.public`;
case 'mysql':
return dbName;
default:
return dbName;
}
};
/**
* Bookshelf hook
*/
@ -83,6 +97,7 @@ module.exports = function(strapi) {
// Add some informations about ORM & client connection & tableName
definition.orm = 'bookshelf';
definition.databaseName = getDatabaseName(connection);
definition.client = _.get(connection.settings, 'client');
_.defaults(definition, {
primaryKey: 'id',

View File

@ -121,16 +121,16 @@ module.exports = {
// set relation to null for all the ids not in the list
const currentIds = response[current];
const diff = _.differenceWith(property, currentIds, (a, b) => {
const toRemove = _.differenceWith(currentIds, property, (a, b) => {
return `${a[assocModel.primaryKey] || a}` === `${b[assocModel.primaryKey] || b}`;
});
const updatePromise = assocModel
.where(assocModel.primaryKey, 'in', currentIds.map(val => val[assocModel.primaryKey]||val))
.where(assocModel.primaryKey, 'in', toRemove.map(val => val[assocModel.primaryKey]||val))
.save({ [details.via] : null }, { method: 'update', patch: true, require: false })
.then(() => {
return assocModel
.where(assocModel.primaryKey, 'in', diff.map(val => val[assocModel.primaryKey]||val))
.where(assocModel.primaryKey, 'in', property.map(val => val[assocModel.primaryKey]||val))
.save({ [details.via] : primaryKeyValue }, { method: 'update', patch: true, require: false });
});

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-bookshelf",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Bookshelf hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [
@ -21,8 +21,8 @@
"lodash": "^4.17.5",
"pluralize": "^6.0.0",
"rimraf": "^2.6.2",
"strapi-hook-knex": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-hook-knex": "3.0.0-alpha.26",
"strapi-utils": "3.0.0-alpha.26"
},
"strapi": {
"dependencies": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-ejs",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "EJS hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-knex",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Knex hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -67,23 +67,21 @@ module.exports = {
return _.set(acc, current, property);
}
case 'oneToMany': {
// receive array of ids or array of objects with ids
// set relation to null for all the ids not in the list
const currentIds = response[current];
const diff = _.differenceWith(property, currentIds, (a, b) => {
const toRemove = _.differenceWith(currentIds, property, (a, b) => {
return `${a[assocModel.primaryKey] || a}` === `${b[assocModel.primaryKey] || b}`;
});
const updatePromise = assocModel.updateMany({
[assocModel.primaryKey]: {
$in: currentIds.map(val => new mongoose.Types.ObjectId(val[assocModel.primaryKey]||val))
$in: toRemove.map(val => new mongoose.Types.ObjectId(val[assocModel.primaryKey]||val))
}
}, { [details.via] : null })
.then(() => {
return assocModel.updateMany({
[assocModel.primaryKey]: {
$in: diff.map(val => new mongoose.Types.ObjectId(val[assocModel.primaryKey]||val))
$in: property.map(val => new mongoose.Types.ObjectId(val[assocModel.primaryKey]||val))
}
}, { [details.via] : primaryKeyValue });
});

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-mongoose",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Mongoose hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [
@ -20,7 +20,7 @@
"mongoose-float": "^1.0.3",
"pluralize": "^6.0.0",
"rimraf": "^2.6.2",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-utils": "3.0.0-alpha.26"
},
"author": {
"email": "hi@strapi.io",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-redis",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Redis hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [
@ -19,7 +19,7 @@
"lodash": "^4.17.5",
"rimraf": "^2.6.2",
"stack-trace": "0.0.10",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-utils": "3.0.0-alpha.26"
},
"author": {
"email": "hi@strapi.io",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-lint",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Strapi eslint and prettier configurations",
"directories": {
"lib": "lib"

View File

@ -1,6 +1,6 @@
{
"name": "strapi-middleware-views",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Views middleware to enable server-side rendering for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-content-manager",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "A powerful UI to easily manage your data.",
"strapi": {
"name": "Content Manager",
@ -26,11 +26,11 @@
"draft-js": "^0.10.5",
"react-select": "^1.2.1",
"showdown": "^1.8.6",
"strapi-helper-plugin": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26"
},
"dependencies": {
"pluralize": "^7.0.0",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-utils": "3.0.0-alpha.26"
},
"author": {
"name": "Strapi team",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-content-type-builder",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Strapi plugin to create content type (API).",
"strapi": {
"name": "Content Type Builder",
@ -24,11 +24,11 @@
"dependencies": {
"immutable": "^3.8.2",
"pluralize": "^7.0.0",
"strapi-generate": "3.0.0-alpha.25.2",
"strapi-generate-api": "3.0.0-alpha.25.2"
"strapi-generate": "3.0.0-alpha.26",
"strapi-generate-api": "3.0.0-alpha.26"
},
"devDependencies": {
"strapi-helper-plugin": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26"
},
"author": {
"name": "Strapi team",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-documentation",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "This is the description of the plugin.",
"strapi": {
"name": "Documentation",
@ -31,7 +31,7 @@
"devDependencies": {
"cross-env": "^5.2.0",
"rimraf": "^2.6.3",
"strapi-helper-plugin": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26"
},
"author": {
"name": "soupette",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-email",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "This is the description of the plugin.",
"strapi": {
"name": "Email",
@ -22,13 +22,13 @@
"prepublishOnly": "IS_MONOREPO=true npm run build"
},
"dependencies": {
"strapi-provider-email-sendmail": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-provider-email-sendmail": "3.0.0-alpha.26",
"strapi-utils": "3.0.0-alpha.26"
},
"devDependencies": {
"react-copy-to-clipboard": "5.0.1",
"rimraf": "^2.6.3",
"strapi-helper-plugin": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26"
},
"author": {
"name": "Strapi team",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-graphql",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "This is the description of the plugin.",
"strapi": {
"name": "graphql",
@ -32,7 +32,7 @@
"graphql-type-json": "^0.2.1",
"graphql-type-long": "^0.1.1",
"pluralize": "^7.0.0",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-utils": "3.0.0-alpha.26"
},
"devDependencies": {
"cross-env": "^5.2.0",

View File

@ -20,15 +20,22 @@ module.exports = {
.filter(model => model !== 'core_store')
.forEach(model => {
(strapi.models[model].associations || []).forEach(association =>
this.createLoader(association.collection || association.model, association.plugin)
this.createLoader(
association.collection || association.model,
association.plugin
)
);
});
// Reproduce the same pattern for each plugin.
Object.keys(strapi.plugins).forEach(plugin => {
Object.keys(strapi.plugins[plugin].models).forEach(model => {
(strapi.plugins[plugin].models[model].associations || []).forEach(association =>
this.createLoader(association.collection || association.model, association.plugin)
(strapi.plugins[plugin].models[model].associations || []).forEach(
association =>
this.createLoader(
association.collection || association.model,
association.plugin
)
);
});
});
@ -55,9 +62,15 @@ module.exports = {
return new Promise(async (resolve, reject) => {
try {
// Extract queries from keys and merge similar queries.
const { queries, map } = this.extractQueries(model, _.cloneDeep(keys));
const { queries, map } = this.extractQueries(
model,
_.cloneDeep(keys)
);
// Run queries in parallel.
const results = await Promise.all(queries.map(query => this.makeQuery(model, query)));
const results = await Promise.all(
queries.map(query => this.makeQuery(model, query))
);
// Use to match initial queries order.
const data = this.mapData(model, keys, map, results);
@ -80,7 +93,9 @@ module.exports = {
// Use map to re-dispatch data correctly based on initial keys.
return originalMap.map((query, index) => {
// Find the index of where we should extract the results.
const indexResults = map.findIndex(queryMap => queryMap.indexOf(index) !== -1);
const indexResults = map.findIndex(
queryMap => queryMap.indexOf(index) !== -1
);
const data = results[indexResults];
// Retrieving referring model.
@ -90,7 +105,8 @@ module.exports = {
// Return object instead of array for one-to-many relationship.
return data.find(
entry =>
entry[ref.primaryKey].toString() === (query.params[ref.primaryKey] || '').toString()
entry[ref.primaryKey].toString() ===
(query.params[ref.primaryKey] || '').toString()
);
}
@ -128,7 +144,11 @@ module.exports = {
return data
.filter(entry => entry !== undefined)
.filter(entry => ids.map(id => id.toString()).includes(entry[ref.primaryKey].toString()))
.filter(entry =>
ids
.map(id => id.toString())
.includes(entry[ref.primaryKey].toString())
)
.slice(skip, skip + limit);
});
},
@ -170,10 +190,9 @@ module.exports = {
.value();
// Run query and remove duplicated ID.
const request = await strapi.plugins['content-manager'].services['contentmanager'].fetchAll(
{ model },
params
);
const request = await strapi.plugins['content-manager'].services[
'contentmanager'
].fetchAll({ model }, params);
return request && request.toJSON ? request.toJSON() : request;
},
@ -196,9 +215,6 @@ module.exports = {
// Retrieving referring model.
const ref = this.retrieveModel(model, options.source);
// Find similar query.
const indexQueries = queries.findIndex(query => _.isEqual(query.options, options));
// Generate array of IDs to fetch.
const ids = [];
@ -211,21 +227,14 @@ module.exports = {
ids.push(query[association.via]);
}
if (indexQueries !== -1) {
// Push to the same query the new IDs to fetch.
queries[indexQueries].ids.push(...ids);
map[indexQueries].push(index);
} else {
// Create new query in the query.
queries.push({
ids,
options,
alias: _.first(Object.keys(query)) || ref.primaryKey,
});
queries.push({
ids,
options,
alias: _.first(Object.keys(query)) || ref.primaryKey,
});
map[queries.length - 1 > 0 ? queries.length - 1 : 0] = [];
map[queries.length - 1].push(index);
}
map[queries.length - 1 > 0 ? queries.length - 1 : 0] = [];
map[queries.length - 1].push(index);
});
return {

View File

@ -263,7 +263,7 @@ module.exports = {
});
if (isController) {
const values = await resolver.call(null, ctx, null, { populate: [] });
const values = await resolver.call(null, ctx, null);
if (ctx.body) {
return ctx.body;

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-settings-manager",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Strapi plugin to manage settings.",
"strapi": {
"name": "Settings Manager",
@ -26,7 +26,7 @@
"cross-env": "^5.2.0",
"flag-icon-css": "^2.8.0",
"rimraf": "^2.6.3",
"strapi-helper-plugin": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26"
},
"dependencies": {
"shelljs": "^0.7.8"

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-upload",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "This is the description of the plugin.",
"strapi": {
"name": "Files Upload",
@ -22,13 +22,13 @@
"prepublishOnly": "IS_MONOREPO=true npm run build"
},
"dependencies": {
"strapi-provider-upload-local": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.25.2",
"strapi-provider-upload-local": "3.0.0-alpha.26",
"strapi-utils": "3.0.0-alpha.26",
"stream-to-array": "^2.3.0",
"uuid": "^3.2.1"
},
"devDependencies": {
"strapi-helper-plugin": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26"
},
"author": {
"name": "A Strapi developer",

View File

@ -51,4 +51,4 @@
}
},
"collectionName": "users-permissions_user"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-users-permissions",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Protect your API with a full-authentication process based on JWT",
"strapi": {
"name": "Roles & Permissions",
@ -29,11 +29,11 @@
"koa2-ratelimit": "^0.6.1",
"purest": "^2.0.1",
"request": "^2.83.0",
"strapi-utils": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.26",
"uuid": "^3.1.0"
},
"devDependencies": {
"strapi-helper-plugin": "3.0.0-alpha.25.2"
"strapi-helper-plugin": "3.0.0-alpha.26"
},
"author": {
"name": "Strapi team",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-amazon-ses",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Amazon SES provider for strapi email",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-mailgun",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Mailgun provider for strapi email plugin",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-sendgrid",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Sendgrid provider for strapi email",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-sendmail",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Sendmail provider for strapi email",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-aws-s3",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "AWS S3 provider for strapi upload",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-cloudinary",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Cloudinary provider for strapi upload",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-local",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Local provider for strapi upload",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-rackspace",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Rackspace provider for strapi upload",
"main": "./lib",
"keywords": [],

View File

@ -5,23 +5,20 @@
const _ = require('lodash');
const defaults = {
start: 0,
limit: 10,
};
/**
* Global convertor
* @param {Object} params
*/
const convertRestQueryParams = (params = {}) => {
const convertRestQueryParams = (params = {}, defaults = {}) => {
if (typeof params !== 'object' || params === null) {
throw new Error(
`convertRestQueryParams expected an object got ${object === null ? 'null' : typeof object}`
`convertRestQueryParams expected an object got ${
params === null ? 'null' : typeof params
}`
);
}
let finalParams = { ...defaults };
let finalParams = Object.assign({ start: 0, limit: 100 }, defaults);
if (Object.keys(params).length === 0) {
return finalParams;
@ -55,7 +52,9 @@ const convertRestQueryParams = (params = {}) => {
*/
const convertSortQueryParams = sortQuery => {
if (typeof sortQuery !== 'string') {
throw new Error(`convertSortQueryParams expected a string, got ${typeof sortQuery}`);
throw new Error(
`convertSortQueryParams expected a string, got ${typeof sortQuery}`
);
}
const sortKeys = [];
@ -88,7 +87,9 @@ const convertStartQueryParams = startQuery => {
const startAsANumber = _.toNumber(startQuery);
if (!_.isInteger(startAsANumber) || startAsANumber < 0) {
throw new Error(`convertStartQueryParams expected a positive integer got ${startAsANumber}`);
throw new Error(
`convertStartQueryParams expected a positive integer got ${startAsANumber}`
);
}
return {
@ -103,8 +104,13 @@ const convertStartQueryParams = startQuery => {
const convertLimitQueryParams = limitQuery => {
const limitAsANumber = _.toNumber(limitQuery);
if (!_.isInteger(limitAsANumber) || (limitAsANumber !== -1 && limitAsANumber < 0)) {
throw new Error(`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`);
if (
!_.isInteger(limitAsANumber) ||
(limitAsANumber !== -1 && limitAsANumber < 0)
) {
throw new Error(
`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`
);
}
return {

View File

@ -1,6 +1,6 @@
{
"name": "strapi-utils",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "Shared utilities for the Strapi packages",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi",
"version": "3.0.0-alpha.25.2",
"version": "3.0.0-alpha.26",
"description": "An open source solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier.",
"homepage": "http://strapi.io",
"keywords": [
@ -63,16 +63,16 @@
"semver": "^5.4.1",
"shelljs": "^0.8.3",
"stack-trace": "0.0.10",
"strapi-generate": "3.0.0-alpha.25.2",
"strapi-generate-admin": "3.0.0-alpha.25.2",
"strapi-generate-api": "3.0.0-alpha.25.2",
"strapi-generate-controller": "3.0.0-alpha.25.2",
"strapi-generate-model": "3.0.0-alpha.25.2",
"strapi-generate-new": "3.0.0-alpha.25.2",
"strapi-generate-plugin": "3.0.0-alpha.25.2",
"strapi-generate-policy": "3.0.0-alpha.25.2",
"strapi-generate-service": "3.0.0-alpha.25.2",
"strapi-utils": "3.0.0-alpha.25.2"
"strapi-generate": "3.0.0-alpha.26",
"strapi-generate-admin": "3.0.0-alpha.26",
"strapi-generate-api": "3.0.0-alpha.26",
"strapi-generate-controller": "3.0.0-alpha.26",
"strapi-generate-model": "3.0.0-alpha.26",
"strapi-generate-new": "3.0.0-alpha.26",
"strapi-generate-plugin": "3.0.0-alpha.26",
"strapi-generate-policy": "3.0.0-alpha.26",
"strapi-generate-service": "3.0.0-alpha.26",
"strapi-utils": "3.0.0-alpha.26"
},
"scripts": {
"test": "jest --forceExit --verbose",

View File

@ -1,7 +1,12 @@
const path = require('path');
const { cleanTestApp, generateTestApp, startTestApp } = require('./helpers/testAppGenerator');
const {
cleanTestApp,
generateTestApp,
startTestApp,
} = require('./helpers/testAppGenerator');
const execa = require('execa');
const waitOn = require('wait-on');
const yargs = require('yargs');
const appName = 'testApp';
@ -25,9 +30,7 @@ const test = async () => {
});
};
const main = async () => {
const database = process.argv.length > 2 ? process.argv.slice(2).join(' ') : databases.sqlite;
const main = async database => {
try {
await cleanTestApp(appName);
await generateTestApp({ appName, database });
@ -45,11 +48,23 @@ const main = async () => {
testAppProcess.kill();
process.exit(0);
} catch (error) {
console.log(error)
console.log(error);
process.stdout.write('Tests failed\n', () => {
process.exit(1);
});
}
};
main();
yargs
.command(
'$0 [databaseName]',
'run end to end tests',
yargs => {
yargs.positional('databaseName', {
default: 'sqlite',
choices: Object.keys(databases),
});
},
({ databaseName }) => main(databases[databaseName])
)
.help().argv;