@c9up/rune 0.1.5 → 0.1.7

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/src/errors.ts CHANGED
@@ -12,3 +12,51 @@ export class RuneError extends Error {
12
12
  this.hint = options?.hint;
13
13
  }
14
14
  }
15
+
16
+ /**
17
+ * A single validation failure in a {@link RuneValidationError} — mirrors the
18
+ * VineJS `SimpleErrorReporter` node shape `{ message, rule, field, index?, meta? }`.
19
+ */
20
+ export interface RuneErrorNode {
21
+ /** Human-readable (already interpolated) error message. */
22
+ message: string;
23
+ /** The rule that failed, e.g. `required`, `minLength`, `email`. */
24
+ rule: string;
25
+ /** Dotted field path, e.g. `user.email` or `tags.0`. */
26
+ field: string;
27
+ /** Array index when the field is an array item (VineJS parity). */
28
+ index?: number;
29
+ /** Rule metadata carried for reporters/i18n (e.g. `{ min: 3 }`). */
30
+ meta?: Record<string, unknown>;
31
+ }
32
+
33
+ /**
34
+ * Thrown by {@link ValidationSchema.validateOrThrow} — VineJS's
35
+ * `E_VALIDATION_ERROR`. Carries the structured `messages` array and an HTTP
36
+ * `status` (422) so web layers can render it directly, matching AdonisJS/VineJS.
37
+ */
38
+ export class RuneValidationError extends Error {
39
+ /** Internal error code for programmatic handling (VineJS parity). */
40
+ readonly code = "E_VALIDATION_ERROR";
41
+ /** HTTP status for the failure (422 Unprocessable Entity). */
42
+ readonly status = 422;
43
+ /** Structured, per-field validation messages. */
44
+ readonly messages: RuneErrorNode[];
45
+
46
+ constructor(messages: RuneErrorNode[], options?: ErrorOptions) {
47
+ super("Validation failure", options);
48
+ this.name = "RuneValidationError";
49
+ this.messages = messages;
50
+ if ("captureStackTrace" in Error) {
51
+ Error.captureStackTrace(this, RuneValidationError);
52
+ }
53
+ }
54
+
55
+ get [Symbol.toStringTag](): string {
56
+ return this.name;
57
+ }
58
+
59
+ override toString(): string {
60
+ return `${this.name} [${this.code}]: ${this.message}`;
61
+ }
62
+ }
package/src/index.ts CHANGED
@@ -4,9 +4,16 @@
4
4
  * @implements FR38, FR39, FR40, FR41, FR42
5
5
  */
6
6
 
7
- export { RuneError } from "./errors.js";
7
+ export { RuneError, RuneValidationError } from "./errors.js";
8
+ export type { MessagesProviderContract } from "./MessagesProvider.js";
9
+ export { SimpleMessagesProvider } from "./MessagesProvider.js";
8
10
  export type {
11
+ CompiledRule,
12
+ FieldContext,
13
+ Infer,
9
14
  RuleChain,
15
+ RuleValidator,
16
+ ValidateOptions,
10
17
  ValidationError,
11
18
  ValidationMessageParams,
12
19
  ValidationResult,
@@ -15,6 +22,7 @@ export type {
15
22
  } from "./Schema.js";
16
23
  export {
17
24
  bindRosetta,
25
+ createRule,
18
26
  rules,
19
27
  schema,
20
28
  setValidationTranslator,