( schema: any, defaultValue?: any, allowNull?: boolean, )
| 27 | import {createCustomSchematizer} from '../index.ts'; |
| 28 | |
| 29 | const unwrapSchema = ( |
| 30 | schema: any, |
| 31 | defaultValue?: any, |
| 32 | allowNull?: boolean, |
| 33 | ): [any, any, boolean] => { |
| 34 | const schemaData = schema?.json ?? schema; |
| 35 | |
| 36 | if (isArray(schemaData)) { |
| 37 | const hasNull = !arrayEvery( |
| 38 | schemaData, |
| 39 | (item: any) => !isNull(item?.[UNIT]) && !isNull(item), |
| 40 | ); |
| 41 | |
| 42 | if ( |
| 43 | size(schemaData) === 2 && |
| 44 | isFalse((schemaData[0] as any)?.[UNIT]) && |
| 45 | isTrue((schemaData[1] as any)?.[UNIT]) |
| 46 | ) { |
| 47 | return [{[TYPE]: BOOLEAN}, defaultValue, allowNull ?? false]; |
| 48 | } |
| 49 | |
| 50 | if (arrayEvery(schemaData, (item: any) => isString(item?.[UNIT] ?? item))) { |
| 51 | return [{[TYPE]: STRING}, defaultValue, allowNull ?? false]; |
| 52 | } |
| 53 | |
| 54 | if (hasNull) { |
| 55 | const nonNullItem = arrayFind( |
| 56 | schemaData, |
| 57 | (item: any) => !isNull(item?.[UNIT]) && !isNull(item) && item !== '=', |
| 58 | ); |
| 59 | if (nonNullItem) { |
| 60 | return unwrapSchema(nonNullItem, defaultValue, true); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (!isArray(schemaData) && !isUndefined(schemaData?.[SEQUENCE])) { |
| 66 | return [{[TYPE]: ARRAY}, defaultValue, allowNull ?? false]; |
| 67 | } |
| 68 | |
| 69 | if (!isArray(schemaData) && isString(schemaData?.[UNIT])) { |
| 70 | return [{[TYPE]: STRING}, defaultValue, allowNull ?? false]; |
| 71 | } |
| 72 | |
| 73 | return [ |
| 74 | {[TYPE]: schemaData?.[DOMAIN] || schemaData}, |
| 75 | defaultValue, |
| 76 | allowNull ?? false, |
| 77 | ]; |
| 78 | }; |
| 79 | |
| 80 | const getProperties = (schema: any) => { |
| 81 | const properties: {[key: string]: any} = objNew(); |
no test coverage detected
searching dependent graphs…