@loadspark/core 0.0.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/LICENSE.md +71 -0
- package/README.md +628 -0
- package/dist/access/accessors.d.ts +22 -0
- package/dist/access/accessors.d.ts.map +1 -0
- package/dist/access/accessors.js +20 -0
- package/dist/access/accessors.js.map +1 -0
- package/dist/access/builders.d.ts +4 -0
- package/dist/access/builders.d.ts.map +1 -0
- package/dist/access/builders.js +26 -0
- package/dist/access/builders.js.map +1 -0
- package/dist/access/index.d.ts +4 -0
- package/dist/access/index.d.ts.map +1 -0
- package/dist/access/index.js +5 -0
- package/dist/access/index.js.map +1 -0
- package/dist/access/roles.d.ts +38 -0
- package/dist/access/roles.d.ts.map +1 -0
- package/dist/access/roles.js +33 -0
- package/dist/access/roles.js.map +1 -0
- package/dist/collections/users/access.d.ts +30 -0
- package/dist/collections/users/access.d.ts.map +1 -0
- package/dist/collections/users/access.js +96 -0
- package/dist/collections/users/access.js.map +1 -0
- package/dist/collections/users/config.d.ts +9 -0
- package/dist/collections/users/config.d.ts.map +1 -0
- package/dist/collections/users/config.js +55 -0
- package/dist/collections/users/config.js.map +1 -0
- package/dist/collections/users/fields.d.ts +4 -0
- package/dist/collections/users/fields.d.ts.map +1 -0
- package/dist/collections/users/fields.js +97 -0
- package/dist/collections/users/fields.js.map +1 -0
- package/dist/collections/users/hooks.d.ts +25 -0
- package/dist/collections/users/hooks.d.ts.map +1 -0
- package/dist/collections/users/hooks.js +50 -0
- package/dist/collections/users/hooks.js.map +1 -0
- package/dist/collections/users/types.d.ts +18 -0
- package/dist/collections/users/types.d.ts.map +1 -0
- package/dist/collections/users/types.js +8 -0
- package/dist/collections/users/types.js.map +1 -0
- package/dist/constants.d.ts +45 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +46 -0
- package/dist/constants.js.map +1 -0
- package/dist/exports/access/index.d.ts +2 -0
- package/dist/exports/access/index.d.ts.map +1 -0
- package/dist/exports/access/index.js +3 -0
- package/dist/exports/access/index.js.map +1 -0
- package/dist/exports/fields/AlertBox/client.d.ts +2 -0
- package/dist/exports/fields/AlertBox/client.d.ts.map +1 -0
- package/dist/exports/fields/AlertBox/client.js +3 -0
- package/dist/exports/fields/AlertBox/client.js.map +1 -0
- package/dist/exports/fields/AlertBox/index.d.ts +2 -0
- package/dist/exports/fields/AlertBox/index.d.ts.map +1 -0
- package/dist/exports/fields/AlertBox/index.js +3 -0
- package/dist/exports/fields/AlertBox/index.js.map +1 -0
- package/dist/exports/fields/ColourText/client.d.ts +2 -0
- package/dist/exports/fields/ColourText/client.d.ts.map +1 -0
- package/dist/exports/fields/ColourText/client.js +3 -0
- package/dist/exports/fields/ColourText/client.js.map +1 -0
- package/dist/exports/fields/ColourText/index.d.ts +2 -0
- package/dist/exports/fields/ColourText/index.d.ts.map +1 -0
- package/dist/exports/fields/ColourText/index.js +3 -0
- package/dist/exports/fields/ColourText/index.js.map +1 -0
- package/dist/exports/fields/Combo/client.d.ts +2 -0
- package/dist/exports/fields/Combo/client.d.ts.map +1 -0
- package/dist/exports/fields/Combo/client.js +3 -0
- package/dist/exports/fields/Combo/client.js.map +1 -0
- package/dist/exports/fields/Combo/index.d.ts +2 -0
- package/dist/exports/fields/Combo/index.d.ts.map +1 -0
- package/dist/exports/fields/Combo/index.js +3 -0
- package/dist/exports/fields/Combo/index.js.map +1 -0
- package/dist/exports/fields/Countries/index.d.ts +2 -0
- package/dist/exports/fields/Countries/index.d.ts.map +1 -0
- package/dist/exports/fields/Countries/index.js +3 -0
- package/dist/exports/fields/Countries/index.js.map +1 -0
- package/dist/exports/fields/Number/client.d.ts +2 -0
- package/dist/exports/fields/Number/client.d.ts.map +1 -0
- package/dist/exports/fields/Number/client.js +3 -0
- package/dist/exports/fields/Number/client.js.map +1 -0
- package/dist/exports/fields/Number/index.d.ts +2 -0
- package/dist/exports/fields/Number/index.d.ts.map +1 -0
- package/dist/exports/fields/Number/index.js +3 -0
- package/dist/exports/fields/Number/index.js.map +1 -0
- package/dist/exports/fields/OpeningHours/client.d.ts +2 -0
- package/dist/exports/fields/OpeningHours/client.d.ts.map +1 -0
- package/dist/exports/fields/OpeningHours/client.js +3 -0
- package/dist/exports/fields/OpeningHours/client.js.map +1 -0
- package/dist/exports/fields/OpeningHours/index.d.ts +2 -0
- package/dist/exports/fields/OpeningHours/index.d.ts.map +1 -0
- package/dist/exports/fields/OpeningHours/index.js +3 -0
- package/dist/exports/fields/OpeningHours/index.js.map +1 -0
- package/dist/exports/fields/Pattern/client.d.ts +2 -0
- package/dist/exports/fields/Pattern/client.d.ts.map +1 -0
- package/dist/exports/fields/Pattern/client.js +3 -0
- package/dist/exports/fields/Pattern/client.js.map +1 -0
- package/dist/exports/fields/Pattern/index.d.ts +2 -0
- package/dist/exports/fields/Pattern/index.d.ts.map +1 -0
- package/dist/exports/fields/Pattern/index.js +3 -0
- package/dist/exports/fields/Pattern/index.js.map +1 -0
- package/dist/exports/fields/Range/client.d.ts +2 -0
- package/dist/exports/fields/Range/client.d.ts.map +1 -0
- package/dist/exports/fields/Range/client.js +3 -0
- package/dist/exports/fields/Range/client.js.map +1 -0
- package/dist/exports/fields/Range/index.d.ts +2 -0
- package/dist/exports/fields/Range/index.d.ts.map +1 -0
- package/dist/exports/fields/Range/index.js +3 -0
- package/dist/exports/fields/Range/index.js.map +1 -0
- package/dist/exports/fields/Telephone/client.d.ts +2 -0
- package/dist/exports/fields/Telephone/client.d.ts.map +1 -0
- package/dist/exports/fields/Telephone/client.js +3 -0
- package/dist/exports/fields/Telephone/client.js.map +1 -0
- package/dist/exports/fields/Telephone/index.d.ts +2 -0
- package/dist/exports/fields/Telephone/index.d.ts.map +1 -0
- package/dist/exports/fields/Telephone/index.js +3 -0
- package/dist/exports/fields/Telephone/index.js.map +1 -0
- package/dist/exports/fields/client.d.ts +2 -0
- package/dist/exports/fields/client.d.ts.map +1 -0
- package/dist/exports/fields/client.js +2 -0
- package/dist/exports/fields/client.js.map +1 -0
- package/dist/exports/fields/index.d.ts +10 -0
- package/dist/exports/fields/index.d.ts.map +1 -0
- package/dist/exports/fields/index.js +11 -0
- package/dist/exports/fields/index.js.map +1 -0
- package/dist/exports/translations/index.d.ts +2 -0
- package/dist/exports/translations/index.d.ts.map +1 -0
- package/dist/exports/translations/index.js +3 -0
- package/dist/exports/translations/index.js.map +1 -0
- package/dist/exports/users/index.d.ts +4 -0
- package/dist/exports/users/index.d.ts.map +1 -0
- package/dist/exports/users/index.js +5 -0
- package/dist/exports/users/index.js.map +1 -0
- package/dist/exports/validations/index.d.ts +4 -0
- package/dist/exports/validations/index.d.ts.map +1 -0
- package/dist/exports/validations/index.js +5 -0
- package/dist/exports/validations/index.js.map +1 -0
- package/dist/fields/AlertBox/Component.d.ts +14 -0
- package/dist/fields/AlertBox/Component.d.ts.map +1 -0
- package/dist/fields/AlertBox/Component.js +32 -0
- package/dist/fields/AlertBox/Component.js.map +1 -0
- package/dist/fields/AlertBox/icons/AlertIcon.d.ts +3 -0
- package/dist/fields/AlertBox/icons/AlertIcon.d.ts.map +1 -0
- package/dist/fields/AlertBox/icons/AlertIcon.js +27 -0
- package/dist/fields/AlertBox/icons/AlertIcon.js.map +1 -0
- package/dist/fields/AlertBox/icons/ErrorIcon.d.ts +3 -0
- package/dist/fields/AlertBox/icons/ErrorIcon.d.ts.map +1 -0
- package/dist/fields/AlertBox/icons/ErrorIcon.js +35 -0
- package/dist/fields/AlertBox/icons/ErrorIcon.js.map +1 -0
- package/dist/fields/AlertBox/icons/InfoIcon.d.ts +3 -0
- package/dist/fields/AlertBox/icons/InfoIcon.d.ts.map +1 -0
- package/dist/fields/AlertBox/icons/InfoIcon.js +29 -0
- package/dist/fields/AlertBox/icons/InfoIcon.js.map +1 -0
- package/dist/fields/AlertBox/index.d.ts +76 -0
- package/dist/fields/AlertBox/index.d.ts.map +1 -0
- package/dist/fields/AlertBox/index.js +64 -0
- package/dist/fields/AlertBox/index.js.map +1 -0
- package/dist/fields/AlertBox/styles.css +42 -0
- package/dist/fields/ColourText/Component.d.ts +8 -0
- package/dist/fields/ColourText/Component.d.ts.map +1 -0
- package/dist/fields/ColourText/Component.js +102 -0
- package/dist/fields/ColourText/Component.js.map +1 -0
- package/dist/fields/ColourText/index.d.ts +35 -0
- package/dist/fields/ColourText/index.d.ts.map +1 -0
- package/dist/fields/ColourText/index.js +41 -0
- package/dist/fields/ColourText/index.js.map +1 -0
- package/dist/fields/ColourText/styles.css +21 -0
- package/dist/fields/ColourText/validate.d.ts +3 -0
- package/dist/fields/ColourText/validate.d.ts.map +1 -0
- package/dist/fields/ColourText/validate.js +30 -0
- package/dist/fields/ColourText/validate.js.map +1 -0
- package/dist/fields/Combo/Component.d.ts +16 -0
- package/dist/fields/Combo/Component.d.ts.map +1 -0
- package/dist/fields/Combo/Component.js +105 -0
- package/dist/fields/Combo/Component.js.map +1 -0
- package/dist/fields/Combo/beforeValidate.d.ts +4 -0
- package/dist/fields/Combo/beforeValidate.d.ts.map +1 -0
- package/dist/fields/Combo/beforeValidate.js +30 -0
- package/dist/fields/Combo/beforeValidate.js.map +1 -0
- package/dist/fields/Combo/index.d.ts +58 -0
- package/dist/fields/Combo/index.d.ts.map +1 -0
- package/dist/fields/Combo/index.js +74 -0
- package/dist/fields/Combo/index.js.map +1 -0
- package/dist/fields/Countries/index.d.ts +49 -0
- package/dist/fields/Countries/index.d.ts.map +1 -0
- package/dist/fields/Countries/index.js +59 -0
- package/dist/fields/Countries/index.js.map +1 -0
- package/dist/fields/Number/Component.d.ts +14 -0
- package/dist/fields/Number/Component.d.ts.map +1 -0
- package/dist/fields/Number/Component.js +108 -0
- package/dist/fields/Number/Component.js.map +1 -0
- package/dist/fields/Number/index.d.ts +64 -0
- package/dist/fields/Number/index.d.ts.map +1 -0
- package/dist/fields/Number/index.js +66 -0
- package/dist/fields/Number/index.js.map +1 -0
- package/dist/fields/Number/styles.css +0 -0
- package/dist/fields/OpeningHours/Component.d.ts +7 -0
- package/dist/fields/OpeningHours/Component.d.ts.map +1 -0
- package/dist/fields/OpeningHours/Component.js +161 -0
- package/dist/fields/OpeningHours/Component.js.map +1 -0
- package/dist/fields/OpeningHours/index.d.ts +51 -0
- package/dist/fields/OpeningHours/index.d.ts.map +1 -0
- package/dist/fields/OpeningHours/index.js +49 -0
- package/dist/fields/OpeningHours/index.js.map +1 -0
- package/dist/fields/OpeningHours/styles.css +124 -0
- package/dist/fields/OpeningHours/validate.d.ts +3 -0
- package/dist/fields/OpeningHours/validate.d.ts.map +1 -0
- package/dist/fields/OpeningHours/validate.js +39 -0
- package/dist/fields/OpeningHours/validate.js.map +1 -0
- package/dist/fields/Pattern/Component.d.ts +14 -0
- package/dist/fields/Pattern/Component.d.ts.map +1 -0
- package/dist/fields/Pattern/Component.js +88 -0
- package/dist/fields/Pattern/Component.js.map +1 -0
- package/dist/fields/Pattern/index.d.ts +59 -0
- package/dist/fields/Pattern/index.d.ts.map +1 -0
- package/dist/fields/Pattern/index.js +55 -0
- package/dist/fields/Pattern/index.js.map +1 -0
- package/dist/fields/Pattern/styles.css +34 -0
- package/dist/fields/Range/Component.d.ts +13 -0
- package/dist/fields/Range/Component.d.ts.map +1 -0
- package/dist/fields/Range/Component.js +138 -0
- package/dist/fields/Range/Component.js.map +1 -0
- package/dist/fields/Range/index.d.ts +82 -0
- package/dist/fields/Range/index.d.ts.map +1 -0
- package/dist/fields/Range/index.js +63 -0
- package/dist/fields/Range/index.js.map +1 -0
- package/dist/fields/Range/range.scss +138 -0
- package/dist/fields/Range/types.d.ts +5 -0
- package/dist/fields/Range/types.d.ts.map +1 -0
- package/dist/fields/Range/types.js +3 -0
- package/dist/fields/Range/types.js.map +1 -0
- package/dist/fields/Telephone/Component.d.ts +13 -0
- package/dist/fields/Telephone/Component.d.ts.map +1 -0
- package/dist/fields/Telephone/Component.js +92 -0
- package/dist/fields/Telephone/Component.js.map +1 -0
- package/dist/fields/Telephone/index.d.ts +99 -0
- package/dist/fields/Telephone/index.d.ts.map +1 -0
- package/dist/fields/Telephone/index.js +59 -0
- package/dist/fields/Telephone/index.js.map +1 -0
- package/dist/fields/Telephone/validate.d.ts +3 -0
- package/dist/fields/Telephone/validate.d.ts.map +1 -0
- package/dist/fields/Telephone/validate.js +13 -0
- package/dist/fields/Telephone/validate.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/index.d.ts +6 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +92 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/languages/ar.d.ts +576 -0
- package/dist/translations/languages/ar.d.ts.map +1 -0
- package/dist/translations/languages/ar.js +329 -0
- package/dist/translations/languages/ar.js.map +1 -0
- package/dist/translations/languages/az.d.ts +576 -0
- package/dist/translations/languages/az.d.ts.map +1 -0
- package/dist/translations/languages/az.js +329 -0
- package/dist/translations/languages/az.js.map +1 -0
- package/dist/translations/languages/bg.d.ts +576 -0
- package/dist/translations/languages/bg.d.ts.map +1 -0
- package/dist/translations/languages/bg.js +329 -0
- package/dist/translations/languages/bg.js.map +1 -0
- package/dist/translations/languages/bnBd.d.ts +576 -0
- package/dist/translations/languages/bnBd.d.ts.map +1 -0
- package/dist/translations/languages/bnBd.js +329 -0
- package/dist/translations/languages/bnBd.js.map +1 -0
- package/dist/translations/languages/bnIn.d.ts +576 -0
- package/dist/translations/languages/bnIn.d.ts.map +1 -0
- package/dist/translations/languages/bnIn.js +329 -0
- package/dist/translations/languages/bnIn.js.map +1 -0
- package/dist/translations/languages/ca.d.ts +576 -0
- package/dist/translations/languages/ca.d.ts.map +1 -0
- package/dist/translations/languages/ca.js +329 -0
- package/dist/translations/languages/ca.js.map +1 -0
- package/dist/translations/languages/cs.d.ts +576 -0
- package/dist/translations/languages/cs.d.ts.map +1 -0
- package/dist/translations/languages/cs.js +329 -0
- package/dist/translations/languages/cs.js.map +1 -0
- package/dist/translations/languages/da.d.ts +576 -0
- package/dist/translations/languages/da.d.ts.map +1 -0
- package/dist/translations/languages/da.js +329 -0
- package/dist/translations/languages/da.js.map +1 -0
- package/dist/translations/languages/de.d.ts +576 -0
- package/dist/translations/languages/de.d.ts.map +1 -0
- package/dist/translations/languages/de.js +329 -0
- package/dist/translations/languages/de.js.map +1 -0
- package/dist/translations/languages/en.d.ts +576 -0
- package/dist/translations/languages/en.d.ts.map +1 -0
- package/dist/translations/languages/en.js +329 -0
- package/dist/translations/languages/en.js.map +1 -0
- package/dist/translations/languages/es.d.ts +576 -0
- package/dist/translations/languages/es.d.ts.map +1 -0
- package/dist/translations/languages/es.js +329 -0
- package/dist/translations/languages/es.js.map +1 -0
- package/dist/translations/languages/et.d.ts +576 -0
- package/dist/translations/languages/et.d.ts.map +1 -0
- package/dist/translations/languages/et.js +329 -0
- package/dist/translations/languages/et.js.map +1 -0
- package/dist/translations/languages/fa.d.ts +576 -0
- package/dist/translations/languages/fa.d.ts.map +1 -0
- package/dist/translations/languages/fa.js +329 -0
- package/dist/translations/languages/fa.js.map +1 -0
- package/dist/translations/languages/fr.d.ts +576 -0
- package/dist/translations/languages/fr.d.ts.map +1 -0
- package/dist/translations/languages/fr.js +329 -0
- package/dist/translations/languages/fr.js.map +1 -0
- package/dist/translations/languages/he.d.ts +576 -0
- package/dist/translations/languages/he.d.ts.map +1 -0
- package/dist/translations/languages/he.js +329 -0
- package/dist/translations/languages/he.js.map +1 -0
- package/dist/translations/languages/hr.d.ts +576 -0
- package/dist/translations/languages/hr.d.ts.map +1 -0
- package/dist/translations/languages/hr.js +329 -0
- package/dist/translations/languages/hr.js.map +1 -0
- package/dist/translations/languages/hu.d.ts +576 -0
- package/dist/translations/languages/hu.d.ts.map +1 -0
- package/dist/translations/languages/hu.js +329 -0
- package/dist/translations/languages/hu.js.map +1 -0
- package/dist/translations/languages/hy.d.ts +576 -0
- package/dist/translations/languages/hy.d.ts.map +1 -0
- package/dist/translations/languages/hy.js +329 -0
- package/dist/translations/languages/hy.js.map +1 -0
- package/dist/translations/languages/id.d.ts +576 -0
- package/dist/translations/languages/id.d.ts.map +1 -0
- package/dist/translations/languages/id.js +329 -0
- package/dist/translations/languages/id.js.map +1 -0
- package/dist/translations/languages/is.d.ts +576 -0
- package/dist/translations/languages/is.d.ts.map +1 -0
- package/dist/translations/languages/is.js +329 -0
- package/dist/translations/languages/is.js.map +1 -0
- package/dist/translations/languages/it.d.ts +576 -0
- package/dist/translations/languages/it.d.ts.map +1 -0
- package/dist/translations/languages/it.js +329 -0
- package/dist/translations/languages/it.js.map +1 -0
- package/dist/translations/languages/ja.d.ts +576 -0
- package/dist/translations/languages/ja.d.ts.map +1 -0
- package/dist/translations/languages/ja.js +329 -0
- package/dist/translations/languages/ja.js.map +1 -0
- package/dist/translations/languages/ko.d.ts +576 -0
- package/dist/translations/languages/ko.d.ts.map +1 -0
- package/dist/translations/languages/ko.js +329 -0
- package/dist/translations/languages/ko.js.map +1 -0
- package/dist/translations/languages/lt.d.ts +576 -0
- package/dist/translations/languages/lt.d.ts.map +1 -0
- package/dist/translations/languages/lt.js +329 -0
- package/dist/translations/languages/lt.js.map +1 -0
- package/dist/translations/languages/lv.d.ts +576 -0
- package/dist/translations/languages/lv.d.ts.map +1 -0
- package/dist/translations/languages/lv.js +329 -0
- package/dist/translations/languages/lv.js.map +1 -0
- package/dist/translations/languages/my.d.ts +576 -0
- package/dist/translations/languages/my.d.ts.map +1 -0
- package/dist/translations/languages/my.js +329 -0
- package/dist/translations/languages/my.js.map +1 -0
- package/dist/translations/languages/nb.d.ts +576 -0
- package/dist/translations/languages/nb.d.ts.map +1 -0
- package/dist/translations/languages/nb.js +329 -0
- package/dist/translations/languages/nb.js.map +1 -0
- package/dist/translations/languages/nl.d.ts +576 -0
- package/dist/translations/languages/nl.d.ts.map +1 -0
- package/dist/translations/languages/nl.js +329 -0
- package/dist/translations/languages/nl.js.map +1 -0
- package/dist/translations/languages/pl.d.ts +576 -0
- package/dist/translations/languages/pl.d.ts.map +1 -0
- package/dist/translations/languages/pl.js +329 -0
- package/dist/translations/languages/pl.js.map +1 -0
- package/dist/translations/languages/pt.d.ts +576 -0
- package/dist/translations/languages/pt.d.ts.map +1 -0
- package/dist/translations/languages/pt.js +329 -0
- package/dist/translations/languages/pt.js.map +1 -0
- package/dist/translations/languages/ro.d.ts +576 -0
- package/dist/translations/languages/ro.d.ts.map +1 -0
- package/dist/translations/languages/ro.js +329 -0
- package/dist/translations/languages/ro.js.map +1 -0
- package/dist/translations/languages/rs.d.ts +576 -0
- package/dist/translations/languages/rs.d.ts.map +1 -0
- package/dist/translations/languages/rs.js +329 -0
- package/dist/translations/languages/rs.js.map +1 -0
- package/dist/translations/languages/rsLatin.d.ts +576 -0
- package/dist/translations/languages/rsLatin.d.ts.map +1 -0
- package/dist/translations/languages/rsLatin.js +329 -0
- package/dist/translations/languages/rsLatin.js.map +1 -0
- package/dist/translations/languages/ru.d.ts +576 -0
- package/dist/translations/languages/ru.d.ts.map +1 -0
- package/dist/translations/languages/ru.js +329 -0
- package/dist/translations/languages/ru.js.map +1 -0
- package/dist/translations/languages/sk.d.ts +576 -0
- package/dist/translations/languages/sk.d.ts.map +1 -0
- package/dist/translations/languages/sk.js +329 -0
- package/dist/translations/languages/sk.js.map +1 -0
- package/dist/translations/languages/sl.d.ts +576 -0
- package/dist/translations/languages/sl.d.ts.map +1 -0
- package/dist/translations/languages/sl.js +329 -0
- package/dist/translations/languages/sl.js.map +1 -0
- package/dist/translations/languages/sv.d.ts +576 -0
- package/dist/translations/languages/sv.d.ts.map +1 -0
- package/dist/translations/languages/sv.js +329 -0
- package/dist/translations/languages/sv.js.map +1 -0
- package/dist/translations/languages/ta.d.ts +576 -0
- package/dist/translations/languages/ta.d.ts.map +1 -0
- package/dist/translations/languages/ta.js +329 -0
- package/dist/translations/languages/ta.js.map +1 -0
- package/dist/translations/languages/th.d.ts +576 -0
- package/dist/translations/languages/th.d.ts.map +1 -0
- package/dist/translations/languages/th.js +329 -0
- package/dist/translations/languages/th.js.map +1 -0
- package/dist/translations/languages/tr.d.ts +576 -0
- package/dist/translations/languages/tr.d.ts.map +1 -0
- package/dist/translations/languages/tr.js +329 -0
- package/dist/translations/languages/tr.js.map +1 -0
- package/dist/translations/languages/uk.d.ts +576 -0
- package/dist/translations/languages/uk.d.ts.map +1 -0
- package/dist/translations/languages/uk.js +329 -0
- package/dist/translations/languages/uk.js.map +1 -0
- package/dist/translations/languages/vi.d.ts +576 -0
- package/dist/translations/languages/vi.d.ts.map +1 -0
- package/dist/translations/languages/vi.js +329 -0
- package/dist/translations/languages/vi.js.map +1 -0
- package/dist/translations/languages/zh.d.ts +576 -0
- package/dist/translations/languages/zh.d.ts.map +1 -0
- package/dist/translations/languages/zh.js +329 -0
- package/dist/translations/languages/zh.js.map +1 -0
- package/dist/translations/languages/zhTw.d.ts +576 -0
- package/dist/translations/languages/zhTw.d.ts.map +1 -0
- package/dist/translations/languages/zhTw.js +329 -0
- package/dist/translations/languages/zhTw.js.map +1 -0
- package/dist/types.d.ts +269 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +257 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +32 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +82 -0
- package/dist/utils.js.map +1 -0
- package/dist/validations/dates.d.ts +230 -0
- package/dist/validations/dates.d.ts.map +1 -0
- package/dist/validations/dates.js +254 -0
- package/dist/validations/dates.js.map +1 -0
- package/dist/validations/numbers.d.ts +118 -0
- package/dist/validations/numbers.d.ts.map +1 -0
- package/dist/validations/numbers.js +151 -0
- package/dist/validations/numbers.js.map +1 -0
- package/dist/validations/relationLinkedUser.d.ts +43 -0
- package/dist/validations/relationLinkedUser.d.ts.map +1 -0
- package/dist/validations/relationLinkedUser.js +54 -0
- package/dist/validations/relationLinkedUser.js.map +1 -0
- package/package.json +228 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { date } from 'payload/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Factory function for creating date validators.
|
|
4
|
+
*
|
|
5
|
+
* This function generates a reusable date validator that can compare a date field
|
|
6
|
+
* against another field or the current date/time. The validator supports:
|
|
7
|
+
* - Field-to-field comparisons
|
|
8
|
+
* - Field-to-now comparisons
|
|
9
|
+
* - Programmatic override conditions
|
|
10
|
+
* - i18n-ready error messages
|
|
11
|
+
* - System user override support
|
|
12
|
+
*
|
|
13
|
+
* @param compareFn - Function that compares two timestamps (current, target) and returns boolean
|
|
14
|
+
* @param messageKey - Translation key for the error message (from loadsparkCoreTranslationsKeys)
|
|
15
|
+
* @param getTarget - Optional function that returns a numeric timestamp (e.g., () => Date.now())
|
|
16
|
+
*
|
|
17
|
+
* @returns A function that takes optional parameters and returns a Payload field validator
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // Field vs field comparison
|
|
22
|
+
* const after = makeDateValidator(
|
|
23
|
+
* (a, b) => a > b,
|
|
24
|
+
* 'loadspark-core:validation:date:mustBeAfterOtherDate'
|
|
25
|
+
* )
|
|
26
|
+
*
|
|
27
|
+
* // Field vs now comparison
|
|
28
|
+
* const future = makeDateValidator(
|
|
29
|
+
* (a, b) => a > b,
|
|
30
|
+
* 'loadspark-core:validation:date:mustBeInFuture',
|
|
31
|
+
* () => Date.now()
|
|
32
|
+
* )
|
|
33
|
+
* ```
|
|
34
|
+
*/ export const makeDateValidator = (compareFn, messageKey, getTarget)=>{
|
|
35
|
+
return (otherField, options)=>{
|
|
36
|
+
return (val, ctx)=>{
|
|
37
|
+
const t = ctx.req.t;
|
|
38
|
+
const locale = ctx.req.i18n.language;
|
|
39
|
+
let defaultLabel = ctx.label ?? ctx.name;
|
|
40
|
+
if (typeof ctx.label === 'string') {
|
|
41
|
+
defaultLabel = ctx.label;
|
|
42
|
+
} else if (typeof ctx.label === 'object') {
|
|
43
|
+
defaultLabel = ctx.label[locale] ?? defaultLabel;
|
|
44
|
+
}
|
|
45
|
+
if (date(val, ctx) !== true) {
|
|
46
|
+
return date(val, ctx);
|
|
47
|
+
}
|
|
48
|
+
if (options?.override || ctx.overrideAccess) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
let targetTime = null;
|
|
52
|
+
if (otherField) {
|
|
53
|
+
const data = ctx.data;
|
|
54
|
+
const rawOther = data[otherField.field];
|
|
55
|
+
if (rawOther == null) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const other = rawOther instanceof Date ? rawOther : typeof rawOther === 'string' || typeof rawOther === 'number' ? new Date(rawOther) : null;
|
|
59
|
+
if (!other || date(other, ctx) !== true) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
targetTime = other.getTime();
|
|
63
|
+
} else if (getTarget) {
|
|
64
|
+
targetTime = getTarget(ctx);
|
|
65
|
+
}
|
|
66
|
+
if (targetTime === null) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
const currentTime = new Date(val).getTime();
|
|
70
|
+
if (compareFn(currentTime, targetTime)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const otherLabel = otherField ? otherField.labels[locale] ?? otherField.field : undefined;
|
|
74
|
+
return t(messageKey, {
|
|
75
|
+
field: defaultLabel,
|
|
76
|
+
otherField: otherLabel
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Field vs Field validators
|
|
83
|
+
*/ /**
|
|
84
|
+
* Validates that a date field is strictly after another date field.
|
|
85
|
+
*
|
|
86
|
+
* @param otherField - Configuration for the field to compare against
|
|
87
|
+
* @param otherField.field - The name of the other field to compare
|
|
88
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
89
|
+
* @param options - Optional validator options
|
|
90
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
91
|
+
*
|
|
92
|
+
* @returns A validation function that can be used in field validate arrays
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* {
|
|
97
|
+
* name: 'endDate',
|
|
98
|
+
* type: 'date',
|
|
99
|
+
* validate: [
|
|
100
|
+
* after({
|
|
101
|
+
* field: 'startDate',
|
|
102
|
+
* labels: { en: 'Start Date', de: 'Startdatum' }
|
|
103
|
+
* })
|
|
104
|
+
* ]
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/ export const after = makeDateValidator((a, b)=>a > b, 'loadspark-core:validation:date:mustBeAfterOtherDate');
|
|
108
|
+
/**
|
|
109
|
+
* Validates that a date field is after or equal to another date field.
|
|
110
|
+
*
|
|
111
|
+
* @param otherField - Configuration for the field to compare against
|
|
112
|
+
* @param otherField.field - The name of the other field to compare
|
|
113
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
114
|
+
* @param options - Optional validator options
|
|
115
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
116
|
+
*
|
|
117
|
+
* @returns A validation function that can be used in field validate arrays
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* {
|
|
122
|
+
* name: 'endDate',
|
|
123
|
+
* type: 'date',
|
|
124
|
+
* validate: [
|
|
125
|
+
* afterOrEqual({
|
|
126
|
+
* field: 'startDate',
|
|
127
|
+
* labels: { en: 'Start Date', de: 'Startdatum' }
|
|
128
|
+
* })
|
|
129
|
+
* ]
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/ export const afterOrEqual = makeDateValidator((a, b)=>a >= b, 'loadspark-core:validation:date:mustBeEqualOrAfterOtherDate');
|
|
133
|
+
/**
|
|
134
|
+
* Validates that a date field is strictly before another date field.
|
|
135
|
+
*
|
|
136
|
+
* @param otherField - Configuration for the field to compare against
|
|
137
|
+
* @param otherField.field - The name of the other field to compare
|
|
138
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
139
|
+
* @param options - Optional validator options
|
|
140
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
141
|
+
*
|
|
142
|
+
* @returns A validation function that can be used in field validate arrays
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* {
|
|
147
|
+
* name: 'startDate',
|
|
148
|
+
* type: 'date',
|
|
149
|
+
* validate: [
|
|
150
|
+
* before({
|
|
151
|
+
* field: 'endDate',
|
|
152
|
+
* labels: { en: 'End Date', de: 'Enddatum' }
|
|
153
|
+
* })
|
|
154
|
+
* ]
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/ export const before = makeDateValidator((a, b)=>a < b, 'loadspark-core:validation:date:mustBeBeforeOtherDate');
|
|
158
|
+
/**
|
|
159
|
+
* Validates that a date field is before or equal to another date field.
|
|
160
|
+
*
|
|
161
|
+
* @param otherField - Configuration for the field to compare against
|
|
162
|
+
* @param otherField.field - The name of the other field to compare
|
|
163
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
164
|
+
* @param options - Optional validator options
|
|
165
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
166
|
+
*
|
|
167
|
+
* @returns A validation function that can be used in field validate arrays
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* {
|
|
172
|
+
* name: 'startDate',
|
|
173
|
+
* type: 'date',
|
|
174
|
+
* validate: [
|
|
175
|
+
* beforeOrEqual({
|
|
176
|
+
* field: 'endDate',
|
|
177
|
+
* labels: { en: 'End Date', de: 'Enddatum' }
|
|
178
|
+
* })
|
|
179
|
+
* ]
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/ export const beforeOrEqual = makeDateValidator((a, b)=>a <= b, 'loadspark-core:validation:date:mustBeEqualOrBeforeOtherDate');
|
|
183
|
+
/**
|
|
184
|
+
* Field vs Now validators
|
|
185
|
+
*/ /**
|
|
186
|
+
* Validates that a date field is strictly in the past (before now).
|
|
187
|
+
*
|
|
188
|
+
* @param otherField - Not used for this validator (pass undefined)
|
|
189
|
+
* @param options - Optional validator options
|
|
190
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
191
|
+
*
|
|
192
|
+
* @returns A validation function that can be used in field validate arrays
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* {
|
|
197
|
+
* name: 'birthDate',
|
|
198
|
+
* type: 'date',
|
|
199
|
+
* validate: [past()]
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* // With programmatic override
|
|
206
|
+
* {
|
|
207
|
+
* name: 'eventDate',
|
|
208
|
+
* type: 'date',
|
|
209
|
+
* validate: (val, ctx) => {
|
|
210
|
+
* return past(undefined, {
|
|
211
|
+
* override: ctx.req?.user?.role === 'admin'
|
|
212
|
+
* })(val, ctx)
|
|
213
|
+
* }
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
*/ export const past = makeDateValidator((a, b)=>a < b, 'loadspark-core:validation:date:mustBeInPast', ()=>Date.now());
|
|
217
|
+
/**
|
|
218
|
+
* Validates that a date field is in the past or equal to now.
|
|
219
|
+
*
|
|
220
|
+
* @param otherField - Not used for this validator (pass undefined)
|
|
221
|
+
* @param options - Optional validator options
|
|
222
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
223
|
+
*
|
|
224
|
+
* @returns A validation function that can be used in field validate arrays
|
|
225
|
+
*/ export const pastOrEqual = makeDateValidator((a, b)=>a <= b, 'loadspark-core:validation:date:mustBeInPast', ()=>Date.now());
|
|
226
|
+
/**
|
|
227
|
+
* Validates that a date field is strictly in the future (after now).
|
|
228
|
+
*
|
|
229
|
+
* @param otherField - Not used for this validator (pass undefined)
|
|
230
|
+
* @param options - Optional validator options
|
|
231
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
232
|
+
*
|
|
233
|
+
* @returns A validation function that can be used in field validate arrays
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* {
|
|
238
|
+
* name: 'publishDate',
|
|
239
|
+
* type: 'date',
|
|
240
|
+
* validate: [future()]
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/ export const future = makeDateValidator((a, b)=>a > b, 'loadspark-core:validation:date:mustBeInFuture', ()=>Date.now());
|
|
244
|
+
/**
|
|
245
|
+
* Validates that a date field is in the future or equal to now.
|
|
246
|
+
*
|
|
247
|
+
* @param otherField - Not used for this validator (pass undefined)
|
|
248
|
+
* @param options - Optional validator options
|
|
249
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
250
|
+
*
|
|
251
|
+
* @returns A validation function that can be used in field validate arrays
|
|
252
|
+
*/ export const futureOrEqual = makeDateValidator((a, b)=>a >= b, 'loadspark-core:validation:date:mustBeInFuture', ()=>Date.now());
|
|
253
|
+
|
|
254
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/validations/dates.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\nimport type { DateField, ValidateOptions } from 'payload'\n\nimport { date } from 'payload/shared'\n\nimport type { loadsparkCoreTranslationsKeys } from '../translations/index.js'\n\ntype CompareFn = (current: number, target: number) => boolean\n\ninterface OtherField {\n field: string\n labels: Record<string, string>\n}\n\ninterface ValidatorOptions {\n /** Skip the comparison, only check if val is a valid date */\n override?: boolean\n}\n\n/**\n * Factory function for creating date validators.\n *\n * This function generates a reusable date validator that can compare a date field\n * against another field or the current date/time. The validator supports:\n * - Field-to-field comparisons\n * - Field-to-now comparisons\n * - Programmatic override conditions\n * - i18n-ready error messages\n * - System user override support\n *\n * @param compareFn - Function that compares two timestamps (current, target) and returns boolean\n * @param messageKey - Translation key for the error message (from loadsparkCoreTranslationsKeys)\n * @param getTarget - Optional function that returns a numeric timestamp (e.g., () => Date.now())\n *\n * @returns A function that takes optional parameters and returns a Payload field validator\n *\n * @example\n * ```ts\n * // Field vs field comparison\n * const after = makeDateValidator(\n * (a, b) => a > b,\n * 'loadspark-core:validation:date:mustBeAfterOtherDate'\n * )\n *\n * // Field vs now comparison\n * const future = makeDateValidator(\n * (a, b) => a > b,\n * 'loadspark-core:validation:date:mustBeInFuture',\n * () => Date.now()\n * )\n * ```\n */\nexport const makeDateValidator = (\n compareFn: CompareFn,\n messageKey: DateValidationKeys,\n getTarget?: (\n ctx: ValidateOptions<unknown, unknown, DateField, Date>,\n otherField?: OtherField,\n ) => null | number,\n) => {\n return (otherField?: OtherField, options?: ValidatorOptions) => {\n return (\n val: Date | null | undefined,\n ctx: ValidateOptions<unknown, unknown, DateField, Date>,\n ) => {\n const t = ctx.req.t as TFunction<loadsparkCoreTranslationsKeys>\n const locale = ctx.req.i18n.language\n let defaultLabel = ctx.label ?? ctx.name\n\n if (typeof ctx.label === 'string') {\n defaultLabel = ctx.label\n } else if (typeof ctx.label === 'object') {\n defaultLabel = ctx.label[locale] ?? defaultLabel\n }\n\n if (date(val, ctx) !== true) {\n return date(val, ctx)\n }\n\n if (options?.override || ctx.overrideAccess) {\n return true\n }\n\n let targetTime: null | number = null\n if (otherField) {\n const data = ctx.data as Record<string, unknown>\n const rawOther = data[otherField.field]\n if (rawOther == null) {\n return true\n }\n\n const other: Date | null =\n rawOther instanceof Date\n ? rawOther\n : typeof rawOther === 'string' || typeof rawOther === 'number'\n ? new Date(rawOther)\n : null\n\n if (!other || date(other, ctx) !== true) {\n return true\n }\n targetTime = other.getTime()\n } else if (getTarget) {\n targetTime = getTarget(ctx)\n }\n\n if (targetTime === null) {\n return true\n }\n\n const currentTime = new Date(val!).getTime()\n\n if (compareFn(currentTime, targetTime)) {\n return true\n }\n\n const otherLabel = otherField ? (otherField.labels[locale] ?? otherField.field) : undefined\n\n return t(messageKey, { field: defaultLabel, otherField: otherLabel })\n }\n }\n}\n\n/** All allowed date validation translation keys */\ntype DateValidationKeys =\n | 'loadspark-core:validation:date:mustBeAfterOtherDate'\n | 'loadspark-core:validation:date:mustBeBeforeOtherDate'\n | 'loadspark-core:validation:date:mustBeEqualOrAfterOtherDate'\n | 'loadspark-core:validation:date:mustBeEqualOrBeforeOtherDate'\n | 'loadspark-core:validation:date:mustBeInFuture'\n | 'loadspark-core:validation:date:mustBeInPast'\n\n/**\n * Field vs Field validators\n */\n\n/**\n * Validates that a date field is strictly after another date field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n *\n * @example\n * ```ts\n * {\n * name: 'endDate',\n * type: 'date',\n * validate: [\n * after({\n * field: 'startDate',\n * labels: { en: 'Start Date', de: 'Startdatum' }\n * })\n * ]\n * }\n * ```\n */\nexport const after = makeDateValidator(\n (a, b) => a > b,\n 'loadspark-core:validation:date:mustBeAfterOtherDate',\n)\n\n/**\n * Validates that a date field is after or equal to another date field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n *\n * @example\n * ```ts\n * {\n * name: 'endDate',\n * type: 'date',\n * validate: [\n * afterOrEqual({\n * field: 'startDate',\n * labels: { en: 'Start Date', de: 'Startdatum' }\n * })\n * ]\n * }\n * ```\n */\nexport const afterOrEqual = makeDateValidator(\n (a, b) => a >= b,\n 'loadspark-core:validation:date:mustBeEqualOrAfterOtherDate',\n)\n\n/**\n * Validates that a date field is strictly before another date field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n *\n * @example\n * ```ts\n * {\n * name: 'startDate',\n * type: 'date',\n * validate: [\n * before({\n * field: 'endDate',\n * labels: { en: 'End Date', de: 'Enddatum' }\n * })\n * ]\n * }\n * ```\n */\nexport const before = makeDateValidator(\n (a, b) => a < b,\n 'loadspark-core:validation:date:mustBeBeforeOtherDate',\n)\n\n/**\n * Validates that a date field is before or equal to another date field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n *\n * @example\n * ```ts\n * {\n * name: 'startDate',\n * type: 'date',\n * validate: [\n * beforeOrEqual({\n * field: 'endDate',\n * labels: { en: 'End Date', de: 'Enddatum' }\n * })\n * ]\n * }\n * ```\n */\nexport const beforeOrEqual = makeDateValidator(\n (a, b) => a <= b,\n 'loadspark-core:validation:date:mustBeEqualOrBeforeOtherDate',\n)\n\n/**\n * Field vs Now validators\n */\n\n/**\n * Validates that a date field is strictly in the past (before now).\n *\n * @param otherField - Not used for this validator (pass undefined)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n *\n * @example\n * ```ts\n * {\n * name: 'birthDate',\n * type: 'date',\n * validate: [past()]\n * }\n * ```\n *\n * @example\n * ```ts\n * // With programmatic override\n * {\n * name: 'eventDate',\n * type: 'date',\n * validate: (val, ctx) => {\n * return past(undefined, {\n * override: ctx.req?.user?.role === 'admin'\n * })(val, ctx)\n * }\n * }\n * ```\n */\nexport const past = makeDateValidator(\n (a, b) => a < b,\n 'loadspark-core:validation:date:mustBeInPast',\n () => Date.now(),\n)\n\n/**\n * Validates that a date field is in the past or equal to now.\n *\n * @param otherField - Not used for this validator (pass undefined)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n */\nexport const pastOrEqual = makeDateValidator(\n (a, b) => a <= b,\n 'loadspark-core:validation:date:mustBeInPast',\n () => Date.now(),\n)\n\n/**\n * Validates that a date field is strictly in the future (after now).\n *\n * @param otherField - Not used for this validator (pass undefined)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n *\n * @example\n * ```ts\n * {\n * name: 'publishDate',\n * type: 'date',\n * validate: [future()]\n * }\n * ```\n */\nexport const future = makeDateValidator(\n (a, b) => a > b,\n 'loadspark-core:validation:date:mustBeInFuture',\n () => Date.now(),\n)\n\n/**\n * Validates that a date field is in the future or equal to now.\n *\n * @param otherField - Not used for this validator (pass undefined)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n */\nexport const futureOrEqual = makeDateValidator(\n (a, b) => a >= b,\n 'loadspark-core:validation:date:mustBeInFuture',\n () => Date.now(),\n)\n"],"names":["date","makeDateValidator","compareFn","messageKey","getTarget","otherField","options","val","ctx","t","req","locale","i18n","language","defaultLabel","label","name","override","overrideAccess","targetTime","data","rawOther","field","other","Date","getTime","currentTime","otherLabel","labels","undefined","after","a","b","afterOrEqual","before","beforeOrEqual","past","now","pastOrEqual","future","futureOrEqual"],"mappings":"AAGA,SAASA,IAAI,QAAQ,iBAAgB;AAgBrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCC,GACD,OAAO,MAAMC,oBAAoB,CAC/BC,WACAC,YACAC;IAKA,OAAO,CAACC,YAAyBC;QAC/B,OAAO,CACLC,KACAC;YAEA,MAAMC,IAAID,IAAIE,GAAG,CAACD,CAAC;YACnB,MAAME,SAASH,IAAIE,GAAG,CAACE,IAAI,CAACC,QAAQ;YACpC,IAAIC,eAAeN,IAAIO,KAAK,IAAIP,IAAIQ,IAAI;YAExC,IAAI,OAAOR,IAAIO,KAAK,KAAK,UAAU;gBACjCD,eAAeN,IAAIO,KAAK;YAC1B,OAAO,IAAI,OAAOP,IAAIO,KAAK,KAAK,UAAU;gBACxCD,eAAeN,IAAIO,KAAK,CAACJ,OAAO,IAAIG;YACtC;YAEA,IAAId,KAAKO,KAAKC,SAAS,MAAM;gBAC3B,OAAOR,KAAKO,KAAKC;YACnB;YAEA,IAAIF,SAASW,YAAYT,IAAIU,cAAc,EAAE;gBAC3C,OAAO;YACT;YAEA,IAAIC,aAA4B;YAChC,IAAId,YAAY;gBACd,MAAMe,OAAOZ,IAAIY,IAAI;gBACrB,MAAMC,WAAWD,IAAI,CAACf,WAAWiB,KAAK,CAAC;gBACvC,IAAID,YAAY,MAAM;oBACpB,OAAO;gBACT;gBAEA,MAAME,QACJF,oBAAoBG,OAChBH,WACA,OAAOA,aAAa,YAAY,OAAOA,aAAa,WAClD,IAAIG,KAAKH,YACT;gBAER,IAAI,CAACE,SAASvB,KAAKuB,OAAOf,SAAS,MAAM;oBACvC,OAAO;gBACT;gBACAW,aAAaI,MAAME,OAAO;YAC5B,OAAO,IAAIrB,WAAW;gBACpBe,aAAaf,UAAUI;YACzB;YAEA,IAAIW,eAAe,MAAM;gBACvB,OAAO;YACT;YAEA,MAAMO,cAAc,IAAIF,KAAKjB,KAAMkB,OAAO;YAE1C,IAAIvB,UAAUwB,aAAaP,aAAa;gBACtC,OAAO;YACT;YAEA,MAAMQ,aAAatB,aAAcA,WAAWuB,MAAM,CAACjB,OAAO,IAAIN,WAAWiB,KAAK,GAAIO;YAElF,OAAOpB,EAAEN,YAAY;gBAAEmB,OAAOR;gBAAcT,YAAYsB;YAAW;QACrE;IACF;AACF,EAAC;AAWD;;CAEC,GAED;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,MAAMG,QAAQ7B,kBACnB,CAAC8B,GAAGC,IAAMD,IAAIC,GACd,uDACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,MAAMC,eAAehC,kBAC1B,CAAC8B,GAAGC,IAAMD,KAAKC,GACf,8DACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,MAAME,SAASjC,kBACpB,CAAC8B,GAAGC,IAAMD,IAAIC,GACd,wDACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,MAAMG,gBAAgBlC,kBAC3B,CAAC8B,GAAGC,IAAMD,KAAKC,GACf,+DACD;AAED;;CAEC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,MAAMI,OAAOnC,kBAClB,CAAC8B,GAAGC,IAAMD,IAAIC,GACd,+CACA,IAAMR,KAAKa,GAAG,IACf;AAED;;;;;;;;CAQC,GACD,OAAO,MAAMC,cAAcrC,kBACzB,CAAC8B,GAAGC,IAAMD,KAAKC,GACf,+CACA,IAAMR,KAAKa,GAAG,IACf;AAED;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,MAAME,SAAStC,kBACpB,CAAC8B,GAAGC,IAAMD,IAAIC,GACd,iDACA,IAAMR,KAAKa,GAAG,IACf;AAED;;;;;;;;CAQC,GACD,OAAO,MAAMG,gBAAgBvC,kBAC3B,CAAC8B,GAAGC,IAAMD,KAAKC,GACf,iDACA,IAAMR,KAAKa,GAAG,IACf"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { NumberField, ValidateOptions } from 'payload';
|
|
2
|
+
/** Function to compare two numbers */
|
|
3
|
+
type CompareFn = (current: number, target: number) => boolean;
|
|
4
|
+
/** Object representing another field to compare against */
|
|
5
|
+
interface OtherField {
|
|
6
|
+
field: string;
|
|
7
|
+
labels: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
/** Optional validator settings */
|
|
10
|
+
interface ValidatorOptions {
|
|
11
|
+
/** Skip comparison, only validate the value exists and is a number */
|
|
12
|
+
override?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** All allowed number validation translation keys */
|
|
15
|
+
type NumberValidationKeys = 'loadspark-core:validation:number:invalid' | 'loadspark-core:validation:number:mustBeEqualOrGreaterThanOtherNumber' | 'loadspark-core:validation:number:mustBeEqualOrLessThanOtherNumber' | 'loadspark-core:validation:number:mustBeGreaterThanOtherNumber' | 'loadspark-core:validation:number:mustBeLessThanOtherNumber';
|
|
16
|
+
/**
|
|
17
|
+
* Factory function for creating number validators.
|
|
18
|
+
*
|
|
19
|
+
* This function generates a reusable number validator that can compare a number field
|
|
20
|
+
* against another field or a constant value. The validator supports:
|
|
21
|
+
* - Field-to-field comparisons
|
|
22
|
+
* - Field-to-constant comparisons
|
|
23
|
+
* - Programmatic override conditions
|
|
24
|
+
* - i18n-ready error messages
|
|
25
|
+
* - System user override support
|
|
26
|
+
*
|
|
27
|
+
* @param compareFn - Function that compares two numbers (current, target) and returns boolean
|
|
28
|
+
* @param messageKey - Translation key for the error message (from loadsparkCoreTranslationsKeys)
|
|
29
|
+
* @param getTarget - Optional function that returns a target number from the data context
|
|
30
|
+
*
|
|
31
|
+
* @returns A function that takes optional parameters and returns a Payload field validator
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* // Field vs field comparison
|
|
36
|
+
* const greaterThan = makeNumberValidator(
|
|
37
|
+
* (a, b) => a > b,
|
|
38
|
+
* 'loadspark-core:validation:number:mustBeGreaterThanOtherNumber'
|
|
39
|
+
* )
|
|
40
|
+
*
|
|
41
|
+
* // Field vs constant comparison
|
|
42
|
+
* const maxValue = makeNumberValidator(
|
|
43
|
+
* (a, b) => a <= b,
|
|
44
|
+
* 'loadspark-core:validation:number:mustBeLessThanOtherNumber',
|
|
45
|
+
* () => 100 // constant max value
|
|
46
|
+
* )
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const makeNumberValidator: (compareFn: CompareFn, messageKey: NumberValidationKeys, getTarget?: (data: Record<string, unknown>, otherField?: OtherField) => null | number) => (otherField?: OtherField, options?: ValidatorOptions) => (val: null | number | undefined, ctx: ValidateOptions<unknown, unknown, NumberField, number>) => string | true | Promise<string | true>;
|
|
50
|
+
/** Field vs Field validators */
|
|
51
|
+
/**
|
|
52
|
+
* Validates that a number field is strictly greater than another number field.
|
|
53
|
+
*
|
|
54
|
+
* @param otherField - Configuration for the field to compare against
|
|
55
|
+
* @param otherField.field - The name of the other field to compare
|
|
56
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
57
|
+
* @param options - Optional validator options
|
|
58
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
59
|
+
*
|
|
60
|
+
* @returns A validation function that can be used in field validate arrays
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* {
|
|
65
|
+
* name: 'maxValue',
|
|
66
|
+
* type: 'number',
|
|
67
|
+
* label: { de: 'Höchstwert', en: 'Maximum Value' },
|
|
68
|
+
* validate: (val, ctx) => {
|
|
69
|
+
* return greaterThan(
|
|
70
|
+
* {
|
|
71
|
+
* field: 'minValue',
|
|
72
|
+
* labels: { de: 'Mindestwert', en: 'Minimum Value' },
|
|
73
|
+
* },
|
|
74
|
+
* { override: ctx.req?.user?.role === 'admin' },
|
|
75
|
+
* )(val, ctx)
|
|
76
|
+
* },
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare const greaterThan: (otherField?: OtherField, options?: ValidatorOptions) => (val: null | number | undefined, ctx: ValidateOptions<unknown, unknown, NumberField, number>) => string | true | Promise<string | true>;
|
|
81
|
+
/**
|
|
82
|
+
* Validates that a number field is greater than or equal to another number field.
|
|
83
|
+
*
|
|
84
|
+
* @param otherField - Configuration for the field to compare against
|
|
85
|
+
* @param otherField.field - The name of the other field to compare
|
|
86
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
87
|
+
* @param options - Optional validator options
|
|
88
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
89
|
+
*
|
|
90
|
+
* @returns A validation function that can be used in field validate arrays
|
|
91
|
+
*/
|
|
92
|
+
export declare const greaterThanOrEqual: (otherField?: OtherField, options?: ValidatorOptions) => (val: null | number | undefined, ctx: ValidateOptions<unknown, unknown, NumberField, number>) => string | true | Promise<string | true>;
|
|
93
|
+
/**
|
|
94
|
+
* Validates that a number field is strictly less than another number field.
|
|
95
|
+
*
|
|
96
|
+
* @param otherField - Configuration for the field to compare against
|
|
97
|
+
* @param otherField.field - The name of the other field to compare
|
|
98
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
99
|
+
* @param options - Optional validator options
|
|
100
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
101
|
+
*
|
|
102
|
+
* @returns A validation function that can be used in field validate arrays
|
|
103
|
+
*/
|
|
104
|
+
export declare const lessThan: (otherField?: OtherField, options?: ValidatorOptions) => (val: null | number | undefined, ctx: ValidateOptions<unknown, unknown, NumberField, number>) => string | true | Promise<string | true>;
|
|
105
|
+
/**
|
|
106
|
+
* Validates that a number field is less than or equal to another number field.
|
|
107
|
+
*
|
|
108
|
+
* @param otherField - Configuration for the field to compare against
|
|
109
|
+
* @param otherField.field - The name of the other field to compare
|
|
110
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
111
|
+
* @param options - Optional validator options
|
|
112
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
113
|
+
*
|
|
114
|
+
* @returns A validation function that can be used in field validate arrays
|
|
115
|
+
*/
|
|
116
|
+
export declare const lessThanOrEqual: (otherField?: OtherField, options?: ValidatorOptions) => (val: null | number | undefined, ctx: ValidateOptions<unknown, unknown, NumberField, number>) => string | true | Promise<string | true>;
|
|
117
|
+
export {};
|
|
118
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/validations/numbers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAM3D,sCAAsC;AACtC,KAAK,SAAS,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAA;AAE7D,2DAA2D;AAC3D,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B;AAED,kCAAkC;AAClC,UAAU,gBAAgB;IACxB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,qDAAqD;AACrD,KAAK,oBAAoB,GACrB,0CAA0C,GAC1C,sEAAsE,GACtE,mEAAmE,GACnE,+DAA+D,GAC/D,4DAA4D,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,mBAAmB,cACnB,SAAS,cACR,oBAAoB,cACpB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,EAAE,UAAU,KAAK,IAAI,GAAG,MAAM,mBAEhE,UAAU,YAAY,gBAAgB,WAElD,IAAI,GAAG,MAAM,GAAG,SAAS,OACzB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,2CA+DhE,CAAA;AAED,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,WAAW,gBAnGD,UAAU,YAAY,gBAAgB,WAElD,IAAI,GAAG,MAAM,GAAG,SAAS,OACzB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,2CAmGhE,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,gBAnHR,UAAU,YAAY,gBAAgB,WAElD,IAAI,GAAG,MAAM,GAAG,SAAS,OACzB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,2CAmHhE,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,gBAnIE,UAAU,YAAY,gBAAgB,WAElD,IAAI,GAAG,MAAM,GAAG,SAAS,OACzB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,2CAmIhE,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,gBAnJL,UAAU,YAAY,gBAAgB,WAElD,IAAI,GAAG,MAAM,GAAG,SAAS,OACzB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,2CAmJhE,CAAA"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { number } from 'payload/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Factory function for creating number validators.
|
|
4
|
+
*
|
|
5
|
+
* This function generates a reusable number validator that can compare a number field
|
|
6
|
+
* against another field or a constant value. The validator supports:
|
|
7
|
+
* - Field-to-field comparisons
|
|
8
|
+
* - Field-to-constant comparisons
|
|
9
|
+
* - Programmatic override conditions
|
|
10
|
+
* - i18n-ready error messages
|
|
11
|
+
* - System user override support
|
|
12
|
+
*
|
|
13
|
+
* @param compareFn - Function that compares two numbers (current, target) and returns boolean
|
|
14
|
+
* @param messageKey - Translation key for the error message (from loadsparkCoreTranslationsKeys)
|
|
15
|
+
* @param getTarget - Optional function that returns a target number from the data context
|
|
16
|
+
*
|
|
17
|
+
* @returns A function that takes optional parameters and returns a Payload field validator
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // Field vs field comparison
|
|
22
|
+
* const greaterThan = makeNumberValidator(
|
|
23
|
+
* (a, b) => a > b,
|
|
24
|
+
* 'loadspark-core:validation:number:mustBeGreaterThanOtherNumber'
|
|
25
|
+
* )
|
|
26
|
+
*
|
|
27
|
+
* // Field vs constant comparison
|
|
28
|
+
* const maxValue = makeNumberValidator(
|
|
29
|
+
* (a, b) => a <= b,
|
|
30
|
+
* 'loadspark-core:validation:number:mustBeLessThanOtherNumber',
|
|
31
|
+
* () => 100 // constant max value
|
|
32
|
+
* )
|
|
33
|
+
* ```
|
|
34
|
+
*/ export const makeNumberValidator = (compareFn, messageKey, getTarget)=>{
|
|
35
|
+
return (otherField, options)=>{
|
|
36
|
+
return (val, ctx)=>{
|
|
37
|
+
const t = ctx.req.t;
|
|
38
|
+
const locale = ctx.req.i18n.language;
|
|
39
|
+
let defaultLabel = ctx.label ?? ctx.name;
|
|
40
|
+
if (typeof ctx.label === 'string') {
|
|
41
|
+
defaultLabel = ctx.label;
|
|
42
|
+
} else if (typeof ctx.label === 'object') {
|
|
43
|
+
defaultLabel = ctx.label[locale] ?? defaultLabel;
|
|
44
|
+
}
|
|
45
|
+
if (number(val, ctx) !== true) {
|
|
46
|
+
return number(val, ctx);
|
|
47
|
+
}
|
|
48
|
+
if (options?.override || ctx.overrideAccess) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
let target = null;
|
|
52
|
+
if (otherField) {
|
|
53
|
+
const data = ctx.data;
|
|
54
|
+
const rawOther = data[otherField.field];
|
|
55
|
+
if (rawOther == null) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const other = typeof rawOther === 'number' ? rawOther : null;
|
|
59
|
+
if (other == null) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
target = other;
|
|
63
|
+
} else if (getTarget) {
|
|
64
|
+
target = getTarget(ctx.data);
|
|
65
|
+
}
|
|
66
|
+
if (target == null) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (val == null) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
const currentVal = val;
|
|
73
|
+
if (target == null) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
const otherVal = target;
|
|
77
|
+
if (!compareFn(currentVal, otherVal)) {
|
|
78
|
+
const otherLabel = otherField ? otherField.labels[locale] ?? otherField.field : undefined;
|
|
79
|
+
return t(messageKey, {
|
|
80
|
+
field: defaultLabel,
|
|
81
|
+
otherField: otherLabel
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/** Field vs Field validators */ /**
|
|
89
|
+
* Validates that a number field is strictly greater than another number field.
|
|
90
|
+
*
|
|
91
|
+
* @param otherField - Configuration for the field to compare against
|
|
92
|
+
* @param otherField.field - The name of the other field to compare
|
|
93
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
94
|
+
* @param options - Optional validator options
|
|
95
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
96
|
+
*
|
|
97
|
+
* @returns A validation function that can be used in field validate arrays
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* {
|
|
102
|
+
* name: 'maxValue',
|
|
103
|
+
* type: 'number',
|
|
104
|
+
* label: { de: 'Höchstwert', en: 'Maximum Value' },
|
|
105
|
+
* validate: (val, ctx) => {
|
|
106
|
+
* return greaterThan(
|
|
107
|
+
* {
|
|
108
|
+
* field: 'minValue',
|
|
109
|
+
* labels: { de: 'Mindestwert', en: 'Minimum Value' },
|
|
110
|
+
* },
|
|
111
|
+
* { override: ctx.req?.user?.role === 'admin' },
|
|
112
|
+
* )(val, ctx)
|
|
113
|
+
* },
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/ export const greaterThan = makeNumberValidator((a, b)=>a > b, 'loadspark-core:validation:number:mustBeGreaterThanOtherNumber');
|
|
117
|
+
/**
|
|
118
|
+
* Validates that a number field is greater than or equal to another number field.
|
|
119
|
+
*
|
|
120
|
+
* @param otherField - Configuration for the field to compare against
|
|
121
|
+
* @param otherField.field - The name of the other field to compare
|
|
122
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
123
|
+
* @param options - Optional validator options
|
|
124
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
125
|
+
*
|
|
126
|
+
* @returns A validation function that can be used in field validate arrays
|
|
127
|
+
*/ export const greaterThanOrEqual = makeNumberValidator((a, b)=>a >= b, 'loadspark-core:validation:number:mustBeEqualOrGreaterThanOtherNumber');
|
|
128
|
+
/**
|
|
129
|
+
* Validates that a number field is strictly less than another number field.
|
|
130
|
+
*
|
|
131
|
+
* @param otherField - Configuration for the field to compare against
|
|
132
|
+
* @param otherField.field - The name of the other field to compare
|
|
133
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
134
|
+
* @param options - Optional validator options
|
|
135
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
136
|
+
*
|
|
137
|
+
* @returns A validation function that can be used in field validate arrays
|
|
138
|
+
*/ export const lessThan = makeNumberValidator((a, b)=>a < b, 'loadspark-core:validation:number:mustBeLessThanOtherNumber');
|
|
139
|
+
/**
|
|
140
|
+
* Validates that a number field is less than or equal to another number field.
|
|
141
|
+
*
|
|
142
|
+
* @param otherField - Configuration for the field to compare against
|
|
143
|
+
* @param otherField.field - The name of the other field to compare
|
|
144
|
+
* @param otherField.labels - Labels for the other field (used in error messages)
|
|
145
|
+
* @param options - Optional validator options
|
|
146
|
+
* @param options.override - If true, skips the validation (useful for programmatic conditions)
|
|
147
|
+
*
|
|
148
|
+
* @returns A validation function that can be used in field validate arrays
|
|
149
|
+
*/ export const lessThanOrEqual = makeNumberValidator((a, b)=>a <= b, 'loadspark-core:validation:number:mustBeEqualOrLessThanOtherNumber');
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/validations/numbers.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\nimport type { NumberField, ValidateOptions } from 'payload'\n\nimport { number } from 'payload/shared'\n\nimport type { loadsparkCoreTranslationsKeys } from '../translations/index.js'\n\n/** Function to compare two numbers */\ntype CompareFn = (current: number, target: number) => boolean\n\n/** Object representing another field to compare against */\ninterface OtherField {\n field: string\n labels: Record<string, string>\n}\n\n/** Optional validator settings */\ninterface ValidatorOptions {\n /** Skip comparison, only validate the value exists and is a number */\n override?: boolean\n}\n\n/** All allowed number validation translation keys */\ntype NumberValidationKeys =\n | 'loadspark-core:validation:number:invalid'\n | 'loadspark-core:validation:number:mustBeEqualOrGreaterThanOtherNumber'\n | 'loadspark-core:validation:number:mustBeEqualOrLessThanOtherNumber'\n | 'loadspark-core:validation:number:mustBeGreaterThanOtherNumber'\n | 'loadspark-core:validation:number:mustBeLessThanOtherNumber'\n\n/**\n * Factory function for creating number validators.\n *\n * This function generates a reusable number validator that can compare a number field\n * against another field or a constant value. The validator supports:\n * - Field-to-field comparisons\n * - Field-to-constant comparisons\n * - Programmatic override conditions\n * - i18n-ready error messages\n * - System user override support\n *\n * @param compareFn - Function that compares two numbers (current, target) and returns boolean\n * @param messageKey - Translation key for the error message (from loadsparkCoreTranslationsKeys)\n * @param getTarget - Optional function that returns a target number from the data context\n *\n * @returns A function that takes optional parameters and returns a Payload field validator\n *\n * @example\n * ```ts\n * // Field vs field comparison\n * const greaterThan = makeNumberValidator(\n * (a, b) => a > b,\n * 'loadspark-core:validation:number:mustBeGreaterThanOtherNumber'\n * )\n *\n * // Field vs constant comparison\n * const maxValue = makeNumberValidator(\n * (a, b) => a <= b,\n * 'loadspark-core:validation:number:mustBeLessThanOtherNumber',\n * () => 100 // constant max value\n * )\n * ```\n */\nexport const makeNumberValidator = (\n compareFn: CompareFn,\n messageKey: NumberValidationKeys,\n getTarget?: (data: Record<string, unknown>, otherField?: OtherField) => null | number,\n) => {\n return (otherField?: OtherField, options?: ValidatorOptions) => {\n return (\n val: null | number | undefined,\n ctx: ValidateOptions<unknown, unknown, NumberField, number>,\n ) => {\n const t = ctx.req.t as TFunction<loadsparkCoreTranslationsKeys>\n const locale = ctx.req.i18n.language\n let defaultLabel = ctx.label ?? ctx.name\n\n if (typeof ctx.label === 'string') {\n defaultLabel = ctx.label\n } else if (typeof ctx.label === 'object') {\n defaultLabel = ctx.label[locale] ?? defaultLabel\n }\n\n if (number(val, ctx) !== true) {\n return number(val, ctx)\n }\n\n if (options?.override || ctx.overrideAccess) {\n return true\n }\n\n let target: null | number = null\n\n if (otherField) {\n const data = ctx.data as Record<string, unknown>\n const rawOther = data[otherField.field]\n\n if (rawOther == null) {\n return true\n }\n\n const other: null | number = typeof rawOther === 'number' ? rawOther : null\n\n if (other == null) {\n return true\n }\n\n target = other\n } else if (getTarget) {\n target = getTarget(ctx.data)\n }\n\n if (target == null) {\n return true\n }\n\n if (val == null) {\n return true\n }\n const currentVal: number = val\n\n if (target == null) {\n return true\n }\n const otherVal: number = target\n\n if (!compareFn(currentVal, otherVal)) {\n const otherLabel = otherField ? (otherField.labels[locale] ?? otherField.field) : undefined\n return t(messageKey, { field: defaultLabel, otherField: otherLabel })\n }\n\n return true\n }\n }\n}\n\n/** Field vs Field validators */\n\n/**\n * Validates that a number field is strictly greater than another number field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n *\n * @example\n * ```ts\n * {\n * name: 'maxValue',\n * type: 'number',\n * label: { de: 'Höchstwert', en: 'Maximum Value' },\n * validate: (val, ctx) => {\n * return greaterThan(\n * {\n * field: 'minValue',\n * labels: { de: 'Mindestwert', en: 'Minimum Value' },\n * },\n * { override: ctx.req?.user?.role === 'admin' },\n * )(val, ctx)\n * },\n * }\n * ```\n */\nexport const greaterThan = makeNumberValidator(\n (a, b) => a > b,\n 'loadspark-core:validation:number:mustBeGreaterThanOtherNumber',\n)\n\n/**\n * Validates that a number field is greater than or equal to another number field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n */\nexport const greaterThanOrEqual = makeNumberValidator(\n (a, b) => a >= b,\n 'loadspark-core:validation:number:mustBeEqualOrGreaterThanOtherNumber',\n)\n\n/**\n * Validates that a number field is strictly less than another number field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n */\nexport const lessThan = makeNumberValidator(\n (a, b) => a < b,\n 'loadspark-core:validation:number:mustBeLessThanOtherNumber',\n)\n\n/**\n * Validates that a number field is less than or equal to another number field.\n *\n * @param otherField - Configuration for the field to compare against\n * @param otherField.field - The name of the other field to compare\n * @param otherField.labels - Labels for the other field (used in error messages)\n * @param options - Optional validator options\n * @param options.override - If true, skips the validation (useful for programmatic conditions)\n *\n * @returns A validation function that can be used in field validate arrays\n */\nexport const lessThanOrEqual = makeNumberValidator(\n (a, b) => a <= b,\n 'loadspark-core:validation:number:mustBeEqualOrLessThanOtherNumber',\n)\n"],"names":["number","makeNumberValidator","compareFn","messageKey","getTarget","otherField","options","val","ctx","t","req","locale","i18n","language","defaultLabel","label","name","override","overrideAccess","target","data","rawOther","field","other","currentVal","otherVal","otherLabel","labels","undefined","greaterThan","a","b","greaterThanOrEqual","lessThan","lessThanOrEqual"],"mappings":"AAGA,SAASA,MAAM,QAAQ,iBAAgB;AA2BvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCC,GACD,OAAO,MAAMC,sBAAsB,CACjCC,WACAC,YACAC;IAEA,OAAO,CAACC,YAAyBC;QAC/B,OAAO,CACLC,KACAC;YAEA,MAAMC,IAAID,IAAIE,GAAG,CAACD,CAAC;YACnB,MAAME,SAASH,IAAIE,GAAG,CAACE,IAAI,CAACC,QAAQ;YACpC,IAAIC,eAAeN,IAAIO,KAAK,IAAIP,IAAIQ,IAAI;YAExC,IAAI,OAAOR,IAAIO,KAAK,KAAK,UAAU;gBACjCD,eAAeN,IAAIO,KAAK;YAC1B,OAAO,IAAI,OAAOP,IAAIO,KAAK,KAAK,UAAU;gBACxCD,eAAeN,IAAIO,KAAK,CAACJ,OAAO,IAAIG;YACtC;YAEA,IAAId,OAAOO,KAAKC,SAAS,MAAM;gBAC7B,OAAOR,OAAOO,KAAKC;YACrB;YAEA,IAAIF,SAASW,YAAYT,IAAIU,cAAc,EAAE;gBAC3C,OAAO;YACT;YAEA,IAAIC,SAAwB;YAE5B,IAAId,YAAY;gBACd,MAAMe,OAAOZ,IAAIY,IAAI;gBACrB,MAAMC,WAAWD,IAAI,CAACf,WAAWiB,KAAK,CAAC;gBAEvC,IAAID,YAAY,MAAM;oBACpB,OAAO;gBACT;gBAEA,MAAME,QAAuB,OAAOF,aAAa,WAAWA,WAAW;gBAEvE,IAAIE,SAAS,MAAM;oBACjB,OAAO;gBACT;gBAEAJ,SAASI;YACX,OAAO,IAAInB,WAAW;gBACpBe,SAASf,UAAUI,IAAIY,IAAI;YAC7B;YAEA,IAAID,UAAU,MAAM;gBAClB,OAAO;YACT;YAEA,IAAIZ,OAAO,MAAM;gBACf,OAAO;YACT;YACA,MAAMiB,aAAqBjB;YAE3B,IAAIY,UAAU,MAAM;gBAClB,OAAO;YACT;YACA,MAAMM,WAAmBN;YAEzB,IAAI,CAACjB,UAAUsB,YAAYC,WAAW;gBACpC,MAAMC,aAAarB,aAAcA,WAAWsB,MAAM,CAAChB,OAAO,IAAIN,WAAWiB,KAAK,GAAIM;gBAClF,OAAOnB,EAAEN,YAAY;oBAAEmB,OAAOR;oBAAcT,YAAYqB;gBAAW;YACrE;YAEA,OAAO;QACT;IACF;AACF,EAAC;AAED,8BAA8B,GAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GACD,OAAO,MAAMG,cAAc5B,oBACzB,CAAC6B,GAAGC,IAAMD,IAAIC,GACd,iEACD;AAED;;;;;;;;;;CAUC,GACD,OAAO,MAAMC,qBAAqB/B,oBAChC,CAAC6B,GAAGC,IAAMD,KAAKC,GACf,wEACD;AAED;;;;;;;;;;CAUC,GACD,OAAO,MAAME,WAAWhC,oBACtB,CAAC6B,GAAGC,IAAMD,IAAIC,GACd,8DACD;AAED;;;;;;;;;;CAUC,GACD,OAAO,MAAMG,kBAAkBjC,oBAC7B,CAAC6B,GAAGC,IAAMD,KAAKC,GACf,qEACD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RelationshipFieldValidation } from 'payload';
|
|
2
|
+
interface RelationValidatorOptions {
|
|
3
|
+
/** Skip the validation if true */
|
|
4
|
+
override?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validates that a relationship field linked to users can only be set to the current user's ID,
|
|
8
|
+
* unless the user has editor-level permissions or higher.
|
|
9
|
+
*
|
|
10
|
+
* Validation rules:
|
|
11
|
+
* - System users, admins, and editors can set any user
|
|
12
|
+
* - Regular users can only set their own user ID
|
|
13
|
+
* - Can be programmatically overridden via the `override` option
|
|
14
|
+
*
|
|
15
|
+
* @param options - Optional validator configuration
|
|
16
|
+
* @param options.override - If true, skips the validation entirely
|
|
17
|
+
*
|
|
18
|
+
* @returns A validation function that can be used in relationship field validate arrays
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* {
|
|
23
|
+
* name: 'assignedUser',
|
|
24
|
+
* type: 'relationship',
|
|
25
|
+
* relationTo: 'users',
|
|
26
|
+
* validate: [relationLinkedUser()]
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // With override
|
|
33
|
+
* {
|
|
34
|
+
* name: 'assignedUser',
|
|
35
|
+
* type: 'relationship',
|
|
36
|
+
* relationTo: 'users',
|
|
37
|
+
* validate: [relationLinkedUser({ override: false })]
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const relationLinkedUser: (options?: RelationValidatorOptions) => RelationshipFieldValidation;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=relationLinkedUser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relationLinkedUser.d.ts","sourceRoot":"","sources":["../../src/validations/relationLinkedUser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAA;AAM1D,UAAU,wBAAwB;IAChC,kCAAkC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,kBAAkB,aACnB,wBAAwB,KACjC,2BAmBF,CAAA"}
|