@blazetrails/activemodel 0.0.0-stage → 0.1.0-alpha0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/LICENSE +21 -0
  2. package/dist/access.d.ts +6 -0
  3. package/dist/access.js +11 -0
  4. package/dist/access.js.map +1 -0
  5. package/dist/api.d.ts +55 -0
  6. package/dist/api.js +28 -0
  7. package/dist/api.js.map +1 -0
  8. package/dist/attribute/user-provided-default.d.ts +13 -0
  9. package/dist/attribute/user-provided-default.js +44 -0
  10. package/dist/attribute/user-provided-default.js.map +1 -0
  11. package/dist/attribute-assignment.d.ts +47 -0
  12. package/dist/attribute-assignment.js +182 -0
  13. package/dist/attribute-assignment.js.map +1 -0
  14. package/dist/attribute-methods.d.ts +231 -0
  15. package/dist/attribute-methods.js +421 -0
  16. package/dist/attribute-methods.js.map +1 -0
  17. package/dist/attribute-mutation-tracker.d.ts +64 -0
  18. package/dist/attribute-mutation-tracker.js +167 -0
  19. package/dist/attribute-mutation-tracker.js.map +1 -0
  20. package/dist/attribute-registration.d.ts +121 -0
  21. package/dist/attribute-registration.js +159 -0
  22. package/dist/attribute-registration.js.map +1 -0
  23. package/dist/attribute-set/builder.d.ts +70 -0
  24. package/dist/attribute-set/builder.js +212 -0
  25. package/dist/attribute-set/builder.js.map +1 -0
  26. package/dist/attribute-set/yaml-encoder.d.ts +12 -0
  27. package/dist/attribute-set/yaml-encoder.js +35 -0
  28. package/dist/attribute-set/yaml-encoder.js.map +1 -0
  29. package/dist/attribute-set.d.ts +40 -0
  30. package/dist/attribute-set.js +106 -0
  31. package/dist/attribute-set.js.map +1 -0
  32. package/dist/attribute.d.ts +93 -0
  33. package/dist/attribute.js +261 -0
  34. package/dist/attribute.js.map +1 -0
  35. package/dist/attributes.d.ts +77 -0
  36. package/dist/attributes.js +78 -0
  37. package/dist/attributes.js.map +1 -0
  38. package/dist/callbacks.d.ts +48 -0
  39. package/dist/callbacks.js +73 -0
  40. package/dist/callbacks.js.map +1 -0
  41. package/dist/constants.generated.d.ts +2 -0
  42. package/dist/constants.generated.js +183 -0
  43. package/dist/constants.generated.js.map +1 -0
  44. package/dist/conversion.d.ts +41 -0
  45. package/dist/conversion.js +40 -0
  46. package/dist/conversion.js.map +1 -0
  47. package/dist/deprecator.d.ts +7 -0
  48. package/dist/deprecator.js +7 -0
  49. package/dist/deprecator.js.map +1 -0
  50. package/dist/dirty.d.ts +79 -0
  51. package/dist/dirty.js +138 -0
  52. package/dist/dirty.js.map +1 -0
  53. package/dist/error.d.ts +27 -0
  54. package/dist/error.js +223 -0
  55. package/dist/error.js.map +1 -0
  56. package/dist/errors.d.ts +81 -0
  57. package/dist/errors.js +215 -0
  58. package/dist/errors.js.map +1 -0
  59. package/dist/forbidden-attributes-protection.d.ts +16 -0
  60. package/dist/forbidden-attributes-protection.js +22 -0
  61. package/dist/forbidden-attributes-protection.js.map +1 -0
  62. package/dist/gem-version.d.ts +10 -0
  63. package/dist/gem-version.js +16 -0
  64. package/dist/gem-version.js.map +1 -0
  65. package/dist/i18n.d.ts +3 -0
  66. package/dist/i18n.js +7 -0
  67. package/dist/i18n.js.map +1 -0
  68. package/dist/index.d.ts +72 -0
  69. package/dist/index.js +59 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/lint.d.ts +60 -0
  72. package/dist/lint.js +58 -0
  73. package/dist/lint.js.map +1 -0
  74. package/dist/locale/en.d.ts +2 -0
  75. package/dist/locale/en.js +41 -0
  76. package/dist/locale/en.js.map +1 -0
  77. package/dist/model.d.ts +90 -0
  78. package/dist/model.js +47 -0
  79. package/dist/model.js.map +1 -0
  80. package/dist/namespaces.d.ts +27 -0
  81. package/dist/namespaces.js +37 -0
  82. package/dist/namespaces.js.map +1 -0
  83. package/dist/naming.d.ts +76 -0
  84. package/dist/naming.js +198 -0
  85. package/dist/naming.js.map +1 -0
  86. package/dist/nested-error.d.ts +18 -0
  87. package/dist/nested-error.js +17 -0
  88. package/dist/nested-error.js.map +1 -0
  89. package/dist/secure-password.d.ts +31 -0
  90. package/dist/secure-password.js +164 -0
  91. package/dist/secure-password.js.map +1 -0
  92. package/dist/serialization.d.ts +40 -0
  93. package/dist/serialization.js +226 -0
  94. package/dist/serialization.js.map +1 -0
  95. package/dist/serializers/json.d.ts +27 -0
  96. package/dist/serializers/json.js +43 -0
  97. package/dist/serializers/json.js.map +1 -0
  98. package/dist/translation.d.ts +27 -0
  99. package/dist/translation.js +64 -0
  100. package/dist/translation.js.map +1 -0
  101. package/dist/type/big-integer.d.ts +6 -0
  102. package/dist/type/big-integer.js +10 -0
  103. package/dist/type/big-integer.js.map +1 -0
  104. package/dist/type/binary.d.ts +19 -0
  105. package/dist/type/binary.js +56 -0
  106. package/dist/type/binary.js.map +1 -0
  107. package/dist/type/boolean.d.ts +10 -0
  108. package/dist/type/boolean.js +38 -0
  109. package/dist/type/boolean.js.map +1 -0
  110. package/dist/type/date-time.d.ts +23 -0
  111. package/dist/type/date-time.js +54 -0
  112. package/dist/type/date-time.js.map +1 -0
  113. package/dist/type/date.d.ts +27 -0
  114. package/dist/type/date.js +78 -0
  115. package/dist/type/date.js.map +1 -0
  116. package/dist/type/decimal.d.ts +28 -0
  117. package/dist/type/decimal.js +71 -0
  118. package/dist/type/decimal.js.map +1 -0
  119. package/dist/type/float.d.ts +19 -0
  120. package/dist/type/float.js +38 -0
  121. package/dist/type/float.js.map +1 -0
  122. package/dist/type/helpers/accepts-multiparameter-time.d.ts +25 -0
  123. package/dist/type/helpers/accepts-multiparameter-time.js +50 -0
  124. package/dist/type/helpers/accepts-multiparameter-time.js.map +1 -0
  125. package/dist/type/helpers/mutable.d.ts +10 -0
  126. package/dist/type/helpers/mutable.js +13 -0
  127. package/dist/type/helpers/mutable.js.map +1 -0
  128. package/dist/type/helpers/numeric.d.ts +23 -0
  129. package/dist/type/helpers/numeric.js +50 -0
  130. package/dist/type/helpers/numeric.js.map +1 -0
  131. package/dist/type/helpers/time-value.d.ts +31 -0
  132. package/dist/type/helpers/time-value.js +100 -0
  133. package/dist/type/helpers/time-value.js.map +1 -0
  134. package/dist/type/helpers/timezone.d.ts +5 -0
  135. package/dist/type/helpers/timezone.js +16 -0
  136. package/dist/type/helpers/timezone.js.map +1 -0
  137. package/dist/type/helpers.d.ts +6 -0
  138. package/dist/type/helpers.js +6 -0
  139. package/dist/type/helpers.js.map +1 -0
  140. package/dist/type/immutable-string.d.ts +19 -0
  141. package/dist/type/immutable-string.js +43 -0
  142. package/dist/type/immutable-string.js.map +1 -0
  143. package/dist/type/integer.d.ts +43 -0
  144. package/dist/type/integer.js +82 -0
  145. package/dist/type/integer.js.map +1 -0
  146. package/dist/type/internal/sentinels.d.ts +12 -0
  147. package/dist/type/internal/sentinels.js +3 -0
  148. package/dist/type/internal/sentinels.js.map +1 -0
  149. package/dist/type/registry.d.ts +19 -0
  150. package/dist/type/registry.js +35 -0
  151. package/dist/type/registry.js.map +1 -0
  152. package/dist/type/serialize-cast-value.d.ts +32 -0
  153. package/dist/type/serialize-cast-value.js +56 -0
  154. package/dist/type/serialize-cast-value.js.map +1 -0
  155. package/dist/type/string.d.ts +8 -0
  156. package/dist/type/string.js +30 -0
  157. package/dist/type/string.js.map +1 -0
  158. package/dist/type/time.d.ts +16 -0
  159. package/dist/type/time.js +62 -0
  160. package/dist/type/time.js.map +1 -0
  161. package/dist/type/value.d.ts +42 -0
  162. package/dist/type/value.js +93 -0
  163. package/dist/type/value.js.map +1 -0
  164. package/dist/type.d.ts +10 -0
  165. package/dist/type.js +47 -0
  166. package/dist/type.js.map +1 -0
  167. package/dist/validations/absence.d.ts +10 -0
  168. package/dist/validations/absence.js +15 -0
  169. package/dist/validations/absence.js.map +1 -0
  170. package/dist/validations/acceptance.d.ts +37 -0
  171. package/dist/validations/acceptance.js +65 -0
  172. package/dist/validations/acceptance.js.map +1 -0
  173. package/dist/validations/callbacks.d.ts +45 -0
  174. package/dist/validations/callbacks.js +42 -0
  175. package/dist/validations/callbacks.js.map +1 -0
  176. package/dist/validations/clusivity.d.ts +37 -0
  177. package/dist/validations/clusivity.js +55 -0
  178. package/dist/validations/clusivity.js.map +1 -0
  179. package/dist/validations/comparability.d.ts +27 -0
  180. package/dist/validations/comparability.js +17 -0
  181. package/dist/validations/comparability.js.map +1 -0
  182. package/dist/validations/comparison.d.ts +15 -0
  183. package/dist/validations/comparison.js +41 -0
  184. package/dist/validations/comparison.js.map +1 -0
  185. package/dist/validations/confirmation.d.ts +29 -0
  186. package/dist/validations/confirmation.js +48 -0
  187. package/dist/validations/confirmation.js.map +1 -0
  188. package/dist/validations/exclusion.d.ts +13 -0
  189. package/dist/validations/exclusion.js +25 -0
  190. package/dist/validations/exclusion.js.map +1 -0
  191. package/dist/validations/format.d.ts +30 -0
  192. package/dist/validations/format.js +80 -0
  193. package/dist/validations/format.js.map +1 -0
  194. package/dist/validations/helper-methods.d.ts +24 -0
  195. package/dist/validations/helper-methods.js +32 -0
  196. package/dist/validations/helper-methods.js.map +1 -0
  197. package/dist/validations/inclusion.d.ts +13 -0
  198. package/dist/validations/inclusion.js +25 -0
  199. package/dist/validations/inclusion.js.map +1 -0
  200. package/dist/validations/length.d.ts +23 -0
  201. package/dist/validations/length.js +106 -0
  202. package/dist/validations/length.js.map +1 -0
  203. package/dist/validations/numericality.d.ts +76 -0
  204. package/dist/validations/numericality.js +196 -0
  205. package/dist/validations/numericality.js.map +1 -0
  206. package/dist/validations/presence.d.ts +10 -0
  207. package/dist/validations/presence.js +15 -0
  208. package/dist/validations/presence.js.map +1 -0
  209. package/dist/validations/resolve-value.d.ts +8 -0
  210. package/dist/validations/resolve-value.js +24 -0
  211. package/dist/validations/resolve-value.js.map +1 -0
  212. package/dist/validations/validates.d.ts +13 -0
  213. package/dist/validations/validates.js +53 -0
  214. package/dist/validations/validates.js.map +1 -0
  215. package/dist/validations/with.d.ts +21 -0
  216. package/dist/validations/with.js +44 -0
  217. package/dist/validations/with.js.map +1 -0
  218. package/dist/validations.d.ts +138 -0
  219. package/dist/validations.js +239 -0
  220. package/dist/validations.js.map +1 -0
  221. package/dist/validator.d.ts +31 -0
  222. package/dist/validator.js +62 -0
  223. package/dist/validator.js.map +1 -0
  224. package/dist/version.d.ts +3 -0
  225. package/dist/version.js +5 -0
  226. package/dist/version.js.map +1 -0
  227. package/package.json +61 -3
  228. package/README.md +0 -3
@@ -0,0 +1,17 @@
1
+ import { except } from "@blazetrails/ruby-compat";
2
+ export const COMPARE_CHECKS = {
3
+ greaterThan: ":>",
4
+ greaterThanOrEqualTo: ":>=",
5
+ equalTo: ":==",
6
+ lessThan: ":<",
7
+ lessThanOrEqualTo: ":<=",
8
+ otherThan: ":!=",
9
+ };
10
+ export function errorOptions(value, optionValue) {
11
+ return Object.assign(except(this.options, ...Object.keys(COMPARE_CHECKS)), {
12
+ count: optionValue,
13
+ value: value,
14
+ });
15
+ }
16
+ export const Comparability = { COMPARE_CHECKS, errorOptions };
17
+ //# sourceMappingURL=comparability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparability.js","sourceRoot":"","sources":["../../lib/validations/comparability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,WAAW,EAAE,IAAI;IACjB,oBAAoB,EAAE,KAAK;IAC3B,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,IAAI;IACd,iBAAiB,EAAE,KAAK;IACxB,SAAS,EAAE,KAAK;CACR,CAAC;AAEX,MAAM,UAAU,YAAY,CAE1B,KAAc,EACd,WAAoB;IAEpB,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE;QACzE,KAAK,EAAE,WAAW;QAClB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;AACL,CAAC;AAQD,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import type { ValidatableRecord } from "../validator.js";
3
+ import { errorOptions } from "./comparability.js";
4
+ import { resolveValue } from "./resolve-value.js";
5
+ import type { AttrNameArg, HelperMethodsHost } from "./helper-methods.js";
6
+ export declare class ComparisonValidator extends EachValidator {
7
+ resolveValue: typeof resolveValue;
8
+ errorOptions: typeof errorOptions;
9
+ checkValidityBang(): void;
10
+ validateEach(record: ValidatableRecord, attrName: string, value: unknown): void;
11
+ }
12
+ export declare const HelperMethods: {
13
+ validatesComparisonOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
14
+ };
15
+ //# sourceMappingURL=comparison.d.ts.map
@@ -0,0 +1,41 @@
1
+ import { ArgumentError } from "../attribute-assignment.js";
2
+ import { EachValidator } from "../validator.js";
3
+ import { isBlank, slice, underscore } from "@blazetrails/activesupport";
4
+ import { rbFSend, rtest } from "@blazetrails/ruby-compat";
5
+ import { COMPARE_CHECKS, errorOptions } from "./comparability.js";
6
+ import { resolveValue } from "./resolve-value.js";
7
+ export class ComparisonValidator extends EachValidator {
8
+ resolveValue = resolveValue;
9
+ errorOptions = errorOptions;
10
+ checkValidityBang() {
11
+ if (!Object.keys(COMPARE_CHECKS).some((k) => this.options[k] !== undefined)) {
12
+ throw new ArgumentError("Expected one of :greater_than, :greater_than_or_equal_to, " +
13
+ ":equal_to, :less_than, :less_than_or_equal_to, or :other_than option to be supplied.");
14
+ }
15
+ }
16
+ validateEach(record, attrName, value) {
17
+ for (const [option, rawOptionValue] of Object.entries(slice(this.options, ...Object.keys(COMPARE_CHECKS)))) {
18
+ try {
19
+ const optionValue = this.resolveValue(record, rawOptionValue);
20
+ if (value == null || isBlank(value)) {
21
+ record.errors.add(attrName, ":blank", this.errorOptions(value, optionValue));
22
+ return;
23
+ }
24
+ if (!rtest(rbFSend(value, COMPARE_CHECKS[option], optionValue))) {
25
+ record.errors.add(attrName, `:${underscore(option)}`, this.errorOptions(value, optionValue));
26
+ }
27
+ }
28
+ catch (e) {
29
+ if (!(e instanceof ArgumentError))
30
+ throw e;
31
+ record.errors.add(attrName, e.message);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ export const HelperMethods = {
37
+ validatesComparisonOf(...attrNames) {
38
+ return this.validatesWith(ComparisonValidator, this._mergeAttributes(attrNames));
39
+ },
40
+ };
41
+ //# sourceMappingURL=comparison.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparison.js","sourceRoot":"","sources":["../../lib/validations/comparison.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IACpD,YAAY,GAAG,YAAY,CAAC;IAC5B,YAAY,GAAG,YAAY,CAAC;IAEnB,iBAAiB;QACxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,EAAE,CAAC;YAC5E,MAAM,IAAI,aAAa,CACrB,4DAA4D;gBAC1D,sFAAsF,CACzF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,YAAY,CAAC,MAAyB,EAAE,QAAgB,EAAE,KAAc;QACtE,KAAK,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CACnD,KAAK,C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ttrNameArg, HelperMethodsHost } from "./helper-methods.js";
4
+ export declare class ConfirmationValidator extends EachValidator {
5
+ /** @internal */
6
+ setupBang: typeof setupBang;
7
+ /** @internal */
8
+ isConfirmationValueEqual: typeof isConfirmationValueEqual;
9
+ constructor(options: Record<string, unknown> & {
10
+ attributes?: string | string[];
11
+ });
12
+ validateEach(record: ValidatableRecord, attribute: string, value: unknown): void;
13
+ }
14
+ interface ConfirmationHost {
15
+ attributes: readonly string[];
16
+ }
17
+ /** @internal */
18
+ export declare function setupBang(this: ConfirmationHost, klass: {
19
+ prototype: object;
20
+ }): void;
21
+ /** @internal */
22
+ export declare function isConfirmationValueEqual(this: {
23
+ options: Record<string, unknown>;
24
+ }, _record: ValidatableRecord, _attribute: string, value: unknown, confirmed: unknown): boolean;
25
+ export declare const HelperMethods: {
26
+ validatesConfirmationOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
27
+ };
28
+ export {};
29
+ //# sourceMappingURL=confirmation.d.ts.map
@@ -0,0 +1,48 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import { casecmp, isNil, rbEqual, rbFSend, rbModAttrReader, rbModAttrWriter, rbModMethodDefined, rtest, filterMap, } from "@blazetrails/ruby-compat";
3
+ export class ConfirmationValidator extends EachValidator {
4
+ constructor(options) {
5
+ super(Object.assign({ caseSensitive: true }, options));
6
+ this.setupBang(options.class);
7
+ }
8
+ validateEach(record, attribute, value) {
9
+ const confirmed = rbFSend(record, `${attribute}Confirmation`);
10
+ if (!isNil(confirmed)) {
11
+ if (!this.isConfirmationValueEqual(record, attribute, value, confirmed)) {
12
+ const humanAttributeName = record.constructor.humanAttributeName(attribute);
13
+ const { caseSensitive, ...options } = this.options;
14
+ record.errors.add(`${attribute}Confirmation`, ":confirmation", Object.assign(options, { attribute: humanAttributeName }));
15
+ }
16
+ }
17
+ }
18
+ }
19
+ /** @internal */
20
+ export function setupBang(klass) {
21
+ rbModAttrReader(klass, ...filterMap([...this.attributes], (attribute) => {
22
+ if (!rbModMethodDefined(klass, `${attribute}Confirmation`)) {
23
+ return `${attribute}Confirmation`;
24
+ }
25
+ }));
26
+ rbModAttrWriter(klass, ...filterMap([...this.attributes], (attribute) => {
27
+ if (!rbModMethodDefined(klass, `${attribute}Confirmation=`)) {
28
+ return `${attribute}Confirmation`;
29
+ }
30
+ }));
31
+ }
32
+ /** @internal */
33
+ export function isConfirmationValueEqual(_record, _attribute, value, confirmed) {
34
+ if (!rtest(this.options.caseSensitive) && typeof value === "string") {
35
+ return casecmp(value, confirmed) === 0;
36
+ }
37
+ else {
38
+ return rbEqual(value, confirmed);
39
+ }
40
+ }
41
+ ConfirmationValidator.prototype.setupBang = setupBang;
42
+ ConfirmationValidator.prototype.isConfirmationValueEqual = isConfirmationValueEqual;
43
+ export const HelperMethods = {
44
+ validatesConfirmationOf(...attrNames) {
45
+ return this.validatesWith(ConfirmationValidator, this._mergeAttributes(attrNames));
46
+ },
47
+ };
48
+ //# sourceMappingURL=confirmation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmation.js","sourceRoot":"","sources":["../../lib/validations/confirmation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EACL,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,KAAK,EACL,SAAS,GACV,MAAM,0BAA0B,CAAC;AAGlC,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IAMtD,YAAY,OAAqE;QAC/E,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAA8B,CAAC,CAAC;IACzD,CAAC;IAED,YAAY,CAAC,MAAyB,EAAE,SAAiB,EAAE,KAAc;QACvE,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG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B,KAAc,EACd,SAAkB;IAElB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACpE,OAAO,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,qBAAqB,CAAC,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC;AACtD,qBAAqB,CAAC,SAAS,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;AAEpF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,uBAAuB,CAA0B,GAAG,SAAwB;QAC1E,OAAO,IAAI,CAAC,aAAa,CAAC,qBAAqB,EAAE,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IACrF,CAAC;CACF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import type { ValidatableRecord } from "../validator.js";
3
+ import type { AttrNameArg, HelperMethodsHost } from "./helper-methods.js";
4
+ import { type Clusivity } from "./clusivity.js";
5
+ export interface ExclusionValidator extends Clusivity {
6
+ }
7
+ export declare class ExclusionValidator extends EachValidator {
8
+ validateEach(record: ValidatableRecord, attribute: string, value: unknown): void;
9
+ }
10
+ export declare const HelperMethods: {
11
+ validatesExclusionOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
12
+ };
13
+ //# sourceMappingURL=exclusion.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import { include } from "@blazetrails/activesupport";
3
+ import { checkValidityBang, delimiter, inclusionMethod, isInclude, resolveValue, } from "./clusivity.js";
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
5
+ export class ExclusionValidator extends EachValidator {
6
+ validateEach(record, attribute, value) {
7
+ if (this.isInclude(record, value)) {
8
+ const { in: _in, within, ...options } = this.options;
9
+ record.errors.add(attribute, ":exclusion", Object.assign(options, { value }));
10
+ }
11
+ }
12
+ }
13
+ include(ExclusionValidator, {
14
+ checkValidityBang,
15
+ resolveValue,
16
+ delimiter,
17
+ inclusionMethod,
18
+ isInclude,
19
+ });
20
+ export const HelperMethods = {
21
+ validatesExclusionOf(...attrNames) {
22
+ return this.validatesWith(ExclusionValidator, this._mergeAttributes(attrNames));
23
+ },
24
+ };
25
+ //# sourceMappingURL=exclusion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exclusion.js","sourceRoot":"","sources":["../../lib/validations/exclusion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,EACL,iBAAiB,EAEjB,SAAS,EACT,eAAe,EACf,SAAS,EACT,YAAY,GACb,MAAM,gBAAgB,CAAC;AAKxB,4EAA4E;AAC5E,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IACnD,YAAY,CAAC,MAAyB,EAAE,SAAiB,EAAE,KAAc;QACvE,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;YAClC,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;CACF;AAED,OAAO,CAAC,kBAAkB,EAAE;IAC1B,iBAAiB;IACjB,YAAY;IACZ,SAAS;IACT,eAAe;IACf,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,oBAAoB,CAA0B,GAAG,SAAwB;QACvE,OAAO,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,CAAC;CACF,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import type { ValidatableRecord } from "../validator.js";
3
+ import { resolveValue } from "./resolve-value.js";
4
+ import type { AttrNameArg, HelperMethodsHost } from "./helper-methods.js";
5
+ export declare class FormatValidator extends EachValidator {
6
+ resolveValue: typeof resolveValue;
7
+ /** @internal */
8
+ recordError: typeof recordError;
9
+ /** @internal */
10
+ checkOptionsValidity: typeof checkOptionsValidity;
11
+ /** @internal */
12
+ regexpUsingMultilineAnchors: typeof regexpUsingMultilineAnchors;
13
+ validateEach(record: ValidatableRecord, attribute: string, value: unknown): void;
14
+ checkValidityBang(): void;
15
+ }
16
+ /** @internal */
17
+ export declare function recordError(this: {
18
+ options: Record<string, unknown>;
19
+ }, record: ValidatableRecord, attribute: string, name: "with" | "without", value: unknown): void;
20
+ /** @internal */
21
+ export declare function checkOptionsValidity(this: {
22
+ options: Record<string, unknown>;
23
+ regexpUsingMultilineAnchors(regexp: RegExp): boolean;
24
+ }, name: "with" | "without"): void;
25
+ /** @internal */
26
+ export declare function regexpUsingMultilineAnchors(regexp: RegExp): boolean;
27
+ export declare const HelperMethods: {
28
+ validatesFormatOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
29
+ };
30
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1,80 @@
1
+ import { ArgumentError } from "../attribute-assignment.js";
2
+ import { EachValidator } from "../validator.js";
3
+ import { hasKey as isInclude } from "@blazetrails/ruby-compat";
4
+ import { resolveValue } from "./resolve-value.js";
5
+ export class FormatValidator extends EachValidator {
6
+ validateEach(record, attribute, value) {
7
+ if (this.options.with) {
8
+ const regexp = this.resolveValue(record, this.options.with);
9
+ if (!matchStateless(regexp, String(value ?? ""))) {
10
+ this.recordError(record, attribute, "with", value);
11
+ }
12
+ }
13
+ else if (this.options.without) {
14
+ const regexp = this.resolveValue(record, this.options.without);
15
+ if (matchStateless(regexp, String(value ?? ""))) {
16
+ this.recordError(record, attribute, "without", value);
17
+ }
18
+ }
19
+ }
20
+ checkValidityBang() {
21
+ // eslint-disable-next-line blazetrails/ruby-compat-native-required -- options can hold { k: undefined } for an absent keyword, which hasKey reads as absent
22
+ if (isInclude(this.options, "with") === isInclude(this.options, "without")) {
23
+ throw new ArgumentError("Either :with or :without must be supplied (but not both)");
24
+ }
25
+ this.checkOptionsValidity("with");
26
+ this.checkOptionsValidity("without");
27
+ }
28
+ }
29
+ /** @internal */
30
+ export function recordError(record, attribute, name, value) {
31
+ const rest = {};
32
+ for (const key of Object.keys(this.options)) {
33
+ if (key !== name)
34
+ rest[key] = this.options[key];
35
+ }
36
+ rest.value = value;
37
+ record.errors.add(attribute, ":invalid", rest);
38
+ }
39
+ /** @internal */
40
+ export function checkOptionsValidity(name) {
41
+ const option = this.options[name];
42
+ if (option === undefined || option === null || option === false)
43
+ return;
44
+ if (option instanceof RegExp) {
45
+ if (this.options.multiline !== true && this.regexpUsingMultilineAnchors(option)) {
46
+ throw new ArgumentError("The provided regular expression is using multiline anchors (^ or $), " +
47
+ "which may present a security risk. Did you mean to use \\A and \\z, " +
48
+ "or forgot to add the :multiline => true option?");
49
+ }
50
+ }
51
+ else if (typeof option !== "function") {
52
+ throw new ArgumentError(`A regular expression or a proc or lambda must be supplied as :${name}`);
53
+ }
54
+ }
55
+ /** @internal */
56
+ export function regexpUsingMultilineAnchors(regexp) {
57
+ const source = regexp.source;
58
+ return (regexp.multiline &&
59
+ (source.startsWith("^") || (source.endsWith("$") && !source.endsWith("\\$"))));
60
+ }
61
+ function matchStateless(regexp, target) {
62
+ const before = regexp.lastIndex;
63
+ regexp.lastIndex = 0;
64
+ try {
65
+ return regexp.test(target);
66
+ }
67
+ finally {
68
+ regexp.lastIndex = before;
69
+ }
70
+ }
71
+ FormatValidator.prototype.resolveValue = resolveValue;
72
+ FormatValidator.prototype.recordError = recordError;
73
+ FormatValidator.prototype.checkOptionsValidity = checkOptionsValidity;
74
+ FormatValidator.prototype.regexpUsingMultilineAnchors = regexpUsingMultilineAnchors;
75
+ export const HelperMethods = {
76
+ validatesFormatOf(...attrNames) {
77
+ return this.validatesWith(FormatValidator, this._mergeAttributes(attrNames));
78
+ },
79
+ };
80
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../lib/validations/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,OAAO,eAAgB,SAAQ,aAAa;IAShD,YAAY,CAAC,MAAyB,EAAE,SAAiB,EAAE,KAAc;QACvE,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACtB,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAW,CAAC;YACtE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBACjD,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAW,CAAC;YACzE,IAAI,cAAc,CAAC,MAAM,EAAE,MAAM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3B,iBAAiB,CAA0B,GAAG,SAAwB;QACpE,OAAO,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/E,CAAC;CACF,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { ValidatableRecord } from "../validator.js";
2
+ export type AttrNameArg = string | readonly AttrNameArg[] | Record<string, unknown>;
3
+ export interface HelperMethodsHost {
4
+ _mergeAttributes(attrNames: unknown[]): Record<string, unknown>;
5
+ validatesWith(validatorClass: new (options: Record<string, unknown>) => {
6
+ validate(record: ValidatableRecord): unknown;
7
+ }, options: Record<string, unknown>): void;
8
+ }
9
+ export declare const HelperMethods: {
10
+ validatesAbsenceOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
11
+ validatesAcceptanceOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
12
+ validatesComparisonOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
13
+ validatesConfirmationOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
14
+ validatesExclusionOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
15
+ validatesFormatOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
16
+ validatesInclusionOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
17
+ validatesLengthOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
18
+ validatesSizeOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
19
+ validatesNumericalityOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
20
+ validatesPresenceOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
21
+ /** @internal */
22
+ _mergeAttributes(attrNames: unknown[]): Record<string, unknown>;
23
+ };
24
+ //# sourceMappingURL=helper-methods.d.ts.map
@@ -0,0 +1,32 @@
1
+ import { extractOptionsBang } from "@blazetrails/activesupport";
2
+ import { flatten } from "@blazetrails/ruby-compat";
3
+ import { HelperMethods as AbsenceHelperMethods } from "./absence.js";
4
+ import { HelperMethods as AcceptanceHelperMethods } from "./acceptance.js";
5
+ import { HelperMethods as ComparisonHelperMethods } from "./comparison.js";
6
+ import { HelperMethods as ConfirmationHelperMethods } from "./confirmation.js";
7
+ import { HelperMethods as ExclusionHelperMethods } from "./exclusion.js";
8
+ import { HelperMethods as FormatHelperMethods } from "./format.js";
9
+ import { HelperMethods as InclusionHelperMethods } from "./inclusion.js";
10
+ import { HelperMethods as LengthHelperMethods } from "./length.js";
11
+ import { HelperMethods as NumericalityHelperMethods } from "./numericality.js";
12
+ import { HelperMethods as PresenceHelperMethods } from "./presence.js";
13
+ export const HelperMethods = {
14
+ /** @internal */
15
+ _mergeAttributes(attrNames) {
16
+ const options = { ...extractOptionsBang(attrNames) };
17
+ attrNames.splice(0, attrNames.length, ...flatten(attrNames));
18
+ options.attributes = attrNames;
19
+ return options;
20
+ },
21
+ ...AbsenceHelperMethods,
22
+ ...AcceptanceHelperMethods,
23
+ ...ComparisonHelperMethods,
24
+ ...ConfirmationHelperMethods,
25
+ ...ExclusionHelperMethods,
26
+ ...FormatHelperMethods,
27
+ ...InclusionHelperMethods,
28
+ ...LengthHelperMethods,
29
+ ...NumericalityHelperMethods,
30
+ ...PresenceHelperMethods,
31
+ };
32
+ //# sourceMappingURL=helper-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper-methods.js","sourceRoot":"","sources":["../../lib/validations/helper-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,aAAa,IAAI,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,aAAa,IAAI,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,aAAa,IAAI,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,aAAa,IAAI,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,aAAa,IAAI,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,aAAa,IAAI,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,aAAa,IAAI,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,aAAa,IAAI,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAcvE,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,gBAAgB;IAChB,gBAAgB,CAAC,SAAoB;QACnC,MAAM,OAAO,GAA4B,EAAE,GAAG,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9E,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;QAC7D,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;QAC/B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,GAAG,oBAAoB;IACvB,GAAG,uBAAuB;IAC1B,GAAG,uBAAuB;IAC1B,GAAG,yBAAyB;IAC5B,GAAG,sBAAsB;IACzB,GAAG,mBAAmB;IACtB,GAAG,sBAAsB;IACzB,GAAG,mBAAmB;IACtB,GAAG,yBAAyB;IAC5B,GAAG,qBAAqB;CACzB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import type { ValidatableRecord } from "../validator.js";
3
+ import type { AttrNameArg, HelperMethodsHost } from "./helper-methods.js";
4
+ import { type Clusivity } from "./clusivity.js";
5
+ export interface InclusionValidator extends Clusivity {
6
+ }
7
+ export declare class InclusionValidator extends EachValidator {
8
+ validateEach(record: ValidatableRecord, attribute: string, value: unknown): void;
9
+ }
10
+ export declare const HelperMethods: {
11
+ validatesInclusionOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
12
+ };
13
+ //# sourceMappingURL=inclusion.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import { include } from "@blazetrails/activesupport";
3
+ import { checkValidityBang, delimiter, inclusionMethod, isInclude, resolveValue, } from "./clusivity.js";
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
5
+ export class InclusionValidator extends EachValidator {
6
+ validateEach(record, attribute, value) {
7
+ if (!this.isInclude(record, value)) {
8
+ const { in: _in, within, ...options } = this.options;
9
+ record.errors.add(attribute, ":inclusion", Object.assign(options, { value }));
10
+ }
11
+ }
12
+ }
13
+ include(InclusionValidator, {
14
+ checkValidityBang,
15
+ resolveValue,
16
+ delimiter,
17
+ inclusionMethod,
18
+ isInclude,
19
+ });
20
+ export const HelperMethods = {
21
+ validatesInclusionOf(...attrNames) {
22
+ return this.validatesWith(InclusionValidator, this._mergeAttributes(attrNames));
23
+ },
24
+ };
25
+ //# sourceMappingURL=inclusion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inclusion.js","sourceRoot":"","sources":["../../lib/validations/inclusion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,EACL,iBAAiB,EAEjB,SAAS,EACT,eAAe,EACf,SAAS,EACT,YAAY,GACb,MAAM,gBAAgB,CAAC;AAKxB,4EAA4E;AAC5E,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IACnD,YAAY,CAAC,MAAyB,EAAE,SAAiB,EAAE,KAAc;QACvE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;CACF;AAED,OAAO,CAAC,kBAAkB,EAAE;IAC1B,iBAAiB;IACjB,YAAY;IACZ,SAAS;IACT,eAAe;IACf,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,oBAAoB,CAA0B,GAAG,SAAwB;QACvE,OAAO,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,CAAC;CACF,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { EachValidator } from "../validator.js";
2
+ import type { ValidatableRecord } from "../validator.js";
3
+ import { resolveValue } from "./resolve-value.js";
4
+ import type { AttrNameArg, HelperMethodsHost } from "./helper-methods.js";
5
+ /** @internal */
6
+ export declare const RESERVED_OPTIONS: readonly ["minimum", "maximum", "within", "is", "tooShort", "tooLong"];
7
+ export declare class LengthValidator extends EachValidator {
8
+ resolveValue: typeof resolveValue;
9
+ /** @internal */
10
+ skipNilCheck: typeof skipNilCheck;
11
+ constructor(options: Record<string, unknown>);
12
+ checkValidityBang(): void;
13
+ validateEach(record: ValidatableRecord, attribute: string, value: unknown): Promise<void>;
14
+ }
15
+ /** @internal */
16
+ export declare function skipNilCheck(this: {
17
+ options: Record<string, unknown>;
18
+ }, key: "minimum" | "maximum" | "is"): boolean;
19
+ export declare const HelperMethods: {
20
+ validatesLengthOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
21
+ validatesSizeOf(this: HelperMethodsHost, ...attrNames: AttrNameArg[]): void;
22
+ };
23
+ //# sourceMappingURL=length.d.ts.map
@@ -0,0 +1,106 @@
1
+ import { ArgumentError } from "../attribute-assignment.js";
2
+ import { EachValidator } from "../validator.js";
3
+ import { camelize } from "@blazetrails/activesupport";
4
+ import { except, hashDelete, Range, rbObjRespondTo, rtest } from "@blazetrails/ruby-compat";
5
+ import { resolveValue } from "./resolve-value.js";
6
+ /** @internal */
7
+ const MESSAGES = {
8
+ is: ":wrong_length",
9
+ minimum: ":too_short",
10
+ maximum: ":too_long",
11
+ };
12
+ /** @internal */
13
+ const CHECKS = {
14
+ is: (valueLength, checkValue) => valueLength === checkValue,
15
+ minimum: (valueLength, checkValue) => valueLength >= checkValue,
16
+ maximum: (valueLength, checkValue) => valueLength <= checkValue,
17
+ };
18
+ /** @internal */
19
+ export const RESERVED_OPTIONS = [
20
+ "minimum",
21
+ "maximum",
22
+ "within",
23
+ "is",
24
+ "tooShort",
25
+ "tooLong",
26
+ ];
27
+ export class LengthValidator extends EachValidator {
28
+ constructor(options) {
29
+ options = { ...options };
30
+ const inOption = hashDelete(options, "in");
31
+ const range = rtest(inOption) ? inOption : hashDelete(options, "within");
32
+ if (range != null && range !== false) {
33
+ if (!(range instanceof Range)) {
34
+ throw new ArgumentError(":in and :within must be a Range");
35
+ }
36
+ const r = range;
37
+ if (r.begin !== null)
38
+ options["minimum"] = r.min();
39
+ if (r.end !== null) {
40
+ options["maximum"] = r.excludeEnd ? r.end - 1 : r.end;
41
+ }
42
+ }
43
+ if (options["allowBlank"] === false &&
44
+ options["minimum"] === undefined &&
45
+ options["is"] === undefined) {
46
+ options["minimum"] = 1;
47
+ }
48
+ super(options);
49
+ }
50
+ checkValidityBang() {
51
+ const optionKeys = new Set(Object.keys(this.options).filter((key) => this.options[key] !== undefined));
52
+ const keys = Object.keys(CHECKS).filter((key) => optionKeys.has(key));
53
+ if (keys.length === 0) {
54
+ throw new ArgumentError("Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option.");
55
+ }
56
+ for (const key of keys) {
57
+ const value = this.options[key];
58
+ if ((Number.isInteger(value) && value >= 0) ||
59
+ value === Infinity ||
60
+ value === -Infinity ||
61
+ (typeof value === "string" && value.startsWith(":")) ||
62
+ typeof value === "function") {
63
+ continue;
64
+ }
65
+ throw new ArgumentError(`:${key} must be a non-negative Integer, Infinity, Symbol, or Proc`);
66
+ }
67
+ }
68
+ async validateEach(record, attribute, value) {
69
+ const valueLength = rbObjRespondTo(value, "length")
70
+ ? value.length
71
+ : String(value == null ? "" : await value.toString()).length;
72
+ const errorsOptions = except(this.options, ...RESERVED_OPTIONS);
73
+ for (const [key, validityCheck] of Object.entries(CHECKS)) {
74
+ let checkValue = this.options[key];
75
+ if (checkValue == null)
76
+ continue;
77
+ if (value != null || this.skipNilCheck(key)) {
78
+ checkValue = this.resolveValue(record, checkValue);
79
+ if (validityCheck(valueLength, checkValue))
80
+ continue;
81
+ }
82
+ errorsOptions["count"] = checkValue;
83
+ const defaultMessage = this.options[camelize(MESSAGES[key].slice(1), false)];
84
+ if (defaultMessage != null)
85
+ errorsOptions["message"] ??= defaultMessage;
86
+ record.errors.add(attribute, MESSAGES[key], { ...errorsOptions });
87
+ }
88
+ }
89
+ }
90
+ /** @internal */
91
+ export function skipNilCheck(key) {
92
+ return (key === "maximum" &&
93
+ this.options.allowNil === undefined &&
94
+ this.options.allowBlank === undefined);
95
+ }
96
+ LengthValidator.prototype.resolveValue = resolveValue;
97
+ LengthValidator.prototype.skipNilCheck = skipNilCheck;
98
+ export const HelperMethods = {
99
+ validatesLengthOf(...attrNames) {
100
+ return this.validatesWith(LengthValidator, this._mergeAttributes(attrNames));
101
+ },
102
+ validatesSizeOf(...attrNames) {
103
+ return this.validatesWith(LengthValidator, this._mergeAttributes(attrNames));
104
+ },
105
+ };
106
+ //# sourceMappingURL=length.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"length.js","sourceRoot":"","sources":["../../lib/validations/length.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,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