@warlock.js/core 3.0.12 → 3.0.14
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/cjs/application.js +1 -1
- package/cjs/application.js.map +1 -1
- package/cjs/console/commander.js +1 -1
- package/cjs/console/commander.js.map +1 -1
- package/cjs/http/errors/index.d.ts +2 -0
- package/cjs/http/errors/index.d.ts.map +1 -0
- package/cjs/http/errors/resource-not-found.error.d.ts +13 -0
- package/cjs/http/errors/resource-not-found.error.d.ts.map +1 -0
- package/cjs/http/errors/resource-not-found.error.js +24 -0
- package/cjs/http/errors/resource-not-found.error.js.map +1 -0
- package/cjs/http/index.d.ts +1 -0
- package/cjs/http/index.d.ts.map +1 -1
- package/cjs/http/middleware/_inject-request-context.d.ts.map +1 -1
- package/cjs/http/middleware/cache-response-middleware.d.ts.map +1 -1
- package/cjs/http/middleware/cache-response-middleware.js +0 -1
- package/cjs/http/middleware/cache-response-middleware.js.map +1 -1
- package/cjs/http/plugins/index.d.ts +1 -1
- package/cjs/http/plugins/index.d.ts.map +1 -1
- package/cjs/http/request.d.ts +20 -5
- package/cjs/http/request.d.ts.map +1 -1
- package/cjs/http/request.js +34 -5
- package/cjs/http/request.js.map +1 -1
- package/cjs/http/response.d.ts +3 -2
- package/cjs/http/response.d.ts.map +1 -1
- package/cjs/http/response.js +15 -4
- package/cjs/http/response.js.map +1 -1
- package/cjs/http/types.d.ts +12 -0
- package/cjs/http/types.d.ts.map +1 -1
- package/cjs/index.d.ts +2 -0
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -1
- package/cjs/modules/uploads/controllers/upload-files.d.ts.map +1 -1
- package/cjs/modules/uploads/controllers/upload-files.js +7 -7
- package/cjs/modules/uploads/controllers/upload-files.js.map +1 -1
- package/cjs/modules/uploads/output/upload-output.d.ts.map +1 -1
- package/cjs/modules/uploads/output/upload-output.js +2 -2
- package/cjs/modules/uploads/output/upload-output.js.map +1 -1
- package/cjs/modules/uploads/utils/get-watermark-options.js +1 -1
- package/cjs/modules/uploads/utils/get-watermark-options.js.map +1 -1
- package/cjs/output/output.js +1 -1
- package/cjs/output/output.js.map +1 -1
- package/cjs/react/index.d.ts +1 -10
- package/cjs/react/index.d.ts.map +1 -1
- package/cjs/react/index.js +3 -4
- package/cjs/react/index.js.map +1 -1
- package/cjs/repositories/repository-list-manager.js +1 -1
- package/cjs/repositories/repository-list-manager.js.map +1 -1
- package/cjs/router/router.d.ts +0 -8
- package/cjs/router/router.d.ts.map +1 -1
- package/cjs/router/router.js +3 -36
- package/cjs/router/router.js.map +1 -1
- package/cjs/router/types.d.ts +1 -1
- package/cjs/router/types.d.ts.map +1 -1
- package/cjs/starters/http-server-starter.d.ts.map +1 -1
- package/cjs/starters/http-server-starter.js +7 -2
- package/cjs/starters/http-server-starter.js.map +1 -1
- package/cjs/starters/start-cli-server.d.ts.map +1 -1
- package/cjs/starters/start-cli-server.js +10 -1
- package/cjs/starters/start-cli-server.js.map +1 -1
- package/cjs/starters/start-http-server.d.ts +3 -2
- package/cjs/starters/start-http-server.d.ts.map +1 -1
- package/cjs/starters/start-http-server.js +12 -6
- package/cjs/starters/start-http-server.js.map +1 -1
- package/cjs/utils/date-output.d.ts.map +1 -1
- package/cjs/utils/date-output.js +2 -4
- package/cjs/utils/date-output.js.map +1 -1
- package/cjs/utils/get-localized.d.ts.map +1 -1
- package/cjs/utils/get-localized.js.map +1 -1
- package/cjs/v/database/exists-except-current-id.d.ts +7 -0
- package/cjs/v/database/exists-except-current-id.d.ts.map +1 -0
- package/cjs/v/database/exists-except-current-id.js +23 -0
- package/cjs/v/database/exists-except-current-id.js.map +1 -0
- package/cjs/v/database/exists-except-current-user.d.ts +7 -0
- package/cjs/v/database/exists-except-current-user.d.ts.map +1 -0
- package/cjs/v/database/exists-except-current-user.js +25 -0
- package/cjs/v/database/exists-except-current-user.js.map +1 -0
- package/cjs/v/database/exists.d.ts +7 -0
- package/cjs/v/database/exists.d.ts.map +1 -0
- package/cjs/v/database/exists.js +21 -0
- package/cjs/v/database/exists.js.map +1 -0
- package/cjs/v/database/index.d.ts +12 -0
- package/cjs/v/database/index.d.ts.map +1 -0
- package/cjs/v/database/types.d.ts +68 -0
- package/cjs/v/database/types.d.ts.map +1 -0
- package/cjs/v/database/unique-except-current-id.d.ts +7 -0
- package/cjs/v/database/unique-except-current-id.d.ts.map +1 -0
- package/cjs/v/database/unique-except-current-id.js +23 -0
- package/cjs/v/database/unique-except-current-id.js.map +1 -0
- package/cjs/v/database/unique-except-current-user.d.ts +7 -0
- package/cjs/v/database/unique-except-current-user.d.ts.map +1 -0
- package/cjs/v/database/unique-except-current-user.js +25 -0
- package/cjs/v/database/unique-except-current-user.js.map +1 -0
- package/cjs/v/database/unique.d.ts +7 -0
- package/cjs/v/database/unique.d.ts.map +1 -0
- package/cjs/v/database/unique.js +30 -0
- package/cjs/v/database/unique.js.map +1 -0
- package/cjs/v/file/file.d.ts +22 -0
- package/cjs/v/file/file.d.ts.map +1 -0
- package/cjs/v/file/file.js +60 -0
- package/cjs/v/file/file.js.map +1 -0
- package/cjs/v/file/index.d.ts +6 -0
- package/cjs/v/file/index.d.ts.map +1 -0
- package/cjs/v/index.d.ts +17 -0
- package/cjs/v/index.d.ts.map +1 -0
- package/cjs/v/init.d.ts +7 -0
- package/cjs/v/init.d.ts.map +1 -0
- package/cjs/v/init.js +40 -0
- package/cjs/v/init.js.map +1 -0
- package/cjs/v/plugins/database-plugin.d.ts +14 -0
- package/cjs/v/plugins/database-plugin.d.ts.map +1 -0
- package/cjs/v/plugins/database-plugin.js +95 -0
- package/cjs/v/plugins/database-plugin.js.map +1 -0
- package/cjs/v/plugins/file-plugin.d.ts +11 -0
- package/cjs/v/plugins/file-plugin.d.ts.map +1 -0
- package/cjs/v/plugins/file-plugin.js +17 -0
- package/cjs/v/plugins/file-plugin.js.map +1 -0
- package/cjs/v/plugins/index.d.ts +8 -0
- package/cjs/v/plugins/index.d.ts.map +1 -0
- package/cjs/v/string/index.d.ts +6 -0
- package/cjs/v/string/index.d.ts.map +1 -0
- package/cjs/v/string/uploadable.d.ts +6 -0
- package/cjs/v/string/uploadable.d.ts.map +1 -0
- package/cjs/v/string/uploadable.js +14 -0
- package/cjs/v/string/uploadable.js.map +1 -0
- package/cjs/v/types.d.ts +53 -0
- package/cjs/v/types.d.ts.map +1 -0
- package/cjs/v/validators/file-validator.d.ts +36 -0
- package/cjs/v/validators/file-validator.d.ts.map +1 -0
- package/cjs/v/validators/file-validator.js +88 -0
- package/cjs/v/validators/file-validator.js.map +1 -0
- package/cjs/v/validators/index.d.ts +7 -0
- package/cjs/v/validators/index.d.ts.map +1 -0
- package/cjs/validator/index.d.ts +0 -1
- package/cjs/validator/index.d.ts.map +1 -1
- package/cjs/validator/locales.js +518 -10
- package/cjs/validator/locales.js.map +1 -1
- package/cjs/validator/types.d.ts +28 -0
- package/cjs/validator/types.d.ts.map +1 -1
- package/cjs/validator/validateAll.d.ts.map +1 -1
- package/cjs/validator/validateAll.js +5 -2
- package/cjs/validator/validateAll.js.map +1 -1
- package/esm/application.js +1 -1
- package/esm/application.js.map +1 -1
- package/esm/console/commander.js +1 -1
- package/esm/console/commander.js.map +1 -1
- package/esm/http/errors/index.d.ts +2 -0
- package/esm/http/errors/index.d.ts.map +1 -0
- package/esm/http/errors/resource-not-found.error.d.ts +13 -0
- package/esm/http/errors/resource-not-found.error.d.ts.map +1 -0
- package/esm/http/errors/resource-not-found.error.js +24 -0
- package/esm/http/errors/resource-not-found.error.js.map +1 -0
- package/esm/http/index.d.ts +1 -0
- package/esm/http/index.d.ts.map +1 -1
- package/esm/http/middleware/_inject-request-context.d.ts.map +1 -1
- package/esm/http/middleware/cache-response-middleware.d.ts.map +1 -1
- package/esm/http/middleware/cache-response-middleware.js +0 -1
- package/esm/http/middleware/cache-response-middleware.js.map +1 -1
- package/esm/http/plugins/index.d.ts +1 -1
- package/esm/http/plugins/index.d.ts.map +1 -1
- package/esm/http/request.d.ts +20 -5
- package/esm/http/request.d.ts.map +1 -1
- package/esm/http/request.js +34 -5
- package/esm/http/request.js.map +1 -1
- package/esm/http/response.d.ts +3 -2
- package/esm/http/response.d.ts.map +1 -1
- package/esm/http/response.js +16 -5
- package/esm/http/response.js.map +1 -1
- package/esm/http/types.d.ts +12 -0
- package/esm/http/types.d.ts.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/modules/uploads/controllers/upload-files.d.ts.map +1 -1
- package/esm/modules/uploads/controllers/upload-files.js +2 -2
- package/esm/modules/uploads/controllers/upload-files.js.map +1 -1
- package/esm/modules/uploads/output/upload-output.d.ts.map +1 -1
- package/esm/modules/uploads/output/upload-output.js +2 -2
- package/esm/modules/uploads/output/upload-output.js.map +1 -1
- package/esm/modules/uploads/utils/get-watermark-options.js +1 -1
- package/esm/modules/uploads/utils/get-watermark-options.js.map +1 -1
- package/esm/output/output.js +1 -1
- package/esm/output/output.js.map +1 -1
- package/esm/react/index.d.ts +1 -10
- package/esm/react/index.d.ts.map +1 -1
- package/esm/react/index.js +2 -3
- package/esm/react/index.js.map +1 -1
- package/esm/repositories/repository-list-manager.js +1 -1
- package/esm/repositories/repository-list-manager.js.map +1 -1
- package/esm/router/router.d.ts +0 -8
- package/esm/router/router.d.ts.map +1 -1
- package/esm/router/router.js +3 -36
- package/esm/router/router.js.map +1 -1
- package/esm/router/types.d.ts +1 -1
- package/esm/router/types.d.ts.map +1 -1
- package/esm/starters/http-server-starter.d.ts.map +1 -1
- package/esm/starters/http-server-starter.js +7 -2
- package/esm/starters/http-server-starter.js.map +1 -1
- package/esm/starters/start-cli-server.d.ts.map +1 -1
- package/esm/starters/start-cli-server.js +10 -1
- package/esm/starters/start-cli-server.js.map +1 -1
- package/esm/starters/start-http-server.d.ts +3 -2
- package/esm/starters/start-http-server.d.ts.map +1 -1
- package/esm/starters/start-http-server.js +10 -4
- package/esm/starters/start-http-server.js.map +1 -1
- package/esm/utils/date-output.d.ts.map +1 -1
- package/esm/utils/date-output.js +2 -4
- package/esm/utils/date-output.js.map +1 -1
- package/esm/utils/get-localized.d.ts.map +1 -1
- package/esm/utils/get-localized.js.map +1 -1
- package/esm/v/database/exists-except-current-id.d.ts +7 -0
- package/esm/v/database/exists-except-current-id.d.ts.map +1 -0
- package/esm/v/database/exists-except-current-id.js +23 -0
- package/esm/v/database/exists-except-current-id.js.map +1 -0
- package/esm/v/database/exists-except-current-user.d.ts +7 -0
- package/esm/v/database/exists-except-current-user.d.ts.map +1 -0
- package/esm/v/database/exists-except-current-user.js +25 -0
- package/esm/v/database/exists-except-current-user.js.map +1 -0
- package/esm/v/database/exists.d.ts +7 -0
- package/esm/v/database/exists.d.ts.map +1 -0
- package/esm/v/database/exists.js +21 -0
- package/esm/v/database/exists.js.map +1 -0
- package/esm/v/database/index.d.ts +12 -0
- package/esm/v/database/index.d.ts.map +1 -0
- package/esm/v/database/types.d.ts +68 -0
- package/esm/v/database/types.d.ts.map +1 -0
- package/esm/v/database/unique-except-current-id.d.ts +7 -0
- package/esm/v/database/unique-except-current-id.d.ts.map +1 -0
- package/esm/v/database/unique-except-current-id.js +23 -0
- package/esm/v/database/unique-except-current-id.js.map +1 -0
- package/esm/v/database/unique-except-current-user.d.ts +7 -0
- package/esm/v/database/unique-except-current-user.d.ts.map +1 -0
- package/esm/v/database/unique-except-current-user.js +25 -0
- package/esm/v/database/unique-except-current-user.js.map +1 -0
- package/esm/v/database/unique.d.ts +7 -0
- package/esm/v/database/unique.d.ts.map +1 -0
- package/esm/v/database/unique.js +30 -0
- package/esm/v/database/unique.js.map +1 -0
- package/esm/v/file/file.d.ts +22 -0
- package/esm/v/file/file.d.ts.map +1 -0
- package/esm/v/file/file.js +60 -0
- package/esm/v/file/file.js.map +1 -0
- package/esm/v/file/index.d.ts +6 -0
- package/esm/v/file/index.d.ts.map +1 -0
- package/esm/v/index.d.ts +17 -0
- package/esm/v/index.d.ts.map +1 -0
- package/esm/v/init.d.ts +7 -0
- package/esm/v/init.d.ts.map +1 -0
- package/esm/v/init.js +40 -0
- package/esm/v/init.js.map +1 -0
- package/esm/v/plugins/database-plugin.d.ts +14 -0
- package/esm/v/plugins/database-plugin.d.ts.map +1 -0
- package/esm/v/plugins/database-plugin.js +95 -0
- package/esm/v/plugins/database-plugin.js.map +1 -0
- package/esm/v/plugins/file-plugin.d.ts +11 -0
- package/esm/v/plugins/file-plugin.d.ts.map +1 -0
- package/esm/v/plugins/file-plugin.js +17 -0
- package/esm/v/plugins/file-plugin.js.map +1 -0
- package/esm/v/plugins/index.d.ts +8 -0
- package/esm/v/plugins/index.d.ts.map +1 -0
- package/esm/v/string/index.d.ts +6 -0
- package/esm/v/string/index.d.ts.map +1 -0
- package/esm/v/string/uploadable.d.ts +6 -0
- package/esm/v/string/uploadable.d.ts.map +1 -0
- package/esm/v/string/uploadable.js +14 -0
- package/esm/v/string/uploadable.js.map +1 -0
- package/esm/v/types.d.ts +53 -0
- package/esm/v/types.d.ts.map +1 -0
- package/esm/v/validators/file-validator.d.ts +36 -0
- package/esm/v/validators/file-validator.d.ts.map +1 -0
- package/esm/v/validators/file-validator.js +88 -0
- package/esm/v/validators/file-validator.js.map +1 -0
- package/esm/v/validators/index.d.ts +7 -0
- package/esm/v/validators/index.d.ts.map +1 -0
- package/esm/validator/index.d.ts +0 -1
- package/esm/validator/index.d.ts.map +1 -1
- package/esm/validator/locales.js +518 -10
- package/esm/validator/locales.js.map +1 -1
- package/esm/validator/types.d.ts +28 -0
- package/esm/validator/types.d.ts.map +1 -1
- package/esm/validator/validateAll.d.ts.map +1 -1
- package/esm/validator/validateAll.js +4 -1
- package/esm/validator/validateAll.js.map +1 -1
- package/package.json +3 -3
- package/cjs/react/page-renderer.d.ts +0 -18
- package/cjs/react/page-renderer.d.ts.map +0 -1
- package/cjs/react/page-renderer.js +0 -69
- package/cjs/react/page-renderer.js.map +0 -1
- package/cjs/react/plugin.d.ts +0 -15
- package/cjs/react/plugin.d.ts.map +0 -1
- package/cjs/react/plugin.js +0 -22
- package/cjs/react/plugin.js.map +0 -1
- package/cjs/react/vite-config.d.ts +0 -9
- package/cjs/react/vite-config.d.ts.map +0 -1
- package/cjs/react/vite-config.js +0 -74
- package/cjs/react/vite-config.js.map +0 -1
- package/cjs/validator/v/array-validator.d.ts +0 -21
- package/cjs/validator/v/array-validator.d.ts.map +0 -1
- package/cjs/validator/v/base-validator.d.ts +0 -117
- package/cjs/validator/v/base-validator.d.ts.map +0 -1
- package/cjs/validator/v/database.d.ts +0 -8
- package/cjs/validator/v/database.d.ts.map +0 -1
- package/cjs/validator/v/database.js +0 -129
- package/cjs/validator/v/database.js.map +0 -1
- package/cjs/validator/v/index.d.ts +0 -3
- package/cjs/validator/v/index.d.ts.map +0 -1
- package/cjs/validator/v/mutators.d.ts +0 -24
- package/cjs/validator/v/mutators.d.ts.map +0 -1
- package/cjs/validator/v/mutators.js +0 -88
- package/cjs/validator/v/mutators.js.map +0 -1
- package/cjs/validator/v/number-validator.d.ts +0 -21
- package/cjs/validator/v/number-validator.d.ts.map +0 -1
- package/cjs/validator/v/object-validator.d.ts +0 -37
- package/cjs/validator/v/object-validator.d.ts.map +0 -1
- package/cjs/validator/v/rules.d.ts +0 -265
- package/cjs/validator/v/rules.d.ts.map +0 -1
- package/cjs/validator/v/rules.js +0 -914
- package/cjs/validator/v/rules.js.map +0 -1
- package/cjs/validator/v/schema.d.ts +0 -625
- package/cjs/validator/v/schema.d.ts.map +0 -1
- package/cjs/validator/v/schema.js +0 -1212
- package/cjs/validator/v/schema.js.map +0 -1
- package/cjs/validator/v/string-validator.d.ts +0 -41
- package/cjs/validator/v/string-validator.d.ts.map +0 -1
- package/cjs/validator/v/types.d.ts +0 -180
- package/cjs/validator/v/types.d.ts.map +0 -1
- package/cjs/validator/v/utils.d.ts +0 -5
- package/cjs/validator/v/utils.d.ts.map +0 -1
- package/cjs/validator/v/utils.js +0 -29
- package/cjs/validator/v/utils.js.map +0 -1
- package/esm/react/page-renderer.d.ts +0 -18
- package/esm/react/page-renderer.d.ts.map +0 -1
- package/esm/react/page-renderer.js +0 -69
- package/esm/react/page-renderer.js.map +0 -1
- package/esm/react/plugin.d.ts +0 -15
- package/esm/react/plugin.d.ts.map +0 -1
- package/esm/react/plugin.js +0 -22
- package/esm/react/plugin.js.map +0 -1
- package/esm/react/vite-config.d.ts +0 -9
- package/esm/react/vite-config.d.ts.map +0 -1
- package/esm/react/vite-config.js +0 -74
- package/esm/react/vite-config.js.map +0 -1
- package/esm/validator/v/array-validator.d.ts +0 -21
- package/esm/validator/v/array-validator.d.ts.map +0 -1
- package/esm/validator/v/base-validator.d.ts +0 -117
- package/esm/validator/v/base-validator.d.ts.map +0 -1
- package/esm/validator/v/database.d.ts +0 -8
- package/esm/validator/v/database.d.ts.map +0 -1
- package/esm/validator/v/database.js +0 -129
- package/esm/validator/v/database.js.map +0 -1
- package/esm/validator/v/index.d.ts +0 -3
- package/esm/validator/v/index.d.ts.map +0 -1
- package/esm/validator/v/mutators.d.ts +0 -24
- package/esm/validator/v/mutators.d.ts.map +0 -1
- package/esm/validator/v/mutators.js +0 -88
- package/esm/validator/v/mutators.js.map +0 -1
- package/esm/validator/v/number-validator.d.ts +0 -21
- package/esm/validator/v/number-validator.d.ts.map +0 -1
- package/esm/validator/v/object-validator.d.ts +0 -37
- package/esm/validator/v/object-validator.d.ts.map +0 -1
- package/esm/validator/v/rules.d.ts +0 -265
- package/esm/validator/v/rules.d.ts.map +0 -1
- package/esm/validator/v/rules.js +0 -914
- package/esm/validator/v/rules.js.map +0 -1
- package/esm/validator/v/schema.d.ts +0 -625
- package/esm/validator/v/schema.d.ts.map +0 -1
- package/esm/validator/v/schema.js +0 -1212
- package/esm/validator/v/schema.js.map +0 -1
- package/esm/validator/v/string-validator.d.ts +0 -41
- package/esm/validator/v/string-validator.d.ts.map +0 -1
- package/esm/validator/v/types.d.ts +0 -180
- package/esm/validator/v/types.d.ts.map +0 -1
- package/esm/validator/v/utils.d.ts +0 -5
- package/esm/validator/v/utils.d.ts.map +0 -1
- package/esm/validator/v/utils.js +0 -29
- package/esm/validator/v/utils.js.map +0 -1
package/esm/validator/v/rules.js
DELETED
|
@@ -1,914 +0,0 @@
|
|
|
1
|
-
import {get}from'@mongez/reinforcements';import {isEmpty,isPlainObject,isEmail,isNumeric}from'@mongez/supportive-is';import dayjs from'dayjs';import {isIP}from'net';import {UploadedFile}from'../../http/UploadedFile.js';import {Upload}from'../../modules/uploads/models/upload.js';import {invalidRule,VALID_RULE,setKeyPath}from'./utils.js';import'@warlock.js/cascade';import'../../http/middleware/inject-request-context.js';const requiredRule = {
|
|
2
|
-
name: "required",
|
|
3
|
-
defaultErrorMessage: "The :input is required",
|
|
4
|
-
requiresValue: false,
|
|
5
|
-
sortOrder: -2,
|
|
6
|
-
async validate(value, context) {
|
|
7
|
-
if (isEmpty(value)) {
|
|
8
|
-
return invalidRule(this, context);
|
|
9
|
-
}
|
|
10
|
-
return VALID_RULE;
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
const requiredWithRule = {
|
|
14
|
-
name: "requiredWith",
|
|
15
|
-
description: "The field is required if another field is present",
|
|
16
|
-
sortOrder: -2,
|
|
17
|
-
requiresValue: false,
|
|
18
|
-
defaultErrorMessage: "The :input is required",
|
|
19
|
-
async validate(value, context) {
|
|
20
|
-
const otherField = this.context.options.field;
|
|
21
|
-
const fieldValue = get(context.allValues, otherField);
|
|
22
|
-
if ([undefined, null].includes(fieldValue)) {
|
|
23
|
-
return VALID_RULE;
|
|
24
|
-
}
|
|
25
|
-
if (isEmpty(value)) {
|
|
26
|
-
return invalidRule(this, context);
|
|
27
|
-
}
|
|
28
|
-
return VALID_RULE;
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
const requiredIfAbsentRule = {
|
|
32
|
-
name: "requiredIfAbsent",
|
|
33
|
-
description: "The field is required if another field is absent",
|
|
34
|
-
sortOrder: -2,
|
|
35
|
-
requiresValue: false,
|
|
36
|
-
defaultErrorMessage: "The :input is required",
|
|
37
|
-
async validate(value, context) {
|
|
38
|
-
const otherField = this.context.options.field;
|
|
39
|
-
const fieldValue = get(context.allValues || {}, otherField);
|
|
40
|
-
const isPresent = ![undefined, null].includes(fieldValue);
|
|
41
|
-
if (!isPresent && isEmpty(value)) {
|
|
42
|
-
return invalidRule(this, context);
|
|
43
|
-
}
|
|
44
|
-
return VALID_RULE;
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
const requiredIfSiblingFieldIsAbsentRule = {
|
|
48
|
-
name: "requiredIfSiblingFieldIsAbsent",
|
|
49
|
-
description: "The :input is required",
|
|
50
|
-
sortOrder: -2,
|
|
51
|
-
requiresValue: false,
|
|
52
|
-
defaultErrorMessage: ":input field is required",
|
|
53
|
-
async validate(value, context) {
|
|
54
|
-
const otherField = this.context.options.field;
|
|
55
|
-
const otherFieldValue = get(context.parent, otherField);
|
|
56
|
-
const isPresent = ![undefined, null].includes(otherFieldValue);
|
|
57
|
-
if (!isPresent && isEmpty(value)) {
|
|
58
|
-
return invalidRule(this, context);
|
|
59
|
-
}
|
|
60
|
-
return VALID_RULE;
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
const requiredIfSiblingFieldAllAbsentRule = {
|
|
64
|
-
name: "requiredIfSiblingFieldAllAbsent",
|
|
65
|
-
description: "The field is required if all other fields are absent",
|
|
66
|
-
sortOrder: -2,
|
|
67
|
-
requiresValue: false,
|
|
68
|
-
defaultErrorMessage: "The :input is required",
|
|
69
|
-
async validate(value, context) {
|
|
70
|
-
const fields = this.context.options.fields;
|
|
71
|
-
let isPresent = false;
|
|
72
|
-
for (const field of fields) {
|
|
73
|
-
const fieldValue = get(context.parent, field);
|
|
74
|
-
if (![undefined, null].includes(fieldValue)) {
|
|
75
|
-
isPresent = true;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (!isPresent && isEmpty(value)) {
|
|
80
|
-
return invalidRule(this, context);
|
|
81
|
-
}
|
|
82
|
-
return VALID_RULE;
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
const requiredIfEmptyRule = {
|
|
86
|
-
name: "requiredIfEmpty",
|
|
87
|
-
description: "The field is required if another field is empty",
|
|
88
|
-
sortOrder: -2,
|
|
89
|
-
requiresValue: false,
|
|
90
|
-
defaultErrorMessage: "The :input is required",
|
|
91
|
-
async validate(value, context) {
|
|
92
|
-
const otherField = this.context.options.field;
|
|
93
|
-
const fieldValue = get(context.allValues, otherField);
|
|
94
|
-
if (isEmpty(fieldValue) && isEmpty(value)) {
|
|
95
|
-
return invalidRule(this, context);
|
|
96
|
-
}
|
|
97
|
-
return VALID_RULE;
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
// required if sibling field is empty
|
|
101
|
-
const requiredIfSiblingFieldEmptyRule = {
|
|
102
|
-
name: "requiredIfSiblingFieldEmpty",
|
|
103
|
-
description: "The field is required if another field in same parent context is empty",
|
|
104
|
-
sortOrder: -2,
|
|
105
|
-
requiresValue: false,
|
|
106
|
-
defaultErrorMessage: "The :input is required",
|
|
107
|
-
async validate(value, context) {
|
|
108
|
-
const otherField = this.context.options.field;
|
|
109
|
-
const fieldValue = get(context.parent, otherField);
|
|
110
|
-
if (isEmpty(fieldValue) && isEmpty(value)) {
|
|
111
|
-
return invalidRule(this, context);
|
|
112
|
-
}
|
|
113
|
-
return VALID_RULE;
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
const requiredIfFieldRule = {
|
|
117
|
-
name: "requiredIfField",
|
|
118
|
-
description: "The field is required if another field has a specific value",
|
|
119
|
-
sortOrder: -2,
|
|
120
|
-
requiresValue: false,
|
|
121
|
-
defaultErrorMessage: "The :input is required",
|
|
122
|
-
async validate(value, context) {
|
|
123
|
-
const otherField = this.context.options.field;
|
|
124
|
-
const otherFieldValue = this.context.options.value;
|
|
125
|
-
if (otherField === undefined) {
|
|
126
|
-
throw new Error("The field option is required for requiredIfField rule");
|
|
127
|
-
}
|
|
128
|
-
const fieldValue = get(context.allValues, otherField);
|
|
129
|
-
if (fieldValue === otherFieldValue && isEmpty(value)) {
|
|
130
|
-
return invalidRule(this, context);
|
|
131
|
-
}
|
|
132
|
-
return VALID_RULE;
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
const requiredIfSiblingFieldRule = {
|
|
136
|
-
name: "requiredIfSiblingField",
|
|
137
|
-
description: "The field is required if another field in same parent context has a specific value",
|
|
138
|
-
sortOrder: -2,
|
|
139
|
-
requiresValue: false,
|
|
140
|
-
defaultErrorMessage: "The :input is required",
|
|
141
|
-
async validate(value, context) {
|
|
142
|
-
const otherField = this.context.options.field;
|
|
143
|
-
const otherFieldValue = this.context.options.value;
|
|
144
|
-
const parentValues = context.parent;
|
|
145
|
-
const fieldValue = get(parentValues, otherField);
|
|
146
|
-
if (fieldValue === otherFieldValue && isEmpty(value)) {
|
|
147
|
-
return invalidRule(this, context);
|
|
148
|
-
}
|
|
149
|
-
return VALID_RULE;
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
const requiredUnlessSiblingFieldRule = {
|
|
153
|
-
name: "requiredUnlessSiblingField",
|
|
154
|
-
description: "The field is required unless another field in same parent context has a specific value",
|
|
155
|
-
sortOrder: -2,
|
|
156
|
-
requiresValue: false,
|
|
157
|
-
defaultErrorMessage: "The :input is required",
|
|
158
|
-
async validate(value, context) {
|
|
159
|
-
const otherField = this.context.options.field;
|
|
160
|
-
const otherFieldValue = this.context.options.value;
|
|
161
|
-
const parentValues = context.parent;
|
|
162
|
-
const fieldValue = get(parentValues, otherField);
|
|
163
|
-
if (fieldValue !== otherFieldValue && isEmpty(value)) {
|
|
164
|
-
return invalidRule(this, context);
|
|
165
|
-
}
|
|
166
|
-
return VALID_RULE;
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
const objectRule = {
|
|
170
|
-
name: "object",
|
|
171
|
-
defaultErrorMessage: "The :input must be an object",
|
|
172
|
-
async validate(value, context) {
|
|
173
|
-
if (isPlainObject(value)) {
|
|
174
|
-
return VALID_RULE;
|
|
175
|
-
}
|
|
176
|
-
return invalidRule(this, context);
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
const stringRule = {
|
|
180
|
-
name: "string",
|
|
181
|
-
defaultErrorMessage: "The :input must be a string",
|
|
182
|
-
async validate(value, context) {
|
|
183
|
-
if (typeof value === "string") {
|
|
184
|
-
return VALID_RULE;
|
|
185
|
-
}
|
|
186
|
-
return invalidRule(this, context);
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
const numberRule = {
|
|
190
|
-
name: "number",
|
|
191
|
-
defaultErrorMessage: "The :input must be a number",
|
|
192
|
-
async validate(value, context) {
|
|
193
|
-
if (typeof value === "number") {
|
|
194
|
-
return VALID_RULE;
|
|
195
|
-
}
|
|
196
|
-
return invalidRule(this, context);
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
const booleanRule = {
|
|
200
|
-
name: "boolean",
|
|
201
|
-
defaultErrorMessage: "The :input must be a boolean",
|
|
202
|
-
async validate(value, context) {
|
|
203
|
-
if (typeof value === "boolean") {
|
|
204
|
-
return VALID_RULE;
|
|
205
|
-
}
|
|
206
|
-
return invalidRule(this, context);
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
const intRule = {
|
|
210
|
-
name: "int",
|
|
211
|
-
defaultErrorMessage: "The :input must be an integer",
|
|
212
|
-
async validate(value, context) {
|
|
213
|
-
if (Number.isInteger(value)) {
|
|
214
|
-
return VALID_RULE;
|
|
215
|
-
}
|
|
216
|
-
return invalidRule(this, context);
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
const floatRule = {
|
|
220
|
-
name: "float",
|
|
221
|
-
defaultErrorMessage: "The :input must be a float",
|
|
222
|
-
async validate(value, context) {
|
|
223
|
-
if (Number.isFinite(value) && !Number.isInteger(value)) {
|
|
224
|
-
return VALID_RULE;
|
|
225
|
-
}
|
|
226
|
-
return invalidRule(this, context);
|
|
227
|
-
},
|
|
228
|
-
};
|
|
229
|
-
const inRule = {
|
|
230
|
-
name: "in",
|
|
231
|
-
defaultErrorMessage: "The :input must be one of the following values: :options",
|
|
232
|
-
async validate(value, context) {
|
|
233
|
-
if (this.context.options.values.includes(value)) {
|
|
234
|
-
return VALID_RULE;
|
|
235
|
-
}
|
|
236
|
-
return invalidRule(this, context);
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
const enumRule = {
|
|
240
|
-
name: "enum",
|
|
241
|
-
defaultErrorMessage: "The :input must be one of the following values: :options",
|
|
242
|
-
async validate(value, context) {
|
|
243
|
-
const enumObject = this.context.options.enum;
|
|
244
|
-
const enumValues = Object.values(enumObject);
|
|
245
|
-
if (enumValues.includes(value)) {
|
|
246
|
-
return VALID_RULE;
|
|
247
|
-
}
|
|
248
|
-
this.context.options.enum = enumValues.join(", ");
|
|
249
|
-
return invalidRule(this, context);
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
const withoutWhitespaceRule = {
|
|
253
|
-
name: "withoutWhitespace",
|
|
254
|
-
defaultErrorMessage: "The :input must not contain whitespace",
|
|
255
|
-
async validate(value, context) {
|
|
256
|
-
if (!/\s/.test(value)) {
|
|
257
|
-
return VALID_RULE;
|
|
258
|
-
}
|
|
259
|
-
return invalidRule(this, context);
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
const minWordsRule = {
|
|
263
|
-
name: "minWords",
|
|
264
|
-
defaultErrorMessage: `The :input must be at least :minWords words`,
|
|
265
|
-
async validate(value, context) {
|
|
266
|
-
if (String(value || "").split(" ").length >= this.context.options.minWords) {
|
|
267
|
-
return VALID_RULE;
|
|
268
|
-
}
|
|
269
|
-
return invalidRule(this, context);
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
const maxWordsRule = {
|
|
273
|
-
name: "maxWords",
|
|
274
|
-
defaultErrorMessage: `The :input must be at most :maxWords words`,
|
|
275
|
-
async validate(value, context) {
|
|
276
|
-
if (String(value || "").split(" ").length <= this.context.options.maxWords) {
|
|
277
|
-
return VALID_RULE;
|
|
278
|
-
}
|
|
279
|
-
return invalidRule(this, context);
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
const wordsRule = {
|
|
283
|
-
name: "words",
|
|
284
|
-
defaultErrorMessage: `The :input must be exactly :words words`,
|
|
285
|
-
async validate(value, context) {
|
|
286
|
-
if (String(value || "").split(" ").length === this.context.options.words) {
|
|
287
|
-
return VALID_RULE;
|
|
288
|
-
}
|
|
289
|
-
return invalidRule(this, context);
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
const minLengthRule = {
|
|
293
|
-
name: "minLength",
|
|
294
|
-
defaultErrorMessage: `The :input must be at least :minLength characters long`,
|
|
295
|
-
async validate(value, context) {
|
|
296
|
-
if (String(value || "").length >= this.context.options.minLength) {
|
|
297
|
-
return VALID_RULE;
|
|
298
|
-
}
|
|
299
|
-
return invalidRule(this, context);
|
|
300
|
-
},
|
|
301
|
-
};
|
|
302
|
-
const maxLengthRule = {
|
|
303
|
-
name: "maxLength",
|
|
304
|
-
defaultErrorMessage: `The :input must not exceed :maxLength characters`,
|
|
305
|
-
async validate(value, context) {
|
|
306
|
-
if (String(value || "").length <= this.context.options.maxLength) {
|
|
307
|
-
return VALID_RULE;
|
|
308
|
-
}
|
|
309
|
-
return invalidRule(this, context);
|
|
310
|
-
},
|
|
311
|
-
};
|
|
312
|
-
const lengthRule = {
|
|
313
|
-
name: "length",
|
|
314
|
-
defaultErrorMessage: `The :input must be exactly :length characters long`,
|
|
315
|
-
async validate(value, context) {
|
|
316
|
-
if (String(value || "").length === this.context.options.length) {
|
|
317
|
-
return VALID_RULE;
|
|
318
|
-
}
|
|
319
|
-
return invalidRule(this, context);
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
const minRule = {
|
|
323
|
-
name: "min",
|
|
324
|
-
defaultErrorMessage: `The :input must be at least :min`,
|
|
325
|
-
async validate(value, context) {
|
|
326
|
-
if (value >= this.context.options.min) {
|
|
327
|
-
return VALID_RULE;
|
|
328
|
-
}
|
|
329
|
-
return invalidRule(this, context);
|
|
330
|
-
},
|
|
331
|
-
};
|
|
332
|
-
const maxRule = {
|
|
333
|
-
name: "max",
|
|
334
|
-
defaultErrorMessage: `The :input must equal to or less than :max`,
|
|
335
|
-
async validate(value, context) {
|
|
336
|
-
if (value <= this.context.options.max) {
|
|
337
|
-
return VALID_RULE;
|
|
338
|
-
}
|
|
339
|
-
return invalidRule(this, context);
|
|
340
|
-
},
|
|
341
|
-
};
|
|
342
|
-
const equalRule = {
|
|
343
|
-
name: "equal",
|
|
344
|
-
defaultErrorMessage: `The :input must be equal to :value`,
|
|
345
|
-
async validate(input, context) {
|
|
346
|
-
if (input === this.context.options.value) {
|
|
347
|
-
return VALID_RULE;
|
|
348
|
-
}
|
|
349
|
-
return invalidRule(this, context);
|
|
350
|
-
},
|
|
351
|
-
};
|
|
352
|
-
const emailRule = {
|
|
353
|
-
name: "email",
|
|
354
|
-
defaultErrorMessage: "The :input must be a valid email address",
|
|
355
|
-
async validate(value, context) {
|
|
356
|
-
if (isEmail(value)) {
|
|
357
|
-
return VALID_RULE;
|
|
358
|
-
}
|
|
359
|
-
return invalidRule(this, context);
|
|
360
|
-
},
|
|
361
|
-
};
|
|
362
|
-
const scalarRule = {
|
|
363
|
-
name: "scalar",
|
|
364
|
-
defaultErrorMessage: "The :input must be a scalar value",
|
|
365
|
-
async validate(value, context) {
|
|
366
|
-
// a valid value considered to beb either a string, number, or boolean
|
|
367
|
-
if (["string", "number", "boolean"].includes(typeof value)) {
|
|
368
|
-
return VALID_RULE;
|
|
369
|
-
}
|
|
370
|
-
return invalidRule(this, context);
|
|
371
|
-
},
|
|
372
|
-
};
|
|
373
|
-
const unknownKeyRule = {
|
|
374
|
-
name: "unknownKey",
|
|
375
|
-
sortOrder: -1,
|
|
376
|
-
defaultErrorMessage: "The :input contains unknown properties",
|
|
377
|
-
async validate(value, context) {
|
|
378
|
-
const schema = this.context.options.schema;
|
|
379
|
-
const allowedKeys = this.context.options.allowedKeys || [];
|
|
380
|
-
for (const key in value) {
|
|
381
|
-
if (!schema[key] && !allowedKeys.includes(key)) {
|
|
382
|
-
this.context.options.key = setKeyPath(context.path, key);
|
|
383
|
-
const newContext = {
|
|
384
|
-
...context,
|
|
385
|
-
key,
|
|
386
|
-
path: setKeyPath(context.path, key),
|
|
387
|
-
};
|
|
388
|
-
return invalidRule(this, newContext);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return VALID_RULE;
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
const matchesRule = {
|
|
395
|
-
name: "matches",
|
|
396
|
-
defaultErrorMessage: "The :input must match the :field",
|
|
397
|
-
async validate(value, context) {
|
|
398
|
-
const otherField = this.context.options.field;
|
|
399
|
-
if (value === get(context.allValues, otherField)) {
|
|
400
|
-
return VALID_RULE;
|
|
401
|
-
}
|
|
402
|
-
return invalidRule(this, context);
|
|
403
|
-
},
|
|
404
|
-
};
|
|
405
|
-
const dateRule = {
|
|
406
|
-
name: "date",
|
|
407
|
-
defaultErrorMessage: "The :input must be a valid date",
|
|
408
|
-
async validate(value, context) {
|
|
409
|
-
const format = this.context.options.format;
|
|
410
|
-
// use dayjs for date validation
|
|
411
|
-
if (format) {
|
|
412
|
-
const date = dayjs(value, format);
|
|
413
|
-
if (date.isValid()) {
|
|
414
|
-
return VALID_RULE;
|
|
415
|
-
}
|
|
416
|
-
return invalidRule(this, context);
|
|
417
|
-
}
|
|
418
|
-
if (new Date(value).toString() !== "Invalid Date") {
|
|
419
|
-
return VALID_RULE;
|
|
420
|
-
}
|
|
421
|
-
return invalidRule(this, context);
|
|
422
|
-
},
|
|
423
|
-
};
|
|
424
|
-
// Must be used with Date mutator
|
|
425
|
-
const minDateRule = {
|
|
426
|
-
name: "minDate",
|
|
427
|
-
description: "The field must be at least the given date",
|
|
428
|
-
defaultErrorMessage: `The :input must be at least :minDate`,
|
|
429
|
-
async validate(value, context) {
|
|
430
|
-
if (value >= this.context.options.minDate) {
|
|
431
|
-
return VALID_RULE;
|
|
432
|
-
}
|
|
433
|
-
return invalidRule(this, context);
|
|
434
|
-
},
|
|
435
|
-
};
|
|
436
|
-
// Must be used with Date mutator
|
|
437
|
-
const maxDateRule = {
|
|
438
|
-
name: "maxDate",
|
|
439
|
-
defaultErrorMessage: `The :input must be at most :maxDate`,
|
|
440
|
-
async validate(value, context) {
|
|
441
|
-
if (value <= this.context.options.maxDate) {
|
|
442
|
-
return VALID_RULE;
|
|
443
|
-
}
|
|
444
|
-
return invalidRule(this, context);
|
|
445
|
-
},
|
|
446
|
-
};
|
|
447
|
-
const urlRule = {
|
|
448
|
-
name: "url",
|
|
449
|
-
defaultErrorMessage: "The :input must be a valid URL",
|
|
450
|
-
async validate(value, context) {
|
|
451
|
-
try {
|
|
452
|
-
new URL(value);
|
|
453
|
-
return VALID_RULE;
|
|
454
|
-
}
|
|
455
|
-
catch (error) {
|
|
456
|
-
return invalidRule(this, context);
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
};
|
|
460
|
-
const ipRule = {
|
|
461
|
-
name: "ip",
|
|
462
|
-
defaultErrorMessage: "The :input must be a valid IP address",
|
|
463
|
-
async validate(value, context) {
|
|
464
|
-
const result = isIP(value);
|
|
465
|
-
if (result !== 0) {
|
|
466
|
-
return VALID_RULE;
|
|
467
|
-
}
|
|
468
|
-
return invalidRule(this, context);
|
|
469
|
-
},
|
|
470
|
-
};
|
|
471
|
-
const ip4Rule = {
|
|
472
|
-
name: "ip4",
|
|
473
|
-
defaultErrorMessage: "The :input must be a valid IPv4 address",
|
|
474
|
-
async validate(value, context) {
|
|
475
|
-
const result = isIP(value);
|
|
476
|
-
if (result === 4) {
|
|
477
|
-
return VALID_RULE;
|
|
478
|
-
}
|
|
479
|
-
return invalidRule(this, context);
|
|
480
|
-
},
|
|
481
|
-
};
|
|
482
|
-
const ip6Rule = {
|
|
483
|
-
name: "ip6",
|
|
484
|
-
defaultErrorMessage: "The :input must be a valid IPv6 address",
|
|
485
|
-
async validate(value, context) {
|
|
486
|
-
const result = isIP(value);
|
|
487
|
-
if (result === 6) {
|
|
488
|
-
return VALID_RULE;
|
|
489
|
-
}
|
|
490
|
-
return invalidRule(this, context);
|
|
491
|
-
},
|
|
492
|
-
};
|
|
493
|
-
const isNumericRule = {
|
|
494
|
-
name: "isNumeric",
|
|
495
|
-
defaultErrorMessage: "The :input must be a numeric value",
|
|
496
|
-
async validate(value, context) {
|
|
497
|
-
if (isNumeric(value)) {
|
|
498
|
-
return VALID_RULE;
|
|
499
|
-
}
|
|
500
|
-
return invalidRule(this, context);
|
|
501
|
-
},
|
|
502
|
-
};
|
|
503
|
-
const startsWithRule = {
|
|
504
|
-
name: "startsWith",
|
|
505
|
-
defaultErrorMessage: "The :input must start with :value",
|
|
506
|
-
async validate(value, context) {
|
|
507
|
-
if (value.startsWith(this.context.options.value)) {
|
|
508
|
-
return VALID_RULE;
|
|
509
|
-
}
|
|
510
|
-
return invalidRule(this, context);
|
|
511
|
-
},
|
|
512
|
-
};
|
|
513
|
-
const endsWithRule = {
|
|
514
|
-
name: "endsWith",
|
|
515
|
-
defaultErrorMessage: "The :input must end with :value",
|
|
516
|
-
async validate(value, context) {
|
|
517
|
-
if (value.endsWith(this.context.options.value)) {
|
|
518
|
-
return VALID_RULE;
|
|
519
|
-
}
|
|
520
|
-
return invalidRule(this, context);
|
|
521
|
-
},
|
|
522
|
-
};
|
|
523
|
-
const containsRule = {
|
|
524
|
-
name: "contains",
|
|
525
|
-
defaultErrorMessage: "The :input must contain :value",
|
|
526
|
-
async validate(value, context) {
|
|
527
|
-
if (value.includes(this.context.options.value)) {
|
|
528
|
-
return VALID_RULE;
|
|
529
|
-
}
|
|
530
|
-
return invalidRule(this, context);
|
|
531
|
-
},
|
|
532
|
-
};
|
|
533
|
-
const notContainsRule = {
|
|
534
|
-
name: "notContains",
|
|
535
|
-
defaultErrorMessage: "The :input must not contain :value",
|
|
536
|
-
async validate(value, context) {
|
|
537
|
-
if (!value.includes(this.context.options.value)) {
|
|
538
|
-
return VALID_RULE;
|
|
539
|
-
}
|
|
540
|
-
return invalidRule(this, context);
|
|
541
|
-
},
|
|
542
|
-
};
|
|
543
|
-
const alphaRule = {
|
|
544
|
-
name: "alpha",
|
|
545
|
-
defaultErrorMessage: "The :input must contain only alphabetic characters",
|
|
546
|
-
async validate(value, context) {
|
|
547
|
-
if (/^[a-zA-Z]+$/.test(value)) {
|
|
548
|
-
return VALID_RULE;
|
|
549
|
-
}
|
|
550
|
-
return invalidRule(this, context);
|
|
551
|
-
},
|
|
552
|
-
};
|
|
553
|
-
const alphaNumericRule = {
|
|
554
|
-
name: "alphaNumeric",
|
|
555
|
-
errorMessage: "The :input must contain only alphabetic and numeric characters",
|
|
556
|
-
async validate(value, context) {
|
|
557
|
-
if (/^[a-zA-Z0-9]+$/.test(value)) {
|
|
558
|
-
return VALID_RULE;
|
|
559
|
-
}
|
|
560
|
-
return invalidRule(this, context);
|
|
561
|
-
},
|
|
562
|
-
};
|
|
563
|
-
const patternRule = {
|
|
564
|
-
name: "pattern",
|
|
565
|
-
defaultErrorMessage: "The :input does not match the pattern",
|
|
566
|
-
async validate(value, context) {
|
|
567
|
-
if (this.context.options.pattern.test(value)) {
|
|
568
|
-
return VALID_RULE;
|
|
569
|
-
}
|
|
570
|
-
return invalidRule(this, context);
|
|
571
|
-
},
|
|
572
|
-
};
|
|
573
|
-
const moduloRule = {
|
|
574
|
-
name: "modulo",
|
|
575
|
-
defaultErrorMessage: "The :input must be a multiple of :value",
|
|
576
|
-
async validate(value, context) {
|
|
577
|
-
if (value % this.context.options.value === 0) {
|
|
578
|
-
return VALID_RULE;
|
|
579
|
-
}
|
|
580
|
-
return invalidRule(this, context);
|
|
581
|
-
},
|
|
582
|
-
};
|
|
583
|
-
const isCreditCardRule = {
|
|
584
|
-
name: "isCreditCard",
|
|
585
|
-
description: "The field must be a valid credit card number",
|
|
586
|
-
defaultErrorMessage: "The :input must be a valid credit card number",
|
|
587
|
-
async validate(value, context) {
|
|
588
|
-
// Luhn algorithm
|
|
589
|
-
const cardNumber = value.toString().replace(/\D/g, "");
|
|
590
|
-
let sum = 0;
|
|
591
|
-
let isEven = false;
|
|
592
|
-
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
593
|
-
let digit = parseInt(cardNumber[i]);
|
|
594
|
-
if (isEven) {
|
|
595
|
-
digit *= 2;
|
|
596
|
-
if (digit > 9) {
|
|
597
|
-
digit -= 9;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
sum += digit;
|
|
601
|
-
isEven = !isEven;
|
|
602
|
-
}
|
|
603
|
-
if (sum % 10 === 0) {
|
|
604
|
-
return VALID_RULE;
|
|
605
|
-
}
|
|
606
|
-
return invalidRule(this, context);
|
|
607
|
-
},
|
|
608
|
-
};
|
|
609
|
-
const positiveRule = {
|
|
610
|
-
name: "positive",
|
|
611
|
-
defaultErrorMessage: "The :input must be a positive number",
|
|
612
|
-
async validate(value, context) {
|
|
613
|
-
if (value > 0) {
|
|
614
|
-
return VALID_RULE;
|
|
615
|
-
}
|
|
616
|
-
return invalidRule(this, context);
|
|
617
|
-
},
|
|
618
|
-
};
|
|
619
|
-
// unique for array
|
|
620
|
-
const uniqueArrayRule = {
|
|
621
|
-
name: "uniqueArray",
|
|
622
|
-
description: "The array must contain unique values",
|
|
623
|
-
defaultErrorMessage: "The :input must contain unique values",
|
|
624
|
-
async validate(value, context) {
|
|
625
|
-
const uniqueValues = new Set(value);
|
|
626
|
-
if (uniqueValues.size === value.length) {
|
|
627
|
-
return VALID_RULE;
|
|
628
|
-
}
|
|
629
|
-
return invalidRule(this, context);
|
|
630
|
-
},
|
|
631
|
-
};
|
|
632
|
-
const uploadableRule = {
|
|
633
|
-
name: "uploadable",
|
|
634
|
-
defaultErrorMessage: "The :input must be a valid uploadable hash id",
|
|
635
|
-
async validate(value, context) {
|
|
636
|
-
const hashExists = await Upload.aggregate().where("hash", value).exists();
|
|
637
|
-
if (hashExists) {
|
|
638
|
-
return VALID_RULE;
|
|
639
|
-
}
|
|
640
|
-
return invalidRule(this, context);
|
|
641
|
-
},
|
|
642
|
-
};
|
|
643
|
-
const fileRule = {
|
|
644
|
-
name: "file",
|
|
645
|
-
defaultErrorMessage: "The :input must be a file",
|
|
646
|
-
async validate(value, context) {
|
|
647
|
-
if (value instanceof UploadedFile) {
|
|
648
|
-
return VALID_RULE;
|
|
649
|
-
}
|
|
650
|
-
return invalidRule(this, context);
|
|
651
|
-
},
|
|
652
|
-
};
|
|
653
|
-
const fileTypeRule = {
|
|
654
|
-
name: "fileType",
|
|
655
|
-
defaultErrorMessage: "The :input must be a :types file",
|
|
656
|
-
async validate(value, context) {
|
|
657
|
-
let mimeTypes = this.context.options.mimeTypes;
|
|
658
|
-
if (typeof mimeTypes === "string") {
|
|
659
|
-
mimeTypes = [mimeTypes];
|
|
660
|
-
}
|
|
661
|
-
if (mimeTypes.includes(value.mimeType)) {
|
|
662
|
-
return VALID_RULE;
|
|
663
|
-
}
|
|
664
|
-
return invalidRule(this, context);
|
|
665
|
-
},
|
|
666
|
-
};
|
|
667
|
-
const fileExtensionRule = {
|
|
668
|
-
name: "fileExtension",
|
|
669
|
-
errorMessage: "The :input must have one of the following extensions: :extensions",
|
|
670
|
-
async validate(value, context) {
|
|
671
|
-
let extensions = this.context.options.extensions;
|
|
672
|
-
if (typeof extensions === "string") {
|
|
673
|
-
extensions = [extensions];
|
|
674
|
-
}
|
|
675
|
-
if (extensions.includes(value.extension)) {
|
|
676
|
-
return VALID_RULE;
|
|
677
|
-
}
|
|
678
|
-
return invalidRule(this, context);
|
|
679
|
-
},
|
|
680
|
-
};
|
|
681
|
-
const maxFileSizeRule = {
|
|
682
|
-
name: "maxFileSize",
|
|
683
|
-
defaultErrorMessage: "The :input must not exceed :maxFileSize",
|
|
684
|
-
async validate(value, context) {
|
|
685
|
-
if (value.size <= this.context.options.maxFileSize) {
|
|
686
|
-
return VALID_RULE;
|
|
687
|
-
}
|
|
688
|
-
return invalidRule(this, context);
|
|
689
|
-
},
|
|
690
|
-
};
|
|
691
|
-
const minFileSizeRule = {
|
|
692
|
-
name: "minFileSize",
|
|
693
|
-
defaultErrorMessage: "The :input must be at least :minFileSize",
|
|
694
|
-
async validate(value, context) {
|
|
695
|
-
if (value.size >= this.context.options.minFileSize) {
|
|
696
|
-
return VALID_RULE;
|
|
697
|
-
}
|
|
698
|
-
return invalidRule(this, context);
|
|
699
|
-
},
|
|
700
|
-
};
|
|
701
|
-
const imageRule = {
|
|
702
|
-
name: "image",
|
|
703
|
-
defaultErrorMessage: "The :input must be an image",
|
|
704
|
-
async validate(value, context) {
|
|
705
|
-
if (value instanceof UploadedFile && value.isImage) {
|
|
706
|
-
return VALID_RULE;
|
|
707
|
-
}
|
|
708
|
-
return invalidRule(this, context);
|
|
709
|
-
},
|
|
710
|
-
};
|
|
711
|
-
const minWidthRule = {
|
|
712
|
-
name: "minWidth",
|
|
713
|
-
defaultErrorMessage: "The :input must be at least :minWidth pixels wide",
|
|
714
|
-
async validate(value, context) {
|
|
715
|
-
const dimensions = await value.dimensions();
|
|
716
|
-
if (dimensions.width >= this.context.options.minWidth) {
|
|
717
|
-
return VALID_RULE;
|
|
718
|
-
}
|
|
719
|
-
return invalidRule(this, context);
|
|
720
|
-
},
|
|
721
|
-
};
|
|
722
|
-
const maxWidthRule = {
|
|
723
|
-
name: "maxWidth",
|
|
724
|
-
defaultErrorMessage: "The :input must be at most :maxWidth pixels wide",
|
|
725
|
-
async validate(value, context) {
|
|
726
|
-
const dimensions = await value.dimensions();
|
|
727
|
-
if (dimensions.width <= this.context.options.maxWidth) {
|
|
728
|
-
return VALID_RULE;
|
|
729
|
-
}
|
|
730
|
-
return invalidRule(this, context);
|
|
731
|
-
},
|
|
732
|
-
};
|
|
733
|
-
const minHeightRule = {
|
|
734
|
-
name: "minHeight",
|
|
735
|
-
defaultErrorMessage: "The :input must be at least :minHeight pixels tall",
|
|
736
|
-
async validate(value, context) {
|
|
737
|
-
const dimensions = await value.dimensions();
|
|
738
|
-
if (dimensions.height >= this.context.options.minHeight) {
|
|
739
|
-
return VALID_RULE;
|
|
740
|
-
}
|
|
741
|
-
return invalidRule(this, context);
|
|
742
|
-
},
|
|
743
|
-
};
|
|
744
|
-
const maxHeightRule = {
|
|
745
|
-
name: "maxHeight",
|
|
746
|
-
defaultErrorMessage: "The :input must be at most :maxHeight pixels tall",
|
|
747
|
-
async validate(value, context) {
|
|
748
|
-
const dimensions = await value.dimensions();
|
|
749
|
-
if (dimensions.height <= this.context.options.maxHeight) {
|
|
750
|
-
return VALID_RULE;
|
|
751
|
-
}
|
|
752
|
-
return invalidRule(this, context);
|
|
753
|
-
},
|
|
754
|
-
};
|
|
755
|
-
/**
|
|
756
|
-
* Check if the value is one of the allowed values
|
|
757
|
-
*/
|
|
758
|
-
const allowedValuesRule = {
|
|
759
|
-
name: "arrayOfValues",
|
|
760
|
-
errorMessage: "The :input must be an array containing only the allowed values: :allowedValues",
|
|
761
|
-
async validate(value, context) {
|
|
762
|
-
const allowedValues = this.context.options.allowedValues;
|
|
763
|
-
// Check if the value is an array
|
|
764
|
-
if (!Array.isArray(value)) {
|
|
765
|
-
return invalidRule(this, context);
|
|
766
|
-
}
|
|
767
|
-
// Check if all elements in the array are allowed values
|
|
768
|
-
const isValid = value.every(item => allowedValues.includes(item));
|
|
769
|
-
if (isValid) {
|
|
770
|
-
return VALID_RULE;
|
|
771
|
-
}
|
|
772
|
-
return invalidRule(this, context);
|
|
773
|
-
},
|
|
774
|
-
};
|
|
775
|
-
/**
|
|
776
|
-
* Value must not be any of the given values
|
|
777
|
-
*/
|
|
778
|
-
const notAllowedValuesRule = {
|
|
779
|
-
name: "notAllowedValues",
|
|
780
|
-
errorMessage: "The :input must not be any of the following values: :notAllowedValues",
|
|
781
|
-
async validate(value, context) {
|
|
782
|
-
const notAllowedValues = this.context.options.notAllowedValues;
|
|
783
|
-
if (!notAllowedValues.includes(value)) {
|
|
784
|
-
return VALID_RULE;
|
|
785
|
-
}
|
|
786
|
-
return invalidRule(this, context);
|
|
787
|
-
},
|
|
788
|
-
};
|
|
789
|
-
// Array rules
|
|
790
|
-
const arrayRule = {
|
|
791
|
-
name: "array",
|
|
792
|
-
defaultErrorMessage: "The :input must be an array",
|
|
793
|
-
async validate(value, context) {
|
|
794
|
-
if (Array.isArray(value)) {
|
|
795
|
-
return VALID_RULE;
|
|
796
|
-
}
|
|
797
|
-
return invalidRule(this, context);
|
|
798
|
-
},
|
|
799
|
-
};
|
|
800
|
-
// End of Array rules
|
|
801
|
-
// Color rules
|
|
802
|
-
const colorValidationRegex = {
|
|
803
|
-
hex: /^#([0-9a-f]{3}){1,2}$/i,
|
|
804
|
-
rgb: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
|
|
805
|
-
rgba: /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(0?\.\d+)\)$/,
|
|
806
|
-
hsl: /^hsl\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
|
|
807
|
-
light: /^#([0-9a-f]{3}){1,2}$/i,
|
|
808
|
-
dark: /^#([0-9a-f]{3}){1,2}$/i,
|
|
809
|
-
};
|
|
810
|
-
const rgbColorRule = {
|
|
811
|
-
name: "rgbColor",
|
|
812
|
-
defaultErrorMessage: "The :input must be a valid RGB color",
|
|
813
|
-
async validate(value, context) {
|
|
814
|
-
if (value.match(colorValidationRegex.rgb)) {
|
|
815
|
-
return VALID_RULE;
|
|
816
|
-
}
|
|
817
|
-
return invalidRule(this, context);
|
|
818
|
-
},
|
|
819
|
-
};
|
|
820
|
-
const rgbaColorRule = {
|
|
821
|
-
name: "rgbaColor",
|
|
822
|
-
defaultErrorMessage: "The :input must be a valid RGBA color",
|
|
823
|
-
async validate(value, context) {
|
|
824
|
-
if (value.match(colorValidationRegex.rgba)) {
|
|
825
|
-
return VALID_RULE;
|
|
826
|
-
}
|
|
827
|
-
return invalidRule(this, context);
|
|
828
|
-
},
|
|
829
|
-
};
|
|
830
|
-
const hexColorRule = {
|
|
831
|
-
name: "hexColor",
|
|
832
|
-
defaultErrorMessage: "The :input must be a valid hex color",
|
|
833
|
-
async validate(value, context) {
|
|
834
|
-
if (value.match(colorValidationRegex.hex)) {
|
|
835
|
-
return VALID_RULE;
|
|
836
|
-
}
|
|
837
|
-
return invalidRule(this, context);
|
|
838
|
-
},
|
|
839
|
-
};
|
|
840
|
-
const hslColorRule = {
|
|
841
|
-
name: "hslColor",
|
|
842
|
-
defaultErrorMessage: "The :input must be a valid HSL color",
|
|
843
|
-
async validate(value, context) {
|
|
844
|
-
if (value.match(colorValidationRegex.hsl)) {
|
|
845
|
-
return VALID_RULE;
|
|
846
|
-
}
|
|
847
|
-
return invalidRule(this, context);
|
|
848
|
-
},
|
|
849
|
-
};
|
|
850
|
-
const lightColorRule = {
|
|
851
|
-
name: "lightColor",
|
|
852
|
-
defaultErrorMessage: "The :input must be a light color",
|
|
853
|
-
async validate(value, context) {
|
|
854
|
-
if (value.match(colorValidationRegex.light)) {
|
|
855
|
-
return VALID_RULE;
|
|
856
|
-
}
|
|
857
|
-
return invalidRule(this, context);
|
|
858
|
-
},
|
|
859
|
-
};
|
|
860
|
-
const darkColorRule = {
|
|
861
|
-
name: "darkColor",
|
|
862
|
-
defaultErrorMessage: "The :input must be a dark color",
|
|
863
|
-
async validate(value, context) {
|
|
864
|
-
if (value.match(colorValidationRegex.dark)) {
|
|
865
|
-
return VALID_RULE;
|
|
866
|
-
}
|
|
867
|
-
return invalidRule(this, context);
|
|
868
|
-
},
|
|
869
|
-
};
|
|
870
|
-
const colorRule = {
|
|
871
|
-
name: "color",
|
|
872
|
-
defaultErrorMessage: "The :input must be a valid color",
|
|
873
|
-
async validate(value, context) {
|
|
874
|
-
if (value.match(colorValidationRegex.hex) ||
|
|
875
|
-
value.match(colorValidationRegex.rgb) ||
|
|
876
|
-
value.match(colorValidationRegex.rgba) ||
|
|
877
|
-
value.match(colorValidationRegex.hsl)) {
|
|
878
|
-
return VALID_RULE;
|
|
879
|
-
}
|
|
880
|
-
return invalidRule(this, context);
|
|
881
|
-
},
|
|
882
|
-
};
|
|
883
|
-
const forbiddenRule = {
|
|
884
|
-
name: "forbidden",
|
|
885
|
-
defaultErrorMessage: "The :input is forbidden",
|
|
886
|
-
async validate(_value, context) {
|
|
887
|
-
return invalidRule(this, context);
|
|
888
|
-
},
|
|
889
|
-
};
|
|
890
|
-
/**
|
|
891
|
-
* When rule applies a condition validation rule based on another field value
|
|
892
|
-
*/
|
|
893
|
-
const whenRule = {
|
|
894
|
-
name: "when",
|
|
895
|
-
description: "Apply conditional validation rules based on another field value",
|
|
896
|
-
async validate(value, context) {
|
|
897
|
-
const { field, is, otherwise, local } = this.context.options;
|
|
898
|
-
const parent = local ? context.parent : context.allValues;
|
|
899
|
-
const fieldValue = get(parent, field);
|
|
900
|
-
const condition = is[fieldValue] || otherwise;
|
|
901
|
-
if (condition) {
|
|
902
|
-
const result = await condition.validate(value, context);
|
|
903
|
-
if (!result.isValid) {
|
|
904
|
-
return {
|
|
905
|
-
isValid: false,
|
|
906
|
-
error: result.errors[0].error,
|
|
907
|
-
input: result.errors[0].input,
|
|
908
|
-
path: context.path,
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
return VALID_RULE;
|
|
913
|
-
},
|
|
914
|
-
};export{allowedValuesRule,alphaNumericRule,alphaRule,arrayRule,booleanRule,colorRule,containsRule,darkColorRule,dateRule,emailRule,endsWithRule,enumRule,equalRule,fileExtensionRule,fileRule,fileTypeRule,floatRule,forbiddenRule,hexColorRule,hslColorRule,imageRule,inRule,intRule,ip4Rule,ip6Rule,ipRule,isCreditCardRule,isNumericRule,lengthRule,lightColorRule,matchesRule,maxDateRule,maxFileSizeRule,maxHeightRule,maxLengthRule,maxRule,maxWidthRule,maxWordsRule,minDateRule,minFileSizeRule,minHeightRule,minLengthRule,minRule,minWidthRule,minWordsRule,moduloRule,notAllowedValuesRule,notContainsRule,numberRule,objectRule,patternRule,positiveRule,requiredIfAbsentRule,requiredIfEmptyRule,requiredIfFieldRule,requiredIfSiblingFieldAllAbsentRule,requiredIfSiblingFieldEmptyRule,requiredIfSiblingFieldIsAbsentRule,requiredIfSiblingFieldRule,requiredRule,requiredUnlessSiblingFieldRule,requiredWithRule,rgbColorRule,rgbaColorRule,scalarRule,startsWithRule,stringRule,uniqueArrayRule,unknownKeyRule,uploadableRule,urlRule,whenRule,withoutWhitespaceRule,wordsRule};//# sourceMappingURL=rules.js.map
|