refactor: Move community package logic to service (no-changelog) (#6973)
This commit is contained in:
@@ -14,8 +14,6 @@ import { sqliteMigrations } from '@db/migrations/sqlite';
|
||||
import { hashPassword } from '@/UserManagement/UserManagementHelper';
|
||||
import { AuthIdentity } from '@db/entities/AuthIdentity';
|
||||
import type { ExecutionEntity } from '@db/entities/ExecutionEntity';
|
||||
import { InstalledNodes } from '@db/entities/InstalledNodes';
|
||||
import { InstalledPackages } from '@db/entities/InstalledPackages';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type { TagEntity } from '@db/entities/TagEntity';
|
||||
import type { User } from '@db/entities/User';
|
||||
@@ -23,13 +21,7 @@ import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import type { ICredentialsDb } from '@/Interfaces';
|
||||
import { DB_INITIALIZATION_TIMEOUT } from './constants';
|
||||
import { randomApiKey, randomEmail, randomName, randomString, randomValidPassword } from './random';
|
||||
import type {
|
||||
CollectionName,
|
||||
CredentialPayload,
|
||||
InstalledNodePayload,
|
||||
InstalledPackagePayload,
|
||||
PostgresSchemaSection,
|
||||
} from './types';
|
||||
import type { CollectionName, CredentialPayload, PostgresSchemaSection } from './types';
|
||||
import type { ExecutionData } from '@db/entities/ExecutionData';
|
||||
import { generateNanoId } from '@db/utils/generators';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
@@ -292,31 +284,6 @@ export async function createManyUsers(
|
||||
return Db.collections.User.save(users);
|
||||
}
|
||||
|
||||
// --------------------------------------
|
||||
// Installed nodes and packages creation
|
||||
// --------------------------------------
|
||||
|
||||
export async function saveInstalledPackage(
|
||||
installedPackagePayload: InstalledPackagePayload,
|
||||
): Promise<InstalledPackages> {
|
||||
const newInstalledPackage = new InstalledPackages();
|
||||
|
||||
Object.assign(newInstalledPackage, installedPackagePayload);
|
||||
|
||||
const savedInstalledPackage = await Db.collections.InstalledPackages.save(newInstalledPackage);
|
||||
return savedInstalledPackage;
|
||||
}
|
||||
|
||||
export async function saveInstalledNode(
|
||||
installedNodePayload: InstalledNodePayload,
|
||||
): Promise<InstalledNodes> {
|
||||
const newInstalledNode = new InstalledNodes();
|
||||
|
||||
Object.assign(newInstalledNode, installedNodePayload);
|
||||
|
||||
return Db.collections.InstalledNodes.save(newInstalledNode);
|
||||
}
|
||||
|
||||
export async function addApiKey(user: User): Promise<User> {
|
||||
user.apiKey = randomApiKey();
|
||||
return Db.collections.User.save(user);
|
||||
|
||||
@@ -59,15 +59,3 @@ export type SaveCredentialFunction = (
|
||||
export type PostgresSchemaSection = {
|
||||
[K in 'host' | 'port' | 'schema' | 'user' | 'password']: { env: string };
|
||||
};
|
||||
|
||||
export type InstalledPackagePayload = {
|
||||
packageName: string;
|
||||
installedVersion: string;
|
||||
};
|
||||
|
||||
export type InstalledNodePayload = {
|
||||
name: string;
|
||||
type: string;
|
||||
latestVersion: number;
|
||||
package: string;
|
||||
};
|
||||
|
||||
@@ -3,27 +3,44 @@ import { InstalledPackages } from '@db/entities/InstalledPackages';
|
||||
|
||||
import { randomName } from '../random';
|
||||
import { COMMUNITY_NODE_VERSION, COMMUNITY_PACKAGE_VERSION } from '../constants';
|
||||
import type { InstalledNodePayload, InstalledPackagePayload } from '../types';
|
||||
import { InstalledNodesRepository, InstalledPackagesRepository } from '@/databases/repositories';
|
||||
import Container from 'typedi';
|
||||
|
||||
export function installedPackagePayload(): InstalledPackagePayload {
|
||||
return {
|
||||
packageName: NODE_PACKAGE_PREFIX + randomName(),
|
||||
export const mockPackageName = () => NODE_PACKAGE_PREFIX + randomName();
|
||||
|
||||
export const mockPackage = () =>
|
||||
Container.get(InstalledPackagesRepository).create({
|
||||
packageName: mockPackageName(),
|
||||
installedVersion: COMMUNITY_PACKAGE_VERSION.CURRENT,
|
||||
};
|
||||
}
|
||||
installedNodes: [],
|
||||
});
|
||||
|
||||
export function installedNodePayload(packageName: string): InstalledNodePayload {
|
||||
export const mockNode = (packageName: string) => {
|
||||
const nodeName = randomName();
|
||||
return {
|
||||
|
||||
return Container.get(InstalledNodesRepository).create({
|
||||
name: nodeName,
|
||||
type: nodeName,
|
||||
latestVersion: COMMUNITY_NODE_VERSION.CURRENT,
|
||||
package: packageName,
|
||||
};
|
||||
}
|
||||
latestVersion: COMMUNITY_NODE_VERSION.CURRENT.toString(),
|
||||
package: { packageName },
|
||||
});
|
||||
};
|
||||
|
||||
export const emptyPackage = async () => {
|
||||
const installedPackage = new InstalledPackages();
|
||||
installedPackage.installedNodes = [];
|
||||
return installedPackage;
|
||||
};
|
||||
|
||||
export function mockPackagePair(): InstalledPackages[] {
|
||||
const pkgA = mockPackage();
|
||||
const nodeA = mockNode(pkgA.packageName);
|
||||
pkgA.installedNodes = [nodeA];
|
||||
|
||||
const pkgB = mockPackage();
|
||||
const nodeB1 = mockNode(pkgB.packageName);
|
||||
const nodeB2 = mockNode(pkgB.packageName);
|
||||
pkgB.installedNodes = [nodeB1, nodeB2];
|
||||
|
||||
return [pkgA, pkgB];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user