@gunubin/vorm-form 0.1.0 → 0.2.0
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/dist/index.cjs +32 -0
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +31 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
buildOutputValues: () => buildOutputValues,
|
|
24
24
|
createField: () => createField,
|
|
25
25
|
createFormSchema: () => createFormSchema,
|
|
26
|
+
formToStandardSchema: () => formToStandardSchema,
|
|
26
27
|
resolveMessage: () => resolveMessage,
|
|
27
28
|
validateField: () => validateField,
|
|
28
29
|
validateForm: () => validateForm
|
|
@@ -164,11 +165,42 @@ function buildOutputValues(values, fields) {
|
|
|
164
165
|
}
|
|
165
166
|
return output;
|
|
166
167
|
}
|
|
168
|
+
|
|
169
|
+
// src/standard-schema.ts
|
|
170
|
+
function formToStandardSchema(schema) {
|
|
171
|
+
return {
|
|
172
|
+
"~standard": {
|
|
173
|
+
version: 1,
|
|
174
|
+
vendor: "vorm",
|
|
175
|
+
validate(value) {
|
|
176
|
+
const values = value;
|
|
177
|
+
const errors = validateForm(values, schema);
|
|
178
|
+
const errorEntries = Object.entries(errors);
|
|
179
|
+
if (errorEntries.length > 0) {
|
|
180
|
+
const issues = errorEntries.map(
|
|
181
|
+
([field, error]) => ({
|
|
182
|
+
message: error.message || error.code,
|
|
183
|
+
path: [field]
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
return { issues };
|
|
187
|
+
}
|
|
188
|
+
const output = buildOutputValues(
|
|
189
|
+
values,
|
|
190
|
+
schema.fields
|
|
191
|
+
);
|
|
192
|
+
return { value: output };
|
|
193
|
+
},
|
|
194
|
+
types: void 0
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
167
198
|
// Annotate the CommonJS export names for ESM import in node:
|
|
168
199
|
0 && (module.exports = {
|
|
169
200
|
buildOutputValues,
|
|
170
201
|
createField,
|
|
171
202
|
createFormSchema,
|
|
203
|
+
formToStandardSchema,
|
|
172
204
|
resolveMessage,
|
|
173
205
|
validateField,
|
|
174
206
|
validateForm
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VOLike, ValidationRule } from '@gunubin/vorm-core';
|
|
1
|
+
import { VOLike, ValidationRule, StandardSchemaV1 } from '@gunubin/vorm-core';
|
|
2
2
|
|
|
3
3
|
type ErrorMessageMap<C extends string = string> = {
|
|
4
4
|
[K in C]?: string;
|
|
@@ -69,4 +69,14 @@ declare function buildOutputValues(values: Record<string, unknown>, fields: Reco
|
|
|
69
69
|
|
|
70
70
|
declare function resolveMessage(code: string, ...messageSources: (ErrorMessages | undefined)[]): string;
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
type AnyFields = Record<string, FieldSchema<any, any, boolean, any>>;
|
|
73
|
+
/**
|
|
74
|
+
* Wraps a FormSchema as a Standard Schema v1 compliant object.
|
|
75
|
+
*
|
|
76
|
+
* - Input: FormInputValues (plain types, e.g. { email: string; password: string })
|
|
77
|
+
* - Output: FormOutputValues (branded types, e.g. { email: Email; password: Password })
|
|
78
|
+
* - On failure, returns issues with field-level path segments
|
|
79
|
+
*/
|
|
80
|
+
declare function formToStandardSchema<TFields extends AnyFields>(schema: FormSchema<TFields>): StandardSchemaV1<FormInputValues<TFields>, FormOutputValues<TFields>>;
|
|
81
|
+
|
|
82
|
+
export { type ErrorMessageFn, type ErrorMessageMap, type ErrorMessages, type FieldError, type FieldSchema, type FormErrors, type FormInputValues, type FormOutputValues, type FormSchema, type FormSchemaConfig, buildOutputValues, createField, createFormSchema, formToStandardSchema, resolveMessage, validateField, validateForm };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VOLike, ValidationRule } from '@gunubin/vorm-core';
|
|
1
|
+
import { VOLike, ValidationRule, StandardSchemaV1 } from '@gunubin/vorm-core';
|
|
2
2
|
|
|
3
3
|
type ErrorMessageMap<C extends string = string> = {
|
|
4
4
|
[K in C]?: string;
|
|
@@ -69,4 +69,14 @@ declare function buildOutputValues(values: Record<string, unknown>, fields: Reco
|
|
|
69
69
|
|
|
70
70
|
declare function resolveMessage(code: string, ...messageSources: (ErrorMessages | undefined)[]): string;
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
type AnyFields = Record<string, FieldSchema<any, any, boolean, any>>;
|
|
73
|
+
/**
|
|
74
|
+
* Wraps a FormSchema as a Standard Schema v1 compliant object.
|
|
75
|
+
*
|
|
76
|
+
* - Input: FormInputValues (plain types, e.g. { email: string; password: string })
|
|
77
|
+
* - Output: FormOutputValues (branded types, e.g. { email: Email; password: Password })
|
|
78
|
+
* - On failure, returns issues with field-level path segments
|
|
79
|
+
*/
|
|
80
|
+
declare function formToStandardSchema<TFields extends AnyFields>(schema: FormSchema<TFields>): StandardSchemaV1<FormInputValues<TFields>, FormOutputValues<TFields>>;
|
|
81
|
+
|
|
82
|
+
export { type ErrorMessageFn, type ErrorMessageMap, type ErrorMessages, type FieldError, type FieldSchema, type FormErrors, type FormInputValues, type FormOutputValues, type FormSchema, type FormSchemaConfig, buildOutputValues, createField, createFormSchema, formToStandardSchema, resolveMessage, validateField, validateForm };
|
package/dist/index.js
CHANGED
|
@@ -133,10 +133,41 @@ function buildOutputValues(values, fields) {
|
|
|
133
133
|
}
|
|
134
134
|
return output;
|
|
135
135
|
}
|
|
136
|
+
|
|
137
|
+
// src/standard-schema.ts
|
|
138
|
+
function formToStandardSchema(schema) {
|
|
139
|
+
return {
|
|
140
|
+
"~standard": {
|
|
141
|
+
version: 1,
|
|
142
|
+
vendor: "vorm",
|
|
143
|
+
validate(value) {
|
|
144
|
+
const values = value;
|
|
145
|
+
const errors = validateForm(values, schema);
|
|
146
|
+
const errorEntries = Object.entries(errors);
|
|
147
|
+
if (errorEntries.length > 0) {
|
|
148
|
+
const issues = errorEntries.map(
|
|
149
|
+
([field, error]) => ({
|
|
150
|
+
message: error.message || error.code,
|
|
151
|
+
path: [field]
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
return { issues };
|
|
155
|
+
}
|
|
156
|
+
const output = buildOutputValues(
|
|
157
|
+
values,
|
|
158
|
+
schema.fields
|
|
159
|
+
);
|
|
160
|
+
return { value: output };
|
|
161
|
+
},
|
|
162
|
+
types: void 0
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
136
166
|
export {
|
|
137
167
|
buildOutputValues,
|
|
138
168
|
createField,
|
|
139
169
|
createFormSchema,
|
|
170
|
+
formToStandardSchema,
|
|
140
171
|
resolveMessage,
|
|
141
172
|
validateField,
|
|
142
173
|
validateForm
|