POC: chore: use Nx workspace lint rules (#3163)
* chore: use Nx workspace lint rules Closes #3162 * Fix lint * Fix lint on BE * Fix tests --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -29,9 +29,8 @@ export class FetchBatchMessagesService {
|
||||
'batch_gmail_messages',
|
||||
);
|
||||
|
||||
const messages = await this.formatBatchResponsesAsGmailMessages(
|
||||
batchResponses,
|
||||
);
|
||||
const messages =
|
||||
await this.formatBatchResponsesAsGmailMessages(batchResponses);
|
||||
|
||||
return messages;
|
||||
}
|
||||
@ -46,9 +45,8 @@ export class FetchBatchMessagesService {
|
||||
'batch_gmail_threads',
|
||||
);
|
||||
|
||||
const threads = await this.formatBatchResponsesAsGmailThreads(
|
||||
batchResponses,
|
||||
);
|
||||
const threads =
|
||||
await this.formatBatchResponsesAsGmailThreads(batchResponses);
|
||||
|
||||
return threads;
|
||||
}
|
||||
@ -242,9 +240,8 @@ export class FetchBatchMessagesService {
|
||||
): Promise<GmailMessage[]> {
|
||||
const formattedResponses = await Promise.all(
|
||||
batchResponses.map(async (response) => {
|
||||
const formattedResponse = await this.formatBatchResponseAsGmailMessage(
|
||||
response,
|
||||
);
|
||||
const formattedResponse =
|
||||
await this.formatBatchResponseAsGmailMessage(response);
|
||||
|
||||
return formattedResponse;
|
||||
}),
|
||||
@ -292,9 +289,8 @@ export class FetchBatchMessagesService {
|
||||
): Promise<GmailThread[]> {
|
||||
const formattedResponses = await Promise.all(
|
||||
batchResponses.map(async (response) => {
|
||||
const formattedResponse = await this.formatBatchResponseAsGmailThread(
|
||||
response,
|
||||
);
|
||||
const formattedResponse =
|
||||
await this.formatBatchResponseAsGmailThread(response);
|
||||
|
||||
return formattedResponse;
|
||||
}),
|
||||
|
||||
@ -44,9 +44,8 @@ export class FetchWorkspaceMessagesService {
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const workspaceDataSource = await this.typeORMService.connectToDataSource(
|
||||
dataSourceMetadata,
|
||||
);
|
||||
const workspaceDataSource =
|
||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error('No workspace data source found');
|
||||
|
||||
@ -23,9 +23,8 @@ export class RefreshAccessTokenService {
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const workspaceDataSource = await this.typeORMService.connectToDataSource(
|
||||
dataSourceMetadata,
|
||||
);
|
||||
const workspaceDataSource =
|
||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error('No workspace data source found');
|
||||
|
||||
@ -27,9 +27,8 @@ export class WorkspaceDataSourceService {
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const dataSource = await this.typeormService.connectToDataSource(
|
||||
dataSourceMetadata,
|
||||
);
|
||||
const dataSource =
|
||||
await this.typeormService.connectToDataSource(dataSourceMetadata);
|
||||
|
||||
if (!dataSource) {
|
||||
throw new Error(
|
||||
|
||||
@ -146,8 +146,8 @@ export class WorkspaceMigrationEnumService {
|
||||
UPDATE "${schemaName}"."${tableName}"
|
||||
SET "${columnDefinition.columnName}" = ${defaultValue}
|
||||
WHERE "${columnDefinition.columnName}" NOT IN (${enumValues
|
||||
.map((e) => `'${e}'`)
|
||||
.join(', ')})
|
||||
.map((e) => `'${e}'`)
|
||||
.join(', ')})
|
||||
`);
|
||||
}
|
||||
|
||||
|
||||
@ -38,11 +38,11 @@ export class CreateManyQueryFactory {
|
||||
insertInto${
|
||||
options.targetTableName
|
||||
}Collection(objects: ${stringifyWithoutKeyQuote(
|
||||
computedArgs.data.map((datum) => ({
|
||||
id: uuidv4(),
|
||||
...datum,
|
||||
})),
|
||||
)}) {
|
||||
computedArgs.data.map((datum) => ({
|
||||
id: uuidv4(),
|
||||
...datum,
|
||||
})),
|
||||
)}) {
|
||||
affectedCount
|
||||
records {
|
||||
${fieldsString}
|
||||
|
||||
@ -25,8 +25,8 @@ export class DeleteManyQueryFactory {
|
||||
deleteFrom${
|
||||
options.targetTableName
|
||||
}Collection(filter: ${stringifyWithoutKeyQuote(
|
||||
args.filter,
|
||||
)}, atMost: 30) {
|
||||
args.filter,
|
||||
)}, atMost: 30) {
|
||||
affectedCount
|
||||
records {
|
||||
${fieldsString}
|
||||
|
||||
@ -38,8 +38,8 @@ export class FindManyQueryFactory {
|
||||
return `
|
||||
query {
|
||||
${options.targetTableName}Collection${
|
||||
argsString ? `(${argsString})` : ''
|
||||
} {
|
||||
argsString ? `(${argsString})` : ''
|
||||
} {
|
||||
${fieldsString}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,8 +32,8 @@ export class FindOneQueryFactory {
|
||||
return `
|
||||
query {
|
||||
${options.targetTableName}Collection${
|
||||
argsString ? `(${argsString})` : ''
|
||||
} {
|
||||
argsString ? `(${argsString})` : ''
|
||||
} {
|
||||
edges {
|
||||
node {
|
||||
${fieldsString}
|
||||
|
||||
@ -105,8 +105,8 @@ export class RelationFieldAliasFactory {
|
||||
|
||||
return `
|
||||
${fieldKey}: ${referencedObjectMetadata.targetTableName}Collection${
|
||||
argsString ? `(${argsString})` : ''
|
||||
} {
|
||||
argsString ? `(${argsString})` : ''
|
||||
} {
|
||||
${fieldsString}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -41,8 +41,8 @@ export class UpdateOneQueryFactory {
|
||||
update${
|
||||
options.targetTableName
|
||||
}Collection(set: ${stringifyWithoutKeyQuote(
|
||||
argsData,
|
||||
)}, filter: { id: { eq: "${computedArgs.id}" } }) {
|
||||
argsData,
|
||||
)}, filter: { id: { eq: "${computedArgs.id}" } }) {
|
||||
affectedCount
|
||||
records {
|
||||
${fieldsString}
|
||||
|
||||
@ -72,14 +72,17 @@ export class EnumTypeDefinitionFactory {
|
||||
return new GraphQLEnumType({
|
||||
name: `${pascalCase(objectName)}${pascalCase(fieldMetadata.name)}Enum`,
|
||||
description: fieldMetadata.description,
|
||||
values: enumOptions.reduce((acc, enumOption) => {
|
||||
acc[enumOption.value] = {
|
||||
value: enumOption.value,
|
||||
description: enumOption.label,
|
||||
};
|
||||
values: enumOptions.reduce(
|
||||
(acc, enumOption) => {
|
||||
acc[enumOption.value] = {
|
||||
value: enumOption.value,
|
||||
description: enumOption.label,
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {} as { [key: string]: { value: string; description: string } }),
|
||||
return acc;
|
||||
},
|
||||
{} as { [key: string]: { value: string; description: string } },
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,9 +28,8 @@ export class WorkspaceSchemaStorageService {
|
||||
(await this.cacheVersionMemoryStorageService.read({
|
||||
key: workspaceId,
|
||||
})) ?? '0';
|
||||
const latestVersion = await this.workspaceCacheVersionService.getVersion(
|
||||
workspaceId,
|
||||
);
|
||||
const latestVersion =
|
||||
await this.workspaceCacheVersionService.getVersion(workspaceId);
|
||||
|
||||
if (currentVersion !== latestVersion) {
|
||||
// Invalidate cache if version mismatch is detected
|
||||
|
||||
@ -36,18 +36,24 @@ export const mapObjectMetadataByUniqueIdentifier = <
|
||||
>(
|
||||
arr: T[],
|
||||
): Record<string, Omit<T, 'fields'> & { fields: Record<string, U> }> => {
|
||||
return arr.reduce((acc, curr) => {
|
||||
acc[curr.nameSingular] = {
|
||||
...curr,
|
||||
fields: curr.fields.reduce((acc, curr) => {
|
||||
acc[curr.name] = curr;
|
||||
return arr.reduce(
|
||||
(acc, curr) => {
|
||||
acc[curr.nameSingular] = {
|
||||
...curr,
|
||||
fields: curr.fields.reduce(
|
||||
(acc, curr) => {
|
||||
acc[curr.name] = curr;
|
||||
|
||||
return acc;
|
||||
}, {} as Record<string, U>),
|
||||
};
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, U>,
|
||||
),
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {} as Record<string, Omit<T, 'fields'> & { fields: Record<string, U> }>);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, Omit<T, 'fields'> & { fields: Record<string, U> }>,
|
||||
);
|
||||
};
|
||||
|
||||
export const convertStringifiedFieldsToJSON = <
|
||||
|
||||
@ -405,7 +405,7 @@ export class WorkspaceSyncMetadataService {
|
||||
WorkspaceMigrationColumnActionType.CREATE,
|
||||
field,
|
||||
),
|
||||
} satisfies WorkspaceMigrationTableAction),
|
||||
}) satisfies WorkspaceMigrationTableAction,
|
||||
),
|
||||
];
|
||||
|
||||
@ -420,11 +420,14 @@ export class WorkspaceSyncMetadataService {
|
||||
// TODO: handle object delete migrations.
|
||||
// Note: we need to delete the relation first due to the DB constraint.
|
||||
|
||||
const objectsInDbById = objectsInDB.reduce((result, currentObject) => {
|
||||
result[currentObject.id] = currentObject;
|
||||
const objectsInDbById = objectsInDB.reduce(
|
||||
(result, currentObject) => {
|
||||
result[currentObject.id] = currentObject;
|
||||
|
||||
return result;
|
||||
}, {} as Record<string, ObjectMetadataEntity>);
|
||||
return result;
|
||||
},
|
||||
{} as Record<string, ObjectMetadataEntity>,
|
||||
);
|
||||
|
||||
if (fieldsToCreate.length > 0) {
|
||||
fieldsToCreate.map((field) => {
|
||||
|
||||
@ -60,9 +60,8 @@ export class WorkspaceFactory {
|
||||
}
|
||||
|
||||
// Get typeDefs from cache
|
||||
let typeDefs = await this.workspaceSchemaStorageService.getTypeDefs(
|
||||
workspaceId,
|
||||
);
|
||||
let typeDefs =
|
||||
await this.workspaceSchemaStorageService.getTypeDefs(workspaceId);
|
||||
let usedScalarNames =
|
||||
await this.workspaceSchemaStorageService.getUsedScalarNames(workspaceId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user