mirror of
https://github.com/logto-io/logto.git
synced 2025-03-17 22:31:28 -05:00
refactor: update SchemaValuePrimitive
and add docs for convertToPrimitive()
This commit is contained in:
parent
b192b7d17c
commit
acc2031e82
2 changed files with 12 additions and 3 deletions
|
@ -21,9 +21,18 @@ export const excludeAutoSetFields = <T extends string>(fields: readonly T[]) =>
|
|||
)
|
||||
);
|
||||
|
||||
export const convertToPrimitive = (value: SchemaValue): SchemaValuePrimitive => {
|
||||
/**
|
||||
* Note `undefined` is removed from the acceptable list,
|
||||
* since you should NOT call this function if ignoring the field is the desired behavior.
|
||||
* Calling this function with `null` means an explicit `null` setting in database is expected.
|
||||
* @param value The value to convert.
|
||||
* @returns A primitive that can be saved into database.
|
||||
*/
|
||||
export const convertToPrimitive = (
|
||||
value: NonNullable<SchemaValue> | null
|
||||
): NonNullable<SchemaValuePrimitive> | null => {
|
||||
if (value === null) {
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export type SchemaValuePrimitive = string | number | boolean | null;
|
||||
export type SchemaValuePrimitive = string | number | boolean | undefined;
|
||||
export type SchemaValue = SchemaValuePrimitive | Record<string, unknown>;
|
||||
export type SchemaLike<Key extends string> = {
|
||||
[key in Key]: SchemaValue;
|
||||
|
|
Loading…
Add table
Reference in a new issue