Set special flags when configuring db-only fields (#15640)

Co-authored-by: ian <licitdev@gmail.com>
This commit is contained in:
Azri Kahar
2022-10-15 12:15:27 +08:00
committed by GitHub
parent 372d042a48
commit 18bf1344e1
4 changed files with 51 additions and 17 deletions

View File

@@ -0,0 +1,28 @@
import { TYPES } from '@directus/shared/constants';
import { expect, test } from 'vitest';
import { getSpecialForType } from './get-special-for-type';
const castPrefixedSpecials = ['json', 'csv', 'boolean'];
const nonPrefixedSpecials = ['uuid', 'hash', 'geometry'];
test('Returns cast-prefixed special array for json, csv, and boolean field types', () => {
const types = TYPES.filter((type) => castPrefixedSpecials.includes(type));
for (const type of types) {
expect(getSpecialForType(type)).toStrictEqual(['cast-' + type]);
}
});
test('Returns special array for uuid, hash, and geometry field types', () => {
const types = TYPES.filter((type) => nonPrefixedSpecials.includes(type));
for (const type of types) {
expect(getSpecialForType(type)).toStrictEqual([type]);
}
});
test('Returns null for other field types', () => {
const specials = [...castPrefixedSpecials, ...nonPrefixedSpecials];
const types = TYPES.filter((type) => !specials.includes(type));
for (const type of types) {
expect(getSpecialForType(type)).toStrictEqual(null);
}
});

View File

@@ -0,0 +1,16 @@
import { Type } from '@directus/shared/types';
export function getSpecialForType(type: Type): string[] | null {
switch (type) {
case 'json':
case 'csv':
case 'boolean':
return ['cast-' + type];
case 'uuid':
case 'hash':
case 'geometry':
return [type];
default:
return null;
}
}