MCPcopy
hub / github.com/directus/directus / processValues

Method processValues

api/src/services/payload.ts:214–283  ·  view source on GitHub ↗
(
		action: PayloadAction,
		payload: Partial<Item> | Partial<Item>[],
		aliasMap: Record<string, string> = {},
		aggregate: Aggregate = {},
	)

Source from the content-addressed store, hash-verified

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 });

Callers 4

runFunction · 0.95
prepareDeltaMethod · 0.95
createOneMethod · 0.95
updateManyMethod · 0.95

Calls 6

processFieldMethod · 0.95
processGeometriesMethod · 0.95
processDatesMethod · 0.95
processAggregatesMethod · 0.95
toArrayFunction · 0.90

Tested by

no test coverage detected