svelte-reflector 2.1.7 → 2.1.9

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.
@@ -14,6 +14,7 @@ export declare class PrimitiveProp {
14
14
  private readonly example;
15
15
  private readonly fallbackExample;
16
16
  private readonly defaultValue;
17
+ private readonly max;
17
18
  private get effectiveType();
18
19
  /** Non-required fields become nullable (| null) instead of optional (?) */
19
20
  private get isEffectivelyNullable();
@@ -13,6 +13,7 @@ export class PrimitiveProp {
13
13
  example;
14
14
  fallbackExample;
15
15
  defaultValue;
16
+ max;
16
17
  get effectiveType() {
17
18
  return this.customType ?? this.rawType;
18
19
  }
@@ -30,6 +31,7 @@ export class PrimitiveProp {
30
31
  this.example = example;
31
32
  this.fallbackExample = emptyExample;
32
33
  this.defaultValue = schemaObject.default;
34
+ this.max = schemaObject.maximum;
33
35
  const buildedType = customType ?? type;
34
36
  const treated = treatPropertyName(name);
35
37
  this.name = treated.name;
@@ -113,8 +115,9 @@ export class PrimitiveProp {
113
115
  typeParam = `<${this.effectiveType}>`;
114
116
  }
115
117
  const nullableParam = this.isNullable ? "nullable: true, " : "";
118
+ const maxParam = this.max !== undefined ? `max: ${this.max}, ` : "";
116
119
  return `
117
- build${typeParam}({ key: ${keyExpr}, placeholder: ${this.example}, example: ${buildedExample}, required: ${required}, ${nullableParam}${buildedValidator()}})
120
+ build${typeParam}({ key: ${keyExpr}, placeholder: ${this.example}, example: ${buildedExample}, required: ${required}, ${nullableParam}${maxParam}${buildedValidator()}})
118
121
  `;
119
122
  }
120
123
  thisDot() {
@@ -30,9 +30,18 @@ export type SvelteEvent = {
30
30
  currentTarget: EventTarget & SeiLa;
31
31
  };
32
32
 
33
+ export interface ValidationErrorItem {
34
+ field: string;
35
+ code: string;
36
+ message: string;
37
+ received?: string;
38
+ }
39
+
33
40
  export interface ApiErrorResponse {
34
41
  error: string;
35
42
  message: string;
43
+ statusCode?: number;
44
+ errors?: ValidationErrorItem[];
36
45
  }
37
46
 
38
47
  export class Behavior<TSuccess = unknown, TError = unknown> {
@@ -43,9 +52,12 @@ export class Behavior<TSuccess = unknown, TError = unknown> {
43
52
  export class BuildedInput<T> {
44
53
  value = $state<T>(null as any);
45
54
  display = $state<T>(null as any);
55
+ private serverErrorMessage = $state<string | null>(null);
56
+ private serverErrorValue = $state.raw<T | null>(null);
46
57
  required: boolean;
47
58
  nullable: boolean;
48
59
  placeholder: T;
60
+ max?: number;
49
61
  readonly kind = "builded";
50
62
  readonly validator?: ValidatorFn<T>;
51
63
 
@@ -55,9 +67,10 @@ export class BuildedInput<T> {
55
67
  required: boolean;
56
68
  nullable?: boolean;
57
69
  placeholder: T;
70
+ max?: number;
58
71
  validator?: ValidatorFn<T>;
59
72
  }) {
60
- const { example, required, nullable, key, validator, placeholder } = params;
73
+ const { example, required, nullable, key, validator, placeholder, max } = params;
61
74
 
62
75
  const initial = key === undefined ? example : key;
63
76
 
@@ -67,6 +80,10 @@ export class BuildedInput<T> {
67
80
  this.nullable = nullable ?? false;
68
81
  this.placeholder = placeholder;
69
82
 
83
+ if (max !== undefined) {
84
+ this.max = max;
85
+ }
86
+
70
87
  if (validator) {
71
88
  this.validator = validator;
72
89
  }
@@ -76,6 +93,21 @@ export class BuildedInput<T> {
76
93
  if (!this.validator) return null;
77
94
  return this.validator(this.value);
78
95
  }
96
+
97
+ setServerError(message: string) {
98
+ this.serverErrorMessage = message;
99
+ this.serverErrorValue = this.value;
100
+ }
101
+
102
+ clearServerError() {
103
+ this.serverErrorMessage = null;
104
+ this.serverErrorValue = null;
105
+ }
106
+
107
+ get serverError(): string | null {
108
+ if (this.serverErrorMessage === null) return null;
109
+ return this.value === this.serverErrorValue ? this.serverErrorMessage : null;
110
+ }
79
111
  }
80
112
 
81
113
  export class EnumQueryBuilder<T> {
@@ -116,6 +148,7 @@ export function build<T>(params: {
116
148
  placeholder: T;
117
149
  required: boolean;
118
150
  nullable?: boolean;
151
+ max?: number;
119
152
  validator?: ValidatorFn<T>;
120
153
  }): BuildedInput<T> {
121
154
  return new BuildedInput(params);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "2.1.7",
4
- "description": "Reflects zod types from openAPI schemas",
3
+ "version": "2.1.9",
4
+ "description": "Reflects types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",