@jcoreio/zod-forms 1.0.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/FieldPath.d.ts +26 -0
- package/FieldPath.d.ts.map +1 -0
- package/FieldPath.js +155 -0
- package/FieldPath.js.map +1 -0
- package/FieldPath.mjs +138 -0
- package/FieldPath.mjs.map +1 -0
- package/FormAction.d.ts +15 -0
- package/FormAction.d.ts.map +1 -0
- package/FormAction.js +6 -0
- package/FormAction.js.map +1 -0
- package/FormAction.mjs +2 -0
- package/FormAction.mjs.map +1 -0
- package/FormContext.d.ts +39 -0
- package/FormContext.d.ts.map +1 -0
- package/FormContext.js +10 -0
- package/FormContext.js.map +1 -0
- package/FormContext.mjs +3 -0
- package/FormContext.mjs.map +1 -0
- package/FormState.d.ts +31 -0
- package/FormState.d.ts.map +1 -0
- package/FormState.js +6 -0
- package/FormState.js.map +1 -0
- package/FormState.mjs +2 -0
- package/FormState.mjs.map +1 -0
- package/FormStateContext.d.ts +8 -0
- package/FormStateContext.d.ts.map +1 -0
- package/FormStateContext.js +10 -0
- package/FormStateContext.js.map +1 -0
- package/FormStateContext.mjs +3 -0
- package/FormStateContext.mjs.map +1 -0
- package/LICENSE.md +21 -0
- package/README.md +154 -0
- package/actions/addHandlers.d.ts +15 -0
- package/actions/addHandlers.d.ts.map +1 -0
- package/actions/addHandlers.js +16 -0
- package/actions/addHandlers.js.map +1 -0
- package/actions/addHandlers.mjs +7 -0
- package/actions/addHandlers.mjs.map +1 -0
- package/actions/arrayActions.d.ts +113 -0
- package/actions/arrayActions.d.ts.map +1 -0
- package/actions/arrayActions.js +146 -0
- package/actions/arrayActions.js.map +1 -0
- package/actions/arrayActions.mjs +120 -0
- package/actions/arrayActions.mjs.map +1 -0
- package/actions/initialize.d.ts +13 -0
- package/actions/initialize.d.ts.map +1 -0
- package/actions/initialize.js +16 -0
- package/actions/initialize.js.map +1 -0
- package/actions/initialize.mjs +7 -0
- package/actions/initialize.mjs.map +1 -0
- package/actions/removeHandlers.d.ts +10 -0
- package/actions/removeHandlers.d.ts.map +1 -0
- package/actions/removeHandlers.js +16 -0
- package/actions/removeHandlers.js.map +1 -0
- package/actions/removeHandlers.mjs +7 -0
- package/actions/removeHandlers.mjs.map +1 -0
- package/actions/setMeta.d.ts +9 -0
- package/actions/setMeta.d.ts.map +1 -0
- package/actions/setMeta.js +14 -0
- package/actions/setMeta.js.map +1 -0
- package/actions/setMeta.mjs +8 -0
- package/actions/setMeta.mjs.map +1 -0
- package/actions/setMounted.d.ts +6 -0
- package/actions/setMounted.d.ts.map +1 -0
- package/actions/setMounted.js +13 -0
- package/actions/setMounted.js.map +1 -0
- package/actions/setMounted.mjs +7 -0
- package/actions/setMounted.mjs.map +1 -0
- package/actions/setRawValue.d.ts +9 -0
- package/actions/setRawValue.d.ts.map +1 -0
- package/actions/setRawValue.js +14 -0
- package/actions/setRawValue.js.map +1 -0
- package/actions/setRawValue.mjs +8 -0
- package/actions/setRawValue.mjs.map +1 -0
- package/actions/setSubmitStatus.d.ts +14 -0
- package/actions/setSubmitStatus.d.ts.map +1 -0
- package/actions/setSubmitStatus.js +16 -0
- package/actions/setSubmitStatus.js.map +1 -0
- package/actions/setSubmitStatus.mjs +7 -0
- package/actions/setSubmitStatus.mjs.map +1 -0
- package/actions/setValue.d.ts +12 -0
- package/actions/setValue.d.ts.map +1 -0
- package/actions/setValue.js +18 -0
- package/actions/setValue.js.map +1 -0
- package/actions/setValue.mjs +9 -0
- package/actions/setValue.mjs.map +1 -0
- package/actions/submit.d.ts +5 -0
- package/actions/submit.d.ts.map +1 -0
- package/actions/submit.js +12 -0
- package/actions/submit.js.map +1 -0
- package/actions/submit.mjs +6 -0
- package/actions/submit.mjs.map +1 -0
- package/actions/submitSucceeded.d.ts +5 -0
- package/actions/submitSucceeded.d.ts.map +1 -0
- package/actions/submitSucceeded.js +12 -0
- package/actions/submitSucceeded.js.map +1 -0
- package/actions/submitSucceeded.mjs +6 -0
- package/actions/submitSucceeded.mjs.map +1 -0
- package/createFormMiddleware.d.ts +6 -0
- package/createFormMiddleware.d.ts.map +1 -0
- package/createFormMiddleware.js +186 -0
- package/createFormMiddleware.js.map +1 -0
- package/createFormMiddleware.mjs +53 -0
- package/createFormMiddleware.mjs.map +1 -0
- package/createFormProvider.d.ts +7 -0
- package/createFormProvider.d.ts.map +1 -0
- package/createFormProvider.js +85 -0
- package/createFormProvider.js.map +1 -0
- package/createFormProvider.mjs +63 -0
- package/createFormProvider.mjs.map +1 -0
- package/createFormReducer.d.ts +9 -0
- package/createFormReducer.d.ts.map +1 -0
- package/createFormReducer.js +95 -0
- package/createFormReducer.js.map +1 -0
- package/createFormReducer.mjs +84 -0
- package/createFormReducer.mjs.map +1 -0
- package/createSelectFieldErrorMap.d.ts +32 -0
- package/createSelectFieldErrorMap.d.ts.map +1 -0
- package/createSelectFieldErrorMap.js +43 -0
- package/createSelectFieldErrorMap.js.map +1 -0
- package/createSelectFieldErrorMap.mjs +24 -0
- package/createSelectFieldErrorMap.mjs.map +1 -0
- package/createSelectFormStatus.d.ts +89 -0
- package/createSelectFormStatus.d.ts.map +1 -0
- package/createSelectFormStatus.js +54 -0
- package/createSelectFormStatus.js.map +1 -0
- package/createSelectFormStatus.mjs +28 -0
- package/createSelectFormStatus.mjs.map +1 -0
- package/createSelectFormValues.d.ts +45 -0
- package/createSelectFormValues.d.ts.map +1 -0
- package/createSelectFormValues.js +24 -0
- package/createSelectFormValues.js.map +1 -0
- package/createSelectFormValues.mjs +10 -0
- package/createSelectFormValues.mjs.map +1 -0
- package/createZodForm.d.ts +33 -0
- package/createZodForm.d.ts.map +1 -0
- package/createZodForm.js +51 -0
- package/createZodForm.js.map +1 -0
- package/createZodForm.mjs +46 -0
- package/createZodForm.mjs.map +1 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/index.js +76 -0
- package/index.js.map +1 -0
- package/index.mjs +11 -0
- package/index.mjs.map +1 -0
- package/initFormState.d.ts +4 -0
- package/initFormState.d.ts.map +1 -0
- package/initFormState.js +22 -0
- package/initFormState.js.map +1 -0
- package/initFormState.mjs +16 -0
- package/initFormState.mjs.map +1 -0
- package/package.json +49 -0
- package/reducers/addHandlers.d.ts +24 -0
- package/reducers/addHandlers.d.ts.map +1 -0
- package/reducers/addHandlers.js +24 -0
- package/reducers/addHandlers.js.map +1 -0
- package/reducers/addHandlers.mjs +21 -0
- package/reducers/addHandlers.mjs.map +1 -0
- package/reducers/arrayInsert.d.ts +7 -0
- package/reducers/arrayInsert.d.ts.map +1 -0
- package/reducers/arrayInsert.js +16 -0
- package/reducers/arrayInsert.js.map +1 -0
- package/reducers/arrayInsert.mjs +12 -0
- package/reducers/arrayInsert.mjs.map +1 -0
- package/reducers/arrayInsertRaw.d.ts +7 -0
- package/reducers/arrayInsertRaw.d.ts.map +1 -0
- package/reducers/arrayInsertRaw.js +22 -0
- package/reducers/arrayInsertRaw.js.map +1 -0
- package/reducers/arrayInsertRaw.mjs +14 -0
- package/reducers/arrayInsertRaw.mjs.map +1 -0
- package/reducers/arrayMove.d.ts +8 -0
- package/reducers/arrayMove.d.ts.map +1 -0
- package/reducers/arrayMove.js +25 -0
- package/reducers/arrayMove.js.map +1 -0
- package/reducers/arrayMove.mjs +16 -0
- package/reducers/arrayMove.mjs.map +1 -0
- package/reducers/arrayPop.d.ts +7 -0
- package/reducers/arrayPop.d.ts.map +1 -0
- package/reducers/arrayPop.js +13 -0
- package/reducers/arrayPop.js.map +1 -0
- package/reducers/arrayPop.mjs +5 -0
- package/reducers/arrayPop.mjs.map +1 -0
- package/reducers/arrayPush.d.ts +7 -0
- package/reducers/arrayPush.d.ts.map +1 -0
- package/reducers/arrayPush.js +15 -0
- package/reducers/arrayPush.js.map +1 -0
- package/reducers/arrayPush.mjs +11 -0
- package/reducers/arrayPush.mjs.map +1 -0
- package/reducers/arrayPushRaw.d.ts +7 -0
- package/reducers/arrayPushRaw.d.ts.map +1 -0
- package/reducers/arrayPushRaw.js +17 -0
- package/reducers/arrayPushRaw.js.map +1 -0
- package/reducers/arrayPushRaw.mjs +9 -0
- package/reducers/arrayPushRaw.mjs.map +1 -0
- package/reducers/arrayRemove.d.ts +7 -0
- package/reducers/arrayRemove.d.ts.map +1 -0
- package/reducers/arrayRemove.js +21 -0
- package/reducers/arrayRemove.js.map +1 -0
- package/reducers/arrayRemove.mjs +13 -0
- package/reducers/arrayRemove.mjs.map +1 -0
- package/reducers/arrayRemoveAll.d.ts +7 -0
- package/reducers/arrayRemoveAll.d.ts.map +1 -0
- package/reducers/arrayRemoveAll.js +14 -0
- package/reducers/arrayRemoveAll.js.map +1 -0
- package/reducers/arrayRemoveAll.mjs +8 -0
- package/reducers/arrayRemoveAll.mjs.map +1 -0
- package/reducers/arrayShift.d.ts +7 -0
- package/reducers/arrayShift.d.ts.map +1 -0
- package/reducers/arrayShift.js +14 -0
- package/reducers/arrayShift.js.map +1 -0
- package/reducers/arrayShift.mjs +8 -0
- package/reducers/arrayShift.mjs.map +1 -0
- package/reducers/arraySplice.d.ts +7 -0
- package/reducers/arraySplice.d.ts.map +1 -0
- package/reducers/arraySplice.js +20 -0
- package/reducers/arraySplice.js.map +1 -0
- package/reducers/arraySplice.mjs +14 -0
- package/reducers/arraySplice.mjs.map +1 -0
- package/reducers/arraySpliceRaw.d.ts +7 -0
- package/reducers/arraySpliceRaw.d.ts.map +1 -0
- package/reducers/arraySpliceRaw.js +26 -0
- package/reducers/arraySpliceRaw.js.map +1 -0
- package/reducers/arraySpliceRaw.mjs +18 -0
- package/reducers/arraySpliceRaw.mjs.map +1 -0
- package/reducers/arraySwap.d.ts +8 -0
- package/reducers/arraySwap.d.ts.map +1 -0
- package/reducers/arraySwap.js +27 -0
- package/reducers/arraySwap.js.map +1 -0
- package/reducers/arraySwap.mjs +18 -0
- package/reducers/arraySwap.mjs.map +1 -0
- package/reducers/arrayUnshift.d.ts +7 -0
- package/reducers/arrayUnshift.d.ts.map +1 -0
- package/reducers/arrayUnshift.js +15 -0
- package/reducers/arrayUnshift.js.map +1 -0
- package/reducers/arrayUnshift.mjs +11 -0
- package/reducers/arrayUnshift.mjs.map +1 -0
- package/reducers/arrayUnshiftRaw.d.ts +7 -0
- package/reducers/arrayUnshiftRaw.d.ts.map +1 -0
- package/reducers/arrayUnshiftRaw.js +17 -0
- package/reducers/arrayUnshiftRaw.js.map +1 -0
- package/reducers/arrayUnshiftRaw.mjs +9 -0
- package/reducers/arrayUnshiftRaw.mjs.map +1 -0
- package/reducers/initialize.d.ts +46 -0
- package/reducers/initialize.d.ts.map +1 -0
- package/reducers/initialize.js +46 -0
- package/reducers/initialize.js.map +1 -0
- package/reducers/initialize.mjs +38 -0
- package/reducers/initialize.mjs.map +1 -0
- package/reducers/removeHandlers.d.ts +24 -0
- package/reducers/removeHandlers.d.ts.map +1 -0
- package/reducers/removeHandlers.js +24 -0
- package/reducers/removeHandlers.js.map +1 -0
- package/reducers/removeHandlers.mjs +21 -0
- package/reducers/removeHandlers.mjs.map +1 -0
- package/reducers/setMeta.d.ts +6 -0
- package/reducers/setMeta.d.ts.map +1 -0
- package/reducers/setMeta.js +28 -0
- package/reducers/setMeta.js.map +1 -0
- package/reducers/setMeta.mjs +21 -0
- package/reducers/setMeta.mjs.map +1 -0
- package/reducers/setRawValue.d.ts +27 -0
- package/reducers/setRawValue.d.ts.map +1 -0
- package/reducers/setRawValue.js +35 -0
- package/reducers/setRawValue.js.map +1 -0
- package/reducers/setRawValue.mjs +26 -0
- package/reducers/setRawValue.mjs.map +1 -0
- package/reducers/setSubmitStatus.d.ts +24 -0
- package/reducers/setSubmitStatus.d.ts.map +1 -0
- package/reducers/setSubmitStatus.js +18 -0
- package/reducers/setSubmitStatus.js.map +1 -0
- package/reducers/setSubmitStatus.mjs +12 -0
- package/reducers/setSubmitStatus.mjs.map +1 -0
- package/reducers/setValue.d.ts +28 -0
- package/reducers/setValue.d.ts.map +1 -0
- package/reducers/setValue.js +41 -0
- package/reducers/setValue.js.map +1 -0
- package/reducers/setValue.mjs +32 -0
- package/reducers/setValue.mjs.map +1 -0
- package/reducers/submitSucceeded.d.ts +23 -0
- package/reducers/submitSucceeded.d.ts.map +1 -0
- package/reducers/submitSucceeded.js +22 -0
- package/reducers/submitSucceeded.js.map +1 -0
- package/reducers/submitSucceeded.mjs +13 -0
- package/reducers/submitSucceeded.mjs.map +1 -0
- package/reducers/util/getInverseArrayElementSchema.d.ts +3 -0
- package/reducers/util/getInverseArrayElementSchema.d.ts.map +1 -0
- package/reducers/util/getInverseArrayElementSchema.js +14 -0
- package/reducers/util/getInverseArrayElementSchema.js.map +1 -0
- package/reducers/util/getInverseArrayElementSchema.mjs +8 -0
- package/reducers/util/getInverseArrayElementSchema.mjs.map +1 -0
- package/reducers/util/updateRawArray.d.ts +7 -0
- package/reducers/util/updateRawArray.d.ts.map +1 -0
- package/reducers/util/updateRawArray.js +14 -0
- package/reducers/util/updateRawArray.js.map +1 -0
- package/reducers/util/updateRawArray.mjs +8 -0
- package/reducers/util/updateRawArray.mjs.map +1 -0
- package/src/FieldPath.ts +215 -0
- package/src/FormAction.ts +26 -0
- package/src/FormContext.ts +44 -0
- package/src/FormState.ts +36 -0
- package/src/FormStateContext.ts +13 -0
- package/src/actions/addHandlers.ts +23 -0
- package/src/actions/arrayActions.ts +183 -0
- package/src/actions/initialize.ts +16 -0
- package/src/actions/removeHandlers.ts +13 -0
- package/src/actions/setMeta.ts +17 -0
- package/src/actions/setMounted.ts +8 -0
- package/src/actions/setRawValue.ts +17 -0
- package/src/actions/setSubmitStatus.ts +26 -0
- package/src/actions/setValue.ts +21 -0
- package/src/actions/submit.ts +7 -0
- package/src/actions/submitSucceeded.ts +7 -0
- package/src/createFormMiddleware.ts +74 -0
- package/src/createFormProvider.tsx +101 -0
- package/src/createFormReducer.ts +91 -0
- package/src/createSelectFieldErrorMap.ts +47 -0
- package/src/createSelectFormStatus.ts +41 -0
- package/src/createSelectFormValues.ts +16 -0
- package/src/createZodForm.ts +57 -0
- package/src/index.ts +32 -0
- package/src/initFormState.ts +18 -0
- package/src/reducers/addHandlers.ts +21 -0
- package/src/reducers/arrayInsert.ts +19 -0
- package/src/reducers/arrayInsertRaw.ts +22 -0
- package/src/reducers/arrayMove.ts +36 -0
- package/src/reducers/arrayPop.ts +16 -0
- package/src/reducers/arrayPush.ts +20 -0
- package/src/reducers/arrayPushRaw.ts +18 -0
- package/src/reducers/arrayRemove.ts +22 -0
- package/src/reducers/arrayRemoveAll.ts +15 -0
- package/src/reducers/arrayShift.ts +15 -0
- package/src/reducers/arraySplice.ts +17 -0
- package/src/reducers/arraySpliceRaw.ts +30 -0
- package/src/reducers/arraySwap.ts +29 -0
- package/src/reducers/arrayUnshift.ts +16 -0
- package/src/reducers/arrayUnshiftRaw.ts +18 -0
- package/src/reducers/initialize.ts +47 -0
- package/src/reducers/removeHandlers.ts +21 -0
- package/src/reducers/setMeta.ts +26 -0
- package/src/reducers/setRawValue.ts +40 -0
- package/src/reducers/setSubmitStatus.ts +15 -0
- package/src/reducers/setValue.ts +49 -0
- package/src/reducers/submitSucceeded.ts +17 -0
- package/src/reducers/util/getInverseArrayElementSchema.ts +9 -0
- package/src/reducers/util/updateRawArray.ts +25 -0
- package/src/useArrayField.ts +161 -0
- package/src/useField.ts +152 -0
- package/src/useFormContext.ts +11 -0
- package/src/useFormDispatch.ts +13 -0
- package/src/useFormSelector.ts +9 -0
- package/src/useFormStatus.ts +14 -0
- package/src/useFormValues.ts +8 -0
- package/src/useHtmlField.ts +235 -0
- package/src/useInitialize.ts +14 -0
- package/src/useSubmit.ts +29 -0
- package/src/util/PathInSchema.ts +7 -0
- package/src/util/PathInType.ts +26 -0
- package/src/util/SchemaAt.ts +68 -0
- package/src/util/acceptsArray.ts +72 -0
- package/src/util/acceptsBigint.ts +71 -0
- package/src/util/acceptsNumber.ts +71 -0
- package/src/util/bindActionsToField.ts +22 -0
- package/src/util/get.ts +10 -0
- package/src/util/getArrayElementSchema.ts +74 -0
- package/src/util/maybeParse.ts +9 -0
- package/src/util/parsePathstring.ts +119 -0
- package/src/util/pathstring.ts +32 -0
- package/src/util/set.ts +25 -0
- package/src/util/setAdd.ts +6 -0
- package/src/util/setDelete.ts +6 -0
- package/useArrayField.d.ts +34 -0
- package/useArrayField.d.ts.map +1 -0
- package/useArrayField.js +99 -0
- package/useArrayField.js.map +1 -0
- package/useArrayField.mjs +75 -0
- package/useArrayField.mjs.map +1 -0
- package/useField.d.ts +34 -0
- package/useField.d.ts.map +1 -0
- package/useField.js +98 -0
- package/useField.js.map +1 -0
- package/useField.mjs +75 -0
- package/useField.mjs.map +1 -0
- package/useFormContext.d.ts +4 -0
- package/useFormContext.d.ts.map +1 -0
- package/useFormContext.js +17 -0
- package/useFormContext.js.map +1 -0
- package/useFormContext.mjs +10 -0
- package/useFormContext.mjs.map +1 -0
- package/useFormDispatch.d.ts +7 -0
- package/useFormDispatch.d.ts.map +1 -0
- package/useFormDispatch.js +10 -0
- package/useFormDispatch.js.map +1 -0
- package/useFormDispatch.mjs +4 -0
- package/useFormDispatch.mjs.map +1 -0
- package/useFormSelector.d.ts +6 -0
- package/useFormSelector.d.ts.map +1 -0
- package/useFormSelector.js +10 -0
- package/useFormSelector.js.map +1 -0
- package/useFormSelector.mjs +4 -0
- package/useFormSelector.mjs.map +1 -0
- package/useFormStatus.d.ts +13 -0
- package/useFormStatus.d.ts.map +1 -0
- package/useFormStatus.js +15 -0
- package/useFormStatus.js.map +1 -0
- package/useFormStatus.mjs +10 -0
- package/useFormStatus.mjs.map +1 -0
- package/useFormValues.d.ts +8 -0
- package/useFormValues.d.ts.map +1 -0
- package/useFormValues.js +14 -0
- package/useFormValues.js.map +1 -0
- package/useFormValues.mjs +9 -0
- package/useFormValues.mjs.map +1 -0
- package/useHtmlField.d.ts +41 -0
- package/useHtmlField.d.ts.map +1 -0
- package/useHtmlField.js +161 -0
- package/useHtmlField.js.map +1 -0
- package/useHtmlField.mjs +148 -0
- package/useHtmlField.mjs.map +1 -0
- package/useInitialize.d.ts +5 -0
- package/useInitialize.d.ts.map +1 -0
- package/useInitialize.js +18 -0
- package/useInitialize.js.map +1 -0
- package/useInitialize.mjs +11 -0
- package/useInitialize.mjs.map +1 -0
- package/useSubmit.d.ts +5 -0
- package/useSubmit.d.ts.map +1 -0
- package/useSubmit.js +53 -0
- package/useSubmit.js.map +1 -0
- package/useSubmit.mjs +39 -0
- package/useSubmit.mjs.map +1 -0
- package/util/PathInSchema.d.ts +5 -0
- package/util/PathInSchema.d.ts.map +1 -0
- package/util/PathInSchema.js +6 -0
- package/util/PathInSchema.js.map +1 -0
- package/util/PathInSchema.mjs +2 -0
- package/util/PathInSchema.mjs.map +1 -0
- package/util/PathInType.d.ts +11 -0
- package/util/PathInType.d.ts.map +1 -0
- package/util/PathInType.js +6 -0
- package/util/PathInType.js.map +1 -0
- package/util/PathInType.mjs +2 -0
- package/util/PathInType.mjs.map +1 -0
- package/util/SchemaAt.d.ts +5 -0
- package/util/SchemaAt.d.ts.map +1 -0
- package/util/SchemaAt.js +6 -0
- package/util/SchemaAt.js.map +1 -0
- package/util/SchemaAt.mjs +2 -0
- package/util/SchemaAt.mjs.map +1 -0
- package/util/acceptsArray.d.ts +3 -0
- package/util/acceptsArray.d.ts.map +1 -0
- package/util/acceptsArray.js +89 -0
- package/util/acceptsArray.js.map +1 -0
- package/util/acceptsArray.mjs +105 -0
- package/util/acceptsArray.mjs.map +1 -0
- package/util/acceptsBigint.d.ts +3 -0
- package/util/acceptsBigint.d.ts.map +1 -0
- package/util/acceptsBigint.js +88 -0
- package/util/acceptsBigint.js.map +1 -0
- package/util/acceptsBigint.mjs +104 -0
- package/util/acceptsBigint.mjs.map +1 -0
- package/util/acceptsNumber.d.ts +3 -0
- package/util/acceptsNumber.d.ts.map +1 -0
- package/util/acceptsNumber.js +88 -0
- package/util/acceptsNumber.js.map +1 -0
- package/util/acceptsNumber.mjs +104 -0
- package/util/acceptsNumber.mjs.map +1 -0
- package/util/bindActionsToField.d.ts +7 -0
- package/util/bindActionsToField.d.ts.map +1 -0
- package/util/bindActionsToField.js +22 -0
- package/util/bindActionsToField.js.map +1 -0
- package/util/bindActionsToField.mjs +4 -0
- package/util/bindActionsToField.mjs.map +1 -0
- package/util/get.d.ts +2 -0
- package/util/get.d.ts.map +1 -0
- package/util/get.js +12 -0
- package/util/get.js.map +1 -0
- package/util/get.mjs +4 -0
- package/util/get.mjs.map +1 -0
- package/util/getArrayElementSchema.d.ts +3 -0
- package/util/getArrayElementSchema.d.ts.map +1 -0
- package/util/getArrayElementSchema.js +87 -0
- package/util/getArrayElementSchema.js.map +1 -0
- package/util/getArrayElementSchema.mjs +102 -0
- package/util/getArrayElementSchema.mjs.map +1 -0
- package/util/maybeParse.d.ts +3 -0
- package/util/maybeParse.d.ts.map +1 -0
- package/util/maybeParse.js +11 -0
- package/util/maybeParse.js.map +1 -0
- package/util/maybeParse.mjs +5 -0
- package/util/maybeParse.mjs.map +1 -0
- package/util/parsePathstring.d.ts +40 -0
- package/util/parsePathstring.d.ts.map +1 -0
- package/util/parsePathstring.js +55 -0
- package/util/parsePathstring.js.map +1 -0
- package/util/parsePathstring.mjs +35 -0
- package/util/parsePathstring.mjs.map +1 -0
- package/util/pathstring.d.ts +13 -0
- package/util/pathstring.d.ts.map +1 -0
- package/util/pathstring.js +15 -0
- package/util/pathstring.js.map +1 -0
- package/util/pathstring.mjs +7 -0
- package/util/pathstring.mjs.map +1 -0
- package/util/set.d.ts +2 -0
- package/util/set.d.ts.map +1 -0
- package/util/set.js +33 -0
- package/util/set.js.map +1 -0
- package/util/set.mjs +23 -0
- package/util/set.mjs.map +1 -0
- package/util/setAdd.d.ts +2 -0
- package/util/setAdd.d.ts.map +1 -0
- package/util/setAdd.js +13 -0
- package/util/setAdd.js.map +1 -0
- package/util/setAdd.mjs +7 -0
- package/util/setAdd.mjs.map +1 -0
- package/util/setDelete.d.ts +2 -0
- package/util/setDelete.d.ts.map +1 -0
- package/util/setDelete.js +13 -0
- package/util/setDelete.js.map +1 -0
- package/util/setDelete.mjs +7 -0
- package/util/setDelete.mjs.map +1 -0
package/src/useSubmit.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { Handlers } from './actions/addHandlers'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { useFormContext } from './useFormContext'
|
|
5
|
+
|
|
6
|
+
export function useSubmit<T extends z.ZodTypeAny>(handlers?: Handlers<T>) {
|
|
7
|
+
const handlersRef = React.useRef<Handlers<T> | undefined>(handlers)
|
|
8
|
+
handlersRef.current = handlers
|
|
9
|
+
const { addHandlers, removeHandlers } = useFormContext<T>()
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
const handlers: Handlers<T> = {
|
|
12
|
+
onSubmit: (...args) => handlersRef.current?.onSubmit?.(...args),
|
|
13
|
+
onSubmitSucceeded: (...args) =>
|
|
14
|
+
handlersRef.current?.onSubmitSucceeded?.(...args),
|
|
15
|
+
onSubmitFailed: (...args) =>
|
|
16
|
+
handlersRef.current?.onSubmitFailed?.(...args),
|
|
17
|
+
}
|
|
18
|
+
addHandlers(handlers)
|
|
19
|
+
return () => {
|
|
20
|
+
removeHandlers(handlers)
|
|
21
|
+
}
|
|
22
|
+
}, [])
|
|
23
|
+
const { submit } = useFormContext()
|
|
24
|
+
return React.useCallback((e: React.FormEvent) => {
|
|
25
|
+
e.preventDefault()
|
|
26
|
+
e.stopPropagation()
|
|
27
|
+
submit()
|
|
28
|
+
}, [])
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BasePath } from '../FieldPath'
|
|
2
|
+
import { pathstring } from './pathstring'
|
|
3
|
+
|
|
4
|
+
export type PathInType<T> = [] | SubPathInType<T>
|
|
5
|
+
|
|
6
|
+
type SubPathInType<T> = 0 extends 1 & T
|
|
7
|
+
? BasePath
|
|
8
|
+
: T extends
|
|
9
|
+
| string
|
|
10
|
+
| number
|
|
11
|
+
| boolean
|
|
12
|
+
| bigint
|
|
13
|
+
| symbol
|
|
14
|
+
| null
|
|
15
|
+
| undefined
|
|
16
|
+
| void
|
|
17
|
+
| never
|
|
18
|
+
| ((...args: any[]) => any)
|
|
19
|
+
? []
|
|
20
|
+
: T extends readonly any[]
|
|
21
|
+
? { [K in keyof T & number]-?: [K, ...PathInType<T[K]>] }[keyof T & number]
|
|
22
|
+
: {
|
|
23
|
+
[K in keyof T]-?: K extends symbol ? never : [K, ...PathInType<T[K]>]
|
|
24
|
+
}[keyof T]
|
|
25
|
+
|
|
26
|
+
export type PathstringInType<T> = pathstring<PathInType<T>>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
type BasePath = (string | number)[]
|
|
4
|
+
|
|
5
|
+
export type SchemaAt<T extends z.ZodTypeAny, Path> = 0 extends 1 & Path
|
|
6
|
+
? z.ZodTypeAny
|
|
7
|
+
: 0 extends 1 & T
|
|
8
|
+
? z.ZodTypeAny
|
|
9
|
+
: 0 extends 1 & z.input<T>
|
|
10
|
+
? z.ZodTypeAny
|
|
11
|
+
: Path extends [infer Head, ...infer Tail extends BasePath]
|
|
12
|
+
? T extends z.ZodLazy<infer U>
|
|
13
|
+
? SchemaAt<U, Path>
|
|
14
|
+
: T extends z.ZodCatch<infer U>
|
|
15
|
+
? SchemaAt<U, Path>
|
|
16
|
+
: T extends z.ZodBranded<infer U, any>
|
|
17
|
+
? SchemaAt<U, Path>
|
|
18
|
+
: T extends z.ZodOptional<infer U>
|
|
19
|
+
? SchemaAt<U, Path>
|
|
20
|
+
: T extends z.ZodDefault<infer U>
|
|
21
|
+
? SchemaAt<U, Path>
|
|
22
|
+
: T extends z.ZodNullable<infer U>
|
|
23
|
+
? SchemaAt<U, Path>
|
|
24
|
+
: T extends z.ZodUnion<infer Options>
|
|
25
|
+
? SchemaAt<Options[number], Path>
|
|
26
|
+
: T extends z.ZodDiscriminatedUnion<any, infer Options>
|
|
27
|
+
? SchemaAt<Options[number], Path>
|
|
28
|
+
: T extends z.ZodPipeline<infer In, any>
|
|
29
|
+
? SchemaAt<In, Path>
|
|
30
|
+
: T extends z.ZodEffects<infer U>
|
|
31
|
+
? SchemaAt<U, Path>
|
|
32
|
+
: T extends z.ZodReadonly<infer U>
|
|
33
|
+
? SchemaAt<U, Path>
|
|
34
|
+
: T extends z.ZodRecord<infer Key, infer Value>
|
|
35
|
+
? Head extends z.input<Key>
|
|
36
|
+
? SchemaAt<Value, Tail>
|
|
37
|
+
: never
|
|
38
|
+
: T extends z.ZodMap<infer Key, infer Value>
|
|
39
|
+
? Head extends z.input<Key>
|
|
40
|
+
? SchemaAt<Value, Tail>
|
|
41
|
+
: never
|
|
42
|
+
: T extends z.ZodObject<
|
|
43
|
+
infer Shape,
|
|
44
|
+
infer UnknownKeys,
|
|
45
|
+
infer Catchall extends z.ZodTypeAny
|
|
46
|
+
>
|
|
47
|
+
? Head extends keyof Shape
|
|
48
|
+
? SchemaAt<Shape[Head], Tail>
|
|
49
|
+
: UnknownKeys extends 'passthrough'
|
|
50
|
+
? SchemaAt<Catchall, Tail>
|
|
51
|
+
: never
|
|
52
|
+
: T extends z.ZodTuple<
|
|
53
|
+
infer Elements extends [z.ZodTypeAny, ...z.ZodTypeAny[]],
|
|
54
|
+
infer Rest
|
|
55
|
+
>
|
|
56
|
+
? Head extends number & keyof Elements
|
|
57
|
+
? SchemaAt<Elements[Head], Tail>
|
|
58
|
+
: Rest extends z.ZodTypeAny
|
|
59
|
+
? Head extends number
|
|
60
|
+
? SchemaAt<Rest, Tail>
|
|
61
|
+
: never
|
|
62
|
+
: never
|
|
63
|
+
: T extends z.ZodArray<infer Element>
|
|
64
|
+
? Head extends number
|
|
65
|
+
? SchemaAt<Element, Tail>
|
|
66
|
+
: never
|
|
67
|
+
: never
|
|
68
|
+
: T
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
export function acceptsArray(schema: z.ZodTypeAny): boolean {
|
|
4
|
+
switch (schema._def.typeName) {
|
|
5
|
+
case z.ZodFirstPartyTypeKind.ZodArray:
|
|
6
|
+
case z.ZodFirstPartyTypeKind.ZodTuple:
|
|
7
|
+
return true
|
|
8
|
+
case z.ZodFirstPartyTypeKind.ZodUnion: {
|
|
9
|
+
const { options } = schema as z.ZodUnion<z.ZodUnionOptions>
|
|
10
|
+
return options.some(acceptsArray)
|
|
11
|
+
}
|
|
12
|
+
case z.ZodFirstPartyTypeKind.ZodIntersection: {
|
|
13
|
+
const {
|
|
14
|
+
_def: { left, right },
|
|
15
|
+
} = schema as z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>
|
|
16
|
+
return acceptsArray(left) && acceptsArray(right)
|
|
17
|
+
}
|
|
18
|
+
case z.ZodFirstPartyTypeKind.ZodLazy: {
|
|
19
|
+
const { schema: innerSchema } = schema as z.ZodLazy<z.ZodTypeAny>
|
|
20
|
+
return acceptsArray(innerSchema)
|
|
21
|
+
}
|
|
22
|
+
case z.ZodFirstPartyTypeKind.ZodLiteral: {
|
|
23
|
+
const { value } = schema as z.ZodLiteral<any>
|
|
24
|
+
return typeof value === 'number'
|
|
25
|
+
}
|
|
26
|
+
case z.ZodFirstPartyTypeKind.ZodEffects: {
|
|
27
|
+
const {
|
|
28
|
+
_def: { schema: innerSchema },
|
|
29
|
+
} = schema as z.ZodEffects<z.ZodTypeAny>
|
|
30
|
+
return acceptsArray(innerSchema)
|
|
31
|
+
}
|
|
32
|
+
case z.ZodFirstPartyTypeKind.ZodOptional: {
|
|
33
|
+
const innerSchema = (schema as z.ZodOptional<z.ZodTypeAny>).unwrap()
|
|
34
|
+
return acceptsArray(innerSchema)
|
|
35
|
+
}
|
|
36
|
+
case z.ZodFirstPartyTypeKind.ZodNullable: {
|
|
37
|
+
const innerSchema = (schema as z.ZodNullable<z.ZodTypeAny>).unwrap()
|
|
38
|
+
return acceptsArray(innerSchema)
|
|
39
|
+
}
|
|
40
|
+
case z.ZodFirstPartyTypeKind.ZodDefault: {
|
|
41
|
+
const {
|
|
42
|
+
_def: { innerType },
|
|
43
|
+
} = schema as z.ZodDefault<z.ZodTypeAny>
|
|
44
|
+
return acceptsArray(innerType)
|
|
45
|
+
}
|
|
46
|
+
case z.ZodFirstPartyTypeKind.ZodCatch: {
|
|
47
|
+
const {
|
|
48
|
+
_def: { innerType },
|
|
49
|
+
} = schema as z.ZodCatch<z.ZodTypeAny>
|
|
50
|
+
return acceptsArray(innerType)
|
|
51
|
+
}
|
|
52
|
+
case z.ZodFirstPartyTypeKind.ZodBranded: {
|
|
53
|
+
const {
|
|
54
|
+
_def: { type: innerType },
|
|
55
|
+
} = schema as z.ZodBranded<z.ZodTypeAny, string | number | symbol>
|
|
56
|
+
return acceptsArray(innerType)
|
|
57
|
+
}
|
|
58
|
+
case z.ZodFirstPartyTypeKind.ZodPipeline: {
|
|
59
|
+
const {
|
|
60
|
+
_def: { in: input },
|
|
61
|
+
} = schema as z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny>
|
|
62
|
+
return acceptsArray(input)
|
|
63
|
+
}
|
|
64
|
+
case z.ZodFirstPartyTypeKind.ZodReadonly: {
|
|
65
|
+
const {
|
|
66
|
+
_def: { innerType },
|
|
67
|
+
} = schema as z.ZodReadonly<z.ZodTypeAny>
|
|
68
|
+
return acceptsArray(innerType)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
export function acceptsBigint(schema: z.ZodTypeAny): boolean {
|
|
4
|
+
switch (schema._def.typeName) {
|
|
5
|
+
case z.ZodFirstPartyTypeKind.ZodBigInt:
|
|
6
|
+
return true
|
|
7
|
+
case z.ZodFirstPartyTypeKind.ZodUnion: {
|
|
8
|
+
const { options } = schema as z.ZodUnion<z.ZodUnionOptions>
|
|
9
|
+
return options.some(acceptsBigint)
|
|
10
|
+
}
|
|
11
|
+
case z.ZodFirstPartyTypeKind.ZodIntersection: {
|
|
12
|
+
const {
|
|
13
|
+
_def: { left, right },
|
|
14
|
+
} = schema as z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>
|
|
15
|
+
return acceptsBigint(left) && acceptsBigint(right)
|
|
16
|
+
}
|
|
17
|
+
case z.ZodFirstPartyTypeKind.ZodLazy: {
|
|
18
|
+
const { schema: innerSchema } = schema as z.ZodLazy<z.ZodTypeAny>
|
|
19
|
+
return acceptsBigint(innerSchema)
|
|
20
|
+
}
|
|
21
|
+
case z.ZodFirstPartyTypeKind.ZodLiteral: {
|
|
22
|
+
const { value } = schema as z.ZodLiteral<any>
|
|
23
|
+
return typeof value === 'bigint'
|
|
24
|
+
}
|
|
25
|
+
case z.ZodFirstPartyTypeKind.ZodEffects: {
|
|
26
|
+
const {
|
|
27
|
+
_def: { schema: innerSchema },
|
|
28
|
+
} = schema as z.ZodEffects<z.ZodTypeAny>
|
|
29
|
+
return acceptsBigint(innerSchema)
|
|
30
|
+
}
|
|
31
|
+
case z.ZodFirstPartyTypeKind.ZodOptional: {
|
|
32
|
+
const innerSchema = (schema as z.ZodOptional<z.ZodTypeAny>).unwrap()
|
|
33
|
+
return acceptsBigint(innerSchema)
|
|
34
|
+
}
|
|
35
|
+
case z.ZodFirstPartyTypeKind.ZodNullable: {
|
|
36
|
+
const innerSchema = (schema as z.ZodNullable<z.ZodTypeAny>).unwrap()
|
|
37
|
+
return acceptsBigint(innerSchema)
|
|
38
|
+
}
|
|
39
|
+
case z.ZodFirstPartyTypeKind.ZodDefault: {
|
|
40
|
+
const {
|
|
41
|
+
_def: { innerType },
|
|
42
|
+
} = schema as z.ZodDefault<z.ZodTypeAny>
|
|
43
|
+
return acceptsBigint(innerType)
|
|
44
|
+
}
|
|
45
|
+
case z.ZodFirstPartyTypeKind.ZodCatch: {
|
|
46
|
+
const {
|
|
47
|
+
_def: { innerType },
|
|
48
|
+
} = schema as z.ZodCatch<z.ZodTypeAny>
|
|
49
|
+
return acceptsBigint(innerType)
|
|
50
|
+
}
|
|
51
|
+
case z.ZodFirstPartyTypeKind.ZodBranded: {
|
|
52
|
+
const {
|
|
53
|
+
_def: { type: innerType },
|
|
54
|
+
} = schema as z.ZodBranded<z.ZodTypeAny, string | number | symbol>
|
|
55
|
+
return acceptsBigint(innerType)
|
|
56
|
+
}
|
|
57
|
+
case z.ZodFirstPartyTypeKind.ZodPipeline: {
|
|
58
|
+
const {
|
|
59
|
+
_def: { in: input },
|
|
60
|
+
} = schema as z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny>
|
|
61
|
+
return acceptsBigint(input)
|
|
62
|
+
}
|
|
63
|
+
case z.ZodFirstPartyTypeKind.ZodReadonly: {
|
|
64
|
+
const {
|
|
65
|
+
_def: { innerType },
|
|
66
|
+
} = schema as z.ZodReadonly<z.ZodTypeAny>
|
|
67
|
+
return acceptsBigint(innerType)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
export function acceptsNumber(schema: z.ZodTypeAny): boolean {
|
|
4
|
+
switch (schema._def.typeName) {
|
|
5
|
+
case z.ZodFirstPartyTypeKind.ZodNumber:
|
|
6
|
+
return true
|
|
7
|
+
case z.ZodFirstPartyTypeKind.ZodUnion: {
|
|
8
|
+
const { options } = schema as z.ZodUnion<z.ZodUnionOptions>
|
|
9
|
+
return options.some(acceptsNumber)
|
|
10
|
+
}
|
|
11
|
+
case z.ZodFirstPartyTypeKind.ZodIntersection: {
|
|
12
|
+
const {
|
|
13
|
+
_def: { left, right },
|
|
14
|
+
} = schema as z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>
|
|
15
|
+
return acceptsNumber(left) && acceptsNumber(right)
|
|
16
|
+
}
|
|
17
|
+
case z.ZodFirstPartyTypeKind.ZodLazy: {
|
|
18
|
+
const { schema: innerSchema } = schema as z.ZodLazy<z.ZodTypeAny>
|
|
19
|
+
return acceptsNumber(innerSchema)
|
|
20
|
+
}
|
|
21
|
+
case z.ZodFirstPartyTypeKind.ZodLiteral: {
|
|
22
|
+
const { value } = schema as z.ZodLiteral<any>
|
|
23
|
+
return typeof value === 'number'
|
|
24
|
+
}
|
|
25
|
+
case z.ZodFirstPartyTypeKind.ZodEffects: {
|
|
26
|
+
const {
|
|
27
|
+
_def: { schema: innerSchema },
|
|
28
|
+
} = schema as z.ZodEffects<z.ZodTypeAny>
|
|
29
|
+
return acceptsNumber(innerSchema)
|
|
30
|
+
}
|
|
31
|
+
case z.ZodFirstPartyTypeKind.ZodOptional: {
|
|
32
|
+
const innerSchema = (schema as z.ZodOptional<z.ZodTypeAny>).unwrap()
|
|
33
|
+
return acceptsNumber(innerSchema)
|
|
34
|
+
}
|
|
35
|
+
case z.ZodFirstPartyTypeKind.ZodNullable: {
|
|
36
|
+
const innerSchema = (schema as z.ZodNullable<z.ZodTypeAny>).unwrap()
|
|
37
|
+
return acceptsNumber(innerSchema)
|
|
38
|
+
}
|
|
39
|
+
case z.ZodFirstPartyTypeKind.ZodDefault: {
|
|
40
|
+
const {
|
|
41
|
+
_def: { innerType },
|
|
42
|
+
} = schema as z.ZodDefault<z.ZodTypeAny>
|
|
43
|
+
return acceptsNumber(innerType)
|
|
44
|
+
}
|
|
45
|
+
case z.ZodFirstPartyTypeKind.ZodCatch: {
|
|
46
|
+
const {
|
|
47
|
+
_def: { innerType },
|
|
48
|
+
} = schema as z.ZodCatch<z.ZodTypeAny>
|
|
49
|
+
return acceptsNumber(innerType)
|
|
50
|
+
}
|
|
51
|
+
case z.ZodFirstPartyTypeKind.ZodBranded: {
|
|
52
|
+
const {
|
|
53
|
+
_def: { type: innerType },
|
|
54
|
+
} = schema as z.ZodBranded<z.ZodTypeAny, string | number | symbol>
|
|
55
|
+
return acceptsNumber(innerType)
|
|
56
|
+
}
|
|
57
|
+
case z.ZodFirstPartyTypeKind.ZodPipeline: {
|
|
58
|
+
const {
|
|
59
|
+
_def: { in: input },
|
|
60
|
+
} = schema as z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny>
|
|
61
|
+
return acceptsNumber(input)
|
|
62
|
+
}
|
|
63
|
+
case z.ZodFirstPartyTypeKind.ZodReadonly: {
|
|
64
|
+
const {
|
|
65
|
+
_def: { innerType },
|
|
66
|
+
} = schema as z.ZodReadonly<z.ZodTypeAny>
|
|
67
|
+
return acceptsNumber(innerType)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FieldPath } from '../FieldPath'
|
|
2
|
+
|
|
3
|
+
export function bindActionsToField<
|
|
4
|
+
Actions extends { [K in string]: (field: FieldPath, ...rest: any[]) => any }
|
|
5
|
+
>(
|
|
6
|
+
actions: Actions,
|
|
7
|
+
field: FieldPath
|
|
8
|
+
): {
|
|
9
|
+
[K in keyof Actions]: Actions[K] extends (
|
|
10
|
+
field: FieldPath,
|
|
11
|
+
...rest: infer Rest
|
|
12
|
+
) => infer Return
|
|
13
|
+
? (...rest: Rest) => Return
|
|
14
|
+
: never
|
|
15
|
+
} {
|
|
16
|
+
return Object.fromEntries(
|
|
17
|
+
Object.entries(actions).map(([key, action]: any) => [
|
|
18
|
+
key,
|
|
19
|
+
(...args: any[]) => action(field, ...args),
|
|
20
|
+
])
|
|
21
|
+
) as any
|
|
22
|
+
}
|
package/src/util/get.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
export function getArrayElementSchema(
|
|
4
|
+
schema: z.ZodTypeAny
|
|
5
|
+
): z.ZodTypeAny | undefined {
|
|
6
|
+
switch (schema._def.typeName) {
|
|
7
|
+
case z.ZodFirstPartyTypeKind.ZodArray: {
|
|
8
|
+
const { element } = schema as z.ZodArray<z.ZodTypeAny>
|
|
9
|
+
return element
|
|
10
|
+
}
|
|
11
|
+
case z.ZodFirstPartyTypeKind.ZodUnion: {
|
|
12
|
+
const { options } = schema as z.ZodUnion<z.ZodUnionOptions>
|
|
13
|
+
const elements = options
|
|
14
|
+
.map(getArrayElementSchema)
|
|
15
|
+
.filter((s): s is z.ZodTypeAny => s != null)
|
|
16
|
+
return elements.length > 1 ? z.union(elements as any) : elements[0]
|
|
17
|
+
}
|
|
18
|
+
case z.ZodFirstPartyTypeKind.ZodLazy: {
|
|
19
|
+
const { schema: innerSchema } = schema as z.ZodLazy<z.ZodTypeAny>
|
|
20
|
+
return getArrayElementSchema(innerSchema)
|
|
21
|
+
}
|
|
22
|
+
case z.ZodFirstPartyTypeKind.ZodEffects: {
|
|
23
|
+
const {
|
|
24
|
+
_def: { schema: innerSchema },
|
|
25
|
+
} = schema as z.ZodEffects<z.ZodTypeAny>
|
|
26
|
+
return getArrayElementSchema(innerSchema)
|
|
27
|
+
}
|
|
28
|
+
case z.ZodFirstPartyTypeKind.ZodOptional: {
|
|
29
|
+
const innerSchema = (schema as z.ZodOptional<z.ZodTypeAny>).unwrap()
|
|
30
|
+
return getArrayElementSchema(innerSchema)
|
|
31
|
+
}
|
|
32
|
+
case z.ZodFirstPartyTypeKind.ZodNullable: {
|
|
33
|
+
const innerSchema = (schema as z.ZodNullable<z.ZodTypeAny>).unwrap()
|
|
34
|
+
return getArrayElementSchema(innerSchema)
|
|
35
|
+
}
|
|
36
|
+
case z.ZodFirstPartyTypeKind.ZodDefault: {
|
|
37
|
+
const {
|
|
38
|
+
_def: { innerType },
|
|
39
|
+
} = schema as z.ZodDefault<z.ZodTypeAny>
|
|
40
|
+
return getArrayElementSchema(innerType)
|
|
41
|
+
}
|
|
42
|
+
case z.ZodFirstPartyTypeKind.ZodCatch: {
|
|
43
|
+
const {
|
|
44
|
+
_def: { innerType },
|
|
45
|
+
} = schema as z.ZodCatch<z.ZodTypeAny>
|
|
46
|
+
return getArrayElementSchema(innerType)
|
|
47
|
+
}
|
|
48
|
+
case z.ZodFirstPartyTypeKind.ZodPromise: {
|
|
49
|
+
const {
|
|
50
|
+
_def: { type: innerType },
|
|
51
|
+
} = schema as z.ZodPromise<z.ZodTypeAny>
|
|
52
|
+
return getArrayElementSchema(innerType)
|
|
53
|
+
}
|
|
54
|
+
case z.ZodFirstPartyTypeKind.ZodBranded: {
|
|
55
|
+
const {
|
|
56
|
+
_def: { type: innerType },
|
|
57
|
+
} = schema as z.ZodBranded<z.ZodTypeAny, string | number | symbol>
|
|
58
|
+
return getArrayElementSchema(innerType)
|
|
59
|
+
}
|
|
60
|
+
case z.ZodFirstPartyTypeKind.ZodPipeline: {
|
|
61
|
+
const {
|
|
62
|
+
_def: { in: input },
|
|
63
|
+
} = schema as z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny>
|
|
64
|
+
return getArrayElementSchema(input)
|
|
65
|
+
}
|
|
66
|
+
case z.ZodFirstPartyTypeKind.ZodReadonly: {
|
|
67
|
+
const {
|
|
68
|
+
_def: { innerType },
|
|
69
|
+
} = schema as z.ZodReadonly<z.ZodTypeAny>
|
|
70
|
+
return getArrayElementSchema(innerType)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined
|
|
74
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { BasePath } from '../FieldPath'
|
|
2
|
+
|
|
3
|
+
export type parsePathstring<Path extends string, IsTail = false> = [
|
|
4
|
+
Path
|
|
5
|
+
] extends ['']
|
|
6
|
+
? []
|
|
7
|
+
: [Path] extends [`[${infer Rest}`]
|
|
8
|
+
? Rest extends `${infer N extends number}]${infer Tail}`
|
|
9
|
+
? [N, ...parsePathstring<Tail, true>]
|
|
10
|
+
: ExtractInitialStringLiteral<Rest> extends infer StringLiteral extends string
|
|
11
|
+
? [
|
|
12
|
+
ProcessStringLiteral<StringLiteral>,
|
|
13
|
+
...(Rest extends `${StringLiteral}]${infer Tail}`
|
|
14
|
+
? parsePathstring<Tail, true>
|
|
15
|
+
: never)
|
|
16
|
+
]
|
|
17
|
+
: never
|
|
18
|
+
: [IsTail] extends [true]
|
|
19
|
+
? [Path] extends [`.${infer Rest}`]
|
|
20
|
+
? parsePathstring<Rest>
|
|
21
|
+
: never
|
|
22
|
+
: [Path] extends [`${infer Head}[${infer Tail}`]
|
|
23
|
+
? [Path] extends [`${infer Head2}.${infer Tail2}`]
|
|
24
|
+
? Head2 extends `${Head}[${string}` // make sure we pick up to . or [, whichever comes first
|
|
25
|
+
? [Head, ...parsePathstring<`[${Tail}`, true>]
|
|
26
|
+
: [Head2, ...parsePathstring<`.${Tail2}`, true>]
|
|
27
|
+
: [Head, ...parsePathstring<`[${Tail}`, true>]
|
|
28
|
+
: [Path] extends [`${infer Head}.${infer Tail}`]
|
|
29
|
+
? [Head, ...parsePathstring<`.${Tail}`, true>]
|
|
30
|
+
: [Path]
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* If T starts with a quoted string literal, returns that string literal.
|
|
34
|
+
* Otherwise returns never
|
|
35
|
+
*/
|
|
36
|
+
type ExtractInitialStringLiteral<T extends string> = [T] extends [
|
|
37
|
+
`"${infer Rest}`
|
|
38
|
+
]
|
|
39
|
+
? `"${RestOfStringLiteral<Rest, '"'>}`
|
|
40
|
+
: [T] extends [`'${infer Rest}`]
|
|
41
|
+
? `'${RestOfStringLiteral<Rest, "'">}`
|
|
42
|
+
: never
|
|
43
|
+
|
|
44
|
+
type RestOfStringLiteral<
|
|
45
|
+
/**
|
|
46
|
+
* A substring right after an opening quote
|
|
47
|
+
*/
|
|
48
|
+
T extends string,
|
|
49
|
+
/**
|
|
50
|
+
* The opening quote type
|
|
51
|
+
*/
|
|
52
|
+
Q extends '"' | "'"
|
|
53
|
+
> = [T] extends [`${infer A}${Q}${infer B}`] // find the next quote
|
|
54
|
+
? A extends `${infer C}\\${infer D}` // the quote may be escaped, so find the first backslash
|
|
55
|
+
? D extends '' // nothing after the backslash, so it escapes the quote Q
|
|
56
|
+
? `${A}${Q}${RestOfStringLiteral<B, Q>}` // keep scanning until the closing quote
|
|
57
|
+
: D extends `${infer E extends keyof EscapeChars}${infer F}`
|
|
58
|
+
? `${C}\\${E}${RestOfStringLiteral<`${F}${Q}${B}`, Q>}` // keep scanning until the closing quote
|
|
59
|
+
: never
|
|
60
|
+
: `${A}${Q}` // no backslash, Q is a closing quote and we're done!
|
|
61
|
+
: never
|
|
62
|
+
|
|
63
|
+
type EscapeChars = typeof EscapeChars
|
|
64
|
+
const EscapeChars = {
|
|
65
|
+
"'": "'",
|
|
66
|
+
'"': '"',
|
|
67
|
+
'\\': '\\',
|
|
68
|
+
b: '\b',
|
|
69
|
+
f: '\f',
|
|
70
|
+
n: '\n',
|
|
71
|
+
r: '\r',
|
|
72
|
+
t: '\t',
|
|
73
|
+
v: '\v',
|
|
74
|
+
} as const
|
|
75
|
+
|
|
76
|
+
type ProcessEscapes<T extends string> = T extends `${infer A}\\${infer B}`
|
|
77
|
+
? B extends `${infer C extends keyof EscapeChars}${infer D}`
|
|
78
|
+
? `${A}${EscapeChars[C]}${ProcessEscapes<D>}`
|
|
79
|
+
: never
|
|
80
|
+
: T
|
|
81
|
+
|
|
82
|
+
type ProcessStringLiteral<T extends string> = T extends `"${infer Content}"`
|
|
83
|
+
? ProcessEscapes<Content>
|
|
84
|
+
: T extends `'${infer Content}'`
|
|
85
|
+
? ProcessEscapes<Content>
|
|
86
|
+
: never
|
|
87
|
+
|
|
88
|
+
const pathstringRx =
|
|
89
|
+
/((?:^|\.)([^.[\]]+))|\[((\d+)|("(?:[^\\"]|\\['"\\bfnrtv])+"|'(?:[^\\']|\\['"\\bfnrtv])+'))\]/g
|
|
90
|
+
|
|
91
|
+
export function parsePathstring(pathstring: string): BasePath {
|
|
92
|
+
const path: BasePath = []
|
|
93
|
+
let lastIndex = 0
|
|
94
|
+
for (const match of pathstring.matchAll(pathstringRx)) {
|
|
95
|
+
if (
|
|
96
|
+
match.index !== lastIndex ||
|
|
97
|
+
(match.index === 0 && match[0][0] === '.')
|
|
98
|
+
) {
|
|
99
|
+
throw new Error(`invalid pathstring: ${pathstring} (at ${match.index})`)
|
|
100
|
+
}
|
|
101
|
+
lastIndex = match.index + match[0].length
|
|
102
|
+
if (match[2]) path.push(match[2])
|
|
103
|
+
else if (match[4]) path.push(parseInt(match[4]))
|
|
104
|
+
else if (match[5]) {
|
|
105
|
+
path.push(
|
|
106
|
+
match[5]
|
|
107
|
+
.substring(1, match[5].length - 1)
|
|
108
|
+
.replace(
|
|
109
|
+
/\\['"\\bfnrtv]/g,
|
|
110
|
+
(m) => EscapeChars[m[1] as keyof EscapeChars]
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (lastIndex !== pathstring.length) {
|
|
116
|
+
throw new Error(`invalid pathstring: ${pathstring} (at ${lastIndex})`)
|
|
117
|
+
}
|
|
118
|
+
return path
|
|
119
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type PathElem = string | number
|
|
2
|
+
type BasePath = PathElem[]
|
|
3
|
+
|
|
4
|
+
export type pathstring<Path> = Path extends [
|
|
5
|
+
infer Head extends PathElem,
|
|
6
|
+
...infer Tail extends PathElem[]
|
|
7
|
+
]
|
|
8
|
+
? `${Head extends number ? `[${Head}]` : Head}${pathstringTail<Tail>}`
|
|
9
|
+
: ''
|
|
10
|
+
|
|
11
|
+
type pathstringTail<Path extends BasePath> = Path extends [
|
|
12
|
+
infer Head extends PathElem,
|
|
13
|
+
...infer Tail extends PathElem[]
|
|
14
|
+
]
|
|
15
|
+
? `${Head extends number ? `[${Head}]` : `.${Head}`}${pathstringTail<Tail>}`
|
|
16
|
+
: ''
|
|
17
|
+
|
|
18
|
+
export function pathstring<Path extends BasePath>(
|
|
19
|
+
path: Path
|
|
20
|
+
): pathstring<Path> {
|
|
21
|
+
return path
|
|
22
|
+
.map((elem, index) =>
|
|
23
|
+
typeof elem === 'string' && isValidIdentifier(elem)
|
|
24
|
+
? `${index > 0 ? '.' : ''}${elem}`
|
|
25
|
+
: `[${JSON.stringify(elem)}]`
|
|
26
|
+
)
|
|
27
|
+
.join('') as any
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isValidIdentifier(s: string): boolean {
|
|
31
|
+
return /^[_$a-z][_$a-z0-9]*$/i.test(s)
|
|
32
|
+
}
|
package/src/util/set.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function set(
|
|
2
|
+
from: unknown,
|
|
3
|
+
path: (string | number | symbol)[],
|
|
4
|
+
value: unknown,
|
|
5
|
+
index = 0
|
|
6
|
+
): unknown {
|
|
7
|
+
if (index === path.length) return value
|
|
8
|
+
if (from instanceof Map) {
|
|
9
|
+
const oldValue = from.get(path[index])
|
|
10
|
+
const newValue = set(oldValue, path, value, index + 1)
|
|
11
|
+
if (Object.is(oldValue, newValue)) return from
|
|
12
|
+
const result = new Map(from)
|
|
13
|
+
result.set(path[index], newValue)
|
|
14
|
+
return result
|
|
15
|
+
}
|
|
16
|
+
if (from instanceof Object) {
|
|
17
|
+
const oldValue = (from as any)[path[index]]
|
|
18
|
+
const newValue = set(oldValue, path, value, index + 1)
|
|
19
|
+
if (Object.is(oldValue, newValue)) return from
|
|
20
|
+
const result: any = Array.isArray(from) ? [...from] : { ...from }
|
|
21
|
+
result[path[index]] = newValue
|
|
22
|
+
return result
|
|
23
|
+
}
|
|
24
|
+
return set(typeof path[index] === 'number' ? [] : {}, path, value, index)
|
|
25
|
+
}
|