@strapi/utils 5.29.0 → 5.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/convert-query-params.js.map +1 -1
- package/dist/convert-query-params.mjs.map +1 -1
- package/dist/env-helper.js.map +1 -1
- package/dist/env-helper.mjs.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/file.js.map +1 -1
- package/dist/file.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/install-id.js.map +1 -1
- package/dist/install-id.mjs.map +1 -1
- package/dist/parse-type.js.map +1 -1
- package/dist/parse-type.mjs.map +1 -1
- package/dist/print-value.js.map +1 -1
- package/dist/print-value.mjs.map +1 -1
- package/dist/provider-factory.js.map +1 -1
- package/dist/provider-factory.mjs.map +1 -1
- package/dist/sanitize/visitors/remove-disallowed-fields.js.map +1 -1
- package/dist/sanitize/visitors/remove-disallowed-fields.mjs.map +1 -1
- package/dist/sanitize/visitors/remove-restricted-fields.js.map +1 -1
- package/dist/sanitize/visitors/remove-restricted-fields.mjs.map +1 -1
- package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -1
- package/dist/sanitize/visitors/remove-restricted-relations.mjs.map +1 -1
- package/dist/security.d.ts +23 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +49 -0
- package/dist/security.js.map +1 -0
- package/dist/security.mjs +46 -0
- package/dist/security.mjs.map +1 -0
- package/dist/traverse/factory.js.map +1 -1
- package/dist/traverse/factory.mjs.map +1 -1
- package/dist/traverse/query-filters.js.map +1 -1
- package/dist/traverse/query-filters.mjs.map +1 -1
- package/dist/traverse/query-populate.js.map +1 -1
- package/dist/traverse/query-populate.mjs.map +1 -1
- package/dist/traverse/query-sort.js.map +1 -1
- package/dist/traverse/query-sort.mjs.map +1 -1
- package/dist/traverse-entity.d.ts.map +1 -1
- package/dist/traverse-entity.js +24 -7
- package/dist/traverse-entity.js.map +1 -1
- package/dist/traverse-entity.mjs +24 -7
- package/dist/traverse-entity.mjs.map +1 -1
- package/dist/validate/utils.js.map +1 -1
- package/dist/validate/utils.mjs.map +1 -1
- package/dist/validate/validators.js.map +1 -1
- package/dist/validate/validators.mjs.map +1 -1
- package/dist/validate/visitors/throw-disallowed-fields.js.map +1 -1
- package/dist/validate/visitors/throw-disallowed-fields.mjs.map +1 -1
- package/dist/validate/visitors/throw-restricted-fields.js.map +1 -1
- package/dist/validate/visitors/throw-restricted-fields.mjs.map +1 -1
- package/dist/validate/visitors/throw-restricted-relations.js.map +1 -1
- package/dist/validate/visitors/throw-restricted-relations.mjs.map +1 -1
- package/dist/validation/utilities.js.map +1 -1
- package/dist/validation/utilities.mjs.map +1 -1
- package/dist/yup.js.map +1 -1
- package/dist/yup.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throw-restricted-fields.js","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"sourcesContent":["import { isArray, isString } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (restrictedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // all fields\n if (restrictedFields === null) {\n throwInvalidKey({ key, path });\n }\n\n // Throw on invalid formats\n if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for restrictedFields but got \"${typeof restrictedFields}\"`\n );\n }\n\n // if an exact match was found\n if (restrictedFields.includes(path as string)) {\n throwInvalidKey({ key, path });\n }\n\n // nested matches\n const isRestrictedNested = restrictedFields.some((allowedPath) =>\n path?.toString().startsWith(`${allowedPath}.`)\n );\n if (isRestrictedNested) {\n throwInvalidKey({ key, path });\n }\n };\n"],"names":["restrictedFields","key","path","attribute","throwInvalidKey","isArray","every","isString","TypeError","includes","isRestrictedNested","some","allowedPath","toString","startsWith"],"mappings":";;;;;AAIA,4BAAe,CAAA,CAACA,gBAAoC,GAAA,IAAI,GACtD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,qBAAqB,IAAM,EAAA;YAC7BI,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;QAGA,IAAI,EAAEG,UAAQL,CAAAA,gBAAAA,CAAAA,IAAqBA,iBAAiBM,KAAK,CAACC,YAAQ,CAAI,EAAA;YACpE,MAAM,IAAIC,UACR,CAAC,wDAAwD,EAAE,OAAOR,gBAAAA,CAAiB,CAAC,CAAC,CAAA;AAEzF;;QAGA,IAAIA,gBAAAA,CAAiBS,QAAQ,CAACP,IAAiB,CAAA,EAAA;YAC7CE,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;AAGA,QAAA,MAAMQ,kBAAqBV,GAAAA,gBAAAA,CAAiBW,IAAI,CAAC,CAACC,WAAAA,GAChDV,IAAMW,EAAAA,QAAAA,EAAAA,CAAWC,UAAW,CAAA,
|
|
1
|
+
{"version":3,"file":"throw-restricted-fields.js","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"sourcesContent":["import { isArray, isString } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (restrictedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // all fields\n if (restrictedFields === null) {\n throwInvalidKey({ key, path });\n }\n\n // Throw on invalid formats\n if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for restrictedFields but got \"${typeof restrictedFields}\"`\n );\n }\n\n // if an exact match was found\n if (restrictedFields.includes(path as string)) {\n throwInvalidKey({ key, path });\n }\n\n // nested matches\n const isRestrictedNested = restrictedFields.some((allowedPath) =>\n path?.toString().startsWith(`${allowedPath}.`)\n );\n if (isRestrictedNested) {\n throwInvalidKey({ key, path });\n }\n };\n"],"names":["restrictedFields","key","path","attribute","throwInvalidKey","isArray","every","isString","TypeError","includes","isRestrictedNested","some","allowedPath","toString","startsWith"],"mappings":";;;;;AAIA,4BAAe,CAAA,CAACA,gBAAoC,GAAA,IAAI,GACtD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,qBAAqB,IAAM,EAAA;YAC7BI,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;QAGA,IAAI,EAAEG,UAAQL,CAAAA,gBAAAA,CAAAA,IAAqBA,iBAAiBM,KAAK,CAACC,YAAQ,CAAI,EAAA;YACpE,MAAM,IAAIC,UACR,CAAC,wDAAwD,EAAE,OAAOR,gBAAAA,CAAiB,CAAC,CAAC,CAAA;AAEzF;;QAGA,IAAIA,gBAAAA,CAAiBS,QAAQ,CAACP,IAAiB,CAAA,EAAA;YAC7CE,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;AAGA,QAAA,MAAMQ,kBAAqBV,GAAAA,gBAAAA,CAAiBW,IAAI,CAAC,CAACC,WAAAA,GAChDV,IAAMW,EAAAA,QAAAA,EAAAA,CAAWC,UAAW,CAAA,CAAA,EAAGF,WAAY,CAAA,CAAC,CAAC,CAAA,CAAA;AAE/C,QAAA,IAAIF,kBAAoB,EAAA;YACtBN,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;AACF,KAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throw-restricted-fields.mjs","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"sourcesContent":["import { isArray, isString } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (restrictedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // all fields\n if (restrictedFields === null) {\n throwInvalidKey({ key, path });\n }\n\n // Throw on invalid formats\n if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for restrictedFields but got \"${typeof restrictedFields}\"`\n );\n }\n\n // if an exact match was found\n if (restrictedFields.includes(path as string)) {\n throwInvalidKey({ key, path });\n }\n\n // nested matches\n const isRestrictedNested = restrictedFields.some((allowedPath) =>\n path?.toString().startsWith(`${allowedPath}.`)\n );\n if (isRestrictedNested) {\n throwInvalidKey({ key, path });\n }\n };\n"],"names":["restrictedFields","key","path","attribute","throwInvalidKey","isArray","every","isString","TypeError","includes","isRestrictedNested","some","allowedPath","toString","startsWith"],"mappings":";;;AAIA,4BAAe,CAAA,CAACA,gBAAoC,GAAA,IAAI,GACtD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,qBAAqB,IAAM,EAAA;YAC7BI,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;QAGA,IAAI,EAAEG,OAAQL,CAAAA,gBAAAA,CAAAA,IAAqBA,iBAAiBM,KAAK,CAACC,SAAQ,CAAI,EAAA;YACpE,MAAM,IAAIC,UACR,CAAC,wDAAwD,EAAE,OAAOR,gBAAAA,CAAiB,CAAC,CAAC,CAAA;AAEzF;;QAGA,IAAIA,gBAAAA,CAAiBS,QAAQ,CAACP,IAAiB,CAAA,EAAA;YAC7CE,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;AAGA,QAAA,MAAMQ,kBAAqBV,GAAAA,gBAAAA,CAAiBW,IAAI,CAAC,CAACC,WAAAA,GAChDV,IAAMW,EAAAA,QAAAA,EAAAA,CAAWC,UAAW,CAAA,
|
|
1
|
+
{"version":3,"file":"throw-restricted-fields.mjs","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"sourcesContent":["import { isArray, isString } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (restrictedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // all fields\n if (restrictedFields === null) {\n throwInvalidKey({ key, path });\n }\n\n // Throw on invalid formats\n if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for restrictedFields but got \"${typeof restrictedFields}\"`\n );\n }\n\n // if an exact match was found\n if (restrictedFields.includes(path as string)) {\n throwInvalidKey({ key, path });\n }\n\n // nested matches\n const isRestrictedNested = restrictedFields.some((allowedPath) =>\n path?.toString().startsWith(`${allowedPath}.`)\n );\n if (isRestrictedNested) {\n throwInvalidKey({ key, path });\n }\n };\n"],"names":["restrictedFields","key","path","attribute","throwInvalidKey","isArray","every","isString","TypeError","includes","isRestrictedNested","some","allowedPath","toString","startsWith"],"mappings":";;;AAIA,4BAAe,CAAA,CAACA,gBAAoC,GAAA,IAAI,GACtD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,qBAAqB,IAAM,EAAA;YAC7BI,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;QAGA,IAAI,EAAEG,OAAQL,CAAAA,gBAAAA,CAAAA,IAAqBA,iBAAiBM,KAAK,CAACC,SAAQ,CAAI,EAAA;YACpE,MAAM,IAAIC,UACR,CAAC,wDAAwD,EAAE,OAAOR,gBAAAA,CAAiB,CAAC,CAAC,CAAA;AAEzF;;QAGA,IAAIA,gBAAAA,CAAiBS,QAAQ,CAACP,IAAiB,CAAA,EAAA;YAC7CE,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;AAGA,QAAA,MAAMQ,kBAAqBV,GAAAA,gBAAAA,CAAiBW,IAAI,CAAC,CAACC,WAAAA,GAChDV,IAAMW,EAAAA,QAAAA,EAAAA,CAAWC,UAAW,CAAA,CAAA,EAAGF,WAAY,CAAA,CAAC,CAAC,CAAA,CAAA;AAE/C,QAAA,IAAIF,kBAAoB,EAAA;YACtBN,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;AACF,KAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throw-restricted-relations.js","sources":["../../../src/validate/visitors/throw-restricted-relations.ts"],"sourcesContent":["import { isArray, isObject } from 'lodash/fp';\nimport * as contentTypeUtils from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\nimport { VALID_RELATION_ORDERING_KEYS } from '../../relations';\n\nconst ACTIONS_TO_VERIFY = ['find'];\nconst { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypeUtils.constants;\n\ntype MorphArray = Array<{ __type: string }>;\n\nexport default (auth: unknown): Visitor =>\n async ({ data, key, attribute, schema, path }) => {\n if (!attribute) {\n return;\n }\n\n const isRelation = attribute.type === 'relation';\n\n if (!isRelation) {\n return;\n }\n\n const handleMorphRelation = async () => {\n const elements: any = (data as Record<string, MorphArray>)[key];\n\n if (\n 'connect' in elements ||\n 'set' in elements ||\n 'disconnect' in elements ||\n 'options' in elements\n ) {\n await handleMorphElements(elements.connect || []);\n await handleMorphElements(elements.set || []);\n await handleMorphElements(elements.disconnect || []);\n\n // TODO: this should technically be in its own visitor to check morph options, but for now we'll handle it here\n if ('options' in elements) {\n if (elements.options === null || elements.options === undefined) {\n return;\n }\n\n if (typeof elements.options !== 'object') {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const optionKeys = Object.keys(elements.options);\n\n // Validate each key based on its validator function\n for (const key of optionKeys) {\n if (!(key in VALID_RELATION_ORDERING_KEYS)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n if (!VALID_RELATION_ORDERING_KEYS[key](elements.options[key])) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n }\n } else {\n await handleMorphElements(elements);\n }\n };\n\n const handleMorphElements = async (elements: any[]) => {\n if (!isArray(elements)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n for (const element of elements) {\n if (!isObject(element) || !('__type' in element)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${element.__type}.${action}`);\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n };\n\n const handleRegularRelation = async () => {\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${attribute.target}.${action}`);\n\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n // If the authenticated user don't have access to any of the scopes\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n };\n\n const isCreatorRelation = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(key);\n\n // Polymorphic relations\n if (contentTypeUtils.isMorphToRelationalAttribute(attribute)) {\n await handleMorphRelation();\n return;\n }\n\n // Creator relations\n if (isCreatorRelation && schema.options?.populateCreatorFields) {\n // do nothing\n return;\n }\n\n // Regular relations\n await handleRegularRelation();\n };\n\nconst hasAccessToSomeScopes = async (scopes: string[], auth: unknown) => {\n for (const scope of scopes) {\n try {\n await strapi.auth.verify(auth, { scope });\n return true;\n } catch {\n continue;\n }\n }\n\n return false;\n};\n"],"names":["ACTIONS_TO_VERIFY","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypeUtils","auth","data","key","attribute","schema","path","isRelation","type","handleMorphRelation","elements","handleMorphElements","connect","set","disconnect","options","undefined","throwInvalidKey","optionKeys","Object","keys","VALID_RELATION_ORDERING_KEYS","isArray","element","isObject","scopes","map","action","__type","isAllowed","hasAccessToSomeScopes","handleRegularRelation","target","isCreatorRelation","includes","populateCreatorFields","scope","strapi","verify"],"mappings":";;;;;;;AAMA,MAAMA,iBAAoB,GAAA;AAAC,IAAA;AAAO,CAAA;AAClC,MAAM,EAAEC,oBAAoB,EAAEC,oBAAoB,EAAE,GAAGC,sBAA0B;AAIjF,+BAAe,CAAA,CAACC,IACd,GAAA,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAA;AAC3C,QAAA,IAAI,CAACF,SAAW,EAAA;AACd,YAAA;AACF;QAEA,MAAMG,UAAAA,GAAaH,SAAUI,CAAAA,IAAI,KAAK,UAAA;AAEtC,QAAA,IAAI,CAACD,UAAY,EAAA;AACf,YAAA;AACF;AAEA,QAAA,MAAME,mBAAsB,GAAA,UAAA;AAC1B,YAAA,MAAMC,QAAgB,GAACR,IAAmC,CAACC,GAAI,CAAA;AAE/D,YAAA,IACE,aAAaO,QACb,IAAA,KAAA,IAASA,YACT,YAAgBA,IAAAA,QAAAA,IAChB,aAAaA,QACb,EAAA;AACA,gBAAA,MAAMC,mBAAoBD,CAAAA,QAAAA,CAASE,OAAO,IAAI,EAAE,CAAA;AAChD,gBAAA,MAAMD,mBAAoBD,CAAAA,QAAAA,CAASG,GAAG,IAAI,EAAE,CAAA;AAC5C,gBAAA,MAAMF,mBAAoBD,CAAAA,QAAAA,CAASI,UAAU,IAAI,EAAE,CAAA;;AAGnD,gBAAA,IAAI,aAAaJ,QAAU,EAAA;AACzB,oBAAA,IAAIA,SAASK,OAAO,KAAK,QAAQL,QAASK,CAAAA,OAAO,KAAKC,SAAW,EAAA;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,CAAA;AAC9C;AAEA,gBAAA,MAAMqB,MAAS5B,GAAAA,iBAAAA,CAAkB6B,GAAG,CAAC,CAACC,
|
|
1
|
+
{"version":3,"file":"throw-restricted-relations.js","sources":["../../../src/validate/visitors/throw-restricted-relations.ts"],"sourcesContent":["import { isArray, isObject } from 'lodash/fp';\nimport * as contentTypeUtils from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\nimport { VALID_RELATION_ORDERING_KEYS } from '../../relations';\n\nconst ACTIONS_TO_VERIFY = ['find'];\nconst { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypeUtils.constants;\n\ntype MorphArray = Array<{ __type: string }>;\n\nexport default (auth: unknown): Visitor =>\n async ({ data, key, attribute, schema, path }) => {\n if (!attribute) {\n return;\n }\n\n const isRelation = attribute.type === 'relation';\n\n if (!isRelation) {\n return;\n }\n\n const handleMorphRelation = async () => {\n const elements: any = (data as Record<string, MorphArray>)[key];\n\n if (\n 'connect' in elements ||\n 'set' in elements ||\n 'disconnect' in elements ||\n 'options' in elements\n ) {\n await handleMorphElements(elements.connect || []);\n await handleMorphElements(elements.set || []);\n await handleMorphElements(elements.disconnect || []);\n\n // TODO: this should technically be in its own visitor to check morph options, but for now we'll handle it here\n if ('options' in elements) {\n if (elements.options === null || elements.options === undefined) {\n return;\n }\n\n if (typeof elements.options !== 'object') {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const optionKeys = Object.keys(elements.options);\n\n // Validate each key based on its validator function\n for (const key of optionKeys) {\n if (!(key in VALID_RELATION_ORDERING_KEYS)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n if (!VALID_RELATION_ORDERING_KEYS[key](elements.options[key])) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n }\n } else {\n await handleMorphElements(elements);\n }\n };\n\n const handleMorphElements = async (elements: any[]) => {\n if (!isArray(elements)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n for (const element of elements) {\n if (!isObject(element) || !('__type' in element)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${element.__type}.${action}`);\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n };\n\n const handleRegularRelation = async () => {\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${attribute.target}.${action}`);\n\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n // If the authenticated user don't have access to any of the scopes\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n };\n\n const isCreatorRelation = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(key);\n\n // Polymorphic relations\n if (contentTypeUtils.isMorphToRelationalAttribute(attribute)) {\n await handleMorphRelation();\n return;\n }\n\n // Creator relations\n if (isCreatorRelation && schema.options?.populateCreatorFields) {\n // do nothing\n return;\n }\n\n // Regular relations\n await handleRegularRelation();\n };\n\nconst hasAccessToSomeScopes = async (scopes: string[], auth: unknown) => {\n for (const scope of scopes) {\n try {\n await strapi.auth.verify(auth, { scope });\n return true;\n } catch {\n continue;\n }\n }\n\n return false;\n};\n"],"names":["ACTIONS_TO_VERIFY","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypeUtils","auth","data","key","attribute","schema","path","isRelation","type","handleMorphRelation","elements","handleMorphElements","connect","set","disconnect","options","undefined","throwInvalidKey","optionKeys","Object","keys","VALID_RELATION_ORDERING_KEYS","isArray","element","isObject","scopes","map","action","__type","isAllowed","hasAccessToSomeScopes","handleRegularRelation","target","isCreatorRelation","includes","populateCreatorFields","scope","strapi","verify"],"mappings":";;;;;;;AAMA,MAAMA,iBAAoB,GAAA;AAAC,IAAA;AAAO,CAAA;AAClC,MAAM,EAAEC,oBAAoB,EAAEC,oBAAoB,EAAE,GAAGC,sBAA0B;AAIjF,+BAAe,CAAA,CAACC,IACd,GAAA,OAAO,E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["import { isArray, isObject } from 'lodash/fp';\nimport * as contentTypeUtils from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\nimport { VALID_RELATION_ORDERING_KEYS } from '../../relations';\n\nconst ACTIONS_TO_VERIFY = ['find'];\nconst { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypeUtils.constants;\n\ntype MorphArray = Array<{ __type: string }>;\n\nexport default (auth: unknown): Visitor =>\n async ({ data, key, attribute, schema, path }) => {\n if (!attribute) {\n return;\n }\n\n const isRelation = attribute.type === 'relation';\n\n if (!isRelation) {\n return;\n }\n\n const handleMorphRelation = async () => {\n const elements: any = (data as Record<string, MorphArray>)[key];\n\n if (\n 'connect' in elements ||\n 'set' in elements ||\n 'disconnect' in elements ||\n 'options' in elements\n ) {\n await handleMorphElements(elements.connect || []);\n await handleMorphElements(elements.set || []);\n await handleMorphElements(elements.disconnect || []);\n\n // TODO: this should technically be in its own visitor to check morph options, but for now we'll handle it here\n if ('options' in elements) {\n if (elements.options === null || elements.options === undefined) {\n return;\n }\n\n if (typeof elements.options !== 'object') {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const optionKeys = Object.keys(elements.options);\n\n // Validate each key based on its validator function\n for (const key of optionKeys) {\n if (!(key in VALID_RELATION_ORDERING_KEYS)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n if (!VALID_RELATION_ORDERING_KEYS[key](elements.options[key])) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n }\n } else {\n await handleMorphElements(elements);\n }\n };\n\n const handleMorphElements = async (elements: any[]) => {\n if (!isArray(elements)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n for (const element of elements) {\n if (!isObject(element) || !('__type' in element)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${element.__type}.${action}`);\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n };\n\n const handleRegularRelation = async () => {\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${attribute.target}.${action}`);\n\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n // If the authenticated user don't have access to any of the scopes\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n };\n\n const isCreatorRelation = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(key);\n\n // Polymorphic relations\n if (contentTypeUtils.isMorphToRelationalAttribute(attribute)) {\n await handleMorphRelation();\n return;\n }\n\n // Creator relations\n if (isCreatorRelation && schema.options?.populateCreatorFields) {\n // do nothing\n return;\n }\n\n // Regular relations\n await handleRegularRelation();\n };\n\nconst hasAccessToSomeScopes = async (scopes: string[], auth: unknown) => {\n for (const scope of scopes) {\n try {\n await strapi.auth.verify(auth, { scope });\n return true;\n } catch {\n continue;\n }\n }\n\n return false;\n};\n"],"names":["ACTIONS_TO_VERIFY","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypeUtils","auth","data","key","attribute","schema","path","isRelation","type","handleMorphRelation","elements","handleMorphElements","connect","set","disconnect","options","undefined","throwInvalidKey","optionKeys","Object","keys","VALID_RELATION_ORDERING_KEYS","isArray","element","isObject","scopes","map","action","__type","isAllowed","hasAccessToSomeScopes","handleRegularRelation","target","isCreatorRelation","includes","populateCreatorFields","scope","strapi","verify"],"mappings":";;;;;AAMA,MAAMA,iBAAoB,GAAA;AAAC,IAAA;AAAO,CAAA;AAClC,MAAM,EAAEC,oBAAoB,EAAEC,oBAAoB,EAAE,GAAGC,SAA0B;AAIjF,+BAAe,CAAA,CAACC,IACd,GAAA,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAA;AAC3C,QAAA,IAAI,CAACF,SAAW,EAAA;AACd,YAAA;AACF;QAEA,MAAMG,UAAAA,GAAaH,SAAUI,CAAAA,IAAI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AAEd,gCAAAA,GAAAA;AAAKG,gCAAAA,IAAAA,EAAMA,KAAKF;AAAU,6BAAA,CAAA;AAC9C;AACF;AACF;aACK,MAAA;AACL,gBAAA,MAAMO,mBAAoBD,CAAAA,QAAAA,CAAAA;AAC5B;AACF,SAAA;AAEA,QAAA,MAAMC,sBAAsB,OAAOD,QAAAA,GAAAA;YACjC,IAAI,CAACY,QAAQZ,QAAW,CAAA,EAAA;gBACtBO,eAAgB,CAAA;AAAEd,oBAAAA,GAAAA;AAAKG,oBAAAA,IAAAA,EAAMA,KAAKF;AAAU,iBAAA,CAAA;AAC9C;YAEA,KAAK,MAAMmB,WAAWb,QAAU,CAAA;AAC9B,gBAAA,IAAI,CAACc,QAASD,CAAAA,OAAAA,CAAAA,IAAY,EAAE,QAAA,IAAYA,OAAM,CAAI,EAAA;oBAChDN,eAAgB,CAAA;AAAEd,wBAAAA,GAAAA;AAAKG,wBAAAA,IAAAA,EAAMA,KAAKF;AAAU,qBAAA,CAAA;AAC9C;AAEA,gBAAA,MAAMqB,MAAS5B,GAAAA,iBAAAA,CAAkB6B,GAAG,CAAC,CAACC,
|
|
1
|
+
{"version":3,"file":"throw-restricted-relations.mjs","sources":["../../../src/validate/visitors/throw-restricted-relations.ts"],"sourcesContent":["import { isArray, isObject } from 'lodash/fp';\nimport * as contentTypeUtils from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\nimport { VALID_RELATION_ORDERING_KEYS } from '../../relations';\n\nconst ACTIONS_TO_VERIFY = ['find'];\nconst { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypeUtils.constants;\n\ntype MorphArray = Array<{ __type: string }>;\n\nexport default (auth: unknown): Visitor =>\n async ({ data, key, attribute, schema, path }) => {\n if (!attribute) {\n return;\n }\n\n const isRelation = attribute.type === 'relation';\n\n if (!isRelation) {\n return;\n }\n\n const handleMorphRelation = async () => {\n const elements: any = (data as Record<string, MorphArray>)[key];\n\n if (\n 'connect' in elements ||\n 'set' in elements ||\n 'disconnect' in elements ||\n 'options' in elements\n ) {\n await handleMorphElements(elements.connect || []);\n await handleMorphElements(elements.set || []);\n await handleMorphElements(elements.disconnect || []);\n\n // TODO: this should technically be in its own visitor to check morph options, but for now we'll handle it here\n if ('options' in elements) {\n if (elements.options === null || elements.options === undefined) {\n return;\n }\n\n if (typeof elements.options !== 'object') {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const optionKeys = Object.keys(elements.options);\n\n // Validate each key based on its validator function\n for (const key of optionKeys) {\n if (!(key in VALID_RELATION_ORDERING_KEYS)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n if (!VALID_RELATION_ORDERING_KEYS[key](elements.options[key])) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n }\n } else {\n await handleMorphElements(elements);\n }\n };\n\n const handleMorphElements = async (elements: any[]) => {\n if (!isArray(elements)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n for (const element of elements) {\n if (!isObject(element) || !('__type' in element)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${element.__type}.${action}`);\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n }\n };\n\n const handleRegularRelation = async () => {\n const scopes = ACTIONS_TO_VERIFY.map((action) => `${attribute.target}.${action}`);\n\n const isAllowed = await hasAccessToSomeScopes(scopes, auth);\n\n // If the authenticated user don't have access to any of the scopes\n if (!isAllowed) {\n throwInvalidKey({ key, path: path.attribute });\n }\n };\n\n const isCreatorRelation = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(key);\n\n // Polymorphic relations\n if (contentTypeUtils.isMorphToRelationalAttribute(attribute)) {\n await handleMorphRelation();\n return;\n }\n\n // Creator relations\n if (isCreatorRelation && schema.options?.populateCreatorFields) {\n // do nothing\n return;\n }\n\n // Regular relations\n await handleRegularRelation();\n };\n\nconst hasAccessToSomeScopes = async (scopes: string[], auth: unknown) => {\n for (const scope of scopes) {\n try {\n await strapi.auth.verify(auth, { scope });\n return true;\n } catch {\n continue;\n }\n }\n\n return false;\n};\n"],"names":["ACTIONS_TO_VERIFY","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypeUtils","auth","data","key","attribute","schema","path","isRelation","type","handleMorphRelation","elements","handleMorphElements","connect","set","disconnect","options","undefined","throwInvalidKey","optionKeys","Object","keys","VALID_RELATION_ORDERING_KEYS","isArray","element","isObject","scopes","map","action","__type","isAllowed","hasAccessToSomeScopes","handleRegularRelation","target","isCreatorRelation","includes","populateCreatorFields","scope","strapi","verify"],"mappings":";;;;;AAMA,MAAMA,iBAAoB,GAAA;AAAC,IAAA;AAAO,CAAA;AAClC,MAAM,EAAEC,oBAAoB,EAAEC,oBAAoB,EAAE,GAAGC,SAA0B;AAIjF,+BAAe,CAAA,CAACC,IACd,GAAA,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAA;AAC3C,QAAA,IAAI,CAACF,SAAW,EAAA;AACd,YAAA;AACF;QAEA,MAAMG,UAAAA,GAAaH,SAAUI,CAAAA,IAAI,KAAK,UAAA;AAEtC,QAAA,IAAI,CAACD,UAAY,EAAA;AACf,YAAA;AACF;AAEA,QAAA,MAAME,mBAAsB,GAAA,UAAA;AAC1B,YAAA,MAAMC,QAAgB,GAACR,IAAmC,CAACC,GAAI,CAAA;AAE/D,YAAA,IACE,aAAaO,QACb,IAAA,KAAA,IAASA,YACT,YAAgBA,IAAAA,QAAAA,IAChB,aAAaA,QACb,EAAA;AACA,gBAAA,MAAMC,mBAAoBD,CAAAA,QAAAA,CAASE,OAAO,IAAI,EAAE,CAAA;AAChD,gBAAA,MAAMD,mBAAoBD,CAAAA,QAAAA,CAASG,GAAG,IAAI,EAAE,CAAA;AAC5C,gBAAA,MAAMF,mBAAoBD,CAAAA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AAA;AACN,YAAA;AACF;;AAGA,QAAA,IAAIwB,iBAAqB5B,IAAAA,MAAAA,CAAOU,OAAO,EAAEoB,qBAAuB,EAAA;;AAE9D,YAAA;AACF;;QAGA,MAAMJ,qBAAAA,EAAAA;AACR,KAAA;AAEF,MAAMD,qBAAAA,GAAwB,OAAOL,MAAkBxB,EAAAA,IAAAA,GAAAA;IACrD,KAAK,MAAMmC,SAASX,MAAQ,CAAA;QAC1B,IAAI;AACF,YAAA,MAAMY,MAAOpC,CAAAA,IAAI,CAACqC,MAAM,CAACrC,IAAM,EAAA;AAAEmC,gBAAAA;AAAM,aAAA,CAAA;YACvC,OAAO,IAAA;AACT,SAAA,CAAE,OAAM;AACN,YAAA;AACF;AACF;IAEA,OAAO,KAAA;AACT,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.js","sources":["../../src/validation/utilities.ts"],"sourcesContent":["/**\n * @file This file contains utility functions for working with Zod schemas.\n * It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),\n * and to safely register and create schemas within Zod's global registry.\n */\n\nimport * as z from 'zod/v4';\n\n/**\n * Transforms a Strapi UID into an OpenAPI-compliant component name.\n *\n * @param uid - The Strapi UID to transform (e.g., \"basic.seo\", \"api::category.category\", \"plugin::upload.file\")\n * @returns The OpenAPI-compliant component name (e.g., \"BasicSeoEntry\", \"ApiCategoryCategoryDocument\", \"PluginUploadFileDocument\")\n */\nexport const transformUidToValidOpenApiName = (uid: string): string => {\n const capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n };\n\n const toPascalCase = (str: string): string => {\n return str.split(/[-_]/).map(capitalize).join('');\n };\n\n // Check if it contains double colons (other namespaced UIDs)\n if (uid.includes('::')) {\n const [namespace, ...rest] = uid.split('::');\n const namespacePart = toPascalCase(namespace);\n const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);\n return `${capitalize(namespacePart)}${restParts.join('')}Document`;\n }\n\n if (uid.includes('.')) {\n // basic.seo -> BasicSeoEntry\n const parts = uid.split('.');\n const transformedParts = parts.map(toPascalCase).map(capitalize);\n return `${transformedParts.join('')}Entry`;\n }\n\n return `${toPascalCase(capitalize(uid))}Schema`;\n};\n\n/**\n * Conditionally makes a Zod schema optional based on the `required` parameter.\n *\n * @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.\n * @returns A function that takes a Zod schema and returns a modified schema (optional or required).\n * @example\n * ```typescript\n * const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>\n *\n * const requiredString = maybeRequired(true)(z.string()); // z.ZodString\n * ```\n */\nexport const maybeRequired = (required?: boolean) => {\n return <T extends z.Schema>(schema: T) => {\n return required !== true ? schema.optional() : schema.nonoptional();\n };\n};\n\n/**\n * Conditionally makes a Zod schema readonly based on the `writable` parameter.\n *\n * @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.\n * @returns A function that takes a Zod schema and returns a modified schema (readonly or original).\n * @example\n * ```typescript\n * const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>\n * const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber\n * ```\n */\nexport const maybeReadonly = (writable?: boolean) => {\n return <T extends z.Schema>(schema: T) => (writable !== false ? schema : schema.readonly());\n};\n\n/**\n * Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.\n *\n * @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.\n * If `defaultValue` is a function, its return value will be used as the default.\n * @returns A function that takes a Zod schema and returns a modified schema (with default or original).\n * @example\n * ```typescript\n * const stringWithDefault = maybeWithDefault(\"default\")(z.string()); // z.ZodDefault<z.ZodString>\n * const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());\n * ```\n */\nexport const maybeWithDefault = (defaultValue?: unknown) => {\n return <T extends z.Schema>(schema: T) => {\n if (defaultValue === undefined) {\n return schema;\n }\n\n const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;\n return schema.default(value);\n };\n};\n\n/**\n * Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.\n *\n * @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.\n * @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.\n * @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).\n * @example\n * ```typescript\n * const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)\n * const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)\n * ```\n */\nexport const maybeWithMinMax = (min?: number, max?: number) => {\n return <R extends z.ZodString | z.ZodEmail | z.ZodNumber | z.ZodArray<z.ZodAny>>(schema: R) => {\n return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;\n };\n};\n\n/**\n * Applies a series of modifier functions to a Zod schema sequentially.\n *\n * @template T - The type of the Zod schema.\n * @param schema - The initial Zod schema to which modifiers will be applied.\n * @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.\n * @returns The final Zod schema after all modifiers have been applied.\n * @example\n * ```typescript\n * const modifiedSchema = augmentSchema(z.string(), [\n * maybeRequired(false),\n * maybeWithDefault(\"test\")\n * ]);\n * ```\n */\nexport const augmentSchema = <T extends z.Schema>(\n schema: T,\n modifiers: ((schema: T) => z.Schema)[]\n) => {\n return modifiers.reduce((acc, modifier) => modifier(acc) as T, schema);\n};\n"],"names":["transformUidToValidOpenApiName","uid","capitalize","str","charAt","toUpperCase","slice","toPascalCase","split","map","join","includes","namespace","rest","namespacePart","restParts","parts","transformedParts","maybeRequired","required","schema","optional","nonoptional","maybeReadonly","writable","readonly","maybeWithDefault","defaultValue","undefined","value","default","maybeWithMinMax","min","max","augmentSchema","modifiers","reduce","acc","modifier"],"mappings":";;AAAA;;;;;;;;;IAcaA,MAAAA,8BAAAA,GAAiC,CAACC,GAAAA,GAAAA;AAC7C,IAAA,MAAMC,aAAa,CAACC,GAAAA,GAAAA;QAClB,OAAOA,GAAAA,CAAIC,MAAM,CAAC,CAAA,CAAA,CAAGC,WAAW,EAAKF,GAAAA,GAAAA,CAAIG,KAAK,CAAC,CAAA,CAAA;AACjD,KAAA;AAEA,IAAA,MAAMC,eAAe,CAACJ,GAAAA,GAAAA;QACpB,OAAOA,GAAAA,CAAIK,KAAK,CAAC,MAAA,CAAA,CAAQC,GAAG,CAACP,UAAAA,CAAAA,CAAYQ,IAAI,CAAC,EAAA,CAAA;AAChD,KAAA;;IAGA,IAAIT,GAAAA,CAAIU,QAAQ,CAAC,IAAO,CAAA,EAAA;AACtB,QAAA,MAAM,CAACC,SAAW,EAAA,GAAGC,KAAK,GAAGZ,GAAAA,CAAIO,KAAK,CAAC,IAAA,CAAA;AACvC,QAAA,MAAMM,gBAAgBP,YAAaK,CAAAA,SAAAA,CAAAA;AACnC,QAAA,MAAMG,SAAYF,GAAAA,IAAAA,CAAKH,IAAI,CAAC,GAAKF,CAAAA,CAAAA,KAAK,CAAC,GAAA,CAAA,CAAKC,GAAG,CAACF,YAAcE,CAAAA,CAAAA,GAAG,CAACP,UAAAA,CAAAA;QAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"utilities.js","sources":["../../src/validation/utilities.ts"],"sourcesContent":["/**\n * @file This file contains utility functions for working with Zod schemas.\n * It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),\n * and to safely register and create schemas within Zod's global registry.\n */\n\nimport * as z from 'zod/v4';\n\n/**\n * Transforms a Strapi UID into an OpenAPI-compliant component name.\n *\n * @param uid - The Strapi UID to transform (e.g., \"basic.seo\", \"api::category.category\", \"plugin::upload.file\")\n * @returns The OpenAPI-compliant component name (e.g., \"BasicSeoEntry\", \"ApiCategoryCategoryDocument\", \"PluginUploadFileDocument\")\n */\nexport const transformUidToValidOpenApiName = (uid: string): string => {\n const capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n };\n\n const toPascalCase = (str: string): string => {\n return str.split(/[-_]/).map(capitalize).join('');\n };\n\n // Check if it contains double colons (other namespaced UIDs)\n if (uid.includes('::')) {\n const [namespace, ...rest] = uid.split('::');\n const namespacePart = toPascalCase(namespace);\n const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);\n return `${capitalize(namespacePart)}${restParts.join('')}Document`;\n }\n\n if (uid.includes('.')) {\n // basic.seo -> BasicSeoEntry\n const parts = uid.split('.');\n const transformedParts = parts.map(toPascalCase).map(capitalize);\n return `${transformedParts.join('')}Entry`;\n }\n\n return `${toPascalCase(capitalize(uid))}Schema`;\n};\n\n/**\n * Conditionally makes a Zod schema optional based on the `required` parameter.\n *\n * @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.\n * @returns A function that takes a Zod schema and returns a modified schema (optional or required).\n * @example\n * ```typescript\n * const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>\n *\n * const requiredString = maybeRequired(true)(z.string()); // z.ZodString\n * ```\n */\nexport const maybeRequired = (required?: boolean) => {\n return <T extends z.Schema>(schema: T) => {\n return required !== true ? schema.optional() : schema.nonoptional();\n };\n};\n\n/**\n * Conditionally makes a Zod schema readonly based on the `writable` parameter.\n *\n * @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.\n * @returns A function that takes a Zod schema and returns a modified schema (readonly or original).\n * @example\n * ```typescript\n * const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>\n * const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber\n * ```\n */\nexport const maybeReadonly = (writable?: boolean) => {\n return <T extends z.Schema>(schema: T) => (writable !== false ? schema : schema.readonly());\n};\n\n/**\n * Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.\n *\n * @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.\n * If `defaultValue` is a function, its return value will be used as the default.\n * @returns A function that takes a Zod schema and returns a modified schema (with default or original).\n * @example\n * ```typescript\n * const stringWithDefault = maybeWithDefault(\"default\")(z.string()); // z.ZodDefault<z.ZodString>\n * const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());\n * ```\n */\nexport const maybeWithDefault = (defaultValue?: unknown) => {\n return <T extends z.Schema>(schema: T) => {\n if (defaultValue === undefined) {\n return schema;\n }\n\n const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;\n return schema.default(value);\n };\n};\n\n/**\n * Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.\n *\n * @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.\n * @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.\n * @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).\n * @example\n * ```typescript\n * const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)\n * const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)\n * ```\n */\nexport const maybeWithMinMax = (min?: number, max?: number) => {\n return <R extends z.ZodString | z.ZodEmail | z.ZodNumber | z.ZodArray<z.ZodAny>>(schema: R) => {\n return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;\n };\n};\n\n/**\n * Applies a series of modifier functions to a Zod schema sequentially.\n *\n * @template T - The type of the Zod schema.\n * @param schema - The initial Zod schema to which modifiers will be applied.\n * @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.\n * @returns The final Zod schema after all modifiers have been applied.\n * @example\n * ```typescript\n * const modifiedSchema = augmentSchema(z.string(), [\n * maybeRequired(false),\n * maybeWithDefault(\"test\")\n * ]);\n * ```\n */\nexport const augmentSchema = <T extends z.Schema>(\n schema: T,\n modifiers: ((schema: T) => z.Schema)[]\n) => {\n return modifiers.reduce((acc, modifier) => modifier(acc) as T, schema);\n};\n"],"names":["transformUidToValidOpenApiName","uid","capitalize","str","charAt","toUpperCase","slice","toPascalCase","split","map","join","includes","namespace","rest","namespacePart","restParts","parts","transformedParts","maybeRequired","required","schema","optional","nonoptional","maybeReadonly","writable","readonly","maybeWithDefault","defaultValue","undefined","value","default","maybeWithMinMax","min","max","augmentSchema","modifiers","reduce","acc","modifier"],"mappings":";;AAAA;;;;;;;;;IAcaA,MAAAA,8BAAAA,GAAiC,CAACC,GAAAA,GAAAA;AAC7C,IAAA,MAAMC,aAAa,CAACC,GAAAA,GAAAA;QAClB,OAAOA,GAAAA,CAAIC,MAAM,CAAC,CAAA,CAAA,CAAGC,WAAW,EAAKF,GAAAA,GAAAA,CAAIG,KAAK,CAAC,CAAA,CAAA;AACjD,KAAA;AAEA,IAAA,MAAMC,eAAe,CAACJ,GAAAA,GAAAA;QACpB,OAAOA,GAAAA,CAAIK,KAAK,CAAC,MAAA,CAAA,CAAQC,GAAG,CAACP,UAAAA,CAAAA,CAAYQ,IAAI,CAAC,EAAA,CAAA;AAChD,KAAA;;IAGA,IAAIT,GAAAA,CAAIU,QAAQ,CAAC,IAAO,CAAA,EAAA;AACtB,QAAA,MAAM,CAACC,SAAW,EAAA,GAAGC,KAAK,GAAGZ,GAAAA,CAAIO,KAAK,CAAC,IAAA,CAAA;AACvC,QAAA,MAAMM,gBAAgBP,YAAaK,CAAAA,SAAAA,CAAAA;AACnC,QAAA,MAAMG,SAAYF,GAAAA,IAAAA,CAAKH,IAAI,CAAC,GAAKF,CAAAA,CAAAA,KAAK,CAAC,GAAA,CAAA,CAAKC,GAAG,CAACF,YAAcE,CAAAA,CAAAA,GAAG,CAACP,UAAAA,CAAAA;QAClE,OAAO,CAAA,EAAGA,WAAWY,aAAiBC,CAAAA,CAAAA,EAAAA,SAAAA,CAAUL,IAAI,CAAC,EAAA,CAAA,CAAI,QAAQ,CAAC;AACpE;IAEA,IAAIT,GAAAA,CAAIU,QAAQ,CAAC,GAAM,CAAA,EAAA;;QAErB,MAAMK,KAAAA,GAAQf,GAAIO,CAAAA,KAAK,CAAC,GAAA,CAAA;AACxB,QAAA,MAAMS,mBAAmBD,KAAMP,CAAAA,GAAG,CAACF,YAAAA,CAAAA,CAAcE,GAAG,CAACP,UAAAA,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AA,MAAAA;AAC7E,KAAA;AACF;AAEA;;;;;;;;;;;;;;AAcC,IACM,MAAMc,aAAgB,GAAA,CAC3Bd,MACAe,EAAAA,SAAAA,GAAAA;AAEA,IAAA,OAAOA,UAAUC,MAAM,CAAC,CAACC,GAAKC,EAAAA,QAAAA,GAAaA,SAASD,GAAWjB,CAAAA,EAAAA,MAAAA,CAAAA;AACjE;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.mjs","sources":["../../src/validation/utilities.ts"],"sourcesContent":["/**\n * @file This file contains utility functions for working with Zod schemas.\n * It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),\n * and to safely register and create schemas within Zod's global registry.\n */\n\nimport * as z from 'zod/v4';\n\n/**\n * Transforms a Strapi UID into an OpenAPI-compliant component name.\n *\n * @param uid - The Strapi UID to transform (e.g., \"basic.seo\", \"api::category.category\", \"plugin::upload.file\")\n * @returns The OpenAPI-compliant component name (e.g., \"BasicSeoEntry\", \"ApiCategoryCategoryDocument\", \"PluginUploadFileDocument\")\n */\nexport const transformUidToValidOpenApiName = (uid: string): string => {\n const capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n };\n\n const toPascalCase = (str: string): string => {\n return str.split(/[-_]/).map(capitalize).join('');\n };\n\n // Check if it contains double colons (other namespaced UIDs)\n if (uid.includes('::')) {\n const [namespace, ...rest] = uid.split('::');\n const namespacePart = toPascalCase(namespace);\n const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);\n return `${capitalize(namespacePart)}${restParts.join('')}Document`;\n }\n\n if (uid.includes('.')) {\n // basic.seo -> BasicSeoEntry\n const parts = uid.split('.');\n const transformedParts = parts.map(toPascalCase).map(capitalize);\n return `${transformedParts.join('')}Entry`;\n }\n\n return `${toPascalCase(capitalize(uid))}Schema`;\n};\n\n/**\n * Conditionally makes a Zod schema optional based on the `required` parameter.\n *\n * @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.\n * @returns A function that takes a Zod schema and returns a modified schema (optional or required).\n * @example\n * ```typescript\n * const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>\n *\n * const requiredString = maybeRequired(true)(z.string()); // z.ZodString\n * ```\n */\nexport const maybeRequired = (required?: boolean) => {\n return <T extends z.Schema>(schema: T) => {\n return required !== true ? schema.optional() : schema.nonoptional();\n };\n};\n\n/**\n * Conditionally makes a Zod schema readonly based on the `writable` parameter.\n *\n * @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.\n * @returns A function that takes a Zod schema and returns a modified schema (readonly or original).\n * @example\n * ```typescript\n * const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>\n * const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber\n * ```\n */\nexport const maybeReadonly = (writable?: boolean) => {\n return <T extends z.Schema>(schema: T) => (writable !== false ? schema : schema.readonly());\n};\n\n/**\n * Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.\n *\n * @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.\n * If `defaultValue` is a function, its return value will be used as the default.\n * @returns A function that takes a Zod schema and returns a modified schema (with default or original).\n * @example\n * ```typescript\n * const stringWithDefault = maybeWithDefault(\"default\")(z.string()); // z.ZodDefault<z.ZodString>\n * const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());\n * ```\n */\nexport const maybeWithDefault = (defaultValue?: unknown) => {\n return <T extends z.Schema>(schema: T) => {\n if (defaultValue === undefined) {\n return schema;\n }\n\n const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;\n return schema.default(value);\n };\n};\n\n/**\n * Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.\n *\n * @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.\n * @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.\n * @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).\n * @example\n * ```typescript\n * const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)\n * const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)\n * ```\n */\nexport const maybeWithMinMax = (min?: number, max?: number) => {\n return <R extends z.ZodString | z.ZodEmail | z.ZodNumber | z.ZodArray<z.ZodAny>>(schema: R) => {\n return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;\n };\n};\n\n/**\n * Applies a series of modifier functions to a Zod schema sequentially.\n *\n * @template T - The type of the Zod schema.\n * @param schema - The initial Zod schema to which modifiers will be applied.\n * @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.\n * @returns The final Zod schema after all modifiers have been applied.\n * @example\n * ```typescript\n * const modifiedSchema = augmentSchema(z.string(), [\n * maybeRequired(false),\n * maybeWithDefault(\"test\")\n * ]);\n * ```\n */\nexport const augmentSchema = <T extends z.Schema>(\n schema: T,\n modifiers: ((schema: T) => z.Schema)[]\n) => {\n return modifiers.reduce((acc, modifier) => modifier(acc) as T, schema);\n};\n"],"names":["transformUidToValidOpenApiName","uid","capitalize","str","charAt","toUpperCase","slice","toPascalCase","split","map","join","includes","namespace","rest","namespacePart","restParts","parts","transformedParts","maybeRequired","required","schema","optional","nonoptional","maybeReadonly","writable","readonly","maybeWithDefault","defaultValue","undefined","value","default","maybeWithMinMax","min","max","augmentSchema","modifiers","reduce","acc","modifier"],"mappings":"AAAA;;;;;;;;;IAcaA,MAAAA,8BAAAA,GAAiC,CAACC,GAAAA,GAAAA;AAC7C,IAAA,MAAMC,aAAa,CAACC,GAAAA,GAAAA;QAClB,OAAOA,GAAAA,CAAIC,MAAM,CAAC,CAAA,CAAA,CAAGC,WAAW,EAAKF,GAAAA,GAAAA,CAAIG,KAAK,CAAC,CAAA,CAAA;AACjD,KAAA;AAEA,IAAA,MAAMC,eAAe,CAACJ,GAAAA,GAAAA;QACpB,OAAOA,GAAAA,CAAIK,KAAK,CAAC,MAAA,CAAA,CAAQC,GAAG,CAACP,UAAAA,CAAAA,CAAYQ,IAAI,CAAC,EAAA,CAAA;AAChD,KAAA;;IAGA,IAAIT,GAAAA,CAAIU,QAAQ,CAAC,IAAO,CAAA,EAAA;AACtB,QAAA,MAAM,CAACC,SAAW,EAAA,GAAGC,KAAK,GAAGZ,GAAAA,CAAIO,KAAK,CAAC,IAAA,CAAA;AACvC,QAAA,MAAMM,gBAAgBP,YAAaK,CAAAA,SAAAA,CAAAA;AACnC,QAAA,MAAMG,SAAYF,GAAAA,IAAAA,CAAKH,IAAI,CAAC,GAAKF,CAAAA,CAAAA,KAAK,CAAC,GAAA,CAAA,CAAKC,GAAG,CAACF,YAAcE,CAAAA,CAAAA,GAAG,CAACP,UAAAA,CAAAA;QAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"utilities.mjs","sources":["../../src/validation/utilities.ts"],"sourcesContent":["/**\n * @file This file contains utility functions for working with Zod schemas.\n * It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),\n * and to safely register and create schemas within Zod's global registry.\n */\n\nimport * as z from 'zod/v4';\n\n/**\n * Transforms a Strapi UID into an OpenAPI-compliant component name.\n *\n * @param uid - The Strapi UID to transform (e.g., \"basic.seo\", \"api::category.category\", \"plugin::upload.file\")\n * @returns The OpenAPI-compliant component name (e.g., \"BasicSeoEntry\", \"ApiCategoryCategoryDocument\", \"PluginUploadFileDocument\")\n */\nexport const transformUidToValidOpenApiName = (uid: string): string => {\n const capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n };\n\n const toPascalCase = (str: string): string => {\n return str.split(/[-_]/).map(capitalize).join('');\n };\n\n // Check if it contains double colons (other namespaced UIDs)\n if (uid.includes('::')) {\n const [namespace, ...rest] = uid.split('::');\n const namespacePart = toPascalCase(namespace);\n const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);\n return `${capitalize(namespacePart)}${restParts.join('')}Document`;\n }\n\n if (uid.includes('.')) {\n // basic.seo -> BasicSeoEntry\n const parts = uid.split('.');\n const transformedParts = parts.map(toPascalCase).map(capitalize);\n return `${transformedParts.join('')}Entry`;\n }\n\n return `${toPascalCase(capitalize(uid))}Schema`;\n};\n\n/**\n * Conditionally makes a Zod schema optional based on the `required` parameter.\n *\n * @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.\n * @returns A function that takes a Zod schema and returns a modified schema (optional or required).\n * @example\n * ```typescript\n * const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>\n *\n * const requiredString = maybeRequired(true)(z.string()); // z.ZodString\n * ```\n */\nexport const maybeRequired = (required?: boolean) => {\n return <T extends z.Schema>(schema: T) => {\n return required !== true ? schema.optional() : schema.nonoptional();\n };\n};\n\n/**\n * Conditionally makes a Zod schema readonly based on the `writable` parameter.\n *\n * @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.\n * @returns A function that takes a Zod schema and returns a modified schema (readonly or original).\n * @example\n * ```typescript\n * const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>\n * const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber\n * ```\n */\nexport const maybeReadonly = (writable?: boolean) => {\n return <T extends z.Schema>(schema: T) => (writable !== false ? schema : schema.readonly());\n};\n\n/**\n * Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.\n *\n * @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.\n * If `defaultValue` is a function, its return value will be used as the default.\n * @returns A function that takes a Zod schema and returns a modified schema (with default or original).\n * @example\n * ```typescript\n * const stringWithDefault = maybeWithDefault(\"default\")(z.string()); // z.ZodDefault<z.ZodString>\n * const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());\n * ```\n */\nexport const maybeWithDefault = (defaultValue?: unknown) => {\n return <T extends z.Schema>(schema: T) => {\n if (defaultValue === undefined) {\n return schema;\n }\n\n const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;\n return schema.default(value);\n };\n};\n\n/**\n * Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.\n *\n * @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.\n * @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.\n * @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).\n * @example\n * ```typescript\n * const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)\n * const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)\n * ```\n */\nexport const maybeWithMinMax = (min?: number, max?: number) => {\n return <R extends z.ZodString | z.ZodEmail | z.ZodNumber | z.ZodArray<z.ZodAny>>(schema: R) => {\n return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;\n };\n};\n\n/**\n * Applies a series of modifier functions to a Zod schema sequentially.\n *\n * @template T - The type of the Zod schema.\n * @param schema - The initial Zod schema to which modifiers will be applied.\n * @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.\n * @returns The final Zod schema after all modifiers have been applied.\n * @example\n * ```typescript\n * const modifiedSchema = augmentSchema(z.string(), [\n * maybeRequired(false),\n * maybeWithDefault(\"test\")\n * ]);\n * ```\n */\nexport const augmentSchema = <T extends z.Schema>(\n schema: T,\n modifiers: ((schema: T) => z.Schema)[]\n) => {\n return modifiers.reduce((acc, modifier) => modifier(acc) as T, schema);\n};\n"],"names":["transformUidToValidOpenApiName","uid","capitalize","str","charAt","toUpperCase","slice","toPascalCase","split","map","join","includes","namespace","rest","namespacePart","restParts","parts","transformedParts","maybeRequired","required","schema","optional","nonoptional","maybeReadonly","writable","readonly","maybeWithDefault","defaultValue","undefined","value","default","maybeWithMinMax","min","max","augmentSchema","modifiers","reduce","acc","modifier"],"mappings":"AAAA;;;;;;;;;IAcaA,MAAAA,8BAAAA,GAAiC,CAACC,GAAAA,GAAAA;AAC7C,IAAA,MAAMC,aAAa,CAACC,GAAAA,GAAAA;QAClB,OAAOA,GAAAA,CAAIC,MAAM,CAAC,CAA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AA;AACjE;;;;"}
|
package/dist/yup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.js","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _ from 'lodash';\nimport { isNumber, isInteger, get } from 'lodash/fp';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(propertyName, e) === get(propertyName, element)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","isInteger","
|
|
1
|
+
{"version":3,"file":"yup.js","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _ from 'lodash';\nimport { isNumber, isInteger, get } from 'lodash/fp';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(propertyName, e) === get(propertyName, element)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","isInteger","type","setLocale","notType","options","originalValue","isCast","printValue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAUaA,MAAAA,QAAAA,GAAW,IAA2C,IAAIC,cAAiB;AAExF,MAAMC,eAAe,CAACC,KAAAA,GAAmB,CAACC,CAAAA,CAAEC,KAAK,CAACF,KAAAA,CAAAA;AAElD,MAAMG,gBAAgB,CAACH,KAAAA,GAAmB,CAACC,CAAAA,CAAEG,MAAM,CAACJ,KAAAA,CAAAA;AAEpDK,cAAIC,CAAAA,SAAS,CAACD,cAAIE,CAAAA,KAAK,EAAE,QAAU,EAAA,SAASC,SAAUC,CAAAA,GAAAA,GAAM,0BAA0B,EAAA;AACpF,IAAA,OAAO,IAAI,CAACC,IAAI,CAAC,WAAWD,GAAKV,EAAAA,YAAAA,CAAAA;AACnC,CAAA,CAAA;AAEAM,cAAIC,CAAAA,SAAS,CAACD,cAAIE,CAAAA,KAAK,EAAE,SAAW,EAAA,SAASI,SAAUF,CAAAA,GAAAA,GAAM,yBAAyB,EAAA;AACpF,IAAA,OAAO,IAAI,CAACC,IAAI,CAAC,WAAWD,GAAKN,EAAAA,aAAAA,CAAAA;AACnC,CAAA,CAAA;AAEAE,cAAIC,CAAAA,SAAS,CAACD,cAAIE,CAAAA,KAAK,EAAE,YAAc,EAAA,SAASK,UAAWC,CAAAA,OAAAA,GAAU,2BAA2B,EAAA;AAC9F,IAAA,OAAO,IAAI,CAACH,IAAI,CACd,iBACAG,OACA,EAAA,CAACb,KAAUC,GAAAA,CAAAA,CAAEa,WAAW,CAACd,KAAUC,CAAAA,IAAAA,CAAAA,CAAEW,UAAU,CAACZ,KAAAA,CAAAA,CAAAA;AAEpD,CAAA,CAAA;AAEAK,cAAIC,CAAAA,SAAS,CACXD,cAAIU,CAAAA,MA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IAAK,CAAA,SAAS,CAAC,GACtC,CAAC,2BAA2B,EAAEM,qBAAAA,CAAWpD,KAAO,EAAA,IAAA,CAAA,CAAM,EAAE,EACtDmD,MAAS,GAAA,CAAC,wBAAwB,EAAEC,qBAAWF,CAAAA,aAAAA,EAAe,IAAM,CAAA,CAAA,IAAI,CAAC,GAAG,GAC5E,CAAA,CAAA;AAEJ;;;;AAIA,SACA,OAAOzC,GAAAA;AACT;AACF;AACF,CAAA,CAAA;;;;;;;;;;;"}
|
package/dist/yup.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.mjs","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _ from 'lodash';\nimport { isNumber, isInteger, get } from 'lodash/fp';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(propertyName, e) === get(propertyName, element)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","isInteger","
|
|
1
|
+
{"version":3,"file":"yup.mjs","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _ from 'lodash';\nimport { isNumber, isInteger, get } from 'lodash/fp';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(propertyName, e) === get(propertyName, element)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","isInteger","type","setLocale","notType","options","originalValue","isCast","printValue"],"mappings":";;;;;;;AAUaA,MAAAA,QAAAA,GAAW,IAA2C,IAAIC,cAAiB;AAExF,MAAMC,eAAe,CAACC,KAAAA,GAAmB,CAACC,UAAAA,CAAEC,KAAK,CAACF,KAAAA,CAAAA;AAElD,MAAMG,gBAAgB,CAACH,KAAAA,GAAmB,CAACC,UAAAA,CAAEG,MAAM,CAACJ,KAAAA,CAAAA;AAEpDK,GAAIC,CAAAA,SAAS,CAACD,GAAIE,CAAAA,KAAK,EAAE,QAAU,EAAA,SAASC,SAAUC,CAAAA,GAAAA,GAAM,0BAA0B,EAAA;AACpF,IAAA,OAAO,IAAI,CAACC,IAAI,CAAC,WAAWD,GAAKV,EAAAA,YAAAA,CAAAA;AACnC,CAAA,CAAA;AAEAM,GAAIC,CAAAA,SAAS,CAACD,GAAIE,CAAAA,KAAK,EAAE,SAAW,EAAA,SAASI,SAAUF,CAAAA,GAAAA,GAAM,yBAAyB,EAAA;AACpF,IAAA,OAAO,IAAI,CAACC,IAAI,CAAC,WAAWD,GAAKN,EAAAA,aAAAA,CAAAA;AACnC,CAAA,CAAA;AAEAE,GAAIC,CAAAA,SAAS,CAACD,GAAIE,CAAAA,KAAK,EAAE,YAAc,EAAA,SAASK,UAAWC,CAAAA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AAA,OAAAA,CAAAA,CAAQC,OAAsB,EAAA;YAC5B,MAAM,EAAET,IAAI,EAAEM,IAAI,EAAE9C,KAAK,EAAEkD,aAAa,EAAE,GAAGD,OAAAA;YAC7C,MAAME,MAAAA,GAASD,aAAiB,IAAA,IAAA,IAAQA,aAAkBlD,KAAAA,KAAAA;YAC1D,MAAMS,GAAAA,GACJ,CAAG+B,EAAAA,IAAAA,CAAK,aAAa,EAAEM,IAAK,CAAA,SAAS,CAAC,GACtC,CAAC,2BAA2B,EAAEM,UAAAA,CAAWpD,KAAO,EAAA,IAAA,CAAA,CAAM,EAAE,EACtDmD,MAAS,GAAA,CAAC,wBAAwB,EAAEC,UAAWF,CAAAA,aAAAA,EAAe,IAAM,CAAA,CAAA,IAAI,CAAC,GAAG,GAC5E,CAAA,CAAA;AAEJ;;;;AAIA,SACA,OAAOzC,GAAAA;AACT;AACF;AACF,CAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.30.1",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"@types/http-errors": "2.0.4",
|
|
62
62
|
"@types/koa": "2.13.4",
|
|
63
63
|
"@types/node": "18.19.24",
|
|
64
|
-
"eslint-config-custom": "5.
|
|
64
|
+
"eslint-config-custom": "5.30.1",
|
|
65
65
|
"koa": "2.16.1",
|
|
66
66
|
"koa-body": "6.0.1",
|
|
67
|
-
"tsconfig": "5.
|
|
67
|
+
"tsconfig": "5.30.1"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=18.0.0 <=22.x.x",
|