(
entity: T,
prop: EntityKey<T>,
direction: QueryOrderKeys<T>,
object = false,
)
| 112 | */ |
| 113 | from(entity: Entity | Loaded<Entity, Hint, Fields, Excludes>): string { |
| 114 | const processEntity = <T extends object>( |
| 115 | entity: T, |
| 116 | prop: EntityKey<T>, |
| 117 | direction: QueryOrderKeys<T>, |
| 118 | object = false, |
| 119 | ) => { |
| 120 | if (Utils.isPlainObject(direction)) { |
| 121 | const unwrapped = Reference.unwrapReference(entity[prop] as T); |
| 122 | |
| 123 | // Check if the relation is loaded - for nested properties, undefined means not populated |
| 124 | if (Utils.isEntity(unwrapped) && !helper(unwrapped).isInitialized()) { |
| 125 | throw CursorError.entityNotPopulated(entity, prop); |
| 126 | } |
| 127 | |
| 128 | return Utils.keys(direction).reduce((o, key) => { |
| 129 | Object.assign(o, processEntity(unwrapped, key, direction[key] as QueryOrderKeys<T>, true)); |
| 130 | return o; |
| 131 | }, {} as Dictionary); |
| 132 | } |
| 133 | |
| 134 | let value: unknown = entity[prop]; |
| 135 | |
| 136 | // Allow null/undefined values in cursor - they will be handled in createCursorCondition |
| 137 | // undefined can occur with forceUndefined config option which converts null to undefined |
| 138 | if (value == null) { |
| 139 | return object ? { [prop]: null } : null; |
| 140 | } |
| 141 | |
| 142 | if (Utils.isEntity(value, true)) { |
| 143 | value = helper(value).getPrimaryKey(); |
| 144 | } |
| 145 | |
| 146 | if (Utils.isScalarReference(value)) { |
| 147 | value = value.unwrap(); |
| 148 | } |
| 149 | |
| 150 | if (object) { |
| 151 | return { [prop]: value }; |
| 152 | } |
| 153 | |
| 154 | return value; |
| 155 | }; |
| 156 | const value = this.#definition.map(([key, direction]) => processEntity(entity as Entity, key, direction)); |
| 157 | return Cursor.encode(value); |
| 158 | } |
nothing calls this directly
no test coverage detected