refactor(core): Move initial files to @n8n/db (#14953)

This commit is contained in:
Iván Ovejero
2025-04-29 18:14:52 +02:00
committed by GitHub
parent 8613521aab
commit 20115a8fa1
95 changed files with 423 additions and 369 deletions

View File

@@ -5,17 +5,13 @@ import type {
ICredentialDataDecryptedObject,
INodeCredentialTestRequest,
IPersonalizationSurveyAnswersV4,
IUser,
} from 'n8n-workflow';
import type { CredentialsEntity } from '@/databases/entities/credentials-entity';
import type { Project } from '@/databases/entities/project';
import type { User } from '@/databases/entities/user';
import type { Variables } from '@/databases/entities/variables';
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import type { WorkflowHistory } from '@/databases/entities/workflow-history';
import type { ScopesField } from '@/services/role.service';
import type { SlimProject } from '@/types-db';
import type { ListQuery } from '@/types-db';
export type APIRequest<
RouteParams = {},
@@ -50,80 +46,6 @@ export type AuthenticatedRequest<
// list query
// ----------------------------------
export namespace ListQuery {
export type Request = AuthenticatedRequest<{}, {}, {}, Params> & {
listQueryOptions?: Options;
};
export type Params = {
filter?: string;
skip?: string;
take?: string;
select?: string;
sortBy?: string;
};
export type Options = {
filter?: Record<string, unknown>;
select?: Record<string, true>;
skip?: number;
take?: number;
sortBy?: string;
};
/**
* Slim workflow returned from a list query operation.
*/
export namespace Workflow {
type OptionalBaseFields = 'name' | 'active' | 'versionId' | 'createdAt' | 'updatedAt' | 'tags';
type BaseFields = Pick<WorkflowEntity, 'id'> &
Partial<Pick<WorkflowEntity, OptionalBaseFields>>;
type SharedField = Partial<Pick<WorkflowEntity, 'shared'>>;
type SortingField = 'createdAt' | 'updatedAt' | 'name';
export type SortOrder = `${SortingField}:asc` | `${SortingField}:desc`;
type OwnedByField = { ownedBy: SlimUser | null; homeProject: SlimProject | null };
export type Plain = BaseFields;
export type WithSharing = BaseFields & SharedField;
export type WithOwnership = BaseFields & OwnedByField;
type SharedWithField = { sharedWith: SlimUser[]; sharedWithProjects: SlimProject[] };
export type WithOwnedByAndSharedWith = BaseFields &
OwnedByField &
SharedWithField &
SharedField;
export type WithScopes = BaseFields & ScopesField & SharedField;
}
export namespace Credentials {
type OwnedByField = { homeProject: SlimProject | null };
type SharedField = Partial<Pick<CredentialsEntity, 'shared'>>;
type SharedWithField = { sharedWithProjects: SlimProject[] };
export type WithSharing = CredentialsEntity & SharedField;
export type WithOwnedByAndSharedWith = CredentialsEntity &
OwnedByField &
SharedWithField &
SharedField;
export type WithScopes = CredentialsEntity & ScopesField & SharedField;
}
}
type SlimUser = Pick<IUser, 'id' | 'email' | 'firstName' | 'lastName'>;
export function hasSharing(
workflows: ListQuery.Workflow.Plain[] | ListQuery.Workflow.WithSharing[],
): workflows is ListQuery.Workflow.WithSharing[] {