Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { createHeadlessForm } from './createHeadlessForm';

export { pickXKey } from './internals/helpers';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brennj I cherry-picked the commit we made yesterday at #3 to this PR, so that #3 can remain focused on just release scripts. WDYT?

export { buildCompleteYupSchema } from './yupSchema';
8 changes: 5 additions & 3 deletions src/internals/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/yupSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
}