@warlock.js/notifications 5.0.2 → 5.2.2
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/CHANGELOG.md +28 -0
- package/README.md +8 -0
- package/cjs/{channel_api-CH3DxhRU.cjs → channel_api-ChOeNKM1.cjs} +42 -42
- package/cjs/channel_api-ChOeNKM1.cjs.map +1 -0
- package/cjs/index.cjs +1 -1
- package/cjs/index.cjs.map +1 -1
- package/cjs/rabbitmq-driver-Drn1T40o.cjs +3 -0
- package/cjs/{src-Cus6pYPC.cjs → src-Dy5nwVcs.cjs} +57 -29
- package/cjs/src-Dy5nwVcs.cjs.map +1 -0
- package/esm/channels/database-channel.d.mts.map +1 -1
- package/esm/config.d.mts.map +1 -1
- package/esm/dispatch/define-channel.d.mts.map +1 -1
- package/esm/dispatch/define-notification.d.mts.map +1 -1
- package/esm/dispatch/define-notification.mjs.map +1 -1
- package/esm/dispatch/notifications-event-bus.mjs.map +1 -1
- package/esm/dispatch/notify.mjs.map +1 -1
- package/esm/errors.d.mts.map +1 -1
- package/esm/herald/src/communicators/broker.mjs.map +1 -1
- package/esm/herald/src/drivers/rabbitmq/rabbitmq-channel.mjs.map +1 -1
- package/esm/herald/src/drivers/rabbitmq/rabbitmq-driver.mjs +1 -1
- package/esm/herald/src/drivers/rabbitmq/rabbitmq-driver.mjs.map +1 -1
- package/esm/herald/src/message-managers/event-consumer.mjs.map +1 -1
- package/esm/herald/src/message-managers/event-message.mjs.map +1 -1
- package/esm/herald/src/message-managers/prepare-consumer-subscription.mjs.map +1 -1
- package/esm/herald/src/use-case-broadcast.mjs.map +1 -1
- package/esm/herald/src/utils/connect-to-broker.mjs.map +1 -1
- package/esm/in-app/base-notifications-repository.d.mts.map +1 -1
- package/esm/in-app/database-notification.d.mts.map +1 -1
- package/esm/in-app/in-app.d.mts.map +1 -1
- package/esm/migration/notification-columns.mjs.map +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/Random/_internal.mjs +6 -0
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/Random/_internal.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/mixed/clone/clone.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/mixed/clone/clone.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/number/round.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/number/round.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/object/except.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/object/except.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/object/get.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/object/get.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/object/omit.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/object/omit.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/object/unset.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/object/unset.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/capitalize.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/capitalize.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/ltrim.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/ltrim.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/readMoreChars.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/readMoreChars.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/rtrim.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/rtrim.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/toCamelCase.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/toCamelCase.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/toKebabCase.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/toKebabCase.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/toSnakeCase.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/toSnakeCase.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/toStudlyCase.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/toStudlyCase.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/trim.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/trim.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/ucfirst.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/ucfirst.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/string/words.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/string/words.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/utils/escapeRegex.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/utils/escapeRegex.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/utils/lazy.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/utils/lazy.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/utils/tap.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/utils/tap.mjs.map +1 -0
- package/esm/node_modules/{@mongez → .pnpm/@mongez_supportive-is@2.1.4/node_modules/@mongez}/supportive-is/esm/index.mjs +1 -1
- package/esm/node_modules/.pnpm/@mongez_supportive-is@2.1.4/node_modules/@mongez/supportive-is/esm/index.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/channel_api.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/channel_api.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/api_args.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/api_args.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/bitset.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/bitset.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/channel.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/channel.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/channel_model.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/channel_model.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/codec.mjs +3 -3
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/codec.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/connect.mjs +3 -3
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/connect.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/connection.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/connection.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/credentials.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/credentials.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/defs.mjs +3 -3
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/defs.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/error.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/error.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/format.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/format.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/frame.mjs +3 -3
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/frame.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/heartbeat.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/heartbeat.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/lib/mux.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/lib/mux.mjs.map +1 -0
- package/esm/node_modules/{amqplib → .pnpm/amqplib@0.10.9/node_modules/amqplib}/package.mjs +2 -2
- package/esm/node_modules/.pnpm/amqplib@0.10.9/node_modules/amqplib/package.mjs.map +1 -0
- package/esm/node_modules/{buffer-more-ints → .pnpm/buffer-more-ints@1.0.0/node_modules/buffer-more-ints}/buffer-more-ints.mjs +2 -2
- package/esm/node_modules/.pnpm/buffer-more-ints@1.0.0/node_modules/buffer-more-ints/buffer-more-ints.mjs.map +1 -0
- package/esm/node_modules/{dayjs → .pnpm/dayjs@1.11.23/node_modules/dayjs}/dayjs.min.mjs +2 -2
- package/esm/node_modules/.pnpm/dayjs@1.11.23/node_modules/dayjs/dayjs.min.mjs.map +1 -0
- package/esm/node_modules/{querystringify → .pnpm/querystringify@2.2.0/node_modules/querystringify}/index.mjs +2 -2
- package/esm/node_modules/.pnpm/querystringify@2.2.0/node_modules/querystringify/index.mjs.map +1 -0
- package/esm/node_modules/{requires-port → .pnpm/requires-port@1.0.0/node_modules/requires-port}/index.mjs +2 -2
- package/esm/node_modules/.pnpm/requires-port@1.0.0/node_modules/requires-port/index.mjs.map +1 -0
- package/esm/node_modules/{url-parse → .pnpm/url-parse@1.5.10/node_modules/url-parse}/index.mjs +4 -4
- package/esm/node_modules/.pnpm/url-parse@1.5.10/node_modules/url-parse/index.mjs.map +1 -0
- package/esm/queue/herald-queue.mjs.map +1 -1
- package/esm/queue/notifications-worker.mjs.map +1 -1
- package/esm/seal/src/factory/validators.mjs.map +1 -1
- package/esm/seal/src/helpers/get-field-value.mjs +2 -2
- package/esm/seal/src/helpers/is-empty-value.mjs +1 -1
- package/esm/seal/src/helpers/validation-helpers.mjs.map +1 -1
- package/esm/seal/src/mutators/array-mutators.mjs +2 -2
- package/esm/seal/src/mutators/date-mutators.mjs +1 -1
- package/esm/seal/src/mutators/number-mutators.mjs +3 -3
- package/esm/seal/src/mutators/number-mutators.mjs.map +1 -1
- package/esm/seal/src/mutators/object-mutators.mjs +3 -3
- package/esm/seal/src/mutators/scalar-mutators.mjs.map +1 -1
- package/esm/seal/src/mutators/string-mutators.mjs +10 -10
- package/esm/seal/src/mutators/string-mutators.mjs.map +1 -1
- package/esm/seal/src/rules/array/array-rules.mjs.map +1 -1
- package/esm/seal/src/rules/common/enum.mjs.map +1 -1
- package/esm/seal/src/rules/common/literal.mjs.map +1 -1
- package/esm/seal/src/rules/common/type-rules.mjs +1 -1
- package/esm/seal/src/rules/common/unknown-key.mjs.map +1 -1
- package/esm/seal/src/rules/conditional/present-with-rules.mjs +2 -2
- package/esm/seal/src/rules/conditional/present-without-rules.mjs +2 -2
- package/esm/seal/src/rules/conditional/required-if-rules.mjs +2 -2
- package/esm/seal/src/rules/conditional/required-if-rules.mjs.map +1 -1
- package/esm/seal/src/rules/conditional/required-with-rules.mjs +2 -2
- package/esm/seal/src/rules/conditional/required-without-rules.mjs +2 -2
- package/esm/seal/src/rules/core/union.mjs.map +1 -1
- package/esm/seal/src/rules/core/when.mjs +2 -2
- package/esm/seal/src/rules/core/when.mjs.map +1 -1
- package/esm/seal/src/rules/date/date-day-rules.mjs.map +1 -1
- package/esm/seal/src/rules/date/date-field-comparison-rules.mjs +2 -2
- package/esm/seal/src/rules/date/date-period-rules.mjs +2 -2
- package/esm/seal/src/rules/date/date-period-rules.mjs.map +1 -1
- package/esm/seal/src/rules/date/date-special-rules.mjs.map +1 -1
- package/esm/seal/src/rules/date/date.mjs +2 -2
- package/esm/seal/src/rules/date/date.mjs.map +1 -1
- package/esm/seal/src/rules/length/length-rules.mjs.map +1 -1
- package/esm/seal/src/rules/number/number-rules.mjs +2 -2
- package/esm/seal/src/rules/scalar/accepted-rule.mjs.map +1 -1
- package/esm/seal/src/rules/scalar/declined-rule.mjs.map +1 -1
- package/esm/seal/src/rules/string/credit-card.mjs.map +1 -1
- package/esm/seal/src/rules/string/email.mjs +1 -1
- package/esm/seal/src/rules/string/id-formats.mjs.map +1 -1
- package/esm/seal/src/rules/string/matches.mjs +1 -1
- package/esm/seal/src/rules/string/string-comparison.mjs.map +1 -1
- package/esm/seal/src/standard-schema/json-schema.mjs.map +1 -1
- package/esm/seal/src/standard-schema/map-result.mjs.map +1 -1
- package/esm/seal/src/validators/base-validator.mjs +2 -2
- package/esm/seal/src/validators/date-validator.mjs +1 -1
- package/esm/seal/src/validators/date-validator.mjs.map +1 -1
- package/esm/seal/src/validators/discriminated-union-validator.mjs +1 -1
- package/esm/seal/src/validators/discriminated-union-validator.mjs.map +1 -1
- package/esm/seal/src/validators/lazy-validator.mjs.map +1 -1
- package/esm/seal/src/validators/methods/required-methods.mjs.map +1 -1
- package/esm/seal/src/validators/numeric-validator.mjs +1 -1
- package/esm/seal/src/validators/object-validator.mjs +3 -3
- package/esm/seal/src/validators/object-validator.mjs.map +1 -1
- package/esm/seal/src/validators/record-validator.mjs +1 -1
- package/esm/seal/src/validators/record-validator.mjs.map +1 -1
- package/esm/seal/src/validators/scalar-validator.mjs.map +1 -1
- package/esm/seal/src/validators/union-validator.mjs.map +1 -1
- package/llms-full.txt +4 -0
- package/package.json +9 -6
- package/skills/notifications-basics/SKILL.md +4 -0
- package/cjs/channel_api-CH3DxhRU.cjs.map +0 -1
- package/cjs/chunk-fl3r8ClO.cjs +0 -41
- package/cjs/rabbitmq-driver-CJtyxjUQ.cjs +0 -3
- package/cjs/src-Cus6pYPC.cjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/Random/_internal.mjs +0 -6
- package/esm/node_modules/@mongez/reinforcements/esm/Random/_internal.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/mixed/clone/clone.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/number/round.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/object/except.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/object/get.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/object/omit.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/object/unset.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/capitalize.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/ltrim.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/readMoreChars.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/rtrim.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/toCamelCase.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/toKebabCase.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/toSnakeCase.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/toStudlyCase.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/trim.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/ucfirst.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/string/words.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/utils/escapeRegex.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/utils/lazy.mjs.map +0 -1
- package/esm/node_modules/@mongez/reinforcements/esm/utils/tap.mjs.map +0 -1
- package/esm/node_modules/@mongez/supportive-is/esm/index.mjs.map +0 -1
- package/esm/node_modules/amqplib/channel_api.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/api_args.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/bitset.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/channel.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/channel_model.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/codec.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/connect.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/connection.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/credentials.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/defs.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/error.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/format.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/frame.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/heartbeat.mjs.map +0 -1
- package/esm/node_modules/amqplib/lib/mux.mjs.map +0 -1
- package/esm/node_modules/amqplib/package.mjs.map +0 -1
- package/esm/node_modules/buffer-more-ints/buffer-more-ints.mjs.map +0 -1
- package/esm/node_modules/dayjs/dayjs.min.mjs.map +0 -1
- package/esm/node_modules/querystringify/index.mjs.map +0 -1
- package/esm/node_modules/requires-port/index.mjs.map +0 -1
- package/esm/node_modules/url-parse/index.mjs.map +0 -1
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/bool.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/color.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/date.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/float.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/id.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/int.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/nanoid.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/pick.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/random.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/sample.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/string.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/token.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/uuid.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/Random/weighted.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/async/retry.mjs +0 -0
- /package/esm/node_modules/{@mongez → .pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez}/reinforcements/esm/index.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/date/date.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\r\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isDateValue } from \"../../helpers/date-helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\nimport type { WeekDay } from \"../../types/date-types\";\r\nimport { WEEK_DAYS } from \"../../types/date-types\";\r\n\r\n/**\r\n * Date rule - validates date format\r\n */\r\nexport const dateRule: SchemaRule = {\r\n name: \"date\",\r\n defaultErrorMessage: \"The :input must be a valid date\",\r\n async validate(value: any, context) {\r\n if (value instanceof Date && !isNaN(value.getTime())) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Min date rule - date must be >= given date or field\r\n * Smart detection: date value or field name\r\n */\r\nexport const minDateRule: SchemaRule<{\r\n dateOrField: Date | string | number;\r\n scope?: \"global\" | \"sibling\";\r\n}> = {\r\n name: \"minDate\",\r\n description: \"The field must be at least the given date or field\",\r\n defaultErrorMessage: \"The :input must be at least :dateOrField\",\r\n async validate(value: Date, context) {\r\n const { dateOrField, scope = \"global\" } = this.context.options;\r\n let compareDate: Date;\r\n\r\n if (isDateValue(dateOrField)) {\r\n // Value comparison\r\n compareDate = new Date(dateOrField);\r\n } else {\r\n // Field comparison\r\n const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n const fieldValue = get(source, dateOrField as string);\r\n\r\n if (fieldValue === undefined) {\r\n return VALID_RULE;\r\n }\r\n\r\n compareDate = new Date(fieldValue);\r\n }\r\n\r\n const inputDate = new Date(value);\r\n\r\n if (inputDate >= compareDate) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max date rule - date must be <= given date or field\r\n * Smart detection: date value or field name\r\n */\r\nexport const maxDateRule: SchemaRule<{\r\n dateOrField: Date | string | number;\r\n scope?: \"global\" | \"sibling\";\r\n}> = {\r\n name: \"maxDate\",\r\n defaultErrorMessage: \"The :input must be at most :dateOrField\",\r\n async validate(value: Date, context) {\r\n const { dateOrField, scope = \"global\" } = this.context.options;\r\n let compareDate: Date;\r\n\r\n if (isDateValue(dateOrField)) {\r\n // Value comparison\r\n compareDate = new Date(dateOrField);\r\n } else {\r\n // Field comparison\r\n const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n const fieldValue = get(source, dateOrField as string);\r\n\r\n if (fieldValue === undefined) {\r\n return VALID_RULE;\r\n }\r\n\r\n compareDate = new Date(fieldValue);\r\n }\r\n\r\n const inputDate = new Date(value);\r\n\r\n if (inputDate <= compareDate) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * From today rule - date must be today or in the future\r\n */\r\nexport const fromTodayRule: SchemaRule = {\r\n name: \"fromToday\",\r\n defaultErrorMessage: \"The :input must be today or in the future\",\r\n async validate(value: Date, context) {\r\n const today = new Date();\r\n today.setHours(0, 0, 0, 0);\r\n const inputDate = new Date(value);\r\n inputDate.setHours(0, 0, 0, 0);\r\n\r\n if (inputDate >= today) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Before today rule - date must be before today\r\n */\r\nexport const beforeTodayRule: SchemaRule = {\r\n name: \"beforeToday\",\r\n defaultErrorMessage: \"The :input must be before today\",\r\n async validate(value: Date, context) {\r\n const today = new Date();\r\n today.setHours(0, 0, 0, 0);\r\n const inputDate = new Date(value);\r\n inputDate.setHours(0, 0, 0, 0);\r\n\r\n if (inputDate < today) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * From hour rule - time must be from specific hour onwards\r\n */\r\nexport const fromHourRule: SchemaRule<{ hour: number }> = {\r\n name: \"fromHour\",\r\n defaultErrorMessage: \"The :input must be from :hour:00 onwards\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const hour = inputDate.getHours();\r\n\r\n if (hour >= this.context.options.hour) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.hour = this.context.options.hour;\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Before hour rule - time must be before specific hour\r\n */\r\nexport const beforeHourRule: SchemaRule<{ hour: number }> = {\r\n name: \"beforeHour\",\r\n defaultErrorMessage: \"The :input must be before :hour:00\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const hour = inputDate.getHours();\r\n\r\n if (hour < this.context.options.hour) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.hour = this.context.options.hour;\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Between hours rule - time must be between start and end hours\r\n */\r\nexport const betweenHoursRule: SchemaRule<{\r\n startHour: number;\r\n endHour: number;\r\n}> = {\r\n name: \"betweenHours\",\r\n defaultErrorMessage: \"The :input must be between :startHour:00 and :endHour:00\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const hour = inputDate.getHours();\r\n const { startHour, endHour } = this.context.options;\r\n\r\n if (hour >= startHour && hour <= endHour) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.startHour = startHour;\r\n this.context.translationParams.endHour = endHour;\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * From minute rule - time must be from specific minute onwards\r\n */\r\nexport const fromMinuteRule: SchemaRule<{ minute: number }> = {\r\n name: \"fromMinute\",\r\n defaultErrorMessage: \"The :input must be from minute :minute onwards\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const minute = inputDate.getMinutes();\r\n\r\n if (minute >= this.context.options.minute) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minute = this.context.options.minute;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Before minute rule - time must be before specific minute\r\n */\r\nexport const beforeMinuteRule: SchemaRule<{ minute: number }> = {\r\n name: \"beforeMinute\",\r\n defaultErrorMessage: \"The :input must be before minute :minute\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const minute = inputDate.getMinutes();\r\n\r\n if (minute < this.context.options.minute) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minute = this.context.options.minute;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Between minutes rule - time must be between start and end minutes\r\n */\r\nexport const betweenMinutesRule: SchemaRule<{\r\n startMinute: number;\r\n endMinute: number;\r\n}> = {\r\n name: \"betweenMinutes\",\r\n defaultErrorMessage: \"The :input must be between minute :startMinute and :endMinute\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const minute = inputDate.getMinutes();\r\n const { startMinute, endMinute } = this.context.options;\r\n\r\n if (minute >= startMinute && minute <= endMinute) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.startMinute = startMinute;\r\n this.context.translationParams.endMinute = endMinute;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Age rule - calculate age from date\r\n */\r\nexport const ageRule: SchemaRule<{ years: number }> = {\r\n name: \"age\",\r\n defaultErrorMessage: \"The :input must be exactly :years years old\",\r\n async validate(value: Date, context) {\r\n const birthDate = new Date(value);\r\n const today = new Date();\r\n let age = today.getFullYear() - birthDate.getFullYear();\r\n const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n age--;\r\n }\r\n\r\n if (age === this.context.options.years) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.years = this.context.options.years;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Min age rule - minimum age requirement\r\n */\r\nexport const minAgeRule: SchemaRule<{ years: number }> = {\r\n name: \"minAge\",\r\n defaultErrorMessage: \"The :input must be at least :years years old\",\r\n async validate(value: Date, context) {\r\n const birthDate = new Date(value);\r\n const today = new Date();\r\n let age = today.getFullYear() - birthDate.getFullYear();\r\n const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n age--;\r\n }\r\n\r\n if (age >= this.context.options.years) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.years = this.context.options.years;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max age rule - maximum age requirement\r\n */\r\nexport const maxAgeRule: SchemaRule<{ years: number }> = {\r\n name: \"maxAge\",\r\n defaultErrorMessage: \"The :input must be at most :years years old\",\r\n async validate(value: Date, context) {\r\n const birthDate = new Date(value);\r\n const today = new Date();\r\n let age = today.getFullYear() - birthDate.getFullYear();\r\n const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n age--;\r\n }\r\n\r\n if (age <= this.context.options.years) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.years = this.context.options.years;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Week day rule - date must be specific weekday\r\n */\r\nexport const weekDayRule: SchemaRule<{ day: WeekDay }> = {\r\n name: \"weekDay\",\r\n defaultErrorMessage: \"The :input must be a :day\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const dayOfWeek = inputDate.getDay();\r\n const expectedDay = WEEK_DAYS[this.context.options.day];\r\n\r\n if (dayOfWeek === expectedDay) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.day = this.context.options.day;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,WAAuB;CAClC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,iBAAiB,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,GACjD,OAAO;EAGT,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;AAMA,MAAa,cAGR;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ,aAAa,KAAK,QAAQ;EACvD,IAAI;EAEJ,IAAI,YAAY,WAAW,GAEzB,cAAc,IAAI,KAAK,WAAW;OAC7B;GAGL,MAAM,aAAa,IADJ,UAAU,YAAY,QAAQ,SAAS,QAAQ,WAC/B,WAAqB;GAEpD,IAAI,eAAe,QACjB,OAAO;GAGT,cAAc,IAAI,KAAK,UAAU;EACnC;EAIA,IAAI,IAFkB,KAAK,KAEf,KAAK,aACf,OAAO;EAET,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;AAMA,MAAa,cAGR;CACH,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ,aAAa,KAAK,QAAQ;EACvD,IAAI;EAEJ,IAAI,YAAY,WAAW,GAEzB,cAAc,IAAI,KAAK,WAAW;OAC7B;GAGL,MAAM,aAAa,IADJ,UAAU,YAAY,QAAQ,SAAS,QAAQ,WAC/B,WAAqB;GAEpD,IAAI,eAAe,QACjB,OAAO;GAGT,cAAc,IAAI,KAAK,UAAU;EACnC;EAIA,IA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AAO;EAGT,KAAK,QAAQ,kBAAkB,QAAQ,KAAK,QAAQ,QAAQ;EAE5D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,cAA4C;CACvD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EAKnC,IAHkB,IADI,KAAK,KACD,CAAC,CAAC,OAGhB,MAFQ,UAAU,KAAK,QAAQ,QAAQ,MAGjD,OAAO;EAGT,KAAK,QAAQ,mBAAmB,MAAM,KAAK,QAAQ,QAAQ;EAE3D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}
|
|
1
|
+
{"version":3,"file":"date.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/date/date.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\r\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isDateValue } from \"../../helpers/date-helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\nimport type { WeekDay } from \"../../types/date-types\";\r\nimport { WEEK_DAYS } from \"../../types/date-types\";\r\n\r\n/**\r\n * Date rule - validates date format\r\n */\r\nexport const dateRule: SchemaRule = {\r\n name: \"date\",\r\n defaultErrorMessage: \"The :input must be a valid date\",\r\n async validate(value: any, context) {\r\n if (value instanceof Date && !isNaN(value.getTime())) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Min date rule - date must be >= given date or field\r\n * Smart detection: date value or field name\r\n */\r\nexport const minDateRule: SchemaRule<{\r\n dateOrField: Date | string | number;\r\n scope?: \"global\" | \"sibling\";\r\n}> = {\r\n name: \"minDate\",\r\n description: \"The field must be at least the given date or field\",\r\n defaultErrorMessage: \"The :input must be at least :dateOrField\",\r\n async validate(value: Date, context) {\r\n const { dateOrField, scope = \"global\" } = this.context.options;\r\n let compareDate: Date;\r\n\r\n if (isDateValue(dateOrField)) {\r\n // Value comparison\r\n compareDate = new Date(dateOrField);\r\n } else {\r\n // Field comparison\r\n const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n const fieldValue = get(source, dateOrField as string);\r\n\r\n if (fieldValue === undefined) {\r\n return VALID_RULE;\r\n }\r\n\r\n compareDate = new Date(fieldValue);\r\n }\r\n\r\n const inputDate = new Date(value);\r\n\r\n if (inputDate >= compareDate) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max date rule - date must be <= given date or field\r\n * Smart detection: date value or field name\r\n */\r\nexport const maxDateRule: SchemaRule<{\r\n dateOrField: Date | string | number;\r\n scope?: \"global\" | \"sibling\";\r\n}> = {\r\n name: \"maxDate\",\r\n defaultErrorMessage: \"The :input must be at most :dateOrField\",\r\n async validate(value: Date, context) {\r\n const { dateOrField, scope = \"global\" } = this.context.options;\r\n let compareDate: Date;\r\n\r\n if (isDateValue(dateOrField)) {\r\n // Value comparison\r\n compareDate = new Date(dateOrField);\r\n } else {\r\n // Field comparison\r\n const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n const fieldValue = get(source, dateOrField as string);\r\n\r\n if (fieldValue === undefined) {\r\n return VALID_RULE;\r\n }\r\n\r\n compareDate = new Date(fieldValue);\r\n }\r\n\r\n const inputDate = new Date(value);\r\n\r\n if (inputDate <= compareDate) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * From today rule - date must be today or in the future\r\n */\r\nexport const fromTodayRule: SchemaRule = {\r\n name: \"fromToday\",\r\n defaultErrorMessage: \"The :input must be today or in the future\",\r\n async validate(value: Date, context) {\r\n const today = new Date();\r\n today.setHours(0, 0, 0, 0);\r\n const inputDate = new Date(value);\r\n inputDate.setHours(0, 0, 0, 0);\r\n\r\n if (inputDate >= today) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Before today rule - date must be before today\r\n */\r\nexport const beforeTodayRule: SchemaRule = {\r\n name: \"beforeToday\",\r\n defaultErrorMessage: \"The :input must be before today\",\r\n async validate(value: Date, context) {\r\n const today = new Date();\r\n today.setHours(0, 0, 0, 0);\r\n const inputDate = new Date(value);\r\n inputDate.setHours(0, 0, 0, 0);\r\n\r\n if (inputDate < today) {\r\n return VALID_RULE;\r\n }\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * From hour rule - time must be from specific hour onwards\r\n */\r\nexport const fromHourRule: SchemaRule<{ hour: number }> = {\r\n name: \"fromHour\",\r\n defaultErrorMessage: \"The :input must be from :hour:00 onwards\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const hour = inputDate.getHours();\r\n\r\n if (hour >= this.context.options.hour) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.hour = this.context.options.hour;\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Before hour rule - time must be before specific hour\r\n */\r\nexport const beforeHourRule: SchemaRule<{ hour: number }> = {\r\n name: \"beforeHour\",\r\n defaultErrorMessage: \"The :input must be before :hour:00\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const hour = inputDate.getHours();\r\n\r\n if (hour < this.context.options.hour) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.hour = this.context.options.hour;\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Between hours rule - time must be between start and end hours\r\n */\r\nexport const betweenHoursRule: SchemaRule<{\r\n startHour: number;\r\n endHour: number;\r\n}> = {\r\n name: \"betweenHours\",\r\n defaultErrorMessage: \"The :input must be between :startHour:00 and :endHour:00\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const hour = inputDate.getHours();\r\n const { startHour, endHour } = this.context.options;\r\n\r\n if (hour >= startHour && hour <= endHour) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.startHour = startHour;\r\n this.context.translationParams.endHour = endHour;\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * From minute rule - time must be from specific minute onwards\r\n */\r\nexport const fromMinuteRule: SchemaRule<{ minute: number }> = {\r\n name: \"fromMinute\",\r\n defaultErrorMessage: \"The :input must be from minute :minute onwards\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const minute = inputDate.getMinutes();\r\n\r\n if (minute >= this.context.options.minute) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minute = this.context.options.minute;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Before minute rule - time must be before specific minute\r\n */\r\nexport const beforeMinuteRule: SchemaRule<{ minute: number }> = {\r\n name: \"beforeMinute\",\r\n defaultErrorMessage: \"The :input must be before minute :minute\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const minute = inputDate.getMinutes();\r\n\r\n if (minute < this.context.options.minute) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minute = this.context.options.minute;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Between minutes rule - time must be between start and end minutes\r\n */\r\nexport const betweenMinutesRule: SchemaRule<{\r\n startMinute: number;\r\n endMinute: number;\r\n}> = {\r\n name: \"betweenMinutes\",\r\n defaultErrorMessage: \"The :input must be between minute :startMinute and :endMinute\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const minute = inputDate.getMinutes();\r\n const { startMinute, endMinute } = this.context.options;\r\n\r\n if (minute >= startMinute && minute <= endMinute) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.startMinute = startMinute;\r\n this.context.translationParams.endMinute = endMinute;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Age rule - calculate age from date\r\n */\r\nexport const ageRule: SchemaRule<{ years: number }> = {\r\n name: \"age\",\r\n defaultErrorMessage: \"The :input must be exactly :years years old\",\r\n async validate(value: Date, context) {\r\n const birthDate = new Date(value);\r\n const today = new Date();\r\n let age = today.getFullYear() - birthDate.getFullYear();\r\n const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n age--;\r\n }\r\n\r\n if (age === this.context.options.years) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.years = this.context.options.years;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Min age rule - minimum age requirement\r\n */\r\nexport const minAgeRule: SchemaRule<{ years: number }> = {\r\n name: \"minAge\",\r\n defaultErrorMessage: \"The :input must be at least :years years old\",\r\n async validate(value: Date, context) {\r\n const birthDate = new Date(value);\r\n const today = new Date();\r\n let age = today.getFullYear() - birthDate.getFullYear();\r\n const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n age--;\r\n }\r\n\r\n if (age >= this.context.options.years) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.years = this.context.options.years;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max age rule - maximum age requirement\r\n */\r\nexport const maxAgeRule: SchemaRule<{ years: number }> = {\r\n name: \"maxAge\",\r\n defaultErrorMessage: \"The :input must be at most :years years old\",\r\n async validate(value: Date, context) {\r\n const birthDate = new Date(value);\r\n const today = new Date();\r\n let age = today.getFullYear() - birthDate.getFullYear();\r\n const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n age--;\r\n }\r\n\r\n if (age <= this.context.options.years) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.years = this.context.options.years;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Week day rule - date must be specific weekday\r\n */\r\nexport const weekDayRule: SchemaRule<{ day: WeekDay }> = {\r\n name: \"weekDay\",\r\n defaultErrorMessage: \"The :input must be a :day\",\r\n async validate(value: Date, context) {\r\n const inputDate = new Date(value);\r\n const dayOfWeek = inputDate.getDay();\r\n const expectedDay = WEEK_DAYS[this.context.options.day];\r\n\r\n if (dayOfWeek === expectedDay) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.day = this.context.options.day;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,WAAuB;CAClC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,iBAAiB,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,GACjD,OAAO;EAGT,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;AAMA,MAAa,cAGR;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ,aAAa,KAAK,QAAQ;EACvD,IAAI;EAEJ,IAAI,YAAY,WAAW,GAEzB,cAAc,IAAI,KAAK,WAAW;OAC7B;GAGL,MAAM,aAAa,IADJ,UAAU,YAAY,QAAQ,SAAS,QAAQ,WAC/B,WAAqB;GAEpD,IAAI,eAAe,QACjB,OAAO;GAGT,cAAc,IAAI,KAAK,UAAU;EACnC;EAIA,IAAI,IAFkB,KAAK,KAEf,KAAK,aACf,OAAO;EAET,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;AAMA,MAAa,cAGR;CACH,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ,aAAa,KAAK,QAAQ;EACvD,IAAI;EAEJ,IAAI,YAAY,WAAW,GAEzB,cAAc,IAAI,KAAK,WAAW;OAC7B;GAGL,MAAM,aAAa,IADJ,UAAU,YAAY,QAAQ,SAAS,QAAQ,WAC/B,WAAqB;GAEpD,IAAI,eAAe,QACjB,OAAO;GAGT,cAAc,IAAI,KAAK,UAAU;EACnC;EAIA,IA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Q,KAAK,QAAQ,QAAQ;EAE5D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,cAA4C;CACvD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EAKnC,IAHkB,IADI,KAAK,KACD,EAAE,OAGhB,MAFQ,UAAU,KAAK,QAAQ,QAAQ,MAGjD,OAAO;EAGT,KAAK,QAAQ,mBAAmB,MAAM,KAAK,QAAQ,QAAQ;EAE3D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"length-rules.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/length/length-rules.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Min length rule - validates minimum length\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const minLengthRule: SchemaRule<{ minLength: number }> = {\r\n name: \"minLength\",\r\n defaultErrorMessage: \"The :input must be at least :minLength characters long\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length >= this.context.options.minLength) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minLength = this.context.options.minLength;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max length rule - validates maximum length\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const maxLengthRule: SchemaRule<{ maxLength: number }> = {\r\n name: \"maxLength\",\r\n defaultErrorMessage: \"The :input must not exceed :maxLength characters\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length <= this.context.options.maxLength) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.maxLength = this.context.options.maxLength;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Between length rule - validates length is between min and max (inclusive)\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const betweenLengthRule: SchemaRule<{\r\n minLength: number;\r\n maxLength: number;\r\n}> = {\r\n name: \"betweenLength\",\r\n defaultErrorMessage: \"The :input must be between :minLength and :maxLength characters long\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length >= this.context.options.minLength && length <= this.context.options.maxLength) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minLength = this.context.options.minLength;\r\n this.context.translationParams.maxLength = this.context.options.maxLength;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Length rule - validates exact length\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const lengthRule: SchemaRule<{ length: number }> = {\r\n name: \"length\",\r\n defaultErrorMessage: \"The :input must be exactly :length characters long\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length === this.context.options.length) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.length = this.context.options.length;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Min words rule - validates minimum word count\r\n */\r\nexport const minWordsRule: SchemaRule<{ minWords: number }> = {\r\n name: \"minWords\",\r\n defaultErrorMessage: \"The :input must be at least :minWords words\",\r\n async validate(value: any, context) {\r\n if (String(value || \"\").split(\" \").length >= this.context.options.minWords) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minWords = this.context.options.minWords;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max words rule - validates maximum word count\r\n */\r\nexport const maxWordsRule: SchemaRule<{ maxWords: number }> = {\r\n name: \"maxWords\",\r\n defaultErrorMessage: \"The :input must be at most :maxWords words\",\r\n async validate(value: any, context) {\r\n if (String(value || \"\").split(\" \").length <= this.context.options.maxWords) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.maxWords = this.context.options.maxWords;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Words rule - validates exact word count\r\n */\r\nexport const wordsRule: SchemaRule<{ words: number }> = {\r\n name: \"words\",\r\n defaultErrorMessage: \"The :input must be exactly :words words\",\r\n async validate(value: any, context) {\r\n if (String(value || \"\").split(\" \").length === this.context.options.words) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.words = this.context.options.words;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;;AAOA,MAAa,gBAAmD;CAC9D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAGlC,KAFe,OAAO,OAAO,WAAW,WAAW,MAAM,SAAS,OAAO,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"length-rules.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/length/length-rules.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Min length rule - validates minimum length\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const minLengthRule: SchemaRule<{ minLength: number }> = {\r\n name: \"minLength\",\r\n defaultErrorMessage: \"The :input must be at least :minLength characters long\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length >= this.context.options.minLength) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minLength = this.context.options.minLength;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max length rule - validates maximum length\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const maxLengthRule: SchemaRule<{ maxLength: number }> = {\r\n name: \"maxLength\",\r\n defaultErrorMessage: \"The :input must not exceed :maxLength characters\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length <= this.context.options.maxLength) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.maxLength = this.context.options.maxLength;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Between length rule - validates length is between min and max (inclusive)\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const betweenLengthRule: SchemaRule<{\r\n minLength: number;\r\n maxLength: number;\r\n}> = {\r\n name: \"betweenLength\",\r\n defaultErrorMessage: \"The :input must be between :minLength and :maxLength characters long\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length >= this.context.options.minLength && length <= this.context.options.maxLength) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minLength = this.context.options.minLength;\r\n this.context.translationParams.maxLength = this.context.options.maxLength;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Length rule - validates exact length\r\n * Works for any value with a length property (strings, arrays, etc.)\r\n */\r\nexport const lengthRule: SchemaRule<{ length: number }> = {\r\n name: \"length\",\r\n defaultErrorMessage: \"The :input must be exactly :length characters long\",\r\n async validate(value: any, context) {\r\n const length = typeof value?.length === \"number\" ? value.length : String(value || \"\").length;\r\n\r\n if (length === this.context.options.length) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.length = this.context.options.length;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Min words rule - validates minimum word count\r\n */\r\nexport const minWordsRule: SchemaRule<{ minWords: number }> = {\r\n name: \"minWords\",\r\n defaultErrorMessage: \"The :input must be at least :minWords words\",\r\n async validate(value: any, context) {\r\n if (String(value || \"\").split(\" \").length >= this.context.options.minWords) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.minWords = this.context.options.minWords;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Max words rule - validates maximum word count\r\n */\r\nexport const maxWordsRule: SchemaRule<{ maxWords: number }> = {\r\n name: \"maxWords\",\r\n defaultErrorMessage: \"The :input must be at most :maxWords words\",\r\n async validate(value: any, context) {\r\n if (String(value || \"\").split(\" \").length <= this.context.options.maxWords) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.maxWords = this.context.options.maxWords;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Words rule - validates exact word count\r\n */\r\nexport const wordsRule: SchemaRule<{ words: number }> = {\r\n name: \"words\",\r\n defaultErrorMessage: \"The :input must be exactly :words words\",\r\n async validate(value: any, context) {\r\n if (String(value || \"\").split(\" \").length === this.context.options.words) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translationParams.words = this.context.options.words;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;;AAOA,MAAa,gBAAmD;CAC9D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAGlC,KAFe,OAAO,OAAO,WAAW,WAAW,MAAM,SAAS,OAAO,SAAS,EAAE,EAAE,WAExE,KAAK,QAAQ,QAAQ,WACjC,OAAO;EAGT,KAAK,QAAQ,kBAAkB,YAAY,KAAK,QAAQ,QAAQ;EAEhE,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;AAMA,MAAa,gBAAmD;CAC9D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAGlC,KAFe,OAAO,OAAO,WAAW,WAAW,MAAM,SAAS,OAAO,SAAS,EAAE,EAAE,WAExE,KAAK,QAAQ,QAAQ,WACjC,OAAO;EAGT,KAAK,QAAQ,kBAAkB,YAAY,KAAK,QAAQ,QAAQ;EAEhE,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;AAMA,MAAa,oBAGR;CACH,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,SAAS,OAAO,OAAO,WAAW,WAA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WAAW,KAAK,QAAQ,QAAQ,OACjE,OAAO;EAGT,KAAK,QAAQ,kBAAkB,QAAQ,KAAK,QAAQ,QAAQ;EAE5D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { get } from "../../../../node_modules/@mongez/reinforcements/esm/object/get.mjs";
|
|
2
|
-
import "../../../../node_modules/@mongez/reinforcements/esm/index.mjs";
|
|
1
|
+
import { get } from "../../../../node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/object/get.mjs";
|
|
2
|
+
import "../../../../node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/index.mjs";
|
|
3
3
|
import { VALID_RULE, invalidRule } from "../../helpers/validation-helpers.mjs";
|
|
4
4
|
import "../../helpers/index.mjs";
|
|
5
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accepted-rule.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/scalar/accepted-rule.ts"],"sourcesContent":["import { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isEmptyValue } from \"../../helpers/is-empty-value\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\nconst isAcceptedValue = (value: any) => {\r\n return [\"1\", \"true\", \"yes\", \"y\", \"on\", 1, true, \"Yes\", \"Y\", \"On\"].includes(value);\r\n};\r\n\r\n/**\r\n * Validate value as accepted if it equals:\r\n * 1 | \"1\" | true | \"true\" | \"yes\" | \"y\" | \"on\"\r\n */\r\nexport const acceptedRule: SchemaRule = {\r\n name: \"accepted\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n description:\r\n \"The value must be accepted if it equals: 1 | '1' | true | 'true' | 'yes' | 'y' | 'on' | 1 | true | 'Yes' | 'Y' | 'On'\",\r\n async validate(value: any, context) {\r\n if (isAcceptedValue(value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Accepted value if another field's value equals to a specific value\r\n */\r\nexport const acceptedIfRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"acceptedIf\",\r\n description: \"The field must be accepted if :field's value equals to :value\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n if (fieldValue !== expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is not equal to the given value\r\n */\r\nexport const acceptedUnlessRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"acceptedUnless\",\r\n description: \"The field must be accepted if :field's value is not equal to :value\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n if (fieldValue === expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is required\r\n */\r\nexport const acceptedIfRequiredRule: SchemaRule<{ field: string }> = {\r\n name: \"acceptedIfRequired\",\r\n description: \"The field must be accepted if :field is required\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (isEmptyValue(fieldValue)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is present\r\n */\r\nexport const acceptedIfPresentRule: SchemaRule<{ field: string }> = {\r\n name: \"acceptedIfPresent\",\r\n description: \"The field must be accepted if :field is present\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue === undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is missing\r\n */\r\nexport const acceptedWithoutRule: SchemaRule<{ field: string }> = {\r\n name: \"acceptedWithout\",\r\n description: \"The field must be accepted if :field is missing\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue !== undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n"],"mappings":";;;;;;AAIA,MAAM,mBAAmB,UAAe;CACtC,OAAO;EAAC;EAAK;EAAQ;EAAO;EAAK;EAAM;EAAG;EAAM;EAAO;EAAK;CAAI,
|
|
1
|
+
{"version":3,"file":"accepted-rule.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/scalar/accepted-rule.ts"],"sourcesContent":["import { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isEmptyValue } from \"../../helpers/is-empty-value\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\nconst isAcceptedValue = (value: any) => {\r\n return [\"1\", \"true\", \"yes\", \"y\", \"on\", 1, true, \"Yes\", \"Y\", \"On\"].includes(value);\r\n};\r\n\r\n/**\r\n * Validate value as accepted if it equals:\r\n * 1 | \"1\" | true | \"true\" | \"yes\" | \"y\" | \"on\"\r\n */\r\nexport const acceptedRule: SchemaRule = {\r\n name: \"accepted\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n description:\r\n \"The value must be accepted if it equals: 1 | '1' | true | 'true' | 'yes' | 'y' | 'on' | 1 | true | 'Yes' | 'Y' | 'On'\",\r\n async validate(value: any, context) {\r\n if (isAcceptedValue(value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Accepted value if another field's value equals to a specific value\r\n */\r\nexport const acceptedIfRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"acceptedIf\",\r\n description: \"The field must be accepted if :field's value equals to :value\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n if (fieldValue !== expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is not equal to the given value\r\n */\r\nexport const acceptedUnlessRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"acceptedUnless\",\r\n description: \"The field must be accepted if :field's value is not equal to :value\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n if (fieldValue === expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is required\r\n */\r\nexport const acceptedIfRequiredRule: SchemaRule<{ field: string }> = {\r\n name: \"acceptedIfRequired\",\r\n description: \"The field must be accepted if :field is required\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (isEmptyValue(fieldValue)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is present\r\n */\r\nexport const acceptedIfPresentRule: SchemaRule<{ field: string }> = {\r\n name: \"acceptedIfPresent\",\r\n description: \"The field must be accepted if :field is present\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue === undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Accepted if another field is missing\r\n */\r\nexport const acceptedWithoutRule: SchemaRule<{ field: string }> = {\r\n name: \"acceptedWithout\",\r\n description: \"The field must be accepted if :field is missing\",\r\n defaultErrorMessage: \"The :input must be accepted\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue !== undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isAcceptedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n"],"mappings":";;;;;;AAIA,MAAM,mBAAmB,UAAe;CACtC,OAAO;EAAC;EAAK;EAAQ;EAAO;EAAK;EAAM;EAAG;EAAM;EAAO;EAAK;CAAI,EAAE,SAAS,KAAK;AAClF;;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,YAAY,MAAM,OAAO;EAGlC,IAAI,CAAC,gBAAgB,KAAK,GACxB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF;;;;AAKA,MAAa,wBAAuD;CAClE,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,cAAc,MAAM,OAAO;EAC9C,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,IAAI,eAAe,QACjB,OAAO,YAAY,MAAM,OAAO;EAGlC,IAAI,CAAC,gBAAgB,KAAK,GACxB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF;;;;AAKA,MAAa,sBAAqD;CAChE,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,cAAc,MAAM,OAAO;EAC9C,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,IAAI,eAAe,QACjB,OAAO,YAAY,MAAM,OAAO;EAGlC,IAAI,CAAC,gBAAgB,KAAK,GACxB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declined-rule.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/scalar/declined-rule.ts"],"sourcesContent":["import { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isEmptyValue } from \"../../helpers/is-empty-value\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\nconst isDeclinedValue = (value: any) => {\r\n return [\"0\", \"false\", \"no\", \"n\", \"off\", 0, false, \"No\", \"N\", \"Off\"].includes(value);\r\n};\r\n\r\n/**\r\n * Validate value as declined if it equals:\r\n * 0 | \"0\" | false | \"false\" | \"no\" | \"n\" | \"off\" | 0 | false | \"No\" | \"N\" | \"Off\"\r\n */\r\nexport const declinedRule: SchemaRule = {\r\n name: \"declined\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n description:\r\n \"The value must be declined if it equals: 0 | '0' | false | 'false' | 'no' | 'n' | 'off' | 0 | false | 'No' | 'N' | 'Off'\",\r\n async validate(value: any, context) {\r\n if (isDeclinedValue(value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Declined value if another field's value equals to a specific value\r\n */\r\nexport const declinedIfRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"declinedIf\",\r\n description: \"The field must be declined if :field's value equals to :value\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n if (fieldValue !== expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is not equal to the given value\r\n */\r\nexport const declinedUnlessRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"declinedUnless\",\r\n description: \"The field must be declined if :field's value is not equal to :value\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n if (fieldValue === expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is required\r\n */\r\nexport const declinedIfRequiredRule: SchemaRule<{ field: string }> = {\r\n name: \"declinedIfRequired\",\r\n description: \"The field must be declined if :field is required\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (isEmptyValue(fieldValue)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is present\r\n */\r\nexport const declinedIfPresentRule: SchemaRule<{ field: string }> = {\r\n name: \"declinedIfPresent\",\r\n description: \"The field must be declined if :field is present\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue === undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is missing\r\n */\r\nexport const declinedWithoutRule: SchemaRule<{ field: string }> = {\r\n name: \"declinedWithout\",\r\n description: \"The field must be declined if :field is missing\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue !== undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n"],"mappings":";;;;;;AAIA,MAAM,mBAAmB,UAAe;CACtC,OAAO;EAAC;EAAK;EAAS;EAAM;EAAK;EAAO;EAAG;EAAO;EAAM;EAAK;CAAK,
|
|
1
|
+
{"version":3,"file":"declined-rule.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/scalar/declined-rule.ts"],"sourcesContent":["import { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isEmptyValue } from \"../../helpers/is-empty-value\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\nconst isDeclinedValue = (value: any) => {\r\n return [\"0\", \"false\", \"no\", \"n\", \"off\", 0, false, \"No\", \"N\", \"Off\"].includes(value);\r\n};\r\n\r\n/**\r\n * Validate value as declined if it equals:\r\n * 0 | \"0\" | false | \"false\" | \"no\" | \"n\" | \"off\" | 0 | false | \"No\" | \"N\" | \"Off\"\r\n */\r\nexport const declinedRule: SchemaRule = {\r\n name: \"declined\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n description:\r\n \"The value must be declined if it equals: 0 | '0' | false | 'false' | 'no' | 'n' | 'off' | 0 | false | 'No' | 'N' | 'Off'\",\r\n async validate(value: any, context) {\r\n if (isDeclinedValue(value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Declined value if another field's value equals to a specific value\r\n */\r\nexport const declinedIfRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"declinedIf\",\r\n description: \"The field must be declined if :field's value equals to :value\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n if (fieldValue !== expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is not equal to the given value\r\n */\r\nexport const declinedUnlessRule: SchemaRule<{ field: string; value: any }> = {\r\n name: \"declinedUnless\",\r\n description: \"The field must be declined if :field's value is not equal to :value\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n const { value: expectedValue } = this.context.options;\r\n\r\n this.context.translatableParams.field = this.context.options.field;\r\n this.context.translatableParams.value = this.context.options.value;\r\n if (fieldValue === expectedValue) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is required\r\n */\r\nexport const declinedIfRequiredRule: SchemaRule<{ field: string }> = {\r\n name: \"declinedIfRequired\",\r\n description: \"The field must be declined if :field is required\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (isEmptyValue(fieldValue)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is present\r\n */\r\nexport const declinedIfPresentRule: SchemaRule<{ field: string }> = {\r\n name: \"declinedIfPresent\",\r\n description: \"The field must be declined if :field is present\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue === undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE;\r\n },\r\n};\r\n\r\n/**\r\n * Declined if another field is missing\r\n */\r\nexport const declinedWithoutRule: SchemaRule<{ field: string }> = {\r\n name: \"declinedWithout\",\r\n description: \"The field must be declined if :field is missing\",\r\n defaultErrorMessage: \"The :input must be declined\",\r\n async validate(value: any, context) {\r\n const fieldValue = getFieldValue(this, context);\r\n this.context.translatableParams.field = this.context.options.field;\r\n\r\n if (fieldValue !== undefined) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n if (!isDeclinedValue(value)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n return VALID_RULE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AqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,cAAc,MAAM,OAAO;EAC9C,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,IAAI,aAAa,UAAU,GACzB,OAAO,YAAY,MAAM,OAAO;EAGlC,IAAI,CAAC,gBAAgB,KAAK,GACxB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF;;;;AAKA,MAAa,wBAAuD;CAClE,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,cAAc,MAAM,OAAO;EAC9C,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,IAAI,eAAe,QACjB,OAAO,YAAY,MAAM,OAAO;EAGlC,IAAI,CAAC,gBAAgB,KAAK,GACxB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF;;;;AAKA,MAAa,sBAAqD;CAChE,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,cAAc,MAAM,OAAO;EAC9C,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,IAAI,eAAe,QACjB,OAAO,YAAY,MAAM,OAAO;EAGlC,IAAI,CAAC,gBAAgB,KAAK,GACxB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credit-card.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/string/credit-card.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Credit card rule - validates credit card number\r\n */\r\nexport const isCreditCardRule: SchemaRule = {\r\n name: \"creditCard\",\r\n defaultErrorMessage: \"The :input must be a valid credit card number\",\r\n async validate(value: any, context) {\r\n // Luhn algorithm for credit card validation\r\n const cardNumber = String(value).replace(/\\s/g, \"\");\r\n\r\n if (!/^\\d+$/.test(cardNumber)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n let sum = 0;\r\n let isEven = false;\r\n\r\n for (let i = cardNumber.length - 1; i >= 0; i--) {\r\n let digit = parseInt(cardNumber[i], 10);\r\n\r\n if (isEven) {\r\n digit *= 2;\r\n if (digit > 9) {\r\n digit -= 9;\r\n }\r\n }\r\n\r\n sum += digit;\r\n isEven = !isEven;\r\n }\r\n\r\n if (sum % 10 === 0) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,mBAA+B;CAC1C,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAElC,MAAM,aAAa,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"credit-card.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/string/credit-card.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Credit card rule - validates credit card number\r\n */\r\nexport const isCreditCardRule: SchemaRule = {\r\n name: \"creditCard\",\r\n defaultErrorMessage: \"The :input must be a valid credit card number\",\r\n async validate(value: any, context) {\r\n // Luhn algorithm for credit card validation\r\n const cardNumber = String(value).replace(/\\s/g, \"\");\r\n\r\n if (!/^\\d+$/.test(cardNumber)) {\r\n return invalidRule(this, context);\r\n }\r\n\r\n let sum = 0;\r\n let isEven = false;\r\n\r\n for (let i = cardNumber.length - 1; i >= 0; i--) {\r\n let digit = parseInt(cardNumber[i], 10);\r\n\r\n if (isEven) {\r\n digit *= 2;\r\n if (digit > 9) {\r\n digit -= 9;\r\n }\r\n }\r\n\r\n sum += digit;\r\n isEven = !isEven;\r\n }\r\n\r\n if (sum % 10 === 0) {\r\n return VALID_RULE;\r\n }\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,mBAA+B;CAC1C,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAElC,MAAM,aAAa,OAAO,KAAK,EAAE,QAAQ,OAAO,EAAE;EAElD,IAAI,CAAC,QAAQ,KAAK,UAAU,GAC1B,OAAO,YAAY,MAAM,OAAO;EAGlC,IAAI,MAAM;EACV,IAAI,SAAS;EAEb,KAAK,IAAI,IAAI,WAAW,SAAS,GAAG,KAAK,GAAG,KAAK;GAC/C,IAAI,QAAQ,SAAS,WAAW,IAAI,EAAE;GAEtC,IAAI,QAAQ;IACV,SAAS;IACT,IAAI,QAAQ,GACV,SAAS;GAEb;GAEA,OAAO;GACP,SAAS,CAAC;EACZ;EAEA,IAAI,MAAM,OAAO,GACf,OAAO;EAGT,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VALID_RULE, invalidRule } from "../../helpers/validation-helpers.mjs";
|
|
2
2
|
import "../../helpers/index.mjs";
|
|
3
|
-
import { isEmail } from "../../../../node_modules/@mongez/supportive-is/esm/index.mjs";
|
|
3
|
+
import { isEmail } from "../../../../node_modules/.pnpm/@mongez_supportive-is@2.1.4/node_modules/@mongez/supportive-is/esm/index.mjs";
|
|
4
4
|
|
|
5
5
|
//#region ../seal/src/rules/string/email.ts
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-formats.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/string/id-formats.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule } from \"../../types\";\n\n/**\n * Modern ID format validators — UUID, CUID, ULID, nanoid.\n *\n * Each rule asserts the value is a string in the canonical format for its\n * identifier scheme. Rules are intentionally strict (variant nibbles checked\n * for UUID, character classes enforced for ULID's Crockford base32, etc.)\n * so \"looks-like-but-not-valid\" inputs are rejected.\n */\n\nconst UUID_ANY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nconst UUID_BY_VERSION: Record<1 | 3 | 4 | 5 | 6 | 7, RegExp> = {\n 1: /^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 3: /^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 4: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 5: /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 6: /^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 7: /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n};\n\nexport type UUIDVersion = 1 | 3 | 4 | 5 | 6 | 7;\n\n/**\n * UUID rule — value must be a valid UUID. Optionally restrict to a specific version.\n *\n * @example\n * v.string().uuid() // any RFC 4122 UUID\n * v.string().uuid(4) // only v4 (random)\n * v.string().uuid(7) // only v7 (timestamp-ordered)\n */\nexport const uuidRule: SchemaRule<{ version?: UUIDVersion }> = {\n name: \"uuid\",\n defaultErrorMessage: \"The :input must be a valid UUID\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n\n const version = this.context.options.version;\n\n const pattern = version ? UUID_BY_VERSION[version] : UUID_ANY;\n if (pattern.test(value)) return VALID_RULE;\n\n if (version !== undefined) {\n this.context.translationParams.version = version;\n }\n\n return invalidRule(this, context);\n },\n};\n\n/**\n * CUID rule — value must be a valid CUID.\n *\n * Defaults to CUID2 (24 chars, lowercase, starts with letter — see\n * https://github.com/paralleldrive/cuid2). Pass `{ version: 1 }` for legacy\n * CUID1 format (starts with \"c\", ≥25 chars).\n *\n * @example\n * v.string().cuid() // CUID2\n * v.string().cuid({ version: 1 }) // legacy CUID1\n */\nexport const cuidRule: SchemaRule<{ version?: 1 | 2 }> = {\n name: \"cuid\",\n defaultErrorMessage: \"The :input must be a valid CUID\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n const version = this.context.options.version ?? 2;\n const pattern = version === 1 ? /^c[a-z0-9]{24,}$/ : /^[a-z][a-z0-9]{23}$/;\n if (pattern.test(value)) return VALID_RULE;\n this.context.translationParams.version = version;\n return invalidRule(this, context);\n },\n};\n\n/**\n * ULID rule — value must be a valid ULID (26 chars, Crockford base32).\n *\n * Crockford base32 excludes the letters I, L, O, U to avoid ambiguity.\n *\n * @example\n * v.string().ulid()\n */\nexport const ulidRule: SchemaRule = {\n name: \"ulid\",\n defaultErrorMessage: \"The :input must be a valid ULID\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n if (/^[0-9A-HJKMNP-TV-Z]{26}$/.test(value)) return VALID_RULE;\n return invalidRule(this, context);\n },\n};\n\n/**\n * nanoid rule — value must be a valid nanoid string.\n *\n * Default length is 21 (standard nanoid). URL-safe alphabet:\n * A–Z, a–z, 0–9, `_`, `-`.\n *\n * @example\n * v.string().nanoid() // 21 chars (default)\n * v.string().nanoid(10) // 10 chars\n */\nexport const nanoidRule: SchemaRule<{ length?: number }> = {\n name: \"nanoid\",\n defaultErrorMessage: \"The :input must be a valid nanoid\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n const length = this.context.options.length ?? 21;\n const pattern = new RegExp(`^[A-Za-z0-9_-]{${length}}$`);\n if (pattern.test(value)) return VALID_RULE;\n this.context.translationParams.length = length;\n return invalidRule(this, context);\n },\n};\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,WAAW;AAEjB,MAAM,kBAAyD;CAC7D,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;;;AAYA,MAAa,WAAkD;CAC7D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAO,SAAS;EAC7B,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,MAAM,OAAO;EAE/D,MAAM,UAAU,KAAK,QAAQ,QAAQ;EAGrC,KADgB,UAAU,gBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"id-formats.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/string/id-formats.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule } from \"../../types\";\n\n/**\n * Modern ID format validators — UUID, CUID, ULID, nanoid.\n *\n * Each rule asserts the value is a string in the canonical format for its\n * identifier scheme. Rules are intentionally strict (variant nibbles checked\n * for UUID, character classes enforced for ULID's Crockford base32, etc.)\n * so \"looks-like-but-not-valid\" inputs are rejected.\n */\n\nconst UUID_ANY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nconst UUID_BY_VERSION: Record<1 | 3 | 4 | 5 | 6 | 7, RegExp> = {\n 1: /^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 3: /^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 4: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 5: /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 6: /^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n 7: /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n};\n\nexport type UUIDVersion = 1 | 3 | 4 | 5 | 6 | 7;\n\n/**\n * UUID rule — value must be a valid UUID. Optionally restrict to a specific version.\n *\n * @example\n * v.string().uuid() // any RFC 4122 UUID\n * v.string().uuid(4) // only v4 (random)\n * v.string().uuid(7) // only v7 (timestamp-ordered)\n */\nexport const uuidRule: SchemaRule<{ version?: UUIDVersion }> = {\n name: \"uuid\",\n defaultErrorMessage: \"The :input must be a valid UUID\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n\n const version = this.context.options.version;\n\n const pattern = version ? UUID_BY_VERSION[version] : UUID_ANY;\n if (pattern.test(value)) return VALID_RULE;\n\n if (version !== undefined) {\n this.context.translationParams.version = version;\n }\n\n return invalidRule(this, context);\n },\n};\n\n/**\n * CUID rule — value must be a valid CUID.\n *\n * Defaults to CUID2 (24 chars, lowercase, starts with letter — see\n * https://github.com/paralleldrive/cuid2). Pass `{ version: 1 }` for legacy\n * CUID1 format (starts with \"c\", ≥25 chars).\n *\n * @example\n * v.string().cuid() // CUID2\n * v.string().cuid({ version: 1 }) // legacy CUID1\n */\nexport const cuidRule: SchemaRule<{ version?: 1 | 2 }> = {\n name: \"cuid\",\n defaultErrorMessage: \"The :input must be a valid CUID\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n const version = this.context.options.version ?? 2;\n const pattern = version === 1 ? /^c[a-z0-9]{24,}$/ : /^[a-z][a-z0-9]{23}$/;\n if (pattern.test(value)) return VALID_RULE;\n this.context.translationParams.version = version;\n return invalidRule(this, context);\n },\n};\n\n/**\n * ULID rule — value must be a valid ULID (26 chars, Crockford base32).\n *\n * Crockford base32 excludes the letters I, L, O, U to avoid ambiguity.\n *\n * @example\n * v.string().ulid()\n */\nexport const ulidRule: SchemaRule = {\n name: \"ulid\",\n defaultErrorMessage: \"The :input must be a valid ULID\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n if (/^[0-9A-HJKMNP-TV-Z]{26}$/.test(value)) return VALID_RULE;\n return invalidRule(this, context);\n },\n};\n\n/**\n * nanoid rule — value must be a valid nanoid string.\n *\n * Default length is 21 (standard nanoid). URL-safe alphabet:\n * A–Z, a–z, 0–9, `_`, `-`.\n *\n * @example\n * v.string().nanoid() // 21 chars (default)\n * v.string().nanoid(10) // 10 chars\n */\nexport const nanoidRule: SchemaRule<{ length?: number }> = {\n name: \"nanoid\",\n defaultErrorMessage: \"The :input must be a valid nanoid\",\n async validate(value, context) {\n if (typeof value !== \"string\") return invalidRule(this, context);\n const length = this.context.options.length ?? 21;\n const pattern = new RegExp(`^[A-Za-z0-9_-]{${length}}$`);\n if (pattern.test(value)) return VALID_RULE;\n this.context.translationParams.length = length;\n return invalidRule(this, context);\n },\n};\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,WAAW;AAEjB,MAAM,kBAAyD;CAC7D,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;;;AAYA,MAAa,WAAkD;CAC7D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAO,SAAS;EAC7B,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,MAAM,OAAO;EAE/D,MAAM,UAAU,KAAK,QAAQ,QAAQ;EAGrC,KADgB,UAAU,gBAAgB,WAAW,UACzC,KAAK,KAAK,GAAG,OAAO;EAEhC,IAAI,YAAY,QACd,KAAK,QAAQ,kBAAkB,UAAU;EAG3C,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;;;;;;;;AAaA,MAAa,WAA4C;CACvD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAO,SAAS;EAC7B,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,MAAM,OAAO;EAC/D,MAAM,UAAU,KAAK,QAAQ,QAAQ,WAAW;EAEhD,KADgB,YAAY,IAAI,qBAAqB,uBACzC,KAAK,KAAK,GAAG,OAAO;EAChC,KAAK,QAAQ,kBAAkB,UAAU;EACzC,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;;;;;AAUA,MAAa,WAAuB;CAClC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAO,SAAS;EAC7B,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,MAAM,OAAO;EAC/D,IAAI,2BAA2B,KAAK,KAAK,GAAG,OAAO;EACnD,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;;;;;;;AAYA,MAAa,aAA8C;CACzD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAO,SAAS;EAC7B,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,MAAM,OAAO;EAC/D,MAAM,SAAS,KAAK,QAAQ,QAAQ,UAAU;EAE9C,IAAI,IADgB,OAAO,kBAAkB,OAAO,GAC1C,EAAE,KAAK,KAAK,GAAG,OAAO;EAChC,KAAK,QAAQ,kBAAkB,SAAS;EACxC,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-comparison.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/string/string-comparison.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Starts with rule\r\n */\r\nexport const startsWithRule: SchemaRule<{ value: string }> = {\r\n name: \"startsWith\",\r\n defaultErrorMessage: \"The :input must start with :value\",\r\n async validate(value: any, context) {\r\n if (String(value).startsWith(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Ends with rule\r\n */\r\nexport const endsWithRule: SchemaRule<{ value: string }> = {\r\n name: \"endsWith\",\r\n defaultErrorMessage: \"The :input must end with :value\",\r\n async validate(value: any, context) {\r\n if (String(value).endsWith(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Contains rule\r\n */\r\nexport const containsRule: SchemaRule<{ value: string }> = {\r\n name: \"contains\",\r\n defaultErrorMessage: \"The :input must contain :value\",\r\n async validate(value: any, context) {\r\n if (String(value).includes(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Not contains rule\r\n */\r\nexport const notContainsRule: SchemaRule<{ value: string }> = {\r\n name: \"notContains\",\r\n defaultErrorMessage: \"The :input must not contain :value\",\r\n async validate(value: any, context) {\r\n if (!String(value).includes(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,iBAAgD;CAC3D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"string-comparison.mjs","names":[],"sources":["../../../../../../../../../../seal/src/rules/string/string-comparison.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Starts with rule\r\n */\r\nexport const startsWithRule: SchemaRule<{ value: string }> = {\r\n name: \"startsWith\",\r\n defaultErrorMessage: \"The :input must start with :value\",\r\n async validate(value: any, context) {\r\n if (String(value).startsWith(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Ends with rule\r\n */\r\nexport const endsWithRule: SchemaRule<{ value: string }> = {\r\n name: \"endsWith\",\r\n defaultErrorMessage: \"The :input must end with :value\",\r\n async validate(value: any, context) {\r\n if (String(value).endsWith(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Contains rule\r\n */\r\nexport const containsRule: SchemaRule<{ value: string }> = {\r\n name: \"contains\",\r\n defaultErrorMessage: \"The :input must contain :value\",\r\n async validate(value: any, context) {\r\n if (String(value).includes(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n\r\n/**\r\n * Not contains rule\r\n */\r\nexport const notContainsRule: SchemaRule<{ value: string }> = {\r\n name: \"notContains\",\r\n defaultErrorMessage: \"The :input must not contain :value\",\r\n async validate(value: any, context) {\r\n if (!String(value).includes(this.context.options.value)) {\r\n return VALID_RULE;\r\n }\r\n\r\n this.context.translatableParams.value = this.context.options.value;\r\n\r\n return invalidRule(this, context);\r\n },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,iBAAgD;CAC3D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,OAAO,KAAK,EAAE,WAAW,KAAK,QAAQ,QAAQ,KAAK,GACrD,OAAO;EAGT,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,eAA8C;CACzD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,OAAO,KAAK,EAAE,SAAS,KAAK,QAAQ,QAAQ,KAAK,GACnD,OAAO;EAGT,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,eAA8C;CACzD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,OAAO,KAAK,EAAE,SAAS,KAAK,QAAQ,QAAQ,KAAK,GACnD,OAAO;EAGT,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,kBAAiD;CAC5D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,CAAC,OAAO,KAAK,EAAE,SAAS,KAAK,QAAQ,QAAQ,KAAK,GACpD,OAAO;EAGT,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;EAE7D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.mjs","names":[],"sources":["../../../../../../../../../seal/src/standard-schema/json-schema.ts"],"sourcesContent":["import type { StandardJSONSchemaV1 } from \"./types\";\n\n/**\n * Supported JSON Schema generation targets.\n */\nexport type JsonSchemaTarget = StandardJSONSchemaV1.Target;\n\n/**\n * The result shape for a generated JSON Schema.\n */\nexport type JsonSchemaResult = Record<string, unknown>;\n\n/**\n * Apply nullable to a JSON Schema object based on the target dialect.\n *\n * - draft-2020-12 : `type` becomes an array: `[\"string\", \"null\"]`\n * - openai-strict : same as draft-2020-12 (type array form)\n * - draft-07 : wraps in `oneOf: [{ ...schema }, { type: \"null\" }]`\n * - openapi-3.0 : adds `nullable: true` alongside the existing type\n *\n * Mutates the schema in-place.\n *\n * @example\n * ```ts\n * const schema = { type: \"string\" };\n * applyNullable(schema, \"draft-2020-12\");\n * // → { type: [\"string\", \"null\"] }\n * ```\n */\nexport function applyNullable(schema: JsonSchemaResult, target: JsonSchemaTarget): void {\n if (target === \"openapi-3.0\") {\n schema.nullable = true;\n return;\n }\n\n if (target === \"draft-2020-12\" || target === \"openai-strict\") {\n const baseType = schema.type as string | string[] | undefined;\n schema.type = Array.isArray(baseType)\n ? [...baseType, \"null\"]\n : [baseType as string, \"null\"];\n return;\n }\n\n // draft-07: oneOf wrapping\n const copy = { ...schema };\n for (const key of Object.keys(schema)) {\n delete schema[key];\n }\n schema.oneOf = [copy, { type: \"null\" }];\n}\n\n/**\n * Wrap a field schema as nullable for OpenAI strict mode.\n *\n * OpenAI strict requires optional fields to be expressed as a nullable type\n * rather than being omitted from the `required` array. This helper wraps a\n * given schema into its nullable equivalent using the type-array form.\n *\n * Unlike `applyNullable()` (which mutates in-place), this returns a new\n * schema object to avoid side effects when wrapping child schemas.\n *\n * @example\n * ```ts\n * wrapNullableStrict({ type: \"string\", minLength: 3 })\n * // → { type: [\"string\", \"null\"], minLength: 3 }\n *\n * wrapNullableStrict({ type: \"object\", properties: {...} })\n * // → { type: [\"object\", \"null\"], properties: {...} }\n *\n * wrapNullableStrict({ oneOf: [...] })\n * // → { oneOf: [..., { type: \"null\" }] }\n * ```\n */\nexport function wrapNullableStrict(schema: JsonSchemaResult): JsonSchemaResult {\n // If the schema uses oneOf/anyOf (e.g. union), append null to the list\n if (schema.oneOf) {\n return { ...schema, oneOf: [...(schema.oneOf as unknown[]), { type: \"null\" }] };\n }\n\n if (schema.anyOf) {\n return { ...schema, anyOf: [...(schema.anyOf as unknown[]), { type: \"null\" }] };\n }\n\n // If there's no type at all (permissive `{}`), stay permissive\n if (schema.type === undefined) {\n return schema;\n }\n\n // Standard case: wrap type into array with null\n const baseType = schema.type as string | string[];\n return {\n ...schema,\n type: Array.isArray(baseType) ? [...baseType, \"null\"] : [baseType, \"null\"],\n };\n}\n\n/**\n * Find the first rule matching the given name in a rules array,\n * and return its options bag.\n */\nexport function getRuleOptions(\n rules: Array<{ name: string; context: { options: Record<string, unknown> } }>,\n ruleName: string,\n): Record<string, unknown> | undefined {\n const rule = rules.find(r => r.name === ruleName);\n return rule?.context?.options as Record<string, unknown> | undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,SAAgB,cAAc,QAA0B,QAAgC;CACtF,IAAI,WAAW,eAAe;EAC5B,OAAO,WAAW;EAClB;CACF;CAEA,IAAI,WAAW,mBAAmB,WAAW,iBAAiB;EAC5D,MAAM,WAAW,OAAO;EACxB,OAAO,OAAO,MAAM,QAAQ,QAAQ,IAChC,CAAC,GAAG,UAAU,MAAM,IACpB,CAAC,UAAoB,MAAM;EAC/B;CACF;CAGA,MAAM,OAAO,EAAE,GAAG,OAAO;CACzB,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,OAAO,OAAO;CAEhB,OAAO,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC;AACxC;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,QAA4C;CAE7E,IAAI,OAAO,OACT,OAAO;EAAE,GAAG;EAAQ,OAAO,CAAC,GAAI,OAAO,OAAqB,EAAE,MAAM,OAAO,CAAC;CAAE;CAGhF,IAAI,OAAO,OACT,OAAO;EAAE,GAAG;EAAQ,OAAO,CAAC,GAAI,OAAO,OAAqB,EAAE,MAAM,OAAO,CAAC;CAAE;CAIhF,IAAI,OAAO,SAAS,QAClB,OAAO;CAIT,MAAM,WAAW,OAAO;CACxB,OAAO;EACL,GAAG;EACH,MAAM,MAAM,QAAQ,QAAQ,IAAI,CAAC,GAAG,UAAU,MAAM,IAAI,CAAC,UAAU,MAAM;CAC3E;AACF;;;;;AAMA,SAAgB,eACd,OACA,UACqC;CAErC,OADa,MAAM,MAAK,MAAK,EAAE,SAAS,QAC9B,
|
|
1
|
+
{"version":3,"file":"json-schema.mjs","names":[],"sources":["../../../../../../../../../seal/src/standard-schema/json-schema.ts"],"sourcesContent":["import type { StandardJSONSchemaV1 } from \"./types\";\n\n/**\n * Supported JSON Schema generation targets.\n */\nexport type JsonSchemaTarget = StandardJSONSchemaV1.Target;\n\n/**\n * The result shape for a generated JSON Schema.\n */\nexport type JsonSchemaResult = Record<string, unknown>;\n\n/**\n * Apply nullable to a JSON Schema object based on the target dialect.\n *\n * - draft-2020-12 : `type` becomes an array: `[\"string\", \"null\"]`\n * - openai-strict : same as draft-2020-12 (type array form)\n * - draft-07 : wraps in `oneOf: [{ ...schema }, { type: \"null\" }]`\n * - openapi-3.0 : adds `nullable: true` alongside the existing type\n *\n * Mutates the schema in-place.\n *\n * @example\n * ```ts\n * const schema = { type: \"string\" };\n * applyNullable(schema, \"draft-2020-12\");\n * // → { type: [\"string\", \"null\"] }\n * ```\n */\nexport function applyNullable(schema: JsonSchemaResult, target: JsonSchemaTarget): void {\n if (target === \"openapi-3.0\") {\n schema.nullable = true;\n return;\n }\n\n if (target === \"draft-2020-12\" || target === \"openai-strict\") {\n const baseType = schema.type as string | string[] | undefined;\n schema.type = Array.isArray(baseType)\n ? [...baseType, \"null\"]\n : [baseType as string, \"null\"];\n return;\n }\n\n // draft-07: oneOf wrapping\n const copy = { ...schema };\n for (const key of Object.keys(schema)) {\n delete schema[key];\n }\n schema.oneOf = [copy, { type: \"null\" }];\n}\n\n/**\n * Wrap a field schema as nullable for OpenAI strict mode.\n *\n * OpenAI strict requires optional fields to be expressed as a nullable type\n * rather than being omitted from the `required` array. This helper wraps a\n * given schema into its nullable equivalent using the type-array form.\n *\n * Unlike `applyNullable()` (which mutates in-place), this returns a new\n * schema object to avoid side effects when wrapping child schemas.\n *\n * @example\n * ```ts\n * wrapNullableStrict({ type: \"string\", minLength: 3 })\n * // → { type: [\"string\", \"null\"], minLength: 3 }\n *\n * wrapNullableStrict({ type: \"object\", properties: {...} })\n * // → { type: [\"object\", \"null\"], properties: {...} }\n *\n * wrapNullableStrict({ oneOf: [...] })\n * // → { oneOf: [..., { type: \"null\" }] }\n * ```\n */\nexport function wrapNullableStrict(schema: JsonSchemaResult): JsonSchemaResult {\n // If the schema uses oneOf/anyOf (e.g. union), append null to the list\n if (schema.oneOf) {\n return { ...schema, oneOf: [...(schema.oneOf as unknown[]), { type: \"null\" }] };\n }\n\n if (schema.anyOf) {\n return { ...schema, anyOf: [...(schema.anyOf as unknown[]), { type: \"null\" }] };\n }\n\n // If there's no type at all (permissive `{}`), stay permissive\n if (schema.type === undefined) {\n return schema;\n }\n\n // Standard case: wrap type into array with null\n const baseType = schema.type as string | string[];\n return {\n ...schema,\n type: Array.isArray(baseType) ? [...baseType, \"null\"] : [baseType, \"null\"],\n };\n}\n\n/**\n * Find the first rule matching the given name in a rules array,\n * and return its options bag.\n */\nexport function getRuleOptions(\n rules: Array<{ name: string; context: { options: Record<string, unknown> } }>,\n ruleName: string,\n): Record<string, unknown> | undefined {\n const rule = rules.find(r => r.name === ruleName);\n return rule?.context?.options as Record<string, unknown> | undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,SAAgB,cAAc,QAA0B,QAAgC;CACtF,IAAI,WAAW,eAAe;EAC5B,OAAO,WAAW;EAClB;CACF;CAEA,IAAI,WAAW,mBAAmB,WAAW,iBAAiB;EAC5D,MAAM,WAAW,OAAO;EACxB,OAAO,OAAO,MAAM,QAAQ,QAAQ,IAChC,CAAC,GAAG,UAAU,MAAM,IACpB,CAAC,UAAoB,MAAM;EAC/B;CACF;CAGA,MAAM,OAAO,EAAE,GAAG,OAAO;CACzB,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,OAAO,OAAO;CAEhB,OAAO,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC;AACxC;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,QAA4C;CAE7E,IAAI,OAAO,OACT,OAAO;EAAE,GAAG;EAAQ,OAAO,CAAC,GAAI,OAAO,OAAqB,EAAE,MAAM,OAAO,CAAC;CAAE;CAGhF,IAAI,OAAO,OACT,OAAO;EAAE,GAAG;EAAQ,OAAO,CAAC,GAAI,OAAO,OAAqB,EAAE,MAAM,OAAO,CAAC;CAAE;CAIhF,IAAI,OAAO,SAAS,QAClB,OAAO;CAIT,MAAM,WAAW,OAAO;CACxB,OAAO;EACL,GAAG;EACH,MAAM,MAAM,QAAQ,QAAQ,IAAI,CAAC,GAAG,UAAU,MAAM,IAAI,CAAC,UAAU,MAAM;CAC3E;AACF;;;;;AAMA,SAAgB,eACd,OACA,UACqC;CAErC,OADa,MAAM,MAAK,MAAK,EAAE,SAAS,QAC9B,GAAG,SAAS;AACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result.mjs","names":[],"sources":["../../../../../../../../../seal/src/standard-schema/map-result.ts"],"sourcesContent":["import type { ValidationResult } from \"../types\";\nimport type { StandardSchemaV1 } from \"./types\";\n\n/**\n * Maps a Seal ValidationResult to a Standard Schema result shape.\n *\n * Seal error paths are dot-notation strings (e.g. \"address.city\").\n * Standard Schema expects an array of path segments: [{ key: \"address\" }, { key: \"city\" }].\n *\n * @example\n * ```ts\n * const result = await validator.validate(value, context);\n * return mapToStandardResult(result);\n * // Success → { value: <data> }\n * // Failure → { issues: [{ message: \"...\", path: [{ key: \"...\" }] }] }\n * ```\n */\nexport function mapToStandardResult(\n result: ValidationResult,\n): StandardSchemaV1.Result<unknown> {\n if (result.isValid) {\n return { value: result.data };\n }\n\n return {\n issues: result.errors.map(e => ({\n message: e.error,\n path: e.input\n ? e.input.split(\".\").map(key => ({ key }))\n : undefined,\n })),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAgB,oBACd,QACkC;CAClC,IAAI,OAAO,SACT,OAAO,EAAE,OAAO,OAAO,KAAK;CAG9B,OAAO,EACL,QAAQ,OAAO,OAAO,KAAI,OAAM;EAC9B,SAAS,EAAE;EACX,MAAM,EAAE,QACJ,EAAE,MAAM,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"map-result.mjs","names":[],"sources":["../../../../../../../../../seal/src/standard-schema/map-result.ts"],"sourcesContent":["import type { ValidationResult } from \"../types\";\nimport type { StandardSchemaV1 } from \"./types\";\n\n/**\n * Maps a Seal ValidationResult to a Standard Schema result shape.\n *\n * Seal error paths are dot-notation strings (e.g. \"address.city\").\n * Standard Schema expects an array of path segments: [{ key: \"address\" }, { key: \"city\" }].\n *\n * @example\n * ```ts\n * const result = await validator.validate(value, context);\n * return mapToStandardResult(result);\n * // Success → { value: <data> }\n * // Failure → { issues: [{ message: \"...\", path: [{ key: \"...\" }] }] }\n * ```\n */\nexport function mapToStandardResult(\n result: ValidationResult,\n): StandardSchemaV1.Result<unknown> {\n if (result.isValid) {\n return { value: result.data };\n }\n\n return {\n issues: result.errors.map(e => ({\n message: e.error,\n path: e.input\n ? e.input.split(\".\").map(key => ({ key }))\n : undefined,\n })),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAgB,oBACd,QACkC;CAClC,IAAI,OAAO,SACT,OAAO,EAAE,OAAO,OAAO,KAAK;CAG9B,OAAO,EACL,QAAQ,OAAO,OAAO,KAAI,OAAM;EAC9B,SAAS,EAAE;EACX,MAAM,EAAE,QACJ,EAAE,MAAM,MAAM,GAAG,EAAE,KAAI,SAAQ,EAAE,IAAI,EAAE,IACvC;CACN,EAAE,EACJ;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { clone } from "../../../node_modules/@mongez/reinforcements/esm/mixed/clone/clone.mjs";
|
|
2
|
-
import "../../../node_modules/@mongez/reinforcements/esm/index.mjs";
|
|
1
|
+
import { clone } from "../../../node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/mixed/clone/clone.mjs";
|
|
2
|
+
import "../../../node_modules/.pnpm/@mongez_reinforcements@4.0.1/node_modules/@mongez/reinforcements/esm/index.mjs";
|
|
3
3
|
import { validate } from "../factory/validate.mjs";
|
|
4
4
|
import { VALID_RULE, invalidRule } from "../helpers/validation-helpers.mjs";
|
|
5
5
|
import "../helpers/index.mjs";
|
|
@@ -2,7 +2,7 @@ import { __toESM } from "../../../_virtual/_rolldown/runtime.mjs";
|
|
|
2
2
|
import { applyNullable, getRuleOptions } from "../standard-schema/json-schema.mjs";
|
|
3
3
|
import { isDateValue } from "../helpers/date-helpers.mjs";
|
|
4
4
|
import { BaseValidator } from "./base-validator.mjs";
|
|
5
|
-
import { require_dayjs_min } from "../../../node_modules/dayjs/dayjs.min.mjs";
|
|
5
|
+
import { require_dayjs_min } from "../../../node_modules/.pnpm/dayjs@1.11.23/node_modules/dayjs/dayjs.min.mjs";
|
|
6
6
|
import { addDaysMutator, addHoursMutator, addMonthsMutator, addYearsMutator, dateMutator, toEndOfDayMutator, toEndOfMonthMutator, toEndOfYearMutator, toStartOfDayMutator, toStartOfMonthMutator, toStartOfYearMutator, toUTCMutator } from "../mutators/date-mutators.mjs";
|
|
7
7
|
import "../mutators/index.mjs";
|
|
8
8
|
import { ageRule, beforeHourRule, beforeMinuteRule, beforeTodayRule, betweenHoursRule, betweenMinutesRule, dateRule, fromHourRule, fromMinuteRule, fromTodayRule, maxAgeRule, maxDateRule, minAgeRule, minDateRule, weekDayRule } from "../rules/date/date.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-validator.mjs","names":[],"sources":["../../../../../../../../../seal/src/validators/date-validator.ts"],"sourcesContent":["import dayjs from \"dayjs\";\r\nimport {\r\n addDaysMutator,\r\n addHoursMutator,\r\n addMonthsMutator,\r\n addYearsMutator,\r\n dateMutator,\r\n toEndOfDayMutator,\r\n toEndOfMonthMutator,\r\n toEndOfYearMutator,\r\n toStartOfDayMutator,\r\n toStartOfMonthMutator,\r\n toStartOfYearMutator,\r\n toUTCMutator,\r\n} from \"../mutators\";\r\nimport {\r\n afterFieldRule,\r\n afterTodayRule,\r\n ageRule,\r\n beforeFieldRule,\r\n beforeHourRule,\r\n beforeMinuteRule,\r\n beforeTodayRule,\r\n betweenAgeRule,\r\n betweenDatesRule,\r\n betweenDaysRule,\r\n betweenHoursRule,\r\n betweenMinutesRule,\r\n betweenMonthsRule,\r\n betweenTimesRule,\r\n betweenYearsRule,\r\n birthdayRule,\r\n businessDayRule,\r\n dateRule,\r\n fromHourRule,\r\n fromMinuteRule,\r\n fromTodayRule,\r\n futureRule,\r\n leapYearRule,\r\n maxAgeRule,\r\n maxDateRule,\r\n maxDayRule,\r\n maxMonthRule,\r\n maxYearRule,\r\n minAgeRule,\r\n minDateRule,\r\n minDayRule,\r\n minMonthRule,\r\n minYearRule,\r\n Month,\r\n monthRule,\r\n pastRule,\r\n quarterRule,\r\n sameAsFieldDateRule,\r\n todayRule,\r\n weekDayRule,\r\n weekdaysRule,\r\n weekendRule,\r\n withinDaysRule,\r\n withinFutureDaysRule,\r\n withinPastDaysRule,\r\n yearRule,\r\n} from \"../rules\";\r\nimport type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\r\nimport { applyNullable, getRuleOptions } from \"../standard-schema/json-schema\";\r\nimport type { WeekDay } from \"../types/date-types\";\r\nimport { isDateValue } from \"./../helpers/date-helpers\";\r\nimport { BaseValidator } from \"./base-validator\";\r\n\r\n/**\r\n * Date validator class\r\n */\r\nexport class DateValidator extends BaseValidator {\r\n public constructor(errorMessage?: string) {\r\n super();\r\n this.addMutableMutator(dateMutator); // Normalize to Date object first\r\n this.addMutableRule(dateRule, errorMessage);\r\n }\r\n\r\n /**\r\n * Check if value is a Date type\r\n */\r\n public matchesType(value: any): boolean {\r\n return isDateValue(value);\r\n }\r\n\r\n // ==================== Output Transformers ====================\r\n // These transform the Date after validation into different formats\r\n\r\n /**\r\n * Convert date to ISO string format\r\n * @category transformer\r\n */\r\n public toISOString() {\r\n return this.addTransformer((data) => (data instanceof Date ? data.toISOString() : data));\r\n }\r\n\r\n /** Convert date to Unix timestamp (milliseconds) */\r\n public toTimestamp() {\r\n return this.addTransformer((data) => (data instanceof Date ? data.getTime() : data));\r\n }\r\n\r\n // ==================== String Format Transformers ====================\r\n // These convert Date to formatted strings after validation\r\n\r\n /** Convert date to specific format using dayjs */\r\n public toFormat(format: string) {\r\n return this.addTransformer(\r\n (data, { options }) => (data instanceof Date ? dayjs(data).format(options.format) : data),\r\n { format },\r\n );\r\n }\r\n\r\n /** Convert to date only (remove time, returns YYYY-MM-DD) */\r\n public toDateOnly() {\r\n return this.addTransformer(\r\n (data) => (data instanceof Date ? dayjs(data).format(\"YYYY-MM-DD\") : data),\r\n { __jsonSchemaFormat: \"date\" },\r\n );\r\n }\r\n\r\n /** Convert to time only (returns HH:MM:SS) */\r\n public toTimeOnly() {\r\n return this.addTransformer(\r\n (data) => (data instanceof Date ? dayjs(data).format(\"HH:mm:ss\") : data),\r\n { __jsonSchemaFormat: \"time\" },\r\n );\r\n }\r\n\r\n // ==================== Date Mutators ====================\r\n // These modify the Date object before validation\r\n\r\n /**\r\n * Convert date to start of day (00:00:00)\r\n * @category mutator\r\n */\r\n public toStartOfDay() {\r\n return this.addMutator(toStartOfDayMutator);\r\n }\r\n\r\n /** Convert date to end of day (23:59:59.999) */\r\n public toEndOfDay() {\r\n return this.addMutator(toEndOfDayMutator);\r\n }\r\n\r\n /** Add or subtract days from date */\r\n public addDays(days: number) {\r\n return this.addMutator(addDaysMutator, { days });\r\n }\r\n\r\n /** Add or subtract months from date */\r\n public addMonths(months: number) {\r\n return this.addMutator(addMonthsMutator, { months });\r\n }\r\n\r\n /** Add or subtract years from date */\r\n public addYears(years: number) {\r\n return this.addMutator(addYearsMutator, { years });\r\n }\r\n\r\n /** Add or subtract hours from date */\r\n public addHours(hours: number) {\r\n return this.addMutator(addHoursMutator, { hours });\r\n }\r\n\r\n /** Convert date to UTC */\r\n public toUTC() {\r\n return this.addMutator(toUTCMutator);\r\n }\r\n\r\n // ==================== Date Range Mutators ====================\r\n\r\n /** Set to start of month */\r\n public toStartOfMonth() {\r\n return this.addMutator(toStartOfMonthMutator);\r\n }\r\n\r\n /** Set to end of month */\r\n public toEndOfMonth() {\r\n return this.addMutator(toEndOfMonthMutator);\r\n }\r\n\r\n /** Set to start of year */\r\n public toStartOfYear() {\r\n return this.addMutator(toStartOfYearMutator);\r\n }\r\n\r\n /** Set to end of year */\r\n public toEndOfYear() {\r\n return this.addMutator(toEndOfYearMutator);\r\n }\r\n\r\n // ==================== Date Comparison ====================\r\n\r\n /**\r\n * Date must be greater than or equal to the given date or field (inclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @param dateOrField - Date, timestamp, date string, or field name\r\n *\r\n * @example\r\n * ```ts\r\n * // Value comparison\r\n * v.date().min('2024-01-01')\r\n * v.date().min(new Date())\r\n * v.date().min(1698278400000)\r\n *\r\n * // Field comparison\r\n * v.date().min('startsAt')\r\n * ```\r\n *\r\n * @category Validation Rule\r\n */\r\n public min(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(minDateRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be less than or equal to the given date or field (inclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @category Validation Rule\r\n */\r\n public max(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(maxDateRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be strictly less than the given date or field (exclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @category Validation Rule\r\n */\r\n public before(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(beforeFieldRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be strictly greater than the given date or field (exclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @category Validation Rule\r\n */\r\n public after(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(afterFieldRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /** Date must be between start and end dates */\r\n public between(startDate: Date, endDate: Date, errorMessage?: string) {\r\n return this.addRule(betweenDatesRule, errorMessage, { startDate, endDate });\r\n }\r\n\r\n /** Date must be exactly today */\r\n public today(errorMessage?: string) {\r\n return this.addRule(todayRule, errorMessage);\r\n }\r\n\r\n /** Date must be today or in the future */\r\n public fromToday(errorMessage?: string) {\r\n return this.addRule(fromTodayRule, errorMessage);\r\n }\r\n\r\n /** Date must be before today */\r\n public beforeToday(errorMessage?: string) {\r\n return this.addRule(beforeTodayRule, errorMessage);\r\n }\r\n\r\n /** Date must be after today (not including today) */\r\n public afterToday(errorMessage?: string) {\r\n return this.addRule(afterTodayRule, errorMessage);\r\n }\r\n\r\n /** Date must be in the past */\r\n public past(errorMessage?: string) {\r\n return this.addRule(pastRule, errorMessage);\r\n }\r\n\r\n /** Date must be in the future */\r\n public future(errorMessage?: string) {\r\n return this.addRule(futureRule, errorMessage);\r\n }\r\n\r\n // ==================== Sibling Field Comparison ====================\r\n // Explicit sibling scope methods\r\n\r\n /**\r\n * Date must be >= sibling field value (inclusive)\r\n * @category Validation Rule\r\n */\r\n public minSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minDateRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be <= sibling field value (inclusive)\r\n * @category Validation Rule\r\n */\r\n public maxSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxDateRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be < sibling field value (exclusive)\r\n * @category Validation Rule\r\n */\r\n public beforeSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(beforeFieldRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be > sibling field value (exclusive)\r\n * @category Validation Rule\r\n */\r\n public afterSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(afterFieldRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /** Date must be the same as another field's date */\r\n public sameAsField(field: string, errorMessage?: string) {\r\n return this.addRule(sameAsFieldDateRule, errorMessage, {\r\n field,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /** Date must be the same as another sibling field's date */\r\n public sameAsFieldSibling(field: string, errorMessage?: string) {\r\n return this.addRule(sameAsFieldDateRule, errorMessage, {\r\n field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n // ==================== Time Validation ====================\r\n\r\n /** Time must be from specific hour onwards (0-23) */\r\n public fromHour(hour: number, errorMessage?: string) {\r\n return this.addRule(fromHourRule, errorMessage, { hour });\r\n }\r\n\r\n /** Time must be before specific hour (0-23) */\r\n public beforeHour(hour: number, errorMessage?: string) {\r\n return this.addRule(beforeHourRule, errorMessage, { hour });\r\n }\r\n\r\n /** Time must be between start and end hours (0-23) */\r\n public betweenHours(startHour: number, endHour: number, errorMessage?: string) {\r\n return this.addRule(betweenHoursRule, errorMessage, { startHour, endHour });\r\n }\r\n\r\n /** Time must be from specific minute onwards (0-59) */\r\n public fromMinute(minute: number, errorMessage?: string) {\r\n return this.addRule(fromMinuteRule, errorMessage, { minute });\r\n }\r\n\r\n /** Time must be before specific minute (0-59) */\r\n public beforeMinute(minute: number, errorMessage?: string) {\r\n return this.addRule(beforeMinuteRule, errorMessage, { minute });\r\n }\r\n\r\n /** Time must be between start and end minutes (0-59) */\r\n public betweenMinutes(startMinute: number, endMinute: number, errorMessage?: string) {\r\n return this.addRule(betweenMinutesRule, errorMessage, {\r\n startMinute,\r\n endMinute,\r\n });\r\n }\r\n\r\n /** Time must be between start and end times (HH:MM format) */\r\n public betweenTimes(startTime: string, endTime: string, errorMessage?: string) {\r\n return this.addRule(betweenTimesRule, errorMessage, { startTime, endTime });\r\n }\r\n\r\n // ==================== Age Validation ====================\r\n\r\n /** Age must be exactly the given years */\r\n public age(years: number, errorMessage?: string) {\r\n return this.addRule(ageRule, errorMessage, { years });\r\n }\r\n\r\n /** Minimum age requirement */\r\n public minAge(years: number, errorMessage?: string) {\r\n return this.addRule(minAgeRule, errorMessage, { years });\r\n }\r\n\r\n /** Maximum age requirement */\r\n public maxAge(years: number, errorMessage?: string) {\r\n return this.addRule(maxAgeRule, errorMessage, { years });\r\n }\r\n\r\n /** Age must be between min and max years */\r\n public betweenAge(minAge: number, maxAge: number, errorMessage?: string) {\r\n return this.addRule(betweenAgeRule, errorMessage, { minAge, maxAge });\r\n }\r\n\r\n // ==================== Day Validation ====================\r\n\r\n /** Date must be specific weekday */\r\n public weekDay(day: WeekDay, errorMessage?: string) {\r\n return this.addRule(weekDayRule, errorMessage, { day });\r\n }\r\n\r\n /** Date must be one of specified weekdays */\r\n public weekdays(days: WeekDay[], errorMessage?: string) {\r\n return this.addRule(weekdaysRule, errorMessage, { days });\r\n }\r\n\r\n /** Date must be a weekend (Saturday or Sunday) */\r\n public weekend(errorMessage?: string) {\r\n return this.addRule(weekendRule, errorMessage);\r\n }\r\n\r\n /** Date must be a business day (Monday-Friday) */\r\n public businessDay(errorMessage?: string) {\r\n return this.addRule(businessDayRule, errorMessage);\r\n }\r\n\r\n /** Date must match specific format */\r\n public format(format: string, errorMessage?: string) {\r\n return this.addRule(dateRule, errorMessage, { format });\r\n }\r\n\r\n // ==================== Relative Date Validation ====================\r\n\r\n /** Date must be within X days from now (past or future) */\r\n public withinDays(days: number, errorMessage?: string) {\r\n return this.addRule(withinDaysRule, errorMessage, { days });\r\n }\r\n\r\n /** Date must be within X days in the past */\r\n public withinPastDays(days: number, errorMessage?: string) {\r\n return this.addRule(withinPastDaysRule, errorMessage, { days });\r\n }\r\n\r\n /** Date must be within X days in the future */\r\n public withinFutureDays(days: number, errorMessage?: string) {\r\n return this.addRule(withinFutureDaysRule, errorMessage, { days });\r\n }\r\n\r\n // ==================== Period Validation ====================\r\n\r\n /** Date must be in specific month (1-12) */\r\n public month(month: Month, errorMessage?: string) {\r\n return this.addRule(monthRule, errorMessage, { month });\r\n }\r\n\r\n /** Date must be in specific year */\r\n public year(year: number, errorMessage?: string) {\r\n return this.addRule(yearRule, errorMessage, { year });\r\n }\r\n\r\n /**\r\n * Date must be between start and end years\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public betweenYears(startYear: number | string, endYear: number | string, errorMessage?: string) {\r\n return this.addRule(betweenYearsRule, errorMessage, {\r\n startYear,\r\n endYear,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between start and end months (1-12)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public betweenMonths(\r\n startMonth: Month | string,\r\n endMonth: Month | string,\r\n errorMessage?: string,\r\n ) {\r\n return this.addRule(betweenMonthsRule, errorMessage, {\r\n startMonth,\r\n endMonth,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between start and end days (1-31)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public betweenDays(startDay: number | string, endDay: number | string, errorMessage?: string) {\r\n return this.addRule(betweenDaysRule, errorMessage, {\r\n startDay,\r\n endDay,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between sibling field years\r\n * @category Validation Rule\r\n */\r\n public betweenYearsSibling(startYearField: string, endYearField: string, errorMessage?: string) {\r\n return this.addRule(betweenYearsRule, errorMessage, {\r\n startYear: startYearField,\r\n endYear: endYearField,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between sibling field months\r\n * @category Validation Rule\r\n */\r\n public betweenMonthsSibling(\r\n startMonthField: string,\r\n endMonthField: string,\r\n errorMessage?: string,\r\n ) {\r\n return this.addRule(betweenMonthsRule, errorMessage, {\r\n startMonth: startMonthField,\r\n endMonth: endMonthField,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between sibling field days\r\n * @category Validation Rule\r\n */\r\n public betweenDaysSibling(startDayField: string, endDayField: string, errorMessage?: string) {\r\n return this.addRule(betweenDaysRule, errorMessage, {\r\n startDay: startDayField,\r\n endDay: endDayField,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be >= given year or field\r\n * Smart detection: number or field name\r\n *\r\n * @example\r\n * ```ts\r\n * // Value comparison\r\n * v.date().minYear(2024)\r\n *\r\n * // Field comparison\r\n * v.date().minYear('startYear')\r\n * ```\r\n *\r\n * @category Validation Rule\r\n */\r\n public minYear(yearOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(minYearRule, errorMessage, {\r\n yearOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be <= given year or field\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public maxYear(yearOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(maxYearRule, errorMessage, {\r\n yearOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be >= given month or field (1-12)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public minMonth(monthOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(minMonthRule, errorMessage, {\r\n monthOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be <= given month or field (1-12)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public maxMonth(monthOrField: Month | string, errorMessage?: string): this {\r\n return this.addRule(maxMonthRule, errorMessage, {\r\n monthOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be >= given day or field (1-31)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public minDay(dayOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(minDayRule, errorMessage, {\r\n dayOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be <= given day or field (1-31)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public maxDay(dayOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(maxDayRule, errorMessage, {\r\n dayOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be >= sibling field year\r\n * @category Validation Rule\r\n */\r\n public minYearSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minYearRule, errorMessage, {\r\n yearOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be <= sibling field year\r\n * @category Validation Rule\r\n */\r\n public maxYearSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxYearRule, errorMessage, {\r\n yearOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be >= sibling field month\r\n * @category Validation Rule\r\n */\r\n public minMonthSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minMonthRule, errorMessage, {\r\n monthOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be <= sibling field month\r\n * @category Validation Rule\r\n */\r\n public maxMonthSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxMonthRule, errorMessage, {\r\n monthOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be >= sibling field day\r\n * @category Validation Rule\r\n */\r\n public minDaySibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minDayRule, errorMessage, {\r\n dayOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be <= sibling field day\r\n * @category Validation Rule\r\n */\r\n public maxDaySibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxDayRule, errorMessage, {\r\n dayOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /** Date must be in specific quarter (1-4) */\r\n public quarter(quarter: 1 | 2 | 3 | 4, errorMessage?: string) {\r\n return this.addRule(quarterRule, errorMessage, { quarter });\r\n }\r\n\r\n // ==================== Special Validation ====================\r\n\r\n /** Valid birthday (not in future, reasonable age) */\r\n public birthday(minAge?: number, maxAge?: number, errorMessage?: string) {\r\n return this.addRule(birthdayRule, errorMessage, { minAge, maxAge });\r\n }\r\n\r\n /** Date must be in a leap year */\r\n public leapYear(errorMessage?: string) {\r\n return this.addRule(leapYearRule, errorMessage);\r\n }\r\n\r\n /**\r\n * Set default value as current time of exeuction\r\n */\r\n public defaultNow() {\r\n return this.default(() => new Date());\r\n }\r\n\r\n /**\r\n * @inheritdoc\r\n *\r\n * Maps DateValidator to JSON Schema format keywords.\r\n * Default is `date-time`. If `.toDateOnly()` or `.toTimeOnly()` are used,\r\n * falls back to `date` or `time` formats respectively.\r\n *\r\n * @example\r\n * ```ts\r\n * v.date().toJsonSchema(\"draft-2020-12\")\r\n * // → { type: \"string\", format: \"date-time\" }\r\n *\r\n * v.date().toDateOnly().toJsonSchema(\"draft-2020-12\")\r\n * // → { type: \"string\", format: \"date\" }\r\n * ```\r\n */\r\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\r\n const schema: JsonSchemaResult = { type: \"string\", format: \"date-time\" };\r\n\r\n // Check if an explicit format rule was applied via v.date().format()\r\n const dateOpts = getRuleOptions(this.rules, \"date\");\r\n if (dateOpts?.format === \"YYYY-MM-DD\") {\r\n schema.format = \"date\";\r\n } else if (dateOpts?.format === \"HH:mm:ss\") {\r\n schema.format = \"time\";\r\n }\r\n\r\n // Transformer-based detection (marker-driven; minifier-safe).\r\n // toDateOnly/toTimeOnly tag their options bag with __jsonSchemaFormat.\r\n // toFormat() exposes the user-supplied format string in options.format.\r\n if (schema.format === \"date-time\") {\r\n for (const t of this.dataTransformers) {\r\n const hint = t.options?.__jsonSchemaFormat;\r\n if (hint === \"date\" || hint === \"time\") {\r\n schema.format = hint;\r\n break;\r\n }\r\n\r\n const userFormat = t.options?.format;\r\n\r\n if (userFormat === \"YYYY-MM-DD\") {\r\n schema.format = \"date\";\r\n break;\r\n }\r\n\r\n if (userFormat === \"HH:mm:ss\") {\r\n schema.format = \"time\";\r\n break;\r\n }\r\n }\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,YAAY;GACZ,OAAO;EACT,CAAC;CACH;;;;;CAMA,AAAO,cAAc,OAAe,cAA6B;EAC/D,OAAO,KAAK,QAAQ,YAAY,cAAc;GAC5C,YAAY;GACZ,OAAO;EACT,CAAC;CACH;;CAGA,AAAO,QAAQ,SAAwB,cAAuB;EAC5D,OAAO,KAAK,QAAQ,aAAa,cAAc,EAAE,QAAQ,CAAC;CAC5D;;CAKA,AAAO,SAAS,QAAiB,QAAiB,cAAuB;EACvE,OAAO,KAAK,QAAQ,cAAc,cAAc;GAAE;GAAQ;EAAO,CAAC;CACpE;;CAGA,AAAO,SAAS,cAAuB;EACrC,OAAO,KAAK,QAAQ,cAAc,YAAY;CAChD;;;;CAKA,AAAO,aAAa;EAClB,OAAO,KAAK,8BAAc,IAAI,KAAK,CAAC;CACtC;;;;;;;;;;;;;;;;;CAkBA,AAAgB,aAAa,SAA2B,iBAAmC;EACzF,MAAM,SAA2B;GAAE,MAAM;GAAU,QAAQ;EAAY;EAGvE,MAAM,WAAW,eAAe,KAAK,OAAO,MAAM;EAClD,IAAI,UAAU,WAAW,cACvB,OAAO,SAAS;OACX,IAAI,UAAU,WAAW,YAC9B,OAAO,SAAS;EAMlB,IAAI,OAAO,WAAW,aACpB,KAAK,MAAM,KAAK,KAAK,kBAAkB;GACrC,MAAM,OAAO,EAAE,SAAS;GACxB,IAAI,SAAS,UAAU,SAAS,QAAQ;IACtC,OAAO,SAAS;IAChB;GACF;GAEA,MAAM,aAAa,EAAE,SAAS;GAE9B,IAAI,eAAe,cAAc;IAC/B,OAAO,SAAS;IAChB;GACF;GAEA,IAAI,eAAe,YAAY;IAC7B,OAAO,SAAS;IAChB;GACF;EACF;EAGF,IAAI,KAAK,YAAY,cAAc,QAAQ,MAAM;EAEjD,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"date-validator.mjs","names":[],"sources":["../../../../../../../../../seal/src/validators/date-validator.ts"],"sourcesContent":["import dayjs from \"dayjs\";\r\nimport {\r\n addDaysMutator,\r\n addHoursMutator,\r\n addMonthsMutator,\r\n addYearsMutator,\r\n dateMutator,\r\n toEndOfDayMutator,\r\n toEndOfMonthMutator,\r\n toEndOfYearMutator,\r\n toStartOfDayMutator,\r\n toStartOfMonthMutator,\r\n toStartOfYearMutator,\r\n toUTCMutator,\r\n} from \"../mutators\";\r\nimport {\r\n afterFieldRule,\r\n afterTodayRule,\r\n ageRule,\r\n beforeFieldRule,\r\n beforeHourRule,\r\n beforeMinuteRule,\r\n beforeTodayRule,\r\n betweenAgeRule,\r\n betweenDatesRule,\r\n betweenDaysRule,\r\n betweenHoursRule,\r\n betweenMinutesRule,\r\n betweenMonthsRule,\r\n betweenTimesRule,\r\n betweenYearsRule,\r\n birthdayRule,\r\n businessDayRule,\r\n dateRule,\r\n fromHourRule,\r\n fromMinuteRule,\r\n fromTodayRule,\r\n futureRule,\r\n leapYearRule,\r\n maxAgeRule,\r\n maxDateRule,\r\n maxDayRule,\r\n maxMonthRule,\r\n maxYearRule,\r\n minAgeRule,\r\n minDateRule,\r\n minDayRule,\r\n minMonthRule,\r\n minYearRule,\r\n type Month,\r\n monthRule,\r\n pastRule,\r\n quarterRule,\r\n sameAsFieldDateRule,\r\n todayRule,\r\n weekDayRule,\r\n weekdaysRule,\r\n weekendRule,\r\n withinDaysRule,\r\n withinFutureDaysRule,\r\n withinPastDaysRule,\r\n yearRule,\r\n} from \"../rules\";\r\nimport type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\r\nimport { applyNullable, getRuleOptions } from \"../standard-schema/json-schema\";\r\nimport type { WeekDay } from \"../types/date-types\";\r\nimport { isDateValue } from \"./../helpers/date-helpers\";\r\nimport { BaseValidator } from \"./base-validator\";\r\n\r\n/**\r\n * Date validator class\r\n */\r\nexport class DateValidator extends BaseValidator {\r\n public constructor(errorMessage?: string) {\r\n super();\r\n this.addMutableMutator(dateMutator); // Normalize to Date object first\r\n this.addMutableRule(dateRule, errorMessage);\r\n }\r\n\r\n /**\r\n * Check if value is a Date type\r\n */\r\n public matchesType(value: any): boolean {\r\n return isDateValue(value);\r\n }\r\n\r\n // ==================== Output Transformers ====================\r\n // These transform the Date after validation into different formats\r\n\r\n /**\r\n * Convert date to ISO string format\r\n * @category transformer\r\n */\r\n public toISOString() {\r\n return this.addTransformer((data) => (data instanceof Date ? data.toISOString() : data));\r\n }\r\n\r\n /** Convert date to Unix timestamp (milliseconds) */\r\n public toTimestamp() {\r\n return this.addTransformer((data) => (data instanceof Date ? data.getTime() : data));\r\n }\r\n\r\n // ==================== String Format Transformers ====================\r\n // These convert Date to formatted strings after validation\r\n\r\n /** Convert date to specific format using dayjs */\r\n public toFormat(format: string) {\r\n return this.addTransformer(\r\n (data, { options }) => (data instanceof Date ? dayjs(data).format(options.format) : data),\r\n { format },\r\n );\r\n }\r\n\r\n /** Convert to date only (remove time, returns YYYY-MM-DD) */\r\n public toDateOnly() {\r\n return this.addTransformer(\r\n (data) => (data instanceof Date ? dayjs(data).format(\"YYYY-MM-DD\") : data),\r\n { __jsonSchemaFormat: \"date\" },\r\n );\r\n }\r\n\r\n /** Convert to time only (returns HH:MM:SS) */\r\n public toTimeOnly() {\r\n return this.addTransformer(\r\n (data) => (data instanceof Date ? dayjs(data).format(\"HH:mm:ss\") : data),\r\n { __jsonSchemaFormat: \"time\" },\r\n );\r\n }\r\n\r\n // ==================== Date Mutators ====================\r\n // These modify the Date object before validation\r\n\r\n /**\r\n * Convert date to start of day (00:00:00)\r\n * @category mutator\r\n */\r\n public toStartOfDay() {\r\n return this.addMutator(toStartOfDayMutator);\r\n }\r\n\r\n /** Convert date to end of day (23:59:59.999) */\r\n public toEndOfDay() {\r\n return this.addMutator(toEndOfDayMutator);\r\n }\r\n\r\n /** Add or subtract days from date */\r\n public addDays(days: number) {\r\n return this.addMutator(addDaysMutator, { days });\r\n }\r\n\r\n /** Add or subtract months from date */\r\n public addMonths(months: number) {\r\n return this.addMutator(addMonthsMutator, { months });\r\n }\r\n\r\n /** Add or subtract years from date */\r\n public addYears(years: number) {\r\n return this.addMutator(addYearsMutator, { years });\r\n }\r\n\r\n /** Add or subtract hours from date */\r\n public addHours(hours: number) {\r\n return this.addMutator(addHoursMutator, { hours });\r\n }\r\n\r\n /** Convert date to UTC */\r\n public toUTC() {\r\n return this.addMutator(toUTCMutator);\r\n }\r\n\r\n // ==================== Date Range Mutators ====================\r\n\r\n /** Set to start of month */\r\n public toStartOfMonth() {\r\n return this.addMutator(toStartOfMonthMutator);\r\n }\r\n\r\n /** Set to end of month */\r\n public toEndOfMonth() {\r\n return this.addMutator(toEndOfMonthMutator);\r\n }\r\n\r\n /** Set to start of year */\r\n public toStartOfYear() {\r\n return this.addMutator(toStartOfYearMutator);\r\n }\r\n\r\n /** Set to end of year */\r\n public toEndOfYear() {\r\n return this.addMutator(toEndOfYearMutator);\r\n }\r\n\r\n // ==================== Date Comparison ====================\r\n\r\n /**\r\n * Date must be greater than or equal to the given date or field (inclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @param dateOrField - Date, timestamp, date string, or field name\r\n *\r\n * @example\r\n * ```ts\r\n * // Value comparison\r\n * v.date().min('2024-01-01')\r\n * v.date().min(new Date())\r\n * v.date().min(1698278400000)\r\n *\r\n * // Field comparison\r\n * v.date().min('startsAt')\r\n * ```\r\n *\r\n * @category Validation Rule\r\n */\r\n public min(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(minDateRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be less than or equal to the given date or field (inclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @category Validation Rule\r\n */\r\n public max(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(maxDateRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be strictly less than the given date or field (exclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @category Validation Rule\r\n */\r\n public before(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(beforeFieldRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be strictly greater than the given date or field (exclusive)\r\n *\r\n * Smart detection:\r\n * - Date instance, timestamp, or date string (with - or /) → value comparison\r\n * - Plain string → field comparison\r\n *\r\n * @category Validation Rule\r\n */\r\n public after(dateOrField: Date | string | number, errorMessage?: string): this {\r\n return this.addRule(afterFieldRule, errorMessage, {\r\n dateOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /** Date must be between start and end dates */\r\n public between(startDate: Date, endDate: Date, errorMessage?: string) {\r\n return this.addRule(betweenDatesRule, errorMessage, { startDate, endDate });\r\n }\r\n\r\n /** Date must be exactly today */\r\n public today(errorMessage?: string) {\r\n return this.addRule(todayRule, errorMessage);\r\n }\r\n\r\n /** Date must be today or in the future */\r\n public fromToday(errorMessage?: string) {\r\n return this.addRule(fromTodayRule, errorMessage);\r\n }\r\n\r\n /** Date must be before today */\r\n public beforeToday(errorMessage?: string) {\r\n return this.addRule(beforeTodayRule, errorMessage);\r\n }\r\n\r\n /** Date must be after today (not including today) */\r\n public afterToday(errorMessage?: string) {\r\n return this.addRule(afterTodayRule, errorMessage);\r\n }\r\n\r\n /** Date must be in the past */\r\n public past(errorMessage?: string) {\r\n return this.addRule(pastRule, errorMessage);\r\n }\r\n\r\n /** Date must be in the future */\r\n public future(errorMessage?: string) {\r\n return this.addRule(futureRule, errorMessage);\r\n }\r\n\r\n // ==================== Sibling Field Comparison ====================\r\n // Explicit sibling scope methods\r\n\r\n /**\r\n * Date must be >= sibling field value (inclusive)\r\n * @category Validation Rule\r\n */\r\n public minSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minDateRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be <= sibling field value (inclusive)\r\n * @category Validation Rule\r\n */\r\n public maxSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxDateRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be < sibling field value (exclusive)\r\n * @category Validation Rule\r\n */\r\n public beforeSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(beforeFieldRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be > sibling field value (exclusive)\r\n * @category Validation Rule\r\n */\r\n public afterSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(afterFieldRule, errorMessage, {\r\n dateOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /** Date must be the same as another field's date */\r\n public sameAsField(field: string, errorMessage?: string) {\r\n return this.addRule(sameAsFieldDateRule, errorMessage, {\r\n field,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /** Date must be the same as another sibling field's date */\r\n public sameAsFieldSibling(field: string, errorMessage?: string) {\r\n return this.addRule(sameAsFieldDateRule, errorMessage, {\r\n field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n // ==================== Time Validation ====================\r\n\r\n /** Time must be from specific hour onwards (0-23) */\r\n public fromHour(hour: number, errorMessage?: string) {\r\n return this.addRule(fromHourRule, errorMessage, { hour });\r\n }\r\n\r\n /** Time must be before specific hour (0-23) */\r\n public beforeHour(hour: number, errorMessage?: string) {\r\n return this.addRule(beforeHourRule, errorMessage, { hour });\r\n }\r\n\r\n /** Time must be between start and end hours (0-23) */\r\n public betweenHours(startHour: number, endHour: number, errorMessage?: string) {\r\n return this.addRule(betweenHoursRule, errorMessage, { startHour, endHour });\r\n }\r\n\r\n /** Time must be from specific minute onwards (0-59) */\r\n public fromMinute(minute: number, errorMessage?: string) {\r\n return this.addRule(fromMinuteRule, errorMessage, { minute });\r\n }\r\n\r\n /** Time must be before specific minute (0-59) */\r\n public beforeMinute(minute: number, errorMessage?: string) {\r\n return this.addRule(beforeMinuteRule, errorMessage, { minute });\r\n }\r\n\r\n /** Time must be between start and end minutes (0-59) */\r\n public betweenMinutes(startMinute: number, endMinute: number, errorMessage?: string) {\r\n return this.addRule(betweenMinutesRule, errorMessage, {\r\n startMinute,\r\n endMinute,\r\n });\r\n }\r\n\r\n /** Time must be between start and end times (HH:MM format) */\r\n public betweenTimes(startTime: string, endTime: string, errorMessage?: string) {\r\n return this.addRule(betweenTimesRule, errorMessage, { startTime, endTime });\r\n }\r\n\r\n // ==================== Age Validation ====================\r\n\r\n /** Age must be exactly the given years */\r\n public age(years: number, errorMessage?: string) {\r\n return this.addRule(ageRule, errorMessage, { years });\r\n }\r\n\r\n /** Minimum age requirement */\r\n public minAge(years: number, errorMessage?: string) {\r\n return this.addRule(minAgeRule, errorMessage, { years });\r\n }\r\n\r\n /** Maximum age requirement */\r\n public maxAge(years: number, errorMessage?: string) {\r\n return this.addRule(maxAgeRule, errorMessage, { years });\r\n }\r\n\r\n /** Age must be between min and max years */\r\n public betweenAge(minAge: number, maxAge: number, errorMessage?: string) {\r\n return this.addRule(betweenAgeRule, errorMessage, { minAge, maxAge });\r\n }\r\n\r\n // ==================== Day Validation ====================\r\n\r\n /** Date must be specific weekday */\r\n public weekDay(day: WeekDay, errorMessage?: string) {\r\n return this.addRule(weekDayRule, errorMessage, { day });\r\n }\r\n\r\n /** Date must be one of specified weekdays */\r\n public weekdays(days: WeekDay[], errorMessage?: string) {\r\n return this.addRule(weekdaysRule, errorMessage, { days });\r\n }\r\n\r\n /** Date must be a weekend (Saturday or Sunday) */\r\n public weekend(errorMessage?: string) {\r\n return this.addRule(weekendRule, errorMessage);\r\n }\r\n\r\n /** Date must be a business day (Monday-Friday) */\r\n public businessDay(errorMessage?: string) {\r\n return this.addRule(businessDayRule, errorMessage);\r\n }\r\n\r\n /** Date must match specific format */\r\n public format(format: string, errorMessage?: string) {\r\n return this.addRule(dateRule, errorMessage, { format });\r\n }\r\n\r\n // ==================== Relative Date Validation ====================\r\n\r\n /** Date must be within X days from now (past or future) */\r\n public withinDays(days: number, errorMessage?: string) {\r\n return this.addRule(withinDaysRule, errorMessage, { days });\r\n }\r\n\r\n /** Date must be within X days in the past */\r\n public withinPastDays(days: number, errorMessage?: string) {\r\n return this.addRule(withinPastDaysRule, errorMessage, { days });\r\n }\r\n\r\n /** Date must be within X days in the future */\r\n public withinFutureDays(days: number, errorMessage?: string) {\r\n return this.addRule(withinFutureDaysRule, errorMessage, { days });\r\n }\r\n\r\n // ==================== Period Validation ====================\r\n\r\n /** Date must be in specific month (1-12) */\r\n public month(month: Month, errorMessage?: string) {\r\n return this.addRule(monthRule, errorMessage, { month });\r\n }\r\n\r\n /** Date must be in specific year */\r\n public year(year: number, errorMessage?: string) {\r\n return this.addRule(yearRule, errorMessage, { year });\r\n }\r\n\r\n /**\r\n * Date must be between start and end years\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public betweenYears(startYear: number | string, endYear: number | string, errorMessage?: string) {\r\n return this.addRule(betweenYearsRule, errorMessage, {\r\n startYear,\r\n endYear,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between start and end months (1-12)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public betweenMonths(\r\n startMonth: Month | string,\r\n endMonth: Month | string,\r\n errorMessage?: string,\r\n ) {\r\n return this.addRule(betweenMonthsRule, errorMessage, {\r\n startMonth,\r\n endMonth,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between start and end days (1-31)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public betweenDays(startDay: number | string, endDay: number | string, errorMessage?: string) {\r\n return this.addRule(betweenDaysRule, errorMessage, {\r\n startDay,\r\n endDay,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between sibling field years\r\n * @category Validation Rule\r\n */\r\n public betweenYearsSibling(startYearField: string, endYearField: string, errorMessage?: string) {\r\n return this.addRule(betweenYearsRule, errorMessage, {\r\n startYear: startYearField,\r\n endYear: endYearField,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between sibling field months\r\n * @category Validation Rule\r\n */\r\n public betweenMonthsSibling(\r\n startMonthField: string,\r\n endMonthField: string,\r\n errorMessage?: string,\r\n ) {\r\n return this.addRule(betweenMonthsRule, errorMessage, {\r\n startMonth: startMonthField,\r\n endMonth: endMonthField,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Date must be between sibling field days\r\n * @category Validation Rule\r\n */\r\n public betweenDaysSibling(startDayField: string, endDayField: string, errorMessage?: string) {\r\n return this.addRule(betweenDaysRule, errorMessage, {\r\n startDay: startDayField,\r\n endDay: endDayField,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be >= given year or field\r\n * Smart detection: number or field name\r\n *\r\n * @example\r\n * ```ts\r\n * // Value comparison\r\n * v.date().minYear(2024)\r\n *\r\n * // Field comparison\r\n * v.date().minYear('startYear')\r\n * ```\r\n *\r\n * @category Validation Rule\r\n */\r\n public minYear(yearOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(minYearRule, errorMessage, {\r\n yearOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be <= given year or field\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public maxYear(yearOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(maxYearRule, errorMessage, {\r\n yearOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be >= given month or field (1-12)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public minMonth(monthOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(minMonthRule, errorMessage, {\r\n monthOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be <= given month or field (1-12)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public maxMonth(monthOrField: Month | string, errorMessage?: string): this {\r\n return this.addRule(maxMonthRule, errorMessage, {\r\n monthOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be >= given day or field (1-31)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public minDay(dayOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(minDayRule, errorMessage, {\r\n dayOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be <= given day or field (1-31)\r\n * Smart detection: number or field name\r\n *\r\n * @category Validation Rule\r\n */\r\n public maxDay(dayOrField: number | string, errorMessage?: string): this {\r\n return this.addRule(maxDayRule, errorMessage, {\r\n dayOrField,\r\n scope: \"global\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be >= sibling field year\r\n * @category Validation Rule\r\n */\r\n public minYearSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minYearRule, errorMessage, {\r\n yearOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Year must be <= sibling field year\r\n * @category Validation Rule\r\n */\r\n public maxYearSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxYearRule, errorMessage, {\r\n yearOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be >= sibling field month\r\n * @category Validation Rule\r\n */\r\n public minMonthSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minMonthRule, errorMessage, {\r\n monthOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Month must be <= sibling field month\r\n * @category Validation Rule\r\n */\r\n public maxMonthSibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxMonthRule, errorMessage, {\r\n monthOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be >= sibling field day\r\n * @category Validation Rule\r\n */\r\n public minDaySibling(field: string, errorMessage?: string): this {\r\n return this.addRule(minDayRule, errorMessage, {\r\n dayOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /**\r\n * Day must be <= sibling field day\r\n * @category Validation Rule\r\n */\r\n public maxDaySibling(field: string, errorMessage?: string): this {\r\n return this.addRule(maxDayRule, errorMessage, {\r\n dayOrField: field,\r\n scope: \"sibling\",\r\n });\r\n }\r\n\r\n /** Date must be in specific quarter (1-4) */\r\n public quarter(quarter: 1 | 2 | 3 | 4, errorMessage?: string) {\r\n return this.addRule(quarterRule, errorMessage, { quarter });\r\n }\r\n\r\n // ==================== Special Validation ====================\r\n\r\n /** Valid birthday (not in future, reasonable age) */\r\n public birthday(minAge?: number, maxAge?: number, errorMessage?: string) {\r\n return this.addRule(birthdayRule, errorMessage, { minAge, maxAge });\r\n }\r\n\r\n /** Date must be in a leap year */\r\n public leapYear(errorMessage?: string) {\r\n return this.addRule(leapYearRule, errorMessage);\r\n }\r\n\r\n /**\r\n * Set default value as current time of exeuction\r\n */\r\n public defaultNow() {\r\n return this.default(() => new Date());\r\n }\r\n\r\n /**\r\n * @inheritdoc\r\n *\r\n * Maps DateValidator to JSON Schema format keywords.\r\n * Default is `date-time`. If `.toDateOnly()` or `.toTimeOnly()` are used,\r\n * falls back to `date` or `time` formats respectively.\r\n *\r\n * @example\r\n * ```ts\r\n * v.date().toJsonSchema(\"draft-2020-12\")\r\n * // → { type: \"string\", format: \"date-time\" }\r\n *\r\n * v.date().toDateOnly().toJsonSchema(\"draft-2020-12\")\r\n * // → { type: \"string\", format: \"date\" }\r\n * ```\r\n */\r\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\r\n const schema: JsonSchemaResult = { type: \"string\", format: \"date-time\" };\r\n\r\n // Check if an explicit format rule was applied via v.date().format()\r\n const dateOpts = getRuleOptions(this.rules, \"date\");\r\n if (dateOpts?.format === \"YYYY-MM-DD\") {\r\n schema.format = \"date\";\r\n } else if (dateOpts?.format === \"HH:mm:ss\") {\r\n schema.format = \"time\";\r\n }\r\n\r\n // Transformer-based detection (marker-driven; minifier-safe).\r\n // toDateOnly/toTimeOnly tag their options bag with __jsonSchemaFormat.\r\n // toFormat() exposes the user-supplied format string in options.format.\r\n if (schema.format === \"date-time\") {\r\n for (const t of this.dataTransformers) {\r\n const hint = t.options?.__jsonSchemaFormat;\r\n if (hint === \"date\" || hint === \"time\") {\r\n schema.format = hint;\r\n break;\r\n }\r\n\r\n const userFormat = t.options?.format;\r\n\r\n if (userFormat === \"YYYY-MM-DD\") {\r\n schema.format = \"date\";\r\n break;\r\n }\r\n\r\n if (userFormat === \"HH:mm:ss\") {\r\n schema.format = \"time\";\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this.isNullable) applyNullable(schema, target);\r\n\r\n return schema;\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwEA,IAAa,gBAAb,cAAmC,cAAc;CAC/C,AAAO,YAAY,cAAuB;EACxC,MAAM;EACN,KAAK,kBAAkB,WAAW;EAClC,KAAK,eAAe,UAAU,YAAY;CAC5C;;;;CAKA,AAAO,YAAY,OAAqB;EACtC,OAAO,YAAY,KAAK;CAC1B;;;;;CASA,AAAO,cAAc;EACnB,OAAO,KAAK,gBAAgB,SAAU,gBAAgB,OAAO,KAAK,YAAY,IAAI,IAAK;CACzF;;CAGA,AAAO,cAAc;EACnB,OAAO,KAAK,gBAAgB,SAAU,gBAAgB,OAAO,KAAK,QAAQ,IAAI,IAAK;CACrF;;CAMA,AAAO,SAAS,QAAgB;EAC9B,OAAO,KAAK,gBACT,MAAM,EAAE,cAAe,gBAAgB,qCAAa,IAAI,EAAE,OAAO,QAAQ,MAAM,IAAI,MACpF,EAAE,OAAO,CACX;CACF;;CAGA,AAAO,aAAa;EAClB,OAAO,KAAK,gBACT,SAAU,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W,YAC9B,OAAO,SAAS;EAMlB,IAAI,OAAO,WAAW,aACpB,KAAK,MAAM,KAAK,KAAK,kBAAkB;GACrC,MAAM,OAAO,EAAE,SAAS;GACxB,IAAI,SAAS,UAAU,SAAS,QAAQ;IACtC,OAAO,SAAS;IAChB;GACF;GAEA,MAAM,aAAa,EAAE,SAAS;GAE9B,IAAI,eAAe,cAAc;IAC/B,OAAO,SAAS;IAChB;GACF;GAEA,IAAI,eAAe,YAAY;IAC7B,OAAO,SAAS;IAChB;GACF;EACF;EAGF,IAAI,KAAK,YAAY,cAAc,QAAQ,MAAM;EAEjD,OAAO;CACT;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { applyNullable, wrapNullableStrict } from "../standard-schema/json-schema.mjs";
|
|
2
|
-
import { isPlainObject } from "../../../node_modules/@mongez/supportive-is/esm/index.mjs";
|
|
2
|
+
import { isPlainObject } from "../../../node_modules/.pnpm/@mongez_supportive-is@2.1.4/node_modules/@mongez/supportive-is/esm/index.mjs";
|
|
3
3
|
import { BaseValidator } from "./base-validator.mjs";
|
|
4
4
|
import { LiteralValidator } from "./literal-validator.mjs";
|
|
5
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminated-union-validator.mjs","names":[],"sources":["../../../../../../../../../seal/src/validators/discriminated-union-validator.ts"],"sourcesContent":["import { isPlainObject } from \"@mongez/supportive-is\";\nimport type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\nimport { applyNullable, wrapNullableStrict } from \"../standard-schema/json-schema\";\nimport type { SchemaContext, ValidationResult } from \"../types\";\nimport { BaseValidator } from \"./base-validator\";\nimport { LiteralValidator } from \"./literal-validator\";\nimport { ObjectValidator } from \"./object-validator\";\n\n/**\n * Discriminated union validator — routes payloads by a shared discriminator field.\n *\n * Plain `v.union()` falls back to `matchesType()` to pick a branch, which is\n * coarse for object-vs-object unions (every branch matches \"is plain object\").\n * Discriminated union reads a known field's value and routes directly to the\n * matching branch, producing precise errors instead of confused mash from the\n * wrong branch.\n *\n * **Construction-time validation.** Every branch must:\n * - Be an `ObjectValidator`\n * - Declare the discriminator field\n * - Type the discriminator as `v.literal(...)` (single or multi-literal both work)\n * - Not collide with another branch's literal values\n *\n * Misconfigurations throw eagerly so tests catch them at schema-build time.\n *\n * @example\n * ```ts\n * const email = v.object({ type: v.literal(\"email\"), email: v.string().email() });\n * const sms = v.object({ type: v.literal(\"sms\"), phone: v.string() });\n * const push = v.object({ type: v.literal(\"push\"), deviceId: v.string() });\n *\n * const notif = v.discriminatedUnion(\"type\", [email, sms, push]);\n *\n * await validate(notif, { type: \"sms\", phone: \"555-1234\" });\n * // → routes to sms branch only; errors (if any) come from sms\n * ```\n *\n * @see `domains/seal/plans/2026-05-12-discriminated-union.md`\n */\nexport class DiscriminatedUnionValidator<\n K extends string = string,\n Branches extends ReadonlyArray<ObjectValidator<any>> = ReadonlyArray<ObjectValidator<any>>,\n> extends BaseValidator {\n /** Map from discriminator literal value → matching branch validator. */\n private branches: Map<string | number | boolean, ObjectValidator<any>>;\n\n public constructor(\n public discriminator: K,\n public validators: Branches,\n ) {\n super();\n\n this.branches = DiscriminatedUnionValidator.buildBranchMap(discriminator, validators);\n }\n\n /**\n * Walk every branch, pull out the discriminator's literal values, and build\n * the lookup map. Throws on misconfiguration (missing discriminator,\n * non-literal discriminator, duplicate literal value).\n */\n private static buildBranchMap(\n discriminator: string,\n validators: ReadonlyArray<ObjectValidator<any>>,\n ): Map<string | number | boolean, ObjectValidator<any>> {\n const map = new Map<string | number | boolean, ObjectValidator<any>>();\n\n for (const branch of validators) {\n const discriminatorValidator = branch.schema?.[discriminator];\n\n if (!discriminatorValidator) {\n throw new Error(\n `[Seal] discriminatedUnion: branch missing discriminator field \"${discriminator}\"`,\n );\n }\n\n if (!(discriminatorValidator instanceof LiteralValidator)) {\n throw new Error(\n `[Seal] discriminatedUnion: discriminator \"${discriminator}\" must be v.literal(...) on every branch`,\n );\n }\n\n for (const value of discriminatorValidator.values) {\n if (map.has(value)) {\n throw new Error(\n `[Seal] discriminatedUnion: duplicate discriminator value \"${String(value)}\"`,\n );\n }\n map.set(value, branch);\n }\n }\n\n return map;\n }\n\n public override matchesType(value: any): boolean {\n return isPlainObject(value);\n }\n\n public override async validate(data: any, context: SchemaContext): Promise<ValidationResult> {\n if (data === null && this.isNullable) {\n return { isValid: true, errors: [], data: null };\n }\n\n if (!isPlainObject(data)) {\n return {\n isValid: false,\n errors: [\n {\n type: \"discriminatedUnion\",\n error: `Expected object with discriminator field \"${this.discriminator}\"`,\n input: context.key || context.path || \"value\",\n },\n ],\n data: undefined,\n };\n }\n\n const discriminatorValue = data[this.discriminator];\n const branch = this.branches.get(discriminatorValue);\n\n if (!branch) {\n const allowed = [...this.branches.keys()].map((k) => String(k)).join(\", \");\n return {\n isValid: false,\n errors: [\n {\n type: \"discriminatedUnion\",\n error: `Field \"${this.discriminator}\" must be one of: ${allowed}`,\n input: this.discriminator,\n },\n ],\n data: undefined,\n };\n }\n\n return branch.validate(data, context);\n }\n\n public override clone(): this {\n const cloned = super.clone() as any;\n cloned.discriminator = this.discriminator;\n cloned.validators = this.validators.map((v: ObjectValidator<any>) => v.clone());\n cloned.branches = DiscriminatedUnionValidator.buildBranchMap(\n cloned.discriminator,\n cloned.validators,\n );\n return cloned;\n }\n\n /**\n * Emit `oneOf` of branch schemas. Each branch's own `toJsonSchema()` handles\n * its `properties.{discriminator}.const` and the surrounding required/optional\n * structure — we just enumerate.\n *\n * For `openai-strict`: the per-branch ObjectValidator already inflates\n * `required` to include every field; `oneOf` is OpenAI-accepted as long as\n * each branch passes strict rules independently.\n */\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\n const oneOf = this.validators.map((v) => v.toJsonSchema(target));\n const schema: JsonSchemaResult = { oneOf };\n\n if (this.isNullable) {\n if (target === \"openai-strict\") {\n return wrapNullableStrict(schema);\n }\n applyNullable(schema, target);\n }\n\n return schema;\n }\n}\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validator.mjs","names":[],"sources":["../../../../../../../../../seal/src/validators/discriminated-union-validator.ts"],"sourcesContent":["import { isPlainObject } from \"@mongez/supportive-is\";\nimport type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\nimport { applyNullable, wrapNullableStrict } from \"../standard-schema/json-schema\";\nimport type { SchemaContext, ValidationResult } from \"../types\";\nimport { BaseValidator } from \"./base-validator\";\nimport { LiteralValidator } from \"./literal-validator\";\nimport { ObjectValidator } from \"./object-validator\";\n\n/**\n * Discriminated union validator — routes payloads by a shared discriminator field.\n *\n * Plain `v.union()` falls back to `matchesType()` to pick a branch, which is\n * coarse for object-vs-object unions (every branch matches \"is plain object\").\n * Discriminated union reads a known field's value and routes directly to the\n * matching branch, producing precise errors instead of confused mash from the\n * wrong branch.\n *\n * **Construction-time validation.** Every branch must:\n * - Be an `ObjectValidator`\n * - Declare the discriminator field\n * - Type the discriminator as `v.literal(...)` (single or multi-literal both work)\n * - Not collide with another branch's literal values\n *\n * Misconfigurations throw eagerly so tests catch them at schema-build time.\n *\n * @example\n * ```ts\n * const email = v.object({ type: v.literal(\"email\"), email: v.string().email() });\n * const sms = v.object({ type: v.literal(\"sms\"), phone: v.string() });\n * const push = v.object({ type: v.literal(\"push\"), deviceId: v.string() });\n *\n * const notif = v.discriminatedUnion(\"type\", [email, sms, push]);\n *\n * await validate(notif, { type: \"sms\", phone: \"555-1234\" });\n * // → routes to sms branch only; errors (if any) come from sms\n * ```\n *\n * @see `domains/seal/plans/2026-05-12-discriminated-union.md`\n */\nexport class DiscriminatedUnionValidator<\n K extends string = string,\n Branches extends ReadonlyArray<ObjectValidator<any>> = ReadonlyArray<ObjectValidator<any>>,\n> extends BaseValidator {\n /** Map from discriminator literal value → matching branch validator. */\n private branches: Map<string | number | boolean, ObjectValidator<any>>;\n\n public constructor(\n public discriminator: K,\n public validators: Branches,\n ) {\n super();\n\n this.branches = DiscriminatedUnionValidator.buildBranchMap(discriminator, validators);\n }\n\n /**\n * Walk every branch, pull out the discriminator's literal values, and build\n * the lookup map. Throws on misconfiguration (missing discriminator,\n * non-literal discriminator, duplicate literal value).\n */\n private static buildBranchMap(\n discriminator: string,\n validators: ReadonlyArray<ObjectValidator<any>>,\n ): Map<string | number | boolean, ObjectValidator<any>> {\n const map = new Map<string | number | boolean, ObjectValidator<any>>();\n\n for (const branch of validators) {\n const discriminatorValidator = branch.schema?.[discriminator];\n\n if (!discriminatorValidator) {\n throw new Error(\n `[Seal] discriminatedUnion: branch missing discriminator field \"${discriminator}\"`,\n );\n }\n\n if (!(discriminatorValidator instanceof LiteralValidator)) {\n throw new Error(\n `[Seal] discriminatedUnion: discriminator \"${discriminator}\" must be v.literal(...) on every branch`,\n );\n }\n\n for (const value of discriminatorValidator.values) {\n if (map.has(value)) {\n throw new Error(\n `[Seal] discriminatedUnion: duplicate discriminator value \"${String(value)}\"`,\n );\n }\n map.set(value, branch);\n }\n }\n\n return map;\n }\n\n public override matchesType(value: any): boolean {\n return isPlainObject(value);\n }\n\n public override async validate(data: any, context: SchemaContext): Promise<ValidationResult> {\n if (data === null && this.isNullable) {\n return { isValid: true, errors: [], data: null };\n }\n\n if (!isPlainObject(data)) {\n return {\n isValid: false,\n errors: [\n {\n type: \"discriminatedUnion\",\n error: `Expected object with discriminator field \"${this.discriminator}\"`,\n input: context.key || context.path || \"value\",\n },\n ],\n data: undefined,\n };\n }\n\n const discriminatorValue = data[this.discriminator];\n const branch = this.branches.get(discriminatorValue);\n\n if (!branch) {\n const allowed = [...this.branches.keys()].map((k) => String(k)).join(\", \");\n return {\n isValid: false,\n errors: [\n {\n type: \"discriminatedUnion\",\n error: `Field \"${this.discriminator}\" must be one of: ${allowed}`,\n input: this.discriminator,\n },\n ],\n data: undefined,\n };\n }\n\n return branch.validate(data, context);\n }\n\n public override clone(): this {\n const cloned = super.clone() as any;\n cloned.discriminator = this.discriminator;\n cloned.validators = this.validators.map((v: ObjectValidator<any>) => v.clone());\n cloned.branches = DiscriminatedUnionValidator.buildBranchMap(\n cloned.discriminator,\n cloned.validators,\n );\n return cloned;\n }\n\n /**\n * Emit `oneOf` of branch schemas. Each branch's own `toJsonSchema()` handles\n * its `properties.{discriminator}.const` and the surrounding required/optional\n * structure — we just enumerate.\n *\n * For `openai-strict`: the per-branch ObjectValidator already inflates\n * `required` to include every field; `oneOf` is OpenAI-accepted as long as\n * each branch passes strict rules independently.\n */\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\n const oneOf = this.validators.map((v) => v.toJsonSchema(target));\n const schema: JsonSchemaResult = { oneOf };\n\n if (this.isNullable) {\n if (target === \"openai-strict\") {\n return wrapNullableStrict(schema);\n }\n applyNullable(schema, target);\n }\n\n return schema;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,8BAAb,MAAa,oCAGH,cAAc;CAKb;CACA;;CAJT,AAAQ;CAER,AAAO,YACL,AAAO,eACP,AAAO,YACP;EACA,MAAM;EAHC;EACA;EAIP,KAAK,WAAW,4BAA4B,eAAe,eAAe,UAAU;CACtF;;;;;;CAOA,OAAe,eACb,eACA,YACsD;EACtD,MAAM,sBAAM,IAAI,IAAqD;EAErE,KAAK,MAAM,UAAU,YAAY;GAC/B,MAAM,yBAAyB,OAAO,SAAS;GAE/C,IAAI,CAAC,wBACH,MAAM,IAAI,MACR,kEAAkE,cAAc,EAClF;GAGF,IAAI,EAAE,kCAAkC,mBACtC,MAAM,IAAI,MACR,6CAA6C,cAAc,yCAC7D;GAGF,KAAK,MAAM,SAAS,uBAAuB,QAAQ;IACjD,IAAI,IAAI,IAAI,KAAK,GACf,MAAM,IAAI,MACR,6DAA6D,OAAO,KAAK,EAAE,EAC7E;IAEF,IAAI,IAAI,OAAO,MAAM;GACvB;EACF;EAEA,OAAO;CACT;CAEA,AAAgB,YAAY,OAAqB;EAC/C,OAAO,cAAc,KAAK;CAC5B;CAEA,MAAsB,SAAS,MAAW,SAAmD;EAC3F,IAAI,SAAS,QAAQ,KAAK,YACxB,OAAO;GAAE,SAAS;GAAM,QAAQ,CAAC;GAAG,MAAM;EAAK;EAGjD,IAAI,CAAC,cAAc,IAAI,GACrB,OAAO;GACL,SAAS;GACT,QAAQ,CACN;IACE,MAAM;IACN,OAAO,6CAA6C,KAAK,cAAc;IACvE,OAAO,QAAQ,OAAO,QAAQ,QAAQ;GACxC,CACF;GACA,MAAM;EACR;EAGF,MAAM,qBAAqB,KAAK,KAAK;EACrC,MAAM,SAAS,KAAK,SAAS,IAAI,kBAAkB;EAEnD,IAAI,CAAC,QAAQ;GACX,MAAM,UAAU,CAAC,GAAG,KAAK,SAAS,KAAK,CAAC,EAAE,KAAK,MAAM,OAAO,CAAC,CAAC,EAAE,KAAK,IAAI;GACzE,OAAO;IACL,SAAS;IACT,QAAQ,CACN;KACE,MAAM;KACN,OAAO,UAAU,KAAK,cAAc,oBAAoB;KACxD,OAAO,KAAK;IACd,CACF;IACA,MAAM;GACR;EACF;EAEA,OAAO,OAAO,SAAS,MAAM,OAAO;CACtC;CAEA,AAAgB,QAAc;EAC5B,MAAM,SAAS,MAAM,MAAM;EAC3B,OAAO,gBAAgB,KAAK;EAC5B,OAAO,aAAa,KAAK,WAAW,KAAK,MAA4B,EAAE,MAAM,CAAC;EAC9E,OAAO,WAAW,4BAA4B,eAC5C,OAAO,eACP,OAAO,UACT;EACA,OAAO;CACT;;;;;;;;;;CAWA,AAAgB,aAAa,SAA2B,iBAAmC;EAEzF,MAAM,SAA2B,EAAE,OADrB,KAAK,WAAW,KAAK,MAAM,EAAE,aAAa,MAAM,CACvB,EAAE;EAEzC,IAAI,KAAK,YAAY;GACnB,IAAI,WAAW,iBACb,OAAO,mBAAmB,MAAM;GAElC,cAAc,QAAQ,MAAM;EAC9B;EAEA,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-validator.mjs","names":[],"sources":["../../../../../../../../../seal/src/validators/lazy-validator.ts"],"sourcesContent":["import type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\nimport type { SchemaContext, ValidationResult } from \"../types\";\nimport { BaseValidator } from \"./base-validator\";\n\n/**\n * Lazy validator — defers resolution of the inner validator until validate-time.\n *\n * Solves the chicken-and-egg of self-referencing schemas. JavaScript evaluates\n * an object literal before the `const` binding completes, so this can't work:\n *\n * ```ts\n * const categorySchema = v.object({\n * name: v.string(),\n * children: v.array(categorySchema), // ❌ ReferenceError\n * });\n * ```\n *\n * Wrap the recursive reference in `v.lazy(() => …)` — the thunk isn't invoked\n * during construction, only when `validate()` is called:\n *\n * ```ts\n * type Category = { name: string; children: Category[] };\n *\n * const categorySchema: ObjectValidator<...> = v.object({\n * name: v.string(),\n * children: v.array(v.lazy(() => categorySchema)),\n * });\n *\n * type T = Infer<typeof categorySchema>;\n * // { name: string; children: T[] } ← recursive type\n * ```\n *\n * The thunk is memoized — it's invoked once on the first validate (or\n * `matchesType` / `toJsonSchema`) call and the result is cached. The thunk is\n * expected to return a stable validator; calling it on every validate would be\n * wasteful and could mask bugs where the user accidentally returns a fresh\n * validator each time.\n *\n * **JSON Schema caveat.** v1 uses simple resolve-and-delegate — recursive\n * schemas will infinite-loop in `toJsonSchema()`. If you need JSON Schema for\n * a recursive shape, generate it manually with `$defs` + `$ref` until v2 lands.\n *\n * @see `domains/seal/plans/2026-05-12-lazy-validator.md`\n */\nexport class LazyValidator<T extends BaseValidator = BaseValidator> extends BaseValidator {\n private resolvedValidator: T | undefined;\n\n public constructor(private thunk: () => T) {\n super();\n // Lazy itself defers required handling to the inner validator —\n // mark the wrapper as optional so the required check doesn't fire here.\n this.requiredRule = null;\n this.isOptional = true;\n }\n\n /**\n * Resolve the inner validator. Memoizes the result so subsequent calls\n * don't re-execute the thunk.\n */\n private resolve(): T {\n if (this.resolvedValidator === undefined) {\n this.resolvedValidator = this.thunk();\n }\n\n return this.resolvedValidator;\n }\n\n public override async validate(data: any, context: SchemaContext): Promise<ValidationResult> {\n return this.resolve().validate(data, context);\n }\n\n public override matchesType(value: any): boolean {\n return this.resolve().matchesType(value);\n }\n\n public override clone(): this {\n const cloned = super.clone();\n // Share the thunk reference; reset the memo so the clone resolves\n // independently on its first call (in case the thunk closure resolves\n // differently in a different context — unlikely but cheap insurance).\n cloned.thunk = this.thunk;\n cloned.resolvedValidator = undefined;\n\n return cloned;\n }\n\n /**\n * JSON Schema generation — simple resolve-and-delegate.\n *\n * **Recursive schemas will infinite-loop.** Until v2 adds `$ref` + `$defs`\n * generation, callers needing JSON Schema for recursive shapes must build\n * the schema manually.\n */\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\n return this.resolve().toJsonSchema(target);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,gBAAb,cAA4E,cAAc;CAG7D;CAF3B,AAAQ;CAER,AAAO,YAAY,AAAQ,OAAgB;EACzC,MAAM;EADmB;EAIzB,KAAK,eAAe;EACpB,KAAK,aAAa;CACpB;;;;;CAMA,AAAQ,UAAa;EACnB,IAAI,KAAK,sBAAsB,QAC7B,KAAK,oBAAoB,KAAK,MAAM;EAGtC,OAAO,KAAK;CACd;CAEA,MAAsB,SAAS,MAAW,SAAmD;EAC3F,OAAO,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"lazy-validator.mjs","names":[],"sources":["../../../../../../../../../seal/src/validators/lazy-validator.ts"],"sourcesContent":["import type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\nimport type { SchemaContext, ValidationResult } from \"../types\";\nimport { BaseValidator } from \"./base-validator\";\n\n/**\n * Lazy validator — defers resolution of the inner validator until validate-time.\n *\n * Solves the chicken-and-egg of self-referencing schemas. JavaScript evaluates\n * an object literal before the `const` binding completes, so this can't work:\n *\n * ```ts\n * const categorySchema = v.object({\n * name: v.string(),\n * children: v.array(categorySchema), // ❌ ReferenceError\n * });\n * ```\n *\n * Wrap the recursive reference in `v.lazy(() => …)` — the thunk isn't invoked\n * during construction, only when `validate()` is called:\n *\n * ```ts\n * type Category = { name: string; children: Category[] };\n *\n * const categorySchema: ObjectValidator<...> = v.object({\n * name: v.string(),\n * children: v.array(v.lazy(() => categorySchema)),\n * });\n *\n * type T = Infer<typeof categorySchema>;\n * // { name: string; children: T[] } ← recursive type\n * ```\n *\n * The thunk is memoized — it's invoked once on the first validate (or\n * `matchesType` / `toJsonSchema`) call and the result is cached. The thunk is\n * expected to return a stable validator; calling it on every validate would be\n * wasteful and could mask bugs where the user accidentally returns a fresh\n * validator each time.\n *\n * **JSON Schema caveat.** v1 uses simple resolve-and-delegate — recursive\n * schemas will infinite-loop in `toJsonSchema()`. If you need JSON Schema for\n * a recursive shape, generate it manually with `$defs` + `$ref` until v2 lands.\n *\n * @see `domains/seal/plans/2026-05-12-lazy-validator.md`\n */\nexport class LazyValidator<T extends BaseValidator = BaseValidator> extends BaseValidator {\n private resolvedValidator: T | undefined;\n\n public constructor(private thunk: () => T) {\n super();\n // Lazy itself defers required handling to the inner validator —\n // mark the wrapper as optional so the required check doesn't fire here.\n this.requiredRule = null;\n this.isOptional = true;\n }\n\n /**\n * Resolve the inner validator. Memoizes the result so subsequent calls\n * don't re-execute the thunk.\n */\n private resolve(): T {\n if (this.resolvedValidator === undefined) {\n this.resolvedValidator = this.thunk();\n }\n\n return this.resolvedValidator;\n }\n\n public override async validate(data: any, context: SchemaContext): Promise<ValidationResult> {\n return this.resolve().validate(data, context);\n }\n\n public override matchesType(value: any): boolean {\n return this.resolve().matchesType(value);\n }\n\n public override clone(): this {\n const cloned = super.clone();\n // Share the thunk reference; reset the memo so the clone resolves\n // independently on its first call (in case the thunk closure resolves\n // differently in a different context — unlikely but cheap insurance).\n cloned.thunk = this.thunk;\n cloned.resolvedValidator = undefined;\n\n return cloned;\n }\n\n /**\n * JSON Schema generation — simple resolve-and-delegate.\n *\n * **Recursive schemas will infinite-loop.** Until v2 adds `$ref` + `$defs`\n * generation, callers needing JSON Schema for recursive shapes must build\n * the schema manually.\n */\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\n return this.resolve().toJsonSchema(target);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,gBAAb,cAA4E,cAAc;CAG7D;CAF3B,AAAQ;CAER,AAAO,YAAY,AAAQ,OAAgB;EACzC,MAAM;EADmB;EAIzB,KAAK,eAAe;EACpB,KAAK,aAAa;CACpB;;;;;CAMA,AAAQ,UAAa;EACnB,IAAI,KAAK,sBAAsB,QAC7B,KAAK,oBAAoB,KAAK,MAAM;EAGtC,OAAO,KAAK;CACd;CAEA,MAAsB,SAAS,MAAW,SAAmD;EAC3F,OAAO,KAAK,QAAQ,EAAE,SAAS,MAAM,OAAO;CAC9C;CAEA,AAAgB,YAAY,OAAqB;EAC/C,OAAO,KAAK,QAAQ,EAAE,YAAY,KAAK;CACzC;CAEA,AAAgB,QAAc;EAC5B,MAAM,SAAS,MAAM,MAAM;EAI3B,OAAO,QAAQ,KAAK;EACpB,OAAO,oBAAoB;EAE3B,OAAO;CACT;;;;;;;;CASA,AAAgB,aAAa,SAA2B,iBAAmC;EACzF,OAAO,KAAK,QAAQ,EAAE,aAAa,MAAM;CAC3C;AACF"}
|