(
action: PayloadAction,
payload: Partial<Item> | Partial<Item>[],
aliasMap: Record<string, string> = {},
aggregate: Aggregate = {},
)
| 212 | ): Promise<Partial<Item>>; |
| 213 | |
| 214 | async processValues( |
| 215 | action: PayloadAction, |
| 216 | payload: Partial<Item> | Partial<Item>[], |
| 217 | aliasMap: Record<string, string> = {}, |
| 218 | aggregate: Aggregate = {}, |
| 219 | ): Promise<Partial<Item> | Partial<Item>[]> { |
| 220 | const processedPayload = toArray(payload); |
| 221 | |
| 222 | if (processedPayload.length === 0) return []; |
| 223 | |
| 224 | const fieldsInPayload = Object.keys(processedPayload[0]!); |
| 225 | const fieldEntries = Object.entries(this.schema.collections[this.collection]!.fields); |
| 226 | const aliasEntries = Object.entries(aliasMap); |
| 227 | |
| 228 | let specialFields: [string, FieldOverview][] = []; |
| 229 | |
| 230 | for (const [name, field] of fieldEntries) { |
| 231 | if (field.special && field.special.length > 0) { |
| 232 | specialFields.push([name, field]); |
| 233 | |
| 234 | for (const [aliasName, fieldName] of aliasEntries) { |
| 235 | if (fieldName === name) { |
| 236 | specialFields.push([aliasName, { ...field, field: aliasName }]); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if (action === 'read') { |
| 243 | specialFields = specialFields.filter(([name]) => { |
| 244 | return fieldsInPayload.includes(name); |
| 245 | }); |
| 246 | } |
| 247 | |
| 248 | for (const record of processedPayload) { |
| 249 | for (const [name, field] of specialFields) { |
| 250 | const newValue = await this.processField(field, record, action, this.accountability); |
| 251 | if (newValue !== undefined) record[name] = newValue; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | this.processGeometries(fieldEntries, processedPayload, action); |
| 256 | this.processDates(fieldEntries, processedPayload, action, aliasMap, aggregate); |
| 257 | |
| 258 | if (action === 'read') { |
| 259 | this.processJsonFunctionResults(processedPayload, aliasMap); |
| 260 | } |
| 261 | |
| 262 | if (['create', 'update'].includes(action)) { |
| 263 | processedPayload.forEach((record) => { |
| 264 | for (const [key, value] of Object.entries(record)) { |
| 265 | if (Array.isArray(value) || (typeof value === 'object' && !(value instanceof Date) && value !== null)) { |
| 266 | if (!value.isRawInstance) { |
| 267 | record[key] = JSON.stringify(value); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | }); |
no test coverage detected