Skip to content

Commit b200b4b

Browse files
committed
Merge branch 'main' into biome-enabled
2 parents 01bae54 + f8d1c42 commit b200b4b

File tree

24 files changed

+1480
-3117
lines changed

24 files changed

+1480
-3117
lines changed

Dockerfile.rocketadmin-agent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ COPY rocketadmin-agent /app/rocketadmin-agent
1111
COPY .yarn /app/.yarn
1212
RUN yarn install --network-timeout 1000000
1313
RUN cd shared-code && ../node_modules/.bin/tsc
14-
RUN cd rocketadmin-agent && yarn run nest build
14+
RUN cd rocketadmin-agent && yarn run build
1515

1616
RUN chown -R appuser:appuser /app
1717

backend/package.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
"private": true,
77
"license": "UNLICENSED",
88
"type": "module",
9-
"packageExtensions": {
10-
"ibm_db": {
11-
"dependencies": {
12-
"node-gyp": "^11.5.0"
13-
}
14-
}
15-
},
169
"scripts": {
1710
"prebuild": "rimraf dist",
1811
"build": "nest build",
@@ -79,7 +72,6 @@
7972
"knex": "3.1.0",
8073
"lru-cache": "^11.2.2",
8174
"nanoid": "5.1.6",
82-
"node-gyp": "^11.5.0",
8375
"nodemailer": "^7.0.10",
8476
"nunjucks": "^3.2.4",
8577
"openai": "^6.7.0",
@@ -99,9 +91,6 @@
9991
"validator": "^13.15.20",
10092
"winston": "3.18.3"
10193
},
102-
"optionalDependencies": {
103-
"ibm_db": "3.3.0"
104-
},
10594
"devDependencies": {
10695
"@ava/typescript": "6.0.0",
10796
"@nestjs/cli": "^11.0.10",

backend/src/entities/connection-properties/use-cases/update-connection-properties.use.case.ts

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../utils/build-update-connection-properties-object.js';
1414
import { validateCreateConnectionPropertiesDs } from '../utils/validate-create-connection-properties-ds.js';
1515
import { IUpdateConnectionProperties } from './connection-properties-use.cases.interface.js';
16+
import { TableCategoriesEntity } from '../../table-categories/table-categories.entity.js';
1617

1718
@Injectable()
1819
export class UpdateConnectionPropertiesUseCase
@@ -46,30 +47,62 @@ export class UpdateConnectionPropertiesUseCase
4647
const updatePropertiesObject: IUpdateConnectionPropertiesObject = buildUpdateConnectionPropertiesObject(inputData);
4748
const updated = Object.assign(connectionPropertiesToUpdate, updatePropertiesObject);
4849

49-
const categoriesToRemove = await this._dbContext.tableCategoriesRepository.find({
50+
const foundCategories = await this._dbContext.tableCategoriesRepository.find({
5051
where: { connection_properties_id: connectionPropertiesToUpdate.id },
5152
});
5253

53-
if (categoriesToRemove && categoriesToRemove.length > 0) {
54-
await this._dbContext.tableCategoriesRepository.remove(categoriesToRemove);
55-
updated.table_categories = [];
56-
}
54+
const newCategories: Array<TableCategoriesEntity> = [];
5755

58-
const updatedProperties = await this._dbContext.connectionPropertiesRepository.saveNewConnectionProperties(updated);
59-
if (table_categories && table_categories.length) {
60-
const createdCategories = table_categories.map((category) => {
61-
const newCategory = this._dbContext.tableCategoriesRepository.create({
62-
category_name: category.category_name,
63-
tables: category.tables,
64-
category_color: category.category_color,
65-
category_id: category.category_id,
56+
if (table_categories && table_categories.length > 0) {
57+
const categoriesToRemove = foundCategories.filter((foundCategory) => {
58+
return !table_categories?.some((inputCategory) => inputCategory.category_id === foundCategory.category_id);
59+
});
60+
if (categoriesToRemove && categoriesToRemove.length > 0) {
61+
await this._dbContext.tableCategoriesRepository.remove(categoriesToRemove);
62+
}
63+
64+
const categoriesToCreate = table_categories.filter((inputCategory) => {
65+
return !foundCategories.some((foundCategory) => foundCategory.category_id === inputCategory.category_id);
66+
});
67+
68+
if (categoriesToCreate && categoriesToCreate.length > 0) {
69+
const createdCategories = categoriesToCreate.map((category) => {
70+
const newCategory = this._dbContext.tableCategoriesRepository.create({
71+
category_name: category.category_name,
72+
tables: category.tables,
73+
category_color: category.category_color,
74+
category_id: category.category_id,
75+
});
76+
newCategory.connection_properties = connectionPropertiesToUpdate;
77+
return newCategory;
6678
});
67-
newCategory.connection_properties = updatedProperties;
68-
return newCategory;
79+
const savedNewCategories = await this._dbContext.tableCategoriesRepository.save(createdCategories);
80+
newCategories.push(...savedNewCategories);
81+
}
82+
83+
const categoriesToUpdate = table_categories.filter((inputCategory) => {
84+
return foundCategories.some((foundCategory) => foundCategory.category_id === inputCategory.category_id);
6985
});
70-
const savedCategories = await this._dbContext.tableCategoriesRepository.save(createdCategories);
71-
updatedProperties.table_categories = savedCategories;
86+
87+
for (const category of categoriesToUpdate) {
88+
const categoryToUpdate = foundCategories.find(
89+
(foundCategory) => foundCategory.category_id === category.category_id,
90+
);
91+
if (categoryToUpdate) {
92+
categoryToUpdate.category_name = category.category_name;
93+
categoryToUpdate.category_color = category.category_color;
94+
categoryToUpdate.tables = category.tables;
95+
const savedUpdatedCategory = await this._dbContext.tableCategoriesRepository.save(categoryToUpdate);
96+
newCategories.push(savedUpdatedCategory);
97+
}
98+
}
99+
} else {
100+
newCategories.push(...foundCategories);
72101
}
102+
103+
const updatedProperties = await this._dbContext.connectionPropertiesRepository.saveNewConnectionProperties(updated);
104+
updatedProperties.table_categories = newCategories;
105+
73106
return buildFoundConnectionPropertiesDs(updatedProperties);
74107
}
75108
}
Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js';
2-
import { PrimaryKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/primary-key.ds.js';
3-
import { TableStructureDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/table-structure.ds.js';
4-
import { Knex } from 'knex';
51
import { LRUCache } from 'lru-cache';
6-
import { ConnectionEntity } from '../../entities/connection/connection.entity.js';
72
import { isSaaS } from '../app/is-saas.js';
83
import { Constants } from '../constants/constants.js';
94

10-
const knexCache = new LRUCache(Constants.DEFAULT_CONNECTION_CACHE_OPTIONS);
11-
const tunnelCache = new LRUCache(Constants.DEFAULT_TUNNEL_CACHE_OPTIONS);
12-
const driverCache = new LRUCache(Constants.DEFAULT_DRIVER_CACHE_OPTIONS);
135
const invitationCache = new LRUCache(Constants.DEFAULT_INVITATION_CACHE_OPTIONS);
14-
const tableStructureCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS);
15-
const tableForeignKeysCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS);
16-
const tablePrimaryKeysCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS);
176
const tableReadPermissionCache = new LRUCache(Constants.DEFAULT_TABLE_PERMISSIONS_CACHE_OPTIONS);
187

198
export class Cacher {
@@ -76,129 +65,8 @@ export class Cacher {
7665
return userInvitations <= 10 && groupInvitations <= 10;
7766
}
7867

79-
public static getCachedKnex(connectionConfig): Knex {
80-
const cachedKnex = knexCache.get(JSON.stringify(connectionConfig)) as Knex;
81-
return cachedKnex ? cachedKnex : null;
82-
}
83-
84-
public static setKnexCache(connectionConfig, newKnex: Knex): void {
85-
knexCache.set(JSON.stringify(connectionConfig), newKnex);
86-
}
87-
88-
public static getTunnelCache(connection: ConnectionEntity): any {
89-
const cachedTnl = tunnelCache.get(JSON.stringify(connection));
90-
return cachedTnl ? cachedTnl : null;
91-
}
92-
93-
public static setTunnelCache(connection: ConnectionEntity, tnlObj): void {
94-
tunnelCache.set(JSON.stringify(connection), tnlObj);
95-
}
96-
97-
public static delTunnelCache(connection: ConnectionEntity): void {
98-
tunnelCache.delete(JSON.stringify(connection));
99-
}
100-
101-
public static getDriverCache(connection: ConnectionEntity): any {
102-
const cachedDriver = driverCache.get(JSON.stringify(connection));
103-
return cachedDriver ? cachedDriver : null;
104-
}
105-
106-
public static setDriverCache(connection: ConnectionEntity, newDriver): void {
107-
driverCache.set(JSON.stringify(connection), newDriver);
108-
}
109-
110-
public static delDriverCache(connection: ConnectionEntity): void {
111-
driverCache.delete(JSON.stringify(connection));
112-
}
113-
114-
public static setTableStructureCache(
115-
connection: ConnectionEntity,
116-
tableName: string,
117-
structure: Array<TableStructureDS>,
118-
): void {
119-
const connectionCopy = {
120-
...connection,
121-
};
122-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
123-
tableStructureCache.set(cacheObj, structure);
124-
}
125-
126-
public static getTableStructureCache(connection: ConnectionEntity, tableName: string): Array<TableStructureDS> {
127-
const connectionCopy = {
128-
...connection,
129-
};
130-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
131-
const foundStructure = tableStructureCache.get(cacheObj) as Array<TableStructureDS>;
132-
return foundStructure ? foundStructure : null;
133-
}
134-
135-
public static setTablePrimaryKeysCache(
136-
connection: ConnectionEntity,
137-
tableName: string,
138-
primaryKeys: Array<PrimaryKeyDS>,
139-
): void {
140-
const connectionCopy = {
141-
...connection,
142-
};
143-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
144-
tablePrimaryKeysCache.set(cacheObj, primaryKeys);
145-
}
146-
147-
public static getTablePrimaryKeysCache(connection: ConnectionEntity, tableName: string): Array<PrimaryKeyDS> {
148-
const connectionCopy = {
149-
...connection,
150-
};
151-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
152-
const foundKeys = tablePrimaryKeysCache.get(cacheObj) as Array<PrimaryKeyDS>;
153-
return foundKeys ? foundKeys : null;
154-
}
155-
156-
public static setTableForeignKeysCache(
157-
connection: ConnectionEntity,
158-
tableName: string,
159-
foreignKeys: Array<ForeignKeyDS>,
160-
): void {
161-
const connectionCopy = {
162-
...connection,
163-
};
164-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
165-
tableForeignKeysCache.set(cacheObj, foreignKeys);
166-
}
167-
168-
public static getTableForeignKeysCache(connection: ConnectionEntity, tableName: string): Array<ForeignKeyDS> {
169-
const connectionCopy = {
170-
...connection,
171-
};
172-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
173-
const foundKeys = tableForeignKeysCache.get(cacheObj) as Array<ForeignKeyDS>;
174-
return foundKeys ? foundKeys : null;
175-
}
176-
17768
public static async clearAllCache(): Promise<void> {
178-
const elements = [];
179-
knexCache.forEach((value, key) => {
180-
elements.push({ key, value });
181-
});
182-
for (const element of elements) {
183-
await element.value.destroy();
184-
knexCache.delete(element.key);
185-
}
186-
knexCache.clear();
187-
188-
const tunnelElements = [];
189-
tunnelCache.forEach((value, key) => {
190-
tunnelElements.push({ key, value });
191-
});
192-
for (const element of tunnelElements) {
193-
await element.value.close();
194-
tunnelCache.delete(element.key);
195-
}
196-
tunnelCache.clear();
197-
await driverCache.clear();
19869
await invitationCache.clear();
199-
await tableStructureCache.clear();
200-
await tableForeignKeysCache.clear();
201-
await tablePrimaryKeysCache.clear();
20270
await tableReadPermissionCache.clear();
20371
}
20472
}

backend/src/helpers/constants/constants.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,11 @@ export const Constants = {
118118
},
119119
},
120120

121-
DEFAULT_TUNNEL_CACHE_OPTIONS: {
122-
max: 100,
123-
ttl: 1000 * 60 * 60,
124-
dispose: async (tnl: any) => {
125-
try {
126-
await tnl.close();
127-
} catch (e) {
128-
console.error('Tunnel closing error: ' + e);
129-
}
130-
},
131-
},
132-
133-
DEFAULT_DRIVER_CACHE_OPTIONS: {
134-
max: 50,
135-
ttl: 1000 * 60 * 60,
136-
},
137-
138121
DEFAULT_INVITATION_CACHE_OPTIONS: {
139122
max: 200,
140123
ttl: 1000 * 60 * 60,
141124
},
142125

143-
DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS: {
144-
max: 1000,
145-
ttl: 1000 * 60,
146-
},
147-
148126
DEFAULT_TABLE_PERMISSIONS_CACHE_OPTIONS: {
149127
max: 1000,
150128
ttl: 1000 * 10,

backend/src/shared/config/config.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ConfigService {
9999
migrationsRun: false,
100100
logging: false,
101101
extra: {
102-
max: 2,
102+
max: 10,
103103
},
104104
logger: 'advanced-console',
105105
driver: pgLiteDriver ? pgLiteDriver : undefined,

backend/test/ava-tests/saas-tests/connection-e2e.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ test(`${currentTest} should return a found connection`, async (t) => {
320320
.set('Cookie', token)
321321
.set('Accept', 'application/json');
322322

323+
const foundOneRo = JSON.parse(findOneResponce.text);
324+
console.log('🚀 ~ foundOneRo:', foundOneRo);
323325
t.is(findOneResponce.status, 200);
324326
const result = findOneResponce.body.connection;
325327

@@ -1271,6 +1273,7 @@ test(`${currentTest} throw an exception when group name is not unique`, async (t
12711273
.set('Accept', 'application/json');
12721274

12731275
const createConnectionRO = JSON.parse(createConnectionResponse.text);
1276+
t.is(createConnectionResponse.status, 201);
12741277
newGroup1.title = 'Admin';
12751278
const createGroupResponse = await request(app.getHttpServer())
12761279
.post(`/connection/group/${createConnectionRO.id}`)

0 commit comments

Comments
 (0)