MCPcopy
hub / github.com/directus/directus / parseDynamicVariable

Function parseDynamicVariable

packages/utils/shared/parse-filter.ts:177–208  ·  view source on GitHub ↗
(value: any, accountability: BasicAccountability | null, context: ParseFilterContext)

Source from the content-addressed store, hash-verified

175}
176
177function parseDynamicVariable(value: any, accountability: BasicAccountability | null, context: ParseFilterContext) {
178 if (typeof value !== 'string') {
179 return value;
180 }
181
182 if (value.startsWith('$NOW')) {
183 return parseNow(value);
184 }
185
186 if (value.startsWith('$CURRENT_USER')) {
187 if (value === '$CURRENT_USER') return accountability?.user ?? null;
188 return get(context, value, null);
189 }
190
191 if (value.startsWith('$CURRENT_ROLES')) {
192 if (value === '$CURRENT_ROLES') return accountability?.roles ?? null;
193 return get(context, value, null);
194 }
195
196 if (value.startsWith('$CURRENT_ROLE')) {
197 if (value === '$CURRENT_ROLE') return accountability?.role ?? null;
198 return get(context, value, null);
199 }
200
201 if (value.startsWith('$CURRENT_POLICIES')) {
202 if (value === '$CURRENT_POLICIES')
203 return (get(context, value, null) as Policy[] | null)?.map(({ id }) => id) ?? null;
204 return get(context, value, null);
205 }
206
207 return value;
208}

Callers 4

parseFilterRecursiveFunction · 0.85
parsePresetFunction · 0.85
parseFilterEntryFunction · 0.85
parseJsonFilterValueFunction · 0.85

Calls 2

parseNowFunction · 0.85
getFunction · 0.70

Tested by

no test coverage detected