From 86490ea00cc0a2e4ee6fc3e75dd399cc8f520639 Mon Sep 17 00:00:00 2001 From: Sandrina Pereira Date: Wed, 17 May 2023 22:46:25 +0100 Subject: [PATCH 1/2] feat: Include pickXKey and buildCompleteYupSchema --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 983c56433..37482bacc 100644 --- a/src/index.js +++ b/src/index.js @@ -1 +1,4 @@ export { createHeadlessForm } from './createHeadlessForm'; + +export { pickXKey } from './internals/helpers'; +export { buildCompleteYupSchema } from './yupSchema'; From cdf45c44a5e206d9a2425a91f1b430aa14cf701e Mon Sep 17 00:00:00 2001 From: Sandrina Pereira Date: Thu, 18 May 2023 10:07:28 +0100 Subject: [PATCH 2/2] chore: Add basic docs to pickXKey and buildCompleteYupSchema --- src/internals/helpers.js | 8 +++++--- src/yupSchema.js | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/internals/helpers.js b/src/internals/helpers.js index ff7f6e46a..81111ccf6 100644 --- a/src/internals/helpers.js +++ b/src/internals/helpers.js @@ -10,10 +10,12 @@ import isEmpty from 'lodash/isEmpty'; import isFunction from 'lodash/isFunction'; /** - * Returns the object from the JSON-schema node using the key. - * + * Shorthand to lookup for keys with `x-jsf-*` preffix. * @param {Object} node - JSON-schema node - * @param {String} key - JSON-schema key name + * @param {"presentation"|"errorMessage"} key - JSON-schema key name + * @example + * pickKey(properties, 'presentation') + * is the same as properties["x-jsf-presentation"] * @returns {Object} */ export function pickXKey(node, key) { diff --git a/src/yupSchema.js b/src/yupSchema.js index 6ec2cf84b..362afc9e7 100644 --- a/src/yupSchema.js +++ b/src/yupSchema.js @@ -8,6 +8,7 @@ import { convertDiskSizeFromTo } from './utils'; /** * @typedef {import('./createHeadlessForm').FieldParameters} FieldParameters + * @typedef {import('../createHeadlessForm').JsfConfig} JsfConfig */ export const DEFAULT_DATE_FORMAT = 'yyyy-MM-dd'; @@ -297,6 +298,14 @@ function getSchema(fields = [], config) { return newSchema; } +/** + * Returns the Yup schema structure of given fields. + * These fields must be the same from + * const { fields } = createHeadlessForm() + * @param {Fields[]} fields - List of fields + * @param {JsfConfig} config - Config + * @returns + */ export function buildCompleteYupSchema(fields, config) { return object().shape(getSchema(fields, config), getNoSortEdges(fields)); }