@maestro-js/form 1.0.0-alpha.2 → 1.0.0-alpha.21
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.d.ts +4 -2
- package/dist/index.js +14 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -110,7 +110,9 @@ type ParseFormDataResult<T> = {
|
|
|
110
110
|
};
|
|
111
111
|
interface ParseFormDataOptions<T> {
|
|
112
112
|
handleFile?(file: File, path: string, data: T): Promise<string>;
|
|
113
|
-
|
|
113
|
+
validateLibraryOptions?: Record<string, unknown> | undefined;
|
|
114
|
+
jsonSchemaLibraryOptions?: Record<string, unknown> | undefined;
|
|
115
|
+
skipLogging?: boolean;
|
|
114
116
|
}
|
|
115
117
|
declare function parseFormDataClientSide<T>(schema: StandardSchema<T>, formData: FormData, options?: ParseFormDataOptions<T>): ParseFormDataResult<T> & {
|
|
116
118
|
fileEntries: FoundFile[];
|
|
@@ -180,4 +182,4 @@ declare const HeadlessForm: (<As extends React.ElementType = "form">(props: {
|
|
|
180
182
|
composeValidators: typeof composeValidators;
|
|
181
183
|
};
|
|
182
184
|
|
|
183
|
-
export { HeadlessForm, type HeadlessFormProps, type ValidationFunction, type ValidationResult };
|
|
185
|
+
export { HeadlessForm, type HeadlessFormProps, type ParseFormDataOptions, type ParseFormDataResult, type StandardSchema, type ValidationFunction, type ValidationResult };
|
package/dist/index.js
CHANGED
|
@@ -775,16 +775,21 @@ function formPathsMatch(path1, path2) {
|
|
|
775
775
|
// src/standard-schema-helpers.ts
|
|
776
776
|
function parseFormDataClientSide(schema, formData, options) {
|
|
777
777
|
const formId = formData.get("__formId");
|
|
778
|
-
const jsonSchemaParsed = parseJsonSchemaFormData(
|
|
778
|
+
const jsonSchemaParsed = parseJsonSchemaFormData(
|
|
779
|
+
schema["~standard"].jsonSchema.input({ target: "openapi-3.0", libraryOptions: options?.jsonSchemaLibraryOptions }),
|
|
780
|
+
formData
|
|
781
|
+
);
|
|
779
782
|
const files = findFiles(jsonSchemaParsed);
|
|
780
783
|
files.forEach((f) => set2(jsonSchemaParsed, f.path.join("."), "https://fakeurlforformuploading.com"));
|
|
781
|
-
const safeParsed = schema["~standard"].validate(jsonSchemaParsed, options);
|
|
784
|
+
const safeParsed = schema["~standard"].validate(jsonSchemaParsed, { libraryOptions: options?.validateLibraryOptions });
|
|
782
785
|
if (isPromise(safeParsed)) {
|
|
783
786
|
throw new Error("Async validation not supported");
|
|
784
787
|
}
|
|
785
788
|
if (safeParsed.issues?.length) {
|
|
786
|
-
|
|
787
|
-
|
|
789
|
+
if (!options?.skipLogging) {
|
|
790
|
+
console.log([...formData.entries()].map((e) => [e[0], e[1]]));
|
|
791
|
+
console.log(jsonSchemaParsed);
|
|
792
|
+
}
|
|
788
793
|
return {
|
|
789
794
|
issues: [...safeParsed.issues.map((i) => ({ ...i, path: i.path ? [...i.path] : i.path }))],
|
|
790
795
|
data: jsonSchemaParsed,
|
|
@@ -813,15 +818,17 @@ async function parseFormData(schema, formData, options) {
|
|
|
813
818
|
);
|
|
814
819
|
const obj2 = { ...parsed1.data };
|
|
815
820
|
uploadedFiles.forEach(({ key, value }) => set2(obj2, key, value));
|
|
816
|
-
const safeParsed2 = schema["~standard"].validate(obj2, options);
|
|
821
|
+
const safeParsed2 = schema["~standard"].validate(obj2, { libraryOptions: options?.validateLibraryOptions });
|
|
817
822
|
if (isPromise(safeParsed2)) {
|
|
818
823
|
throw new Error("Async validation not supported");
|
|
819
824
|
}
|
|
820
825
|
if (!safeParsed2.issues?.length) {
|
|
821
826
|
return { data: obj2, issues: void 0, formData, formId, success: true };
|
|
822
827
|
} else {
|
|
823
|
-
|
|
824
|
-
|
|
828
|
+
if (!options?.skipLogging) {
|
|
829
|
+
console.log(obj2);
|
|
830
|
+
console.log("fileEntries", parsed1.fileEntries);
|
|
831
|
+
}
|
|
825
832
|
return {
|
|
826
833
|
issues: [...safeParsed2.issues.map((i) => ({ ...i, path: i.path ? [...i.path] : i.path }))],
|
|
827
834
|
data: obj2,
|