export const LOCAL_VALUE = 'this' export const PARAMETER_VALUE = 'data' export const MODELS_PARAMETER_VALUE = 'models' export const UNDEFINED_VALUE = 'undefined' export const getResultAtom = ( propertyName: string, propertyValueName: string, defaultValue: unknown, isArray?: boolean ) => { // const condition = `${propertyName} : ${PARAMETER_VALUE}?.${propertyValueName} ?? ${ // JSON.stringify(defaultValue) ?? (isArray ? '[]' : UNDEFINED_VALUE) // }` const hasValue = defaultValue !== undefined || isArray const condition = `if (!(${PARAMETER_VALUE}?.${propertyValueName} === ${UNDEFINED_VALUE} || ${PARAMETER_VALUE}?.${propertyValueName} === null)) { output.${propertyName} = ${PARAMETER_VALUE}.${propertyValueName} } ${ hasValue ? ` else { output.${propertyName} = ${JSON.stringify(defaultValue) ?? '[]'} } ` : '' } ` return condition } export const getResultModel = (options: { propertyName: string defaultValue: unknown isArray?: boolean }) => { const { propertyName, isArray } = options let condition = `output.${propertyName} = ${ isArray ? '[]' : `new ${MODELS_PARAMETER_VALUE}.${propertyName}(${PARAMETER_VALUE}?.${propertyName})\n` } ` if (isArray) { condition += `if (Array.isArray(${PARAMETER_VALUE}?.${propertyName})) { for (let index = 0; index < ${PARAMETER_VALUE}.${propertyName}.length; index++) { const element = ${PARAMETER_VALUE}.${propertyName}[index]; output.${propertyName}.push(new ${MODELS_PARAMETER_VALUE}.${propertyName}(element)) } }` } return condition }