File v2 - update core.file table (#17172)

For the following, I'll create the issues first
This commit is contained in:
Etienne
2026-01-16 16:59:39 +01:00
committed by GitHub
parent dcdf9e4d9c
commit 76cbe59929
16 changed files with 229 additions and 65 deletions
@@ -0,0 +1,87 @@
import { extractFolderPathFilenameAndTypeOrThrow } from '@/utils/files/extractFolderPathFilenameAndTypeOrThrow.util';
describe('extractFolderPathFilenameAndType', () => {
it('should extract folder path, filename, and type from a basic path', () => {
const result = extractFolderPathFilenameAndTypeOrThrow(
'folder/subfolder/file.txt',
);
expect(result).toEqual({
folderPath: 'folder/subfolder',
filename: 'file.txt',
type: 'txt',
});
});
it('should handle multiple dots in filename', () => {
const result = extractFolderPathFilenameAndTypeOrThrow(
'path/to/file.config.json',
);
expect(result).toEqual({
folderPath: 'path/to',
filename: 'file.config.json',
type: 'json',
});
});
it('should handle filename without extension', () => {
const result = extractFolderPathFilenameAndTypeOrThrow('folder/Makefile');
expect(result).toEqual({
folderPath: 'folder',
filename: 'Makefile',
type: '',
});
});
it('should handle file at root level', () => {
const result = extractFolderPathFilenameAndTypeOrThrow('document.pdf');
expect(result).toEqual({
folderPath: '',
filename: 'document.pdf',
type: 'pdf',
});
});
it('should handle deeply nested paths', () => {
const result = extractFolderPathFilenameAndTypeOrThrow(
'a/b/c/d/e/image.png',
);
expect(result).toEqual({
folderPath: 'a/b/c/d/e',
filename: 'image.png',
type: 'png',
});
});
it('should handle hidden files', () => {
const result = extractFolderPathFilenameAndTypeOrThrow('folder/.gitignore');
expect(result).toEqual({
folderPath: 'folder',
filename: '.gitignore',
type: 'gitignore',
});
});
it('should throw error for empty string', () => {
expect(() => extractFolderPathFilenameAndTypeOrThrow('')).toThrow(
'Invalid fullPath provided',
);
});
it('should throw error for null value', () => {
expect(() =>
extractFolderPathFilenameAndTypeOrThrow(null as unknown as string),
).toThrow('Invalid fullPath provided');
});
it('should throw error for undefined value', () => {
expect(() =>
extractFolderPathFilenameAndTypeOrThrow(undefined as unknown as string),
).toThrow('Invalid fullPath provided');
});
});
@@ -0,0 +1,21 @@
import { isNonEmptyString } from '@sniptt/guards';
export const extractFolderPathFilenameAndTypeOrThrow = (
fullPath: string,
): {
folderPath: string;
filename: string;
type: string;
} => {
if (!isNonEmptyString(fullPath)) {
throw new Error('Invalid fullPath provided');
}
const parts = fullPath.split('/');
const filename = parts.pop() || '';
const folderPath = parts.join('/');
const lastDotIndex = filename.lastIndexOf('.');
const extension = lastDotIndex !== -1 ? filename.slice(lastDotIndex + 1) : '';
return { folderPath, filename, type: extension };
};
@@ -42,6 +42,7 @@ export { isFieldMetadataDateKind } from './fieldMetadata/isFieldMetadataDateKind
export { isFieldMetadataNumericKind } from './fieldMetadata/isFieldMetadataNumericKind';
export { isFieldMetadataSelectKind } from './fieldMetadata/isFieldMetadataSelectKind';
export { isFieldMetadataTextKind } from './fieldMetadata/isFieldMetadataTextKind';
export { extractFolderPathFilenameAndTypeOrThrow } from './files/extractFolderPathFilenameAndTypeOrThrow.util';
export { checkIfShouldComputeEmptinessFilter } from './filter/checkIfShouldComputeEmptinessFilter';
export { checkIfShouldSkipFiltering } from './filter/checkIfShouldSkipFiltering';
export { computeGqlOperationFilterForEmails } from './filter/compute-record-gql-operation-filter/for-composite-field/computeGqlOperationFilterForEmails';