node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
'use strict';
/**
* @description
* Creates a valid query params object for get requests
* ie. plugins[18n][locale]=en becomes locale=en
*/ const buildValidParams = (query)=>{
if (!query) return query;
// Extract pluginOptions from the query, they shouldn't be part of the URL
const { plugins: _, ...validQueryParams } = {
...query,
...Object.values(query?.plugins ?? {}).reduce((acc, current)=>Object.assign(acc, current), {})
};
return validQueryParams;
};
const isBaseQueryError = (error)=>{
return error.name !== undefined;
};
exports.buildValidParams = buildValidParams;
exports.isBaseQueryError = isBaseQueryError;
//# sourceMappingURL=api.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"api.js","sources":["../../../admin/src/utils/api.ts"],"sourcesContent":["import { SerializedError } from '@reduxjs/toolkit';\nimport { ApiError, type UnknownApiError } from '@strapi/admin/strapi-admin';\n\ninterface Query {\n plugins?: Record<string, unknown>;\n _q?: string;\n [key: string]: any;\n}\n\n/**\n * This type extracts the plugin options from the query\n * and appends them to the root of the query\n */\ntype TransformedQuery<TQuery extends Query> = Omit<TQuery, 'plugins'> & {\n [key: string]: string;\n};\n\n/**\n * @description\n * Creates a valid query params object for get requests\n * ie. plugins[18n][locale]=en becomes locale=en\n */\nconst buildValidParams = <TQuery extends Query>(query: TQuery): TransformedQuery<TQuery> => {\n if (!query) return query;\n\n // Extract pluginOptions from the query, they shouldn't be part of the URL\n const { plugins: _, ...validQueryParams } = {\n ...query,\n ...Object.values(query?.plugins ?? {}).reduce<Record<string, string>>(\n (acc, current) => Object.assign(acc, current),\n {}\n ),\n };\n\n return validQueryParams;\n};\n\ntype BaseQueryError = ApiError | UnknownApiError;\n\nconst isBaseQueryError = (error: BaseQueryError | SerializedError): error is BaseQueryError => {\n return error.name !== undefined;\n};\n\nexport { isBaseQueryError, buildValidParams };\nexport type { BaseQueryError, UnknownApiError };\n"],"names":["buildValidParams","query","plugins","_","validQueryParams","Object","values","reduce","acc","current","assign","isBaseQueryError","error","name","undefined"],"mappings":";;AAiBA;;;;IAKA,MAAMA,mBAAmB,CAAuBC,KAAAA,GAAAA;IAC9C,IAAI,CAACA,OAAO,OAAOA,KAAAA;;AAGnB,IAAA,MAAM,EAAEC,OAASC,EAAAA,CAAC,EAAE,GAAGC,kBAAkB,GAAG;AAC1C,QAAA,GAAGH,KAAK;AACR,QAAA,GAAGI,OAAOC,MAAM,CAACL,OAAOC,OAAW,IAAA,IAAIK,MAAM,CAC3C,CAACC,GAAAA,EAAKC,UAAYJ,MAAOK,CAAAA,MAAM,CAACF,GAAKC,EAAAA,OAAAA,CAAAA,EACrC,EACD;AACH,KAAA;IAEA,OAAOL,gBAAAA;AACT;AAIA,MAAMO,mBAAmB,CAACC,KAAAA,GAAAA;IACxB,OAAOA,KAAAA,CAAMC,IAAI,KAAKC,SAAAA;AACxB;;;;;"}

View File

@@ -0,0 +1,19 @@
/**
* @description
* Creates a valid query params object for get requests
* ie. plugins[18n][locale]=en becomes locale=en
*/ const buildValidParams = (query)=>{
if (!query) return query;
// Extract pluginOptions from the query, they shouldn't be part of the URL
const { plugins: _, ...validQueryParams } = {
...query,
...Object.values(query?.plugins ?? {}).reduce((acc, current)=>Object.assign(acc, current), {})
};
return validQueryParams;
};
const isBaseQueryError = (error)=>{
return error.name !== undefined;
};
export { buildValidParams, isBaseQueryError };
//# sourceMappingURL=api.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"api.mjs","sources":["../../../admin/src/utils/api.ts"],"sourcesContent":["import { SerializedError } from '@reduxjs/toolkit';\nimport { ApiError, type UnknownApiError } from '@strapi/admin/strapi-admin';\n\ninterface Query {\n plugins?: Record<string, unknown>;\n _q?: string;\n [key: string]: any;\n}\n\n/**\n * This type extracts the plugin options from the query\n * and appends them to the root of the query\n */\ntype TransformedQuery<TQuery extends Query> = Omit<TQuery, 'plugins'> & {\n [key: string]: string;\n};\n\n/**\n * @description\n * Creates a valid query params object for get requests\n * ie. plugins[18n][locale]=en becomes locale=en\n */\nconst buildValidParams = <TQuery extends Query>(query: TQuery): TransformedQuery<TQuery> => {\n if (!query) return query;\n\n // Extract pluginOptions from the query, they shouldn't be part of the URL\n const { plugins: _, ...validQueryParams } = {\n ...query,\n ...Object.values(query?.plugins ?? {}).reduce<Record<string, string>>(\n (acc, current) => Object.assign(acc, current),\n {}\n ),\n };\n\n return validQueryParams;\n};\n\ntype BaseQueryError = ApiError | UnknownApiError;\n\nconst isBaseQueryError = (error: BaseQueryError | SerializedError): error is BaseQueryError => {\n return error.name !== undefined;\n};\n\nexport { isBaseQueryError, buildValidParams };\nexport type { BaseQueryError, UnknownApiError };\n"],"names":["buildValidParams","query","plugins","_","validQueryParams","Object","values","reduce","acc","current","assign","isBaseQueryError","error","name","undefined"],"mappings":"AAiBA;;;;IAKA,MAAMA,mBAAmB,CAAuBC,KAAAA,GAAAA;IAC9C,IAAI,CAACA,OAAO,OAAOA,KAAAA;;AAGnB,IAAA,MAAM,EAAEC,OAASC,EAAAA,CAAC,EAAE,GAAGC,kBAAkB,GAAG;AAC1C,QAAA,GAAGH,KAAK;AACR,QAAA,GAAGI,OAAOC,MAAM,CAACL,OAAOC,OAAW,IAAA,IAAIK,MAAM,CAC3C,CAACC,GAAAA,EAAKC,UAAYJ,MAAOK,CAAAA,MAAM,CAACF,GAAKC,EAAAA,OAAAA,CAAAA,EACrC,EACD;AACH,KAAA;IAEA,OAAOL,gBAAAA;AACT;AAIA,MAAMO,mBAAmB,CAACC,KAAAA,GAAAA;IACxB,OAAOA,KAAAA,CAAMC,IAAI,KAAKC,SAAAA;AACxB;;;;"}

View File

@@ -0,0 +1,34 @@
'use strict';
const checkIfAttributeIsDisplayable = (attribute)=>{
const { type } = attribute;
if (type === 'relation') {
return !attribute.relation.toLowerCase().includes('morph');
}
return ![
'json',
'dynamiczone',
'richtext',
'password',
'blocks'
].includes(type) && !!type;
};
/**
* @internal
* @description given an attribute, content-type schemas & component schemas, find the mainField name & type.
* If the attribute does not need a `mainField` then we return undefined. If we do not find the type
* of the field, we assume it's a string #sensible-defaults
*/ const getMainField = (attribute, mainFieldName, { schemas, components })=>{
if (!mainFieldName) {
return undefined;
}
const mainFieldType = attribute.type === 'component' ? components[attribute.component].attributes[mainFieldName].type : schemas.find((schema)=>schema.uid === attribute.targetModel)?.attributes[mainFieldName].type;
return {
name: mainFieldName,
type: mainFieldType ?? 'string'
};
};
exports.checkIfAttributeIsDisplayable = checkIfAttributeIsDisplayable;
exports.getMainField = getMainField;
//# sourceMappingURL=attributes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"attributes.js","sources":["../../../admin/src/utils/attributes.ts"],"sourcesContent":["import type { ComponentsDictionary, Schema } from '../hooks/useDocument';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\nconst checkIfAttributeIsDisplayable = (attribute: SchemaUtils.Attribute.AnyAttribute) => {\n const { type } = attribute;\n\n if (type === 'relation') {\n return !attribute.relation.toLowerCase().includes('morph');\n }\n\n return !['json', 'dynamiczone', 'richtext', 'password', 'blocks'].includes(type) && !!type;\n};\n\ninterface MainField {\n name: string;\n type: SchemaUtils.Attribute.Kind | 'custom';\n}\n\n/**\n * @internal\n * @description given an attribute, content-type schemas & component schemas, find the mainField name & type.\n * If the attribute does not need a `mainField` then we return undefined. If we do not find the type\n * of the field, we assume it's a string #sensible-defaults\n */\nconst getMainField = (\n attribute: SchemaUtils.Attribute.AnyAttribute,\n mainFieldName: string | undefined,\n { schemas, components }: { schemas: Schema[]; components: ComponentsDictionary }\n): MainField | undefined => {\n if (!mainFieldName) {\n return undefined;\n }\n\n const mainFieldType =\n attribute.type === 'component'\n ? components[attribute.component].attributes[mainFieldName].type\n : // @ts-expect-error `targetModel` does exist on the attribute for a relation.\n schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName]\n .type;\n\n return {\n name: mainFieldName,\n type: mainFieldType ?? 'string',\n };\n};\n\nexport { checkIfAttributeIsDisplayable, getMainField };\nexport type { MainField };\n"],"names":["checkIfAttributeIsDisplayable","attribute","type","relation","toLowerCase","includes","getMainField","mainFieldName","schemas","components","undefined","mainFieldType","component","attributes","find","schema","uid","targetModel","name"],"mappings":";;AAGA,MAAMA,gCAAgC,CAACC,SAAAA,GAAAA;IACrC,MAAM,EAAEC,IAAI,EAAE,GAAGD,SAAAA;AAEjB,IAAA,IAAIC,SAAS,UAAY,EAAA;AACvB,QAAA,OAAO,CAACD,SAAUE,CAAAA,QAAQ,CAACC,WAAW,EAAA,CAAGC,QAAQ,CAAC,OAAA,CAAA;AACpD;AAEA,IAAA,OAAO,CAAC;AAAC,QAAA,MAAA;AAAQ,QAAA,aAAA;AAAe,QAAA,UAAA;AAAY,QAAA,UAAA;AAAY,QAAA;AAAS,KAAA,CAACA,QAAQ,CAACH,IAAS,CAAA,IAAA,CAAC,CAACA,IAAAA;AACxF;AAOA;;;;;IAMA,MAAMI,eAAe,CACnBL,SAAAA,EACAM,eACA,EAAEC,OAAO,EAAEC,UAAU,EAA2D,GAAA;AAEhF,IAAA,IAAI,CAACF,aAAe,EAAA;QAClB,OAAOG,SAAAA;AACT;AAEA,IAAA,MAAMC,aACJV,GAAAA,SAAAA,CAAUC,IAAI,KAAK,WACfO,GAAAA,UAAU,CAACR,SAAAA,CAAUW,SAAS,CAAC,CAACC,UAAU,CAACN,aAAc,CAAA,CAACL,IAAI,GAE9DM,OAAQM,CAAAA,IAAI,CAAC,CAACC,SAAWA,MAAOC,CAAAA,GAAG,KAAKf,SAAAA,CAAUgB,WAAW,CAAA,EAAGJ,UAAU,CAACN,cAAc,CACtFL,IAAAA;IAET,OAAO;QACLgB,IAAMX,EAAAA,aAAAA;AACNL,QAAAA,IAAAA,EAAMS,aAAiB,IAAA;AACzB,KAAA;AACF;;;;;"}

View File

@@ -0,0 +1,31 @@
const checkIfAttributeIsDisplayable = (attribute)=>{
const { type } = attribute;
if (type === 'relation') {
return !attribute.relation.toLowerCase().includes('morph');
}
return ![
'json',
'dynamiczone',
'richtext',
'password',
'blocks'
].includes(type) && !!type;
};
/**
* @internal
* @description given an attribute, content-type schemas & component schemas, find the mainField name & type.
* If the attribute does not need a `mainField` then we return undefined. If we do not find the type
* of the field, we assume it's a string #sensible-defaults
*/ const getMainField = (attribute, mainFieldName, { schemas, components })=>{
if (!mainFieldName) {
return undefined;
}
const mainFieldType = attribute.type === 'component' ? components[attribute.component].attributes[mainFieldName].type : schemas.find((schema)=>schema.uid === attribute.targetModel)?.attributes[mainFieldName].type;
return {
name: mainFieldName,
type: mainFieldType ?? 'string'
};
};
export { checkIfAttributeIsDisplayable, getMainField };
//# sourceMappingURL=attributes.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"attributes.mjs","sources":["../../../admin/src/utils/attributes.ts"],"sourcesContent":["import type { ComponentsDictionary, Schema } from '../hooks/useDocument';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\nconst checkIfAttributeIsDisplayable = (attribute: SchemaUtils.Attribute.AnyAttribute) => {\n const { type } = attribute;\n\n if (type === 'relation') {\n return !attribute.relation.toLowerCase().includes('morph');\n }\n\n return !['json', 'dynamiczone', 'richtext', 'password', 'blocks'].includes(type) && !!type;\n};\n\ninterface MainField {\n name: string;\n type: SchemaUtils.Attribute.Kind | 'custom';\n}\n\n/**\n * @internal\n * @description given an attribute, content-type schemas & component schemas, find the mainField name & type.\n * If the attribute does not need a `mainField` then we return undefined. If we do not find the type\n * of the field, we assume it's a string #sensible-defaults\n */\nconst getMainField = (\n attribute: SchemaUtils.Attribute.AnyAttribute,\n mainFieldName: string | undefined,\n { schemas, components }: { schemas: Schema[]; components: ComponentsDictionary }\n): MainField | undefined => {\n if (!mainFieldName) {\n return undefined;\n }\n\n const mainFieldType =\n attribute.type === 'component'\n ? components[attribute.component].attributes[mainFieldName].type\n : // @ts-expect-error `targetModel` does exist on the attribute for a relation.\n schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName]\n .type;\n\n return {\n name: mainFieldName,\n type: mainFieldType ?? 'string',\n };\n};\n\nexport { checkIfAttributeIsDisplayable, getMainField };\nexport type { MainField };\n"],"names":["checkIfAttributeIsDisplayable","attribute","type","relation","toLowerCase","includes","getMainField","mainFieldName","schemas","components","undefined","mainFieldType","component","attributes","find","schema","uid","targetModel","name"],"mappings":"AAGA,MAAMA,gCAAgC,CAACC,SAAAA,GAAAA;IACrC,MAAM,EAAEC,IAAI,EAAE,GAAGD,SAAAA;AAEjB,IAAA,IAAIC,SAAS,UAAY,EAAA;AACvB,QAAA,OAAO,CAACD,SAAUE,CAAAA,QAAQ,CAACC,WAAW,EAAA,CAAGC,QAAQ,CAAC,OAAA,CAAA;AACpD;AAEA,IAAA,OAAO,CAAC;AAAC,QAAA,MAAA;AAAQ,QAAA,aAAA;AAAe,QAAA,UAAA;AAAY,QAAA,UAAA;AAAY,QAAA;AAAS,KAAA,CAACA,QAAQ,CAACH,IAAS,CAAA,IAAA,CAAC,CAACA,IAAAA;AACxF;AAOA;;;;;IAMA,MAAMI,eAAe,CACnBL,SAAAA,EACAM,eACA,EAAEC,OAAO,EAAEC,UAAU,EAA2D,GAAA;AAEhF,IAAA,IAAI,CAACF,aAAe,EAAA;QAClB,OAAOG,SAAAA;AACT;AAEA,IAAA,MAAMC,aACJV,GAAAA,SAAAA,CAAUC,IAAI,KAAK,WACfO,GAAAA,UAAU,CAACR,SAAAA,CAAUW,SAAS,CAAC,CAACC,UAAU,CAACN,aAAc,CAAA,CAACL,IAAI,GAE9DM,OAAQM,CAAAA,IAAI,CAAC,CAACC,SAAWA,MAAOC,CAAAA,GAAG,KAAKf,SAAAA,CAAUgB,WAAW,CAAA,EAAGJ,UAAU,CAACN,cAAc,CACtFL,IAAAA;IAET,OAAO;QACLgB,IAAMX,EAAAA,aAAAA;AACNL,QAAAA,IAAAA,EAAMS,aAAiB,IAAA;AACzB,KAAA;AACF;;;;"}

View File

@@ -0,0 +1,78 @@
'use strict';
var clone = require('lodash/clone');
var toPath = require('lodash/toPath');
/**
* Deeply get a value from an object via its path.
*/ function getIn(obj, key, def, pathStartIndex = 0) {
const path = toPath(key);
while(obj && pathStartIndex < path.length){
obj = obj[path[pathStartIndex++]];
}
// check if path is not in the end
if (pathStartIndex !== path.length && !obj) {
return def;
}
return obj === undefined ? def : obj;
}
/** @internal is the given object an Object? */ const isObject = (obj)=>obj !== null && typeof obj === 'object' && !Array.isArray(obj);
/** @internal is the given object an integer? */ const isInteger = (obj)=>String(Math.floor(Number(obj))) === obj;
/**
* Deeply set a value from in object via its path. If the value at `path`
* has changed, return a shallow copy of obj with `value` set at `path`.
* If `value` has not changed, return the original `obj`.
*
* Existing objects / arrays along `path` are also shallow copied. Sibling
* objects along path retain the same internal js reference. Since new
* objects / arrays are only created along `path`, we can test if anything
* changed in a nested structure by comparing the object's reference in
* the old and new object, similar to how russian doll cache invalidation
* works.
*
* In earlier versions of this function, which used cloneDeep, there were
* issues whereby settings a nested value would mutate the parent
* instead of creating a new object. `clone` avoids that bug making a
* shallow copy of the objects along the update path
* so no object is mutated in place.
*
* Before changing this function, please read through the following
* discussions.
*
* @see https://github.com/developit/linkstate
* @see https://github.com/jaredpalmer/formik/pull/123
*/ function setIn(obj, path, value) {
const res = clone(obj); // this keeps inheritance when obj is a class
let resVal = res;
let i = 0;
const pathArray = toPath(path);
for(; i < pathArray.length - 1; i++){
const currentPath = pathArray[i];
const currentObj = getIn(obj, pathArray.slice(0, i + 1));
if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {
resVal = resVal[currentPath] = clone(currentObj);
} else {
const nextPath = pathArray[i + 1];
resVal = resVal[currentPath] = isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};
}
}
// Return original object if new value is the same as current
if ((i === 0 ? obj : resVal)[pathArray[i]] === value) {
return obj;
}
{
delete resVal[pathArray[i]];
}
// If the path array has a single element, the loop did not run.
// Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.
if (i === 0 && value === undefined) {
delete res[pathArray[i]];
}
return res;
}
exports.getIn = getIn;
exports.isInteger = isInteger;
exports.isObject = isObject;
exports.setIn = setIn;
//# sourceMappingURL=objects.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,73 @@
import clone from 'lodash/clone';
import toPath from 'lodash/toPath';
/**
* Deeply get a value from an object via its path.
*/ function getIn(obj, key, def, pathStartIndex = 0) {
const path = toPath(key);
while(obj && pathStartIndex < path.length){
obj = obj[path[pathStartIndex++]];
}
// check if path is not in the end
if (pathStartIndex !== path.length && !obj) {
return def;
}
return obj === undefined ? def : obj;
}
/** @internal is the given object an Object? */ const isObject = (obj)=>obj !== null && typeof obj === 'object' && !Array.isArray(obj);
/** @internal is the given object an integer? */ const isInteger = (obj)=>String(Math.floor(Number(obj))) === obj;
/**
* Deeply set a value from in object via its path. If the value at `path`
* has changed, return a shallow copy of obj with `value` set at `path`.
* If `value` has not changed, return the original `obj`.
*
* Existing objects / arrays along `path` are also shallow copied. Sibling
* objects along path retain the same internal js reference. Since new
* objects / arrays are only created along `path`, we can test if anything
* changed in a nested structure by comparing the object's reference in
* the old and new object, similar to how russian doll cache invalidation
* works.
*
* In earlier versions of this function, which used cloneDeep, there were
* issues whereby settings a nested value would mutate the parent
* instead of creating a new object. `clone` avoids that bug making a
* shallow copy of the objects along the update path
* so no object is mutated in place.
*
* Before changing this function, please read through the following
* discussions.
*
* @see https://github.com/developit/linkstate
* @see https://github.com/jaredpalmer/formik/pull/123
*/ function setIn(obj, path, value) {
const res = clone(obj); // this keeps inheritance when obj is a class
let resVal = res;
let i = 0;
const pathArray = toPath(path);
for(; i < pathArray.length - 1; i++){
const currentPath = pathArray[i];
const currentObj = getIn(obj, pathArray.slice(0, i + 1));
if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {
resVal = resVal[currentPath] = clone(currentObj);
} else {
const nextPath = pathArray[i + 1];
resVal = resVal[currentPath] = isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};
}
}
// Return original object if new value is the same as current
if ((i === 0 ? obj : resVal)[pathArray[i]] === value) {
return obj;
}
{
delete resVal[pathArray[i]];
}
// If the path array has a single element, the loop did not run.
// Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.
if (i === 0 && value === undefined) {
delete res[pathArray[i]];
}
return res;
}
export { getIn, isInteger, isObject, setIn };
//# sourceMappingURL=objects.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
'use strict';
/**
* @internal
* @description Get the label of a relation, the contract has [key: string]: unknown,
* so we need to check if the mainFieldKey is defined and if the relation has a value
* under that property. If it does, we then verify it's type of string and return it.
*
* We fallback to the documentId.
*/ const getRelationLabel = (relation, mainField)=>{
const label = mainField && relation[mainField.name] ? relation[mainField.name] : null;
if (typeof label === 'string') {
return label;
}
return relation.documentId;
};
exports.getRelationLabel = getRelationLabel;
//# sourceMappingURL=relations.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"relations.js","sources":["../../../admin/src/utils/relations.ts"],"sourcesContent":["import type { MainField } from './attributes';\nimport type { RelationResult } from '../../../shared/contracts/relations';\n\n/**\n * @internal\n * @description Get the label of a relation, the contract has [key: string]: unknown,\n * so we need to check if the mainFieldKey is defined and if the relation has a value\n * under that property. If it does, we then verify it's type of string and return it.\n *\n * We fallback to the documentId.\n */\nconst getRelationLabel = (relation: RelationResult, mainField?: MainField): string => {\n const label = mainField && relation[mainField.name] ? relation[mainField.name] : null;\n\n if (typeof label === 'string') {\n return label;\n }\n\n return relation.documentId;\n};\n\nexport { getRelationLabel };\n"],"names":["getRelationLabel","relation","mainField","label","name","documentId"],"mappings":";;AAGA;;;;;;;IAQA,MAAMA,gBAAmB,GAAA,CAACC,QAA0BC,EAAAA,SAAAA,GAAAA;AAClD,IAAA,MAAMC,KAAQD,GAAAA,SAAAA,IAAaD,QAAQ,CAACC,SAAUE,CAAAA,IAAI,CAAC,GAAGH,QAAQ,CAACC,SAAUE,CAAAA,IAAI,CAAC,GAAG,IAAA;IAEjF,IAAI,OAAOD,UAAU,QAAU,EAAA;QAC7B,OAAOA,KAAAA;AACT;AAEA,IAAA,OAAOF,SAASI,UAAU;AAC5B;;;;"}

View File

@@ -0,0 +1,17 @@
/**
* @internal
* @description Get the label of a relation, the contract has [key: string]: unknown,
* so we need to check if the mainFieldKey is defined and if the relation has a value
* under that property. If it does, we then verify it's type of string and return it.
*
* We fallback to the documentId.
*/ const getRelationLabel = (relation, mainField)=>{
const label = mainField && relation[mainField.name] ? relation[mainField.name] : null;
if (typeof label === 'string') {
return label;
}
return relation.documentId;
};
export { getRelationLabel };
//# sourceMappingURL=relations.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"relations.mjs","sources":["../../../admin/src/utils/relations.ts"],"sourcesContent":["import type { MainField } from './attributes';\nimport type { RelationResult } from '../../../shared/contracts/relations';\n\n/**\n * @internal\n * @description Get the label of a relation, the contract has [key: string]: unknown,\n * so we need to check if the mainFieldKey is defined and if the relation has a value\n * under that property. If it does, we then verify it's type of string and return it.\n *\n * We fallback to the documentId.\n */\nconst getRelationLabel = (relation: RelationResult, mainField?: MainField): string => {\n const label = mainField && relation[mainField.name] ? relation[mainField.name] : null;\n\n if (typeof label === 'string') {\n return label;\n }\n\n return relation.documentId;\n};\n\nexport { getRelationLabel };\n"],"names":["getRelationLabel","relation","mainField","label","name","documentId"],"mappings":"AAGA;;;;;;;IAQA,MAAMA,gBAAmB,GAAA,CAACC,QAA0BC,EAAAA,SAAAA,GAAAA;AAClD,IAAA,MAAMC,KAAQD,GAAAA,SAAAA,IAAaD,QAAQ,CAACC,SAAUE,CAAAA,IAAI,CAAC,GAAGH,QAAQ,CAACC,SAAUE,CAAAA,IAAI,CAAC,GAAG,IAAA;IAEjF,IAAI,OAAOD,UAAU,QAAU,EAAA;QAC7B,OAAOA,KAAAA;AACT;AAEA,IAAA,OAAOF,SAASI,UAAU;AAC5B;;;;"}

View File

@@ -0,0 +1,6 @@
'use strict';
const capitalise = (str)=>str.charAt(0).toUpperCase() + str.slice(1);
exports.capitalise = capitalise;
//# sourceMappingURL=strings.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"strings.js","sources":["../../../admin/src/utils/strings.ts"],"sourcesContent":["const capitalise = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1);\n\nexport { capitalise };\n"],"names":["capitalise","str","charAt","toUpperCase","slice"],"mappings":";;AAAMA,MAAAA,UAAAA,GAAa,CAACC,GAAAA,GAAwBA,GAAIC,CAAAA,MAAM,CAAC,CAAA,CAAA,CAAGC,WAAW,EAAA,GAAKF,GAAIG,CAAAA,KAAK,CAAC,CAAA;;;;"}

View File

@@ -0,0 +1,4 @@
const capitalise = (str)=>str.charAt(0).toUpperCase() + str.slice(1);
export { capitalise };
//# sourceMappingURL=strings.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"strings.mjs","sources":["../../../admin/src/utils/strings.ts"],"sourcesContent":["const capitalise = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1);\n\nexport { capitalise };\n"],"names":["capitalise","str","charAt","toUpperCase","slice"],"mappings":"AAAMA,MAAAA,UAAAA,GAAa,CAACC,GAAAA,GAAwBA,GAAIC,CAAAA,MAAM,CAAC,CAAA,CAAA,CAAGC,WAAW,EAAA,GAAKF,GAAIG,CAAAA,KAAK,CAAC,CAAA;;;;"}

View File

@@ -0,0 +1,13 @@
'use strict';
const prefixPluginTranslations = (trad, pluginId)=>{
return Object.keys(trad).reduce((acc, current)=>{
acc[`${pluginId}.${current}`] = trad[current];
return acc;
}, {});
};
const getTranslation = (id)=>`content-manager.${id}`;
exports.getTranslation = getTranslation;
exports.prefixPluginTranslations = prefixPluginTranslations;
//# sourceMappingURL=translations.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"translations.js","sources":["../../../admin/src/utils/translations.ts"],"sourcesContent":["type TradOptions = Record<string, string>;\n\nconst prefixPluginTranslations = (trad: TradOptions, pluginId: string): TradOptions => {\n if (!pluginId) {\n throw new TypeError(\"pluginId can't be empty\");\n }\n return Object.keys(trad).reduce((acc, current) => {\n acc[`${pluginId}.${current}`] = trad[current];\n return acc;\n }, {} as TradOptions);\n};\n\nconst getTranslation = (id: string) => `content-manager.${id}`;\n\nexport { getTranslation, prefixPluginTranslations };\n"],"names":["prefixPluginTranslations","trad","pluginId","Object","keys","reduce","acc","current","getTranslation","id"],"mappings":";;AAEMA,MAAAA,wBAAAA,GAA2B,CAACC,IAAmBC,EAAAA,QAAAA,GAAAA;AAInD,IAAA,OAAOC,OAAOC,IAAI,CAACH,MAAMI,MAAM,CAAC,CAACC,GAAKC,EAAAA,OAAAA,GAAAA;AACpCD,QAAAA,GAAG,CAAC,CAAC,EAAEJ,QAAAA,CAAS,CAAC,EAAEK,OAAQ,CAAA,CAAC,CAAC,GAAGN,IAAI,CAACM,OAAQ,CAAA;QAC7C,OAAOD,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;AACN;AAEA,MAAME,iBAAiB,CAACC,EAAAA,GAAe,CAAC,gBAAgB,EAAEA,GAAG;;;;;"}

View File

@@ -0,0 +1,10 @@
const prefixPluginTranslations = (trad, pluginId)=>{
return Object.keys(trad).reduce((acc, current)=>{
acc[`${pluginId}.${current}`] = trad[current];
return acc;
}, {});
};
const getTranslation = (id)=>`content-manager.${id}`;
export { getTranslation, prefixPluginTranslations };
//# sourceMappingURL=translations.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"translations.mjs","sources":["../../../admin/src/utils/translations.ts"],"sourcesContent":["type TradOptions = Record<string, string>;\n\nconst prefixPluginTranslations = (trad: TradOptions, pluginId: string): TradOptions => {\n if (!pluginId) {\n throw new TypeError(\"pluginId can't be empty\");\n }\n return Object.keys(trad).reduce((acc, current) => {\n acc[`${pluginId}.${current}`] = trad[current];\n return acc;\n }, {} as TradOptions);\n};\n\nconst getTranslation = (id: string) => `content-manager.${id}`;\n\nexport { getTranslation, prefixPluginTranslations };\n"],"names":["prefixPluginTranslations","trad","pluginId","Object","keys","reduce","acc","current","getTranslation","id"],"mappings":"AAEMA,MAAAA,wBAAAA,GAA2B,CAACC,IAAmBC,EAAAA,QAAAA,GAAAA;AAInD,IAAA,OAAOC,OAAOC,IAAI,CAACH,MAAMI,MAAM,CAAC,CAACC,GAAKC,EAAAA,OAAAA,GAAAA;AACpCD,QAAAA,GAAG,CAAC,CAAC,EAAEJ,QAAAA,CAAS,CAAC,EAAEK,OAAQ,CAAA,CAAC,CAAC,GAAGN,IAAI,CAACM,OAAQ,CAAA;QAC7C,OAAOD,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;AACN;AAEA,MAAME,iBAAiB,CAACC,EAAAA,GAAe,CAAC,gBAAgB,EAAEA,GAAG;;;;"}

View File

@@ -0,0 +1,8 @@
'use strict';
const prefixFileUrlWithBackendUrl = (fileURL)=>{
return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;
};
exports.prefixFileUrlWithBackendUrl = prefixFileUrlWithBackendUrl;
//# sourceMappingURL=urls.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"urls.js","sources":["../../../admin/src/utils/urls.ts"],"sourcesContent":["const prefixFileUrlWithBackendUrl = (fileURL?: string): string | undefined => {\n return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;\n};\n\nexport { prefixFileUrlWithBackendUrl };\n"],"names":["prefixFileUrlWithBackendUrl","fileURL","startsWith","window","strapi","backendURL"],"mappings":";;AAAA,MAAMA,8BAA8B,CAACC,OAAAA,GAAAA;AACnC,IAAA,OAAO,CAAC,CAACA,OAAAA,IAAWA,OAAQC,CAAAA,UAAU,CAAC,GAAO,CAAA,GAAA,CAAC,EAAEC,MAAAA,CAAOC,MAAM,CAACC,UAAU,CAAC,EAAEJ,OAAAA,CAAQ,CAAC,GAAGA,OAAAA;AAC1F;;;;"}

View File

@@ -0,0 +1,6 @@
const prefixFileUrlWithBackendUrl = (fileURL)=>{
return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;
};
export { prefixFileUrlWithBackendUrl };
//# sourceMappingURL=urls.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"urls.mjs","sources":["../../../admin/src/utils/urls.ts"],"sourcesContent":["const prefixFileUrlWithBackendUrl = (fileURL?: string): string | undefined => {\n return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;\n};\n\nexport { prefixFileUrlWithBackendUrl };\n"],"names":["prefixFileUrlWithBackendUrl","fileURL","startsWith","window","strapi","backendURL"],"mappings":"AAAA,MAAMA,8BAA8B,CAACC,OAAAA,GAAAA;AACnC,IAAA,OAAO,CAAC,CAACA,OAAAA,IAAWA,OAAQC,CAAAA,UAAU,CAAC,GAAO,CAAA,GAAA,CAAC,EAAEC,MAAAA,CAAOC,MAAM,CAACC,UAAU,CAAC,EAAEJ,OAAAA,CAAQ,CAAC,GAAGA,OAAAA;AAC1F;;;;"}

View File

@@ -0,0 +1,17 @@
'use strict';
/**
* Retrieves the display name of an admin panel user
*/ const getDisplayName = ({ firstname, lastname, username, email } = {})=>{
if (username) {
return username;
}
// firstname is not required if the user is created with a username
if (firstname) {
return `${firstname} ${lastname ?? ''}`.trim();
}
return email ?? '';
};
exports.getDisplayName = getDisplayName;
//# sourceMappingURL=users.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"users.js","sources":["../../../admin/src/utils/users.ts"],"sourcesContent":["import type { SanitizedAdminUser } from '@strapi/admin/strapi-admin';\n\n/**\n * Retrieves the display name of an admin panel user\n */\nconst getDisplayName = ({\n firstname,\n lastname,\n username,\n email,\n}: Partial<\n Pick<SanitizedAdminUser, 'firstname' | 'lastname' | 'username' | 'email'>\n> = {}): string => {\n if (username) {\n return username;\n }\n\n // firstname is not required if the user is created with a username\n if (firstname) {\n return `${firstname} ${lastname ?? ''}`.trim();\n }\n\n return email ?? '';\n};\n\nexport { getDisplayName };\n"],"names":["getDisplayName","firstname","lastname","username","email","trim"],"mappings":";;AAEA;;AAEC,IACKA,MAAAA,cAAAA,GAAiB,CAAC,EACtBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EAGN,GAAG,EAAE,GAAA;AACJ,IAAA,IAAID,QAAU,EAAA;QACZ,OAAOA,QAAAA;AACT;;AAGA,IAAA,IAAIF,SAAW,EAAA;QACb,OAAO,CAAC,EAAEA,SAAU,CAAA,CAAC,EAAEC,QAAY,IAAA,EAAA,CAAG,CAAC,CAACG,IAAI,EAAA;AAC9C;AAEA,IAAA,OAAOD,KAAS,IAAA,EAAA;AAClB;;;;"}

View File

@@ -0,0 +1,15 @@
/**
* Retrieves the display name of an admin panel user
*/ const getDisplayName = ({ firstname, lastname, username, email } = {})=>{
if (username) {
return username;
}
// firstname is not required if the user is created with a username
if (firstname) {
return `${firstname} ${lastname ?? ''}`.trim();
}
return email ?? '';
};
export { getDisplayName };
//# sourceMappingURL=users.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"users.mjs","sources":["../../../admin/src/utils/users.ts"],"sourcesContent":["import type { SanitizedAdminUser } from '@strapi/admin/strapi-admin';\n\n/**\n * Retrieves the display name of an admin panel user\n */\nconst getDisplayName = ({\n firstname,\n lastname,\n username,\n email,\n}: Partial<\n Pick<SanitizedAdminUser, 'firstname' | 'lastname' | 'username' | 'email'>\n> = {}): string => {\n if (username) {\n return username;\n }\n\n // firstname is not required if the user is created with a username\n if (firstname) {\n return `${firstname} ${lastname ?? ''}`.trim();\n }\n\n return email ?? '';\n};\n\nexport { getDisplayName };\n"],"names":["getDisplayName","firstname","lastname","username","email","trim"],"mappings":"AAEA;;AAEC,IACKA,MAAAA,cAAAA,GAAiB,CAAC,EACtBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EAGN,GAAG,EAAE,GAAA;AACJ,IAAA,IAAID,QAAU,EAAA;QACZ,OAAOA,QAAAA;AACT;;AAGA,IAAA,IAAIF,SAAW,EAAA;QACb,OAAO,CAAC,EAAEA,SAAU,CAAA,CAAC,EAAEC,QAAY,IAAA,EAAA,CAAG,CAAC,CAACG,IAAI,EAAA;AAC9C;AAEA,IAAA,OAAOD,KAAS,IAAA,EAAA;AAClB;;;;"}

View File

@@ -0,0 +1,290 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var pipe = require('lodash/fp/pipe');
var yup = require('yup');
var attributes = require('../constants/attributes.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
const arrayValidator = (attribute, options)=>({
message: strapiAdmin.translatedErrors.required,
test (value) {
if (options.status === 'draft') {
return true;
}
if (!attribute.required) {
return true;
}
if (!value) {
return false;
}
if (Array.isArray(value) && value.length === 0) {
return false;
}
return true;
}
});
/**
* TODO: should we create a Map to store these based on the hash of the schema?
*/ const createYupSchema = (attributes$1 = {}, components = {}, options = {
status: null
})=>{
const createModelSchema = (attributes$1)=>yup__namespace.object().shape(Object.entries(attributes$1).reduce((acc, [name, attribute])=>{
if (attributes.DOCUMENT_META_FIELDS.includes(name)) {
return acc;
}
/**
* These validations won't apply to every attribute
* and that's okay, in that case we just return the
* schema as it was passed.
*/ const validations = [
addNullableValidation,
addRequiredValidation,
addMinLengthValidation,
addMaxLengthValidation,
addMinValidation,
addMaxValidation,
addRegexValidation
].map((fn)=>fn(attribute, options));
const transformSchema = pipe(...validations);
switch(attribute.type){
case 'component':
{
const { attributes } = components[attribute.component];
if (attribute.repeatable) {
return {
...acc,
[name]: transformSchema(yup__namespace.array().of(createModelSchema(attributes).nullable(false))).test(arrayValidator(attribute, options))
};
} else {
return {
...acc,
[name]: transformSchema(createModelSchema(attributes).nullable())
};
}
}
case 'dynamiczone':
return {
...acc,
[name]: transformSchema(yup__namespace.array().of(yup__namespace.lazy((data)=>{
const attributes = components?.[data?.__component]?.attributes;
const validation = yup__namespace.object().shape({
__component: yup__namespace.string().required().oneOf(Object.keys(components))
}).nullable(false);
if (!attributes) {
return validation;
}
return validation.concat(createModelSchema(attributes));
}))).test(arrayValidator(attribute, options))
};
case 'relation':
return {
...acc,
[name]: transformSchema(yup__namespace.lazy((value)=>{
if (!value) {
return yup__namespace.mixed().nullable(true);
} else if (Array.isArray(value)) {
// If a relation value is an array, we expect
// an array of objects with {id} properties, representing the related entities.
return yup__namespace.array().of(yup__namespace.object().shape({
id: yup__namespace.number().required()
}));
} else if (typeof value === 'object') {
// A realtion value can also be an object. Some API
// repsonses return the number of entities in the relation
// as { count: x }
return yup__namespace.object();
} else {
return yup__namespace.mixed().test('type-error', 'Relation values must be either null, an array of objects with {id} or an object.', ()=>false);
}
}))
};
default:
return {
...acc,
[name]: transformSchema(createAttributeSchema(attribute))
};
}
}, {}))/**
* TODO: investigate why an undefined object fails a check of `nullable`.
*/ .default(null);
return createModelSchema(attributes$1);
};
const createAttributeSchema = (attribute)=>{
switch(attribute.type){
case 'biginteger':
return yup__namespace.string().matches(/^-?\d*$/);
case 'boolean':
return yup__namespace.boolean();
case 'blocks':
return yup__namespace.mixed().test('isBlocks', strapiAdmin.translatedErrors.json, (value)=>{
if (!value || Array.isArray(value)) {
return true;
} else {
return false;
}
});
case 'decimal':
case 'float':
case 'integer':
return yup__namespace.number();
case 'email':
return yup__namespace.string().email(strapiAdmin.translatedErrors.email);
case 'enumeration':
return yup__namespace.string().oneOf([
...attribute.enum,
null
]);
case 'json':
return yup__namespace.mixed().test('isJSON', strapiAdmin.translatedErrors.json, (value)=>{
/**
* We don't want to validate the JSON field if it's empty.
*/ if (!value || typeof value === 'string' && value.length === 0) {
return true;
}
// If the value was created via content API and wasn't changed, then it's still an object
if (typeof value === 'object') {
try {
JSON.stringify(value);
return true;
} catch (err) {
return false;
}
}
try {
JSON.parse(value);
return true;
} catch (err) {
return false;
}
});
case 'password':
case 'richtext':
case 'string':
case 'text':
return yup__namespace.string();
case 'uid':
return yup__namespace.string().matches(/^[A-Za-z0-9-_.~]*$/);
default:
/**
* This allows any value.
*/ return yup__namespace.mixed();
}
};
// Helper function to return schema.nullable() if it exists, otherwise return schema
const nullableSchema = (schema)=>{
return schema?.nullable ? schema.nullable() : // e.g. when the schema has been built using yup.lazy (e.g. for relations).
// In these cases we should just return the schema as it is.
schema;
};
const addNullableValidation = ()=>(schema)=>{
return nullableSchema(schema);
};
const addRequiredValidation = (attribute, options)=>(schema)=>{
if (options.status === 'draft' || !attribute.required) {
return schema;
}
if (attribute.required && 'required' in schema) {
return schema.required(strapiAdmin.translatedErrors.required);
}
return schema;
};
const addMinLengthValidation = (attribute, options)=>(schema)=>{
// Skip minLength validation for draft
if (options.status === 'draft') {
return schema;
}
if ('minLength' in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && 'min' in schema) {
return schema.min(attribute.minLength, {
...strapiAdmin.translatedErrors.minLength,
values: {
min: attribute.minLength
}
});
}
return schema;
};
const addMaxLengthValidation = (attribute)=>(schema)=>{
if ('maxLength' in attribute && attribute.maxLength && Number.isInteger(attribute.maxLength) && 'max' in schema) {
return schema.max(attribute.maxLength, {
...strapiAdmin.translatedErrors.maxLength,
values: {
max: attribute.maxLength
}
});
}
return schema;
};
const addMinValidation = (attribute, options)=>(schema)=>{
// do not validate min for draft
if (options.status === 'draft') {
return schema;
}
if ('min' in attribute && 'min' in schema) {
const min = toInteger(attribute.min);
if (min) {
return schema.min(min, {
...strapiAdmin.translatedErrors.min,
values: {
min
}
});
}
}
return schema;
};
const addMaxValidation = (attribute)=>(schema)=>{
if ('max' in attribute) {
const max = toInteger(attribute.max);
if ('max' in schema && max) {
return schema.max(max, {
...strapiAdmin.translatedErrors.max,
values: {
max
}
});
}
}
return schema;
};
const toInteger = (val)=>{
if (typeof val === 'number' || val === undefined) {
return val;
} else {
const num = Number(val);
return isNaN(num) ? undefined : num;
}
};
const addRegexValidation = (attribute)=>(schema)=>{
if ('regex' in attribute && attribute.regex && 'matches' in schema) {
return schema.matches(new RegExp(attribute.regex), {
message: {
id: strapiAdmin.translatedErrors.regex.id,
defaultMessage: 'The value does not match the defined pattern.'
},
excludeEmptyString: !attribute.required
});
}
return schema;
};
exports.createYupSchema = createYupSchema;
//# sourceMappingURL=validation.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,269 @@
import { translatedErrors } from '@strapi/admin/strapi-admin';
import pipe from 'lodash/fp/pipe';
import * as yup from 'yup';
import { DOCUMENT_META_FIELDS } from '../constants/attributes.mjs';
const arrayValidator = (attribute, options)=>({
message: translatedErrors.required,
test (value) {
if (options.status === 'draft') {
return true;
}
if (!attribute.required) {
return true;
}
if (!value) {
return false;
}
if (Array.isArray(value) && value.length === 0) {
return false;
}
return true;
}
});
/**
* TODO: should we create a Map to store these based on the hash of the schema?
*/ const createYupSchema = (attributes = {}, components = {}, options = {
status: null
})=>{
const createModelSchema = (attributes)=>yup.object().shape(Object.entries(attributes).reduce((acc, [name, attribute])=>{
if (DOCUMENT_META_FIELDS.includes(name)) {
return acc;
}
/**
* These validations won't apply to every attribute
* and that's okay, in that case we just return the
* schema as it was passed.
*/ const validations = [
addNullableValidation,
addRequiredValidation,
addMinLengthValidation,
addMaxLengthValidation,
addMinValidation,
addMaxValidation,
addRegexValidation
].map((fn)=>fn(attribute, options));
const transformSchema = pipe(...validations);
switch(attribute.type){
case 'component':
{
const { attributes } = components[attribute.component];
if (attribute.repeatable) {
return {
...acc,
[name]: transformSchema(yup.array().of(createModelSchema(attributes).nullable(false))).test(arrayValidator(attribute, options))
};
} else {
return {
...acc,
[name]: transformSchema(createModelSchema(attributes).nullable())
};
}
}
case 'dynamiczone':
return {
...acc,
[name]: transformSchema(yup.array().of(yup.lazy((data)=>{
const attributes = components?.[data?.__component]?.attributes;
const validation = yup.object().shape({
__component: yup.string().required().oneOf(Object.keys(components))
}).nullable(false);
if (!attributes) {
return validation;
}
return validation.concat(createModelSchema(attributes));
}))).test(arrayValidator(attribute, options))
};
case 'relation':
return {
...acc,
[name]: transformSchema(yup.lazy((value)=>{
if (!value) {
return yup.mixed().nullable(true);
} else if (Array.isArray(value)) {
// If a relation value is an array, we expect
// an array of objects with {id} properties, representing the related entities.
return yup.array().of(yup.object().shape({
id: yup.number().required()
}));
} else if (typeof value === 'object') {
// A realtion value can also be an object. Some API
// repsonses return the number of entities in the relation
// as { count: x }
return yup.object();
} else {
return yup.mixed().test('type-error', 'Relation values must be either null, an array of objects with {id} or an object.', ()=>false);
}
}))
};
default:
return {
...acc,
[name]: transformSchema(createAttributeSchema(attribute))
};
}
}, {}))/**
* TODO: investigate why an undefined object fails a check of `nullable`.
*/ .default(null);
return createModelSchema(attributes);
};
const createAttributeSchema = (attribute)=>{
switch(attribute.type){
case 'biginteger':
return yup.string().matches(/^-?\d*$/);
case 'boolean':
return yup.boolean();
case 'blocks':
return yup.mixed().test('isBlocks', translatedErrors.json, (value)=>{
if (!value || Array.isArray(value)) {
return true;
} else {
return false;
}
});
case 'decimal':
case 'float':
case 'integer':
return yup.number();
case 'email':
return yup.string().email(translatedErrors.email);
case 'enumeration':
return yup.string().oneOf([
...attribute.enum,
null
]);
case 'json':
return yup.mixed().test('isJSON', translatedErrors.json, (value)=>{
/**
* We don't want to validate the JSON field if it's empty.
*/ if (!value || typeof value === 'string' && value.length === 0) {
return true;
}
// If the value was created via content API and wasn't changed, then it's still an object
if (typeof value === 'object') {
try {
JSON.stringify(value);
return true;
} catch (err) {
return false;
}
}
try {
JSON.parse(value);
return true;
} catch (err) {
return false;
}
});
case 'password':
case 'richtext':
case 'string':
case 'text':
return yup.string();
case 'uid':
return yup.string().matches(/^[A-Za-z0-9-_.~]*$/);
default:
/**
* This allows any value.
*/ return yup.mixed();
}
};
// Helper function to return schema.nullable() if it exists, otherwise return schema
const nullableSchema = (schema)=>{
return schema?.nullable ? schema.nullable() : // e.g. when the schema has been built using yup.lazy (e.g. for relations).
// In these cases we should just return the schema as it is.
schema;
};
const addNullableValidation = ()=>(schema)=>{
return nullableSchema(schema);
};
const addRequiredValidation = (attribute, options)=>(schema)=>{
if (options.status === 'draft' || !attribute.required) {
return schema;
}
if (attribute.required && 'required' in schema) {
return schema.required(translatedErrors.required);
}
return schema;
};
const addMinLengthValidation = (attribute, options)=>(schema)=>{
// Skip minLength validation for draft
if (options.status === 'draft') {
return schema;
}
if ('minLength' in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && 'min' in schema) {
return schema.min(attribute.minLength, {
...translatedErrors.minLength,
values: {
min: attribute.minLength
}
});
}
return schema;
};
const addMaxLengthValidation = (attribute)=>(schema)=>{
if ('maxLength' in attribute && attribute.maxLength && Number.isInteger(attribute.maxLength) && 'max' in schema) {
return schema.max(attribute.maxLength, {
...translatedErrors.maxLength,
values: {
max: attribute.maxLength
}
});
}
return schema;
};
const addMinValidation = (attribute, options)=>(schema)=>{
// do not validate min for draft
if (options.status === 'draft') {
return schema;
}
if ('min' in attribute && 'min' in schema) {
const min = toInteger(attribute.min);
if (min) {
return schema.min(min, {
...translatedErrors.min,
values: {
min
}
});
}
}
return schema;
};
const addMaxValidation = (attribute)=>(schema)=>{
if ('max' in attribute) {
const max = toInteger(attribute.max);
if ('max' in schema && max) {
return schema.max(max, {
...translatedErrors.max,
values: {
max
}
});
}
}
return schema;
};
const toInteger = (val)=>{
if (typeof val === 'number' || val === undefined) {
return val;
} else {
const num = Number(val);
return isNaN(num) ? undefined : num;
}
};
const addRegexValidation = (attribute)=>(schema)=>{
if ('regex' in attribute && attribute.regex && 'matches' in schema) {
return schema.matches(new RegExp(attribute.regex), {
message: {
id: translatedErrors.regex.id,
defaultMessage: 'The value does not match the defined pattern.'
},
excludeEmptyString: !attribute.required
});
}
return schema;
};
export { createYupSchema };
//# sourceMappingURL=validation.mjs.map

File diff suppressed because one or more lines are too long