| 66 | .strict(); |
| 67 | |
| 68 | export class FieldsService { |
| 69 | knex: Knex; |
| 70 | helpers: Helpers; |
| 71 | accountability: Accountability | null; |
| 72 | itemsService: ItemsService; |
| 73 | payloadService: PayloadService; |
| 74 | schemaInspector: SchemaInspector; |
| 75 | schema: SchemaOverview; |
| 76 | cache: Keyv<any> | null; |
| 77 | systemCache: Keyv<any>; |
| 78 | schemaCache: Keyv<any>; |
| 79 | |
| 80 | constructor(options: AbstractServiceOptions) { |
| 81 | this.knex = options.knex || getDatabase(); |
| 82 | this.helpers = getHelpers(this.knex); |
| 83 | this.schemaInspector = options.knex ? createInspector(options.knex) : getSchemaInspector(); |
| 84 | this.accountability = options.accountability || null; |
| 85 | this.itemsService = new ItemsService('directus_fields', options); |
| 86 | this.payloadService = new PayloadService('directus_fields', options); |
| 87 | this.schema = options.schema; |
| 88 | |
| 89 | const { cache, systemCache, localSchemaCache } = getCache(); |
| 90 | |
| 91 | this.cache = cache; |
| 92 | this.systemCache = systemCache; |
| 93 | this.schemaCache = localSchemaCache; |
| 94 | } |
| 95 | |
| 96 | async columnInfo(collection?: string): Promise<Column[]>; |
| 97 | async columnInfo(collection: string, field: string): Promise<Column>; |
| 98 | async columnInfo(collection?: string, field?: string): Promise<Column | Column[]> { |
| 99 | const schemaCacheIsEnabled = Boolean(env['CACHE_SCHEMA']); |
| 100 | |
| 101 | let columnInfo: Column[] | null = null; |
| 102 | |
| 103 | if (schemaCacheIsEnabled) { |
| 104 | columnInfo = await getCacheValue(this.schemaCache, 'columnInfo'); |
| 105 | } |
| 106 | |
| 107 | if (!columnInfo) { |
| 108 | columnInfo = await this.schemaInspector.columnInfo(); |
| 109 | |
| 110 | if (schemaCacheIsEnabled) { |
| 111 | await setCacheValue(this.schemaCache, 'columnInfo', columnInfo); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (collection) { |
| 116 | columnInfo = columnInfo.filter((column) => column.table === collection); |
| 117 | } |
| 118 | |
| 119 | if (field) { |
| 120 | return columnInfo.find((column) => column.name === field) as Column; |
| 121 | } |
| 122 | |
| 123 | return columnInfo; |
| 124 | } |
| 125 |
nothing calls this directly
no outgoing calls
no test coverage detected