[AUDIT] Run knip over twenty-server (#21159)
# Introduction Run [knip](https://knip.dev/) over twenty-server Used config: ```json { "$schema": "https://unpkg.com/knip@5/schema.json", "workspaces": { "packages/twenty-server": { "entry": [ "src/main.ts", "src/command/command.ts", "src/queue-worker/queue-worker.ts", "src/database/scripts/setup-db.ts", "src/database/scripts/truncate-db.ts", "src/database/clickHouse/migrations/run-migrations.ts", "src/database/clickHouse/seeds/run-seeds.ts", "src/instrument.ts", "lingui.config.ts", "test/integration/graphql/codegen/index.ts", "test/integration/utils/setup-test.ts", "test/integration/utils/teardown-test.ts", "scripts/**/*.ts", "**/*.spec.ts", "**/*.integration-spec.ts" ], "project": ["src/**/*.ts", "test/**/*.ts", "scripts/**/*.ts"], "ignore": [ "src/database/typeorm/**/migrations/**", "src/database/typeorm/**/*.entity.ts", "**/*.workspace-entity.ts", "**/logic-function-resource/constants/seed-project/**" ], "ignoreDependencies": ["@types/psl", "@types/aws-lambda"], "ignoreBinaries": ["nest", "lingui", "typeorm"] } } } ```
This commit is contained in:
-4
@@ -1,4 +0,0 @@
|
||||
import { type AllFlatEntityTypesByMetadataName } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-types-by-metadata-name';
|
||||
|
||||
export type AllFlatEntities =
|
||||
AllFlatEntityTypesByMetadataName[keyof AllFlatEntityTypesByMetadataName]['flatEntity'];
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
import { type AllMetadataName } from 'twenty-shared/metadata';
|
||||
|
||||
export type FlatEntityMapsKeyToMetadata<T extends string> =
|
||||
T extends `flat${infer Name}Maps`
|
||||
? Uncapitalize<Name> extends AllMetadataName
|
||||
? Uncapitalize<Name>
|
||||
: never
|
||||
: never;
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
import { type AllMetadataName } from 'twenty-shared/metadata';
|
||||
|
||||
import { type MetadataEntity } from 'src/engine/metadata-modules/flat-entity/types/metadata-entity.type';
|
||||
|
||||
type ExtractRelationIdProperties<T> = {
|
||||
[K in keyof T]: K extends `${infer _}Id`
|
||||
? K extends 'id' | 'workspaceId'
|
||||
? never
|
||||
: T[K] extends string | null | undefined
|
||||
? K
|
||||
: never
|
||||
: never;
|
||||
}[keyof T];
|
||||
|
||||
type PropertyNameToRelationName<T extends string> = T extends `${infer Name}Id`
|
||||
? Name
|
||||
: never;
|
||||
|
||||
type ExtractEntityRelations<TEntity> = {
|
||||
[K in ExtractRelationIdProperties<TEntity> as PropertyNameToRelationName<K>]: K;
|
||||
};
|
||||
|
||||
export type MetadataNameAndRelations = {
|
||||
[T in AllMetadataName]: Partial<ExtractEntityRelations<MetadataEntity<T>>>;
|
||||
};
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
import isEmpty from 'lodash.isempty';
|
||||
import { isDefined, removePropertiesFromRecord } from 'twenty-shared/utils';
|
||||
|
||||
import {
|
||||
FlatEntityMapsException,
|
||||
FlatEntityMapsExceptionCode,
|
||||
} from 'src/engine/metadata-modules/flat-entity/exceptions/flat-entity-maps.exception';
|
||||
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';
|
||||
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
|
||||
|
||||
export type DeleteFlatEntityFromFlatEntityMapsOrThrowArgs<
|
||||
T extends SyncableFlatEntity,
|
||||
> = {
|
||||
entityToDeleteId: string;
|
||||
flatEntityMaps: FlatEntityMaps<T>;
|
||||
};
|
||||
|
||||
export const deleteFlatEntityFromFlatEntityMapsOrThrow = <
|
||||
T extends SyncableFlatEntity,
|
||||
>({
|
||||
flatEntityMaps,
|
||||
entityToDeleteId,
|
||||
}: DeleteFlatEntityFromFlatEntityMapsOrThrowArgs<T>): FlatEntityMaps<T> => {
|
||||
const universalIdentifierToDelete =
|
||||
flatEntityMaps.universalIdentifierById[entityToDeleteId];
|
||||
|
||||
if (!isDefined(universalIdentifierToDelete)) {
|
||||
throw new FlatEntityMapsException(
|
||||
'deleteFlatEntityFromFlatEntityMapsOrThrow: entity to delete not found',
|
||||
FlatEntityMapsExceptionCode.ENTITY_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const updatedUniversalIdentifierByIdEntries = Object.entries(
|
||||
flatEntityMaps.universalIdentifierById,
|
||||
).filter(([id]) => id !== entityToDeleteId);
|
||||
|
||||
const updatedUniversalIdentifiersByApplicationIdEntries = Object.entries(
|
||||
flatEntityMaps.universalIdentifiersByApplicationId,
|
||||
)
|
||||
.map(([applicationId, universalIdentifiers]) => {
|
||||
const stillPresentUniversalIdentifiers = universalIdentifiers?.filter(
|
||||
(universalIdentifier) =>
|
||||
universalIdentifier !== universalIdentifierToDelete,
|
||||
);
|
||||
|
||||
if (
|
||||
!isDefined(stillPresentUniversalIdentifiers) ||
|
||||
isEmpty(stillPresentUniversalIdentifiers)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return [applicationId, stillPresentUniversalIdentifiers];
|
||||
})
|
||||
.filter(isDefined);
|
||||
|
||||
return {
|
||||
byUniversalIdentifier: removePropertiesFromRecord(
|
||||
flatEntityMaps.byUniversalIdentifier,
|
||||
[universalIdentifierToDelete],
|
||||
),
|
||||
universalIdentifierById: Object.fromEntries(
|
||||
updatedUniversalIdentifierByIdEntries,
|
||||
),
|
||||
universalIdentifiersByApplicationId: Object.fromEntries(
|
||||
updatedUniversalIdentifiersByApplicationIdEntries,
|
||||
),
|
||||
};
|
||||
};
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
import { uncapitalize } from 'twenty-shared/utils';
|
||||
|
||||
import { type FlatEntityMapsKeyToMetadata } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps-key-to-metadata';
|
||||
|
||||
export const getMetadataNameFromFlatEntityMapsKey = <T extends string>(
|
||||
flatEntityMapsKey: T,
|
||||
): FlatEntityMapsKeyToMetadata<T> => {
|
||||
const withoutPrefix = flatEntityMapsKey.replace(/^flat/, '');
|
||||
const withoutSuffix = withoutPrefix.replace(/Maps$/, '');
|
||||
|
||||
return uncapitalize(withoutSuffix) as FlatEntityMapsKeyToMetadata<T>;
|
||||
};
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';
|
||||
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
|
||||
import { addFlatEntityToFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/add-flat-entity-to-flat-entity-maps-or-throw.util';
|
||||
import { deleteFlatEntityFromFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/delete-flat-entity-from-flat-entity-maps-or-throw.util';
|
||||
|
||||
export type ReplaceFlatEntityInFlatEntityMapsOrThrowArgs<
|
||||
T extends SyncableFlatEntity,
|
||||
> = {
|
||||
flatEntity: T;
|
||||
flatEntityMaps: FlatEntityMaps<T>;
|
||||
};
|
||||
|
||||
export const replaceFlatEntityInFlatEntityMapsOrThrow = <
|
||||
T extends SyncableFlatEntity,
|
||||
>({
|
||||
flatEntity,
|
||||
flatEntityMaps,
|
||||
}: ReplaceFlatEntityInFlatEntityMapsOrThrowArgs<T>): FlatEntityMaps<T> => {
|
||||
const flatEntityMapsToReplace = deleteFlatEntityFromFlatEntityMapsOrThrow({
|
||||
flatEntityMaps,
|
||||
entityToDeleteId: flatEntity.id,
|
||||
});
|
||||
|
||||
return addFlatEntityToFlatEntityMapsOrThrow({
|
||||
flatEntity,
|
||||
flatEntityMaps: flatEntityMapsToReplace,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user