strapi-utils
Advanced tools
Comparing version 3.3.5-next.0 to 3.3.5-next.1
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { convertRestQueryParams } = require('../convert-rest-query-params'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const envHelper = require('../env-helper'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { getNature } = require('../models'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,3 +1,5 @@ | ||
'use strict'; | ||
const format = require('date-fns/format'); | ||
const parseType = require('../parse-type'); | ||
const format = require('date-fns/format'); | ||
@@ -4,0 +6,0 @@ describe('parseType', () => { |
@@ -293,3 +293,8 @@ 'use strict'; | ||
describe('Edge cases', () => { | ||
test('It returns null if the model is nil', () => { | ||
test('It returns the input data if the model is nil and isOutput false', () => { | ||
expect(sanitizeEntity(input, { model: null, isOutput: false })).toEqual(input); | ||
expect(sanitizeEntity(input, { model: undefined, isOutput: false })).toEqual(input); | ||
}); | ||
test('It returns null if the model is nil and isOutput true', () => { | ||
expect(sanitizeEntity(input, { model: null })).toBeNull(); | ||
@@ -296,0 +301,0 @@ expect(sanitizeEntity(input, { model: undefined })).toBeNull(); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { escapeQuery, stringIncludes, stringEquals } = require('../string-formatting'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const yup = require('yup'); | ||
@@ -2,0 +4,0 @@ const { formatYupErrors } = require('../validators'); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
//TODO: move to dbal | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
@@ -2,0 +4,0 @@ const { getCommonBeginning } = require('./string-formatting'); |
@@ -5,2 +5,5 @@ 'use strict'; | ||
const SINGLE_TYPE = 'singleType'; | ||
const COLLECTION_TYPE = 'collectionType'; | ||
const ID_ATTRIBUTE = 'id'; | ||
@@ -25,2 +28,4 @@ const PUBLISHED_AT_ATTRIBUTE = 'published_at'; | ||
DP_PUB_STATE_PREVIEW, | ||
SINGLE_TYPE, | ||
COLLECTION_TYPE, | ||
}; | ||
@@ -37,2 +42,15 @@ | ||
}; | ||
const getTimestampsAttributes = model => { | ||
const timestamps = getTimestamps(model); | ||
return timestamps.reduce( | ||
(attributes, attributeName) => ({ | ||
...attributes, | ||
[attributeName]: { type: 'timestamp' }, | ||
}), | ||
{} | ||
); | ||
}; | ||
const getNonWritableAttributes = (model = {}) => { | ||
@@ -50,2 +68,6 @@ const nonWritableAttributes = _.reduce( | ||
const getWritableAttributes = (model = {}) => { | ||
return _.difference(Object.keys(model.attributes), getNonWritableAttributes(model)); | ||
}; | ||
const getNonVisibleAttributes = model => { | ||
@@ -64,2 +86,6 @@ return _.uniq([model.primaryKey, ...getTimestamps(model), ...NON_VISIBLE_ATTRIBUTES]); | ||
const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE; | ||
const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE; | ||
const isKind = kind => model => model.kind === kind; | ||
const getPrivateAttributes = (model = {}) => { | ||
@@ -77,7 +103,24 @@ return _.union( | ||
const isScalarAttribute = attribute => { | ||
return ( | ||
!attribute.collection && | ||
!attribute.model && | ||
attribute.type !== 'component' && | ||
attribute.type !== 'dynamiczone' | ||
); | ||
}; | ||
const isMediaAttribute = attr => { | ||
return (attr.collection || attr.model) === 'file' && attr.plugin === 'upload'; | ||
}; | ||
module.exports = { | ||
isScalarAttribute, | ||
isMediaAttribute, | ||
getPrivateAttributes, | ||
getTimestampsAttributes, | ||
isPrivateAttribute, | ||
constants, | ||
getNonWritableAttributes, | ||
getWritableAttributes, | ||
getNonVisibleAttributes, | ||
@@ -87,2 +130,5 @@ getVisibleAttributes, | ||
isDraft, | ||
isSingleType, | ||
isCollectionType, | ||
isKind, | ||
}; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/** | ||
@@ -2,0 +4,0 @@ * Converts the standard Strapi REST query params to a moe usable format for querying |
@@ -367,3 +367,8 @@ 'use strict'; | ||
let details; | ||
const targetName = association.model || association.collection || ''; | ||
const targetModel = | ||
targetName !== '*' ? strapi.db.getModel(targetName, association.plugin) : null; | ||
const infos = this.getNature({ | ||
@@ -385,2 +390,3 @@ attribute: association, | ||
type: 'collection', | ||
targetUid: targetModel.uid, | ||
collection: association.collection, | ||
@@ -412,2 +418,3 @@ via: association.via || undefined, | ||
type: 'model', | ||
targetUid: targetModel.uid, | ||
model: association.model, | ||
@@ -466,2 +473,3 @@ via: association.via || undefined, | ||
alias: key, | ||
targetUid: '*', | ||
type: association.model ? 'model' : 'collection', | ||
@@ -468,0 +476,0 @@ related: models, |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const { constants, isPrivateAttribute } = require('./content-types'); | ||
const { | ||
@@ -31,3 +32,7 @@ ID_ATTRIBUTE, | ||
if (_.isNil(model)) { | ||
return null; | ||
if (isOutput) { | ||
return null; | ||
} else { | ||
return data; | ||
} | ||
} | ||
@@ -34,0 +39,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { isString, isPlainObject } = require('lodash'); | ||
@@ -2,0 +4,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use srict'; | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ const webhookEvents = { |
{ | ||
"name": "strapi-utils", | ||
"version": "3.3.5-next.0", | ||
"version": "3.3.5-next.1", | ||
"description": "Shared utilities for the Strapi packages", | ||
@@ -48,3 +48,3 @@ "homepage": "http://strapi.io", | ||
"license": "SEE LICENSE IN LICENSE", | ||
"gitHead": "ea4b0bbe8f16724a85fa62e4f7c8788c6b3f2d32" | ||
"gitHead": "c9c936ba41e9b7d881eb96e515ac2317ce471473" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101584
3003