Moving schema and relation types into shared package (#11179)

* moving schema and relation types into shared package

* updating SchemaOverview imports

* removing duplicate import
This commit is contained in:
John Huffsmith
2022-01-20 13:36:19 -05:00
committed by GitHub
parent a38bcddb7e
commit e7ada1f173
40 changed files with 95 additions and 125 deletions

View File

@@ -1,5 +1,6 @@
import { SchemaOverview } from '@directus/shared/types';
import { Knex } from 'knex';
import { AuthDriverOptions, SchemaOverview, User } from '../types';
import { AuthDriverOptions, User } from '../types';
export abstract class AuthDriver {
knex: Knex;

View File

@@ -6,8 +6,9 @@ import env from '../../../env';
import logger from '../../../logger';
import { getSchema } from '../../../utils/get-schema';
import { RolesService, UsersService, SettingsService } from '../../../services';
import getDatabase, { isInstalled, validateDatabaseConnection, hasDatabaseConnection } from '../../../database';
import { SchemaOverview } from '../../../types';
import { SchemaOverview } from '@directus/shared/types';
import { defaultAdminRole, defaultAdminUser } from '../../utils/defaults';
export default async function bootstrap({ skipAdminInit }: { skipAdminInit?: boolean }): Promise<void> {

View File

@@ -1,7 +1,7 @@
import { Knex } from 'knex';
import SchemaInspector from 'knex-schema-inspector';
import logger from '../../logger';
import { RelationMeta } from '../../types';
import { RelationMeta } from '@directus/shared/types';
import { getDefaultIndexName } from '../../utils/get-default-index-name';
export async function up(knex: Knex): Promise<void> {

View File

@@ -1,7 +1,7 @@
import { Knex } from 'knex';
import { clone, cloneDeep, pick, uniq, merge } from 'lodash';
import { PayloadService } from '../services/payload';
import { Item, SchemaOverview } from '../types';
import { Item, SchemaOverview } from '@directus/shared/types';
import { AST, FieldNode, NestedCollectionNode, M2ONode } from '../types/ast';
import { applyFunctionToColumnName } from '../utils/apply-function-to-column-name';
import applyQuery from '../utils/apply-query';

View File

@@ -1,5 +1,5 @@
import { merge } from 'lodash';
import { RelationMeta } from '../../../types';
import { RelationMeta } from '@directus/shared/types';
import { requireYAML } from '../../../utils/require-yaml';
const systemData = requireYAML(require.resolve('./relations.yaml')) as {

View File

@@ -11,16 +11,8 @@ import { InvalidCredentialsException, InvalidOTPException, UserSuspendedExceptio
import { createRateLimiter } from '../rate-limiter';
import { ActivityService } from './activity';
import { TFAService } from './tfa';
import {
AbstractServiceOptions,
Action,
SchemaOverview,
Session,
User,
DirectusTokenPayload,
LoginResult,
} from '../types';
import { Accountability } from '@directus/shared/types';
import { AbstractServiceOptions, Action, Session, User, DirectusTokenPayload, LoginResult } from '../types';
import { Accountability, SchemaOverview } from '@directus/shared/types';
import { SettingsService } from './settings';
import { clone, cloneDeep } from 'lodash';
import { performance } from 'perf_hooks';

View File

@@ -4,17 +4,15 @@ import getDatabase from '../database';
import { ForbiddenException } from '../exceptions';
import { FailedValidationException } from '@directus/shared/exceptions';
import { validatePayload } from '@directus/shared/utils';
import { Accountability } from '@directus/shared/types';
import { AbstractServiceOptions, AST, FieldNode, Item, NestedCollectionNode, PrimaryKey } from '../types';
import {
AbstractServiceOptions,
AST,
FieldNode,
Item,
NestedCollectionNode,
PrimaryKey,
Query,
Aggregate,
Permission,
PermissionsAction,
Accountability,
SchemaOverview,
} from '../types';
import { Query, Aggregate, Permission, PermissionsAction } from '@directus/shared/types';
} from '@directus/shared/types';
import { ItemsService } from './items';
import { PayloadService } from './payload';

View File

@@ -9,8 +9,8 @@ import { ForbiddenException, InvalidPayloadException } from '../exceptions';
import { FieldsService } from '../services/fields';
import { ItemsService } from '../services/items';
import Keyv from 'keyv';
import { AbstractServiceOptions, Collection, CollectionMeta, SchemaOverview, MutationOptions } from '../types';
import { Accountability, FieldMeta, RawField } from '@directus/shared/types';
import { AbstractServiceOptions, Collection, CollectionMeta, MutationOptions } from '../types';
import { Accountability, FieldMeta, RawField, SchemaOverview } from '@directus/shared/types';
import { Table } from 'knex-schema-inspector/dist/types/table';
export type RawCollection = {

View File

@@ -11,9 +11,8 @@ import { ForbiddenException, InvalidPayloadException } from '../exceptions';
import { translateDatabaseError } from '../exceptions/database/translate';
import { ItemsService } from '../services/items';
import { PayloadService } from '../services/payload';
import { AbstractServiceOptions, SchemaOverview } from '../types';
import { Accountability } from '@directus/shared/types';
import { Field, FieldMeta, RawField, Type } from '@directus/shared/types';
import { AbstractServiceOptions } from '../types';
import { Field, FieldMeta, RawField, Type, Accountability, SchemaOverview } from '@directus/shared/types';
import getDefaultValue from '../utils/get-default-value';
import getLocalType from '../utils/get-local-type';
import { toArray } from '@directus/shared/utils';

View File

@@ -33,7 +33,7 @@ import {
StringValueNode,
validate,
} from 'graphql';
import { Filter } from '@directus/shared/types';
import { Filter, SchemaOverview } from '@directus/shared/types';
import {
GraphQLJSON,
InputTypeComposer,
@@ -53,7 +53,7 @@ import { BaseException } from '@directus/shared/exceptions';
import { ForbiddenException, GraphQLValidationException, InvalidPayloadException } from '../exceptions';
import { getExtensionManager } from '../extensions';
import { Accountability, Query, Aggregate } from '@directus/shared/types';
import { AbstractServiceOptions, Action, GraphQLParams, Item, SchemaOverview } from '../types';
import { AbstractServiceOptions, Action, GraphQLParams, Item } from '../types';
import { getGraphQLType } from '../utils/get-graphql-type';
import { reduceSchema } from '../utils/reduce-schema';
import { sanitizeQuery } from '../utils/sanitize-query';

View File

@@ -1,7 +1,7 @@
import { Knex } from 'knex';
import getDatabase from '../database';
import { AbstractServiceOptions, SchemaOverview } from '../types';
import { Accountability } from '@directus/shared/types';
import { AbstractServiceOptions } from '../types';
import { Accountability, SchemaOverview } from '@directus/shared/types';
import { ForbiddenException, InvalidPayloadException, UnsupportedMediaTypeException } from '../exceptions';
import StreamArray from 'stream-json/streamers/StreamArray';
import { ItemsService } from './items';

View File

@@ -8,14 +8,13 @@ import emitter from '../emitter';
import env from '../env';
import { ForbiddenException } from '../exceptions';
import { translateDatabaseError } from '../exceptions/database/translate';
import { Accountability, Query, PermissionsAction } from '@directus/shared/types';
import { Accountability, Query, PermissionsAction, SchemaOverview } from '@directus/shared/types';
import {
AbstractService,
AbstractServiceOptions,
Action,
Item as AnyItem,
PrimaryKey,
SchemaOverview,
MutationOptions,
} from '../types';
import getASTFromQuery from '../utils/get-ast-from-query';

View File

@@ -6,8 +6,8 @@ import getDatabase from '../../database';
import env from '../../env';
import { InvalidPayloadException } from '../../exceptions';
import logger from '../../logger';
import { AbstractServiceOptions, SchemaOverview } from '../../types';
import { Accountability } from '@directus/shared/types';
import { AbstractServiceOptions } from '../../types';
import { Accountability, SchemaOverview } from '@directus/shared/types';
import getMailer from '../../mailer';
import { Transporter, SendMailOptions } from 'nodemailer';
import { Url } from '../../utils/url';

View File

@@ -1,8 +1,8 @@
import { Knex } from 'knex';
import getDatabase from '../database';
import { ForbiddenException } from '../exceptions';
import { AbstractServiceOptions, SchemaOverview } from '../types';
import { Accountability, Query } from '@directus/shared/types';
import { AbstractServiceOptions } from '../types';
import { Accountability, Query, SchemaOverview } from '@directus/shared/types';
import { applyFilter, applySearch } from '../utils/apply-query';
export class MetaService {

View File

@@ -5,8 +5,8 @@ import { clone, cloneDeep, isObject, isPlainObject, omit, pick, isNil } from 'lo
import { v4 as uuidv4 } from 'uuid';
import getDatabase from '../database';
import { ForbiddenException, InvalidPayloadException } from '../exceptions';
import { AbstractServiceOptions, Item, PrimaryKey, SchemaOverview, Alterations } from '../types';
import { Accountability, Query } from '@directus/shared/types';
import { AbstractServiceOptions, Item, PrimaryKey, Alterations } from '../types';
import { Accountability, Query, SchemaOverview } from '@directus/shared/types';
import { toArray } from '@directus/shared/utils';
import { ItemsService } from './items';
import { unflatten } from 'flat';

View File

@@ -1,9 +1,7 @@
import { Knex } from 'knex';
import { systemRelationRows } from '../database/system-data/relations';
import { ForbiddenException, InvalidPayloadException } from '../exceptions';
import { AbstractServiceOptions, SchemaOverview, Relation, RelationMeta } from '../types';
import { Query } from '@directus/shared/types';
import { Accountability } from '@directus/shared/types';
import { SchemaOverview, Relation, RelationMeta, Accountability, Query } from '@directus/shared/types';
import { toArray } from '@directus/shared/utils';
import { ItemsService, QueryOptions } from './items';
import { PermissionsService } from './permissions';
@@ -13,6 +11,7 @@ import getDatabase, { getSchemaInspector } from '../database';
import { getDefaultIndexName } from '../utils/get-default-index-name';
import { getCache } from '../cache';
import Keyv from 'keyv';
import { AbstractServiceOptions } from '../types';
export class RelationsService {
knex: Knex;

View File

@@ -12,8 +12,8 @@ import env from '../env';
import logger from '../logger';
import { rateLimiter } from '../middleware/rate-limiter';
import storage from '../storage';
import { AbstractServiceOptions, SchemaOverview } from '../types';
import { Accountability } from '@directus/shared/types';
import { AbstractServiceOptions } from '../types';
import { Accountability, SchemaOverview } from '@directus/shared/types';
import { toArray } from '@directus/shared/utils';
import getMailer from '../mailer';
import { SettingsService } from './settings';

View File

@@ -15,8 +15,8 @@ import {
import { version } from '../../package.json';
import getDatabase from '../database';
import env from '../env';
import { AbstractServiceOptions, Collection, Relation, SchemaOverview } from '../types';
import { Accountability, Field, Type, Permission } from '@directus/shared/types';
import { AbstractServiceOptions, Collection } from '../types';
import { Accountability, Field, Type, Permission, SchemaOverview, Relation } from '@directus/shared/types';
import { getRelationType } from '../utils/get-relation-type';
import { CollectionsService } from './collections';
import { FieldsService } from './fields';

View File

@@ -6,9 +6,8 @@ import env from '../env';
import { FailedValidationException } from '@directus/shared/exceptions';
import { ForbiddenException, InvalidPayloadException, UnprocessableEntityException } from '../exceptions';
import { RecordNotUniqueException } from '../exceptions/database/record-not-unique';
import { AbstractServiceOptions, Item, PrimaryKey, SchemaOverview, MutationOptions } from '../types';
import { Query } from '@directus/shared/types';
import { Accountability } from '@directus/shared/types';
import { AbstractServiceOptions, Item, PrimaryKey, MutationOptions } from '../types';
import { Query, SchemaOverview, Accountability } from '@directus/shared/types';
import isUrlAllowed from '../utils/is-url-allowed';
import { toArray } from '@directus/shared/utils';
import { Url } from '../utils/url';

View File

@@ -2,8 +2,8 @@ import { Knex } from 'knex';
import getDatabase from '../database';
import { systemCollectionRows } from '../database/system-data/collections';
import { ForbiddenException, InvalidPayloadException } from '../exceptions';
import { AbstractServiceOptions, PrimaryKey, SchemaOverview } from '../types';
import { Accountability } from '@directus/shared/types';
import { AbstractServiceOptions, PrimaryKey } from '../types';
import { Accountability, SchemaOverview } from '@directus/shared/types';
export class UtilsService {
knex: Knex;

View File

@@ -1,5 +1,4 @@
import { Query } from '@directus/shared/types';
import { Relation } from './relation';
import { Query, Relation } from '@directus/shared/types';
export type M2ONode = {
type: 'm2o';

View File

@@ -1,5 +1,5 @@
import { SchemaOverview } from '@directus/shared/types';
import { Knex } from 'knex';
import { SchemaOverview } from './schema';
export interface AuthDriverOptions {
knex: Knex;

View File

@@ -1,4 +1,4 @@
import { Accountability } from '@directus/shared/types';
import { Accountability, SchemaOverview } from '@directus/shared/types';
import { Router } from 'express';
import { Knex } from 'knex';
import { Logger } from 'pino';
@@ -7,7 +7,6 @@ import * as exceptions from '../exceptions';
import * as services from '../services';
import { Emitter } from '../emitter';
import { getSchema } from '../utils/get-schema';
import { SchemaOverview } from './schema';
export type ExtensionContext = {
services: typeof services;

View File

@@ -9,9 +9,7 @@ export * from './graphql';
export * from './items';
export * from './meta';
export * from './migration';
export * from './relation';
export * from './revision';
export * from './schema';
export * from './services';
export * from './snapshot';
export * from './webhooks';

View File

@@ -1,27 +0,0 @@
import { ForeignKey } from 'knex-schema-inspector/dist/types/foreign-key';
export type RelationMeta = {
id: number;
many_collection: string;
many_field: string;
one_collection: string | null;
one_field: string | null;
one_collection_field: string | null;
one_allowed_collections: string[] | null;
one_deselect_action: 'nullify' | 'delete';
junction_field: string | null;
sort_field: string | null;
system?: boolean;
};
export type Relation = {
collection: string;
field: string;
related_collection: string | null;
schema: ForeignKey | null;
meta: RelationMeta | null;
};

View File

@@ -1,35 +0,0 @@
import { Type } from '@directus/shared/types';
import { Relation } from './relation';
export type FieldOverview = {
field: string;
defaultValue: any;
nullable: boolean;
generated: boolean;
type: Type | 'unknown' | 'alias';
dbType: string | null;
precision: number | null;
scale: number | null;
special: string[];
note: string | null;
alias: boolean;
};
export type CollectionsOverview = {
[name: string]: {
collection: string;
primary: string;
singleton: boolean;
sortField: string | null;
note: string | null;
accountability: 'all' | 'activity' | null;
fields: {
[name: string]: FieldOverview;
};
};
};
export type SchemaOverview = {
collections: CollectionsOverview;
relations: Relation[];
};

View File

@@ -1,8 +1,6 @@
import { Knex } from 'knex';
import { SchemaOverview } from '../types';
import { Accountability } from '@directus/shared/types';
import { Accountability, Query, SchemaOverview } from '@directus/shared/types';
import { Item, PrimaryKey } from './items';
import { Query } from '@directus/shared/types';
export type AbstractServiceOptions = {
knex?: Knex;

View File

@@ -1,6 +1,5 @@
import { Collection } from './collection';
import { Relation, RelationMeta } from './relation';
import { Field, FieldMeta } from '@directus/shared/types';
import { Relation, RelationMeta, Field, FieldMeta } from '@directus/shared/types';
import { Diff } from 'deep-diff';
export type Snapshot = {

View File

@@ -3,8 +3,15 @@ import { clone, cloneDeep, get, isPlainObject, set } from 'lodash';
import { customAlphabet } from 'nanoid';
import validate from 'uuid-validate';
import { InvalidQueryException } from '../exceptions';
import { Relation, RelationMeta, SchemaOverview } from '../types';
import { Aggregate, Filter, LogicalFilterAND, Query } from '@directus/shared/types';
import {
Aggregate,
Filter,
LogicalFilterAND,
Query,
Relation,
RelationMeta,
SchemaOverview,
} from '@directus/shared/types';
import { getColumn } from './get-column';
import { getRelationType } from './get-relation-type';
import { getHelpers } from '../database/helpers';

View File

@@ -1,4 +1,4 @@
import { Snapshot, SnapshotDiff, SchemaOverview, Relation } from '../types';
import { Snapshot, SnapshotDiff } from '../types';
import { getSnapshot } from './get-snapshot';
import { getSnapshotDiff } from './get-snapshot-diff';
import { Knex } from 'knex';
@@ -7,7 +7,7 @@ import { getSchema } from './get-schema';
import { CollectionsService, FieldsService, RelationsService } from '../services';
import { set } from 'lodash';
import { DiffNew } from 'deep-diff';
import { Field } from '@directus/shared/types';
import { Field, Relation, SchemaOverview } from '@directus/shared/types';
import logger from '../logger';
export async function applySnapshot(

View File

@@ -4,9 +4,8 @@
import { Knex } from 'knex';
import { cloneDeep, mapKeys, omitBy, uniq } from 'lodash';
import { Accountability } from '@directus/shared/types';
import { AST, FieldNode, NestedCollectionNode, SchemaOverview } from '../types';
import { Query, PermissionsAction } from '@directus/shared/types';
import { AST, FieldNode, NestedCollectionNode } from '../types';
import { Query, PermissionsAction, Accountability, SchemaOverview } from '@directus/shared/types';
import { getRelationType } from '../utils/get-relation-type';
type GetASTOptions = {

View File

@@ -1,4 +1,4 @@
import { Permission, Accountability } from '@directus/shared/types';
import { Permission, Accountability, SchemaOverview } from '@directus/shared/types';
import { deepMap, parseFilter } from '@directus/shared/utils';
import { cloneDeep } from 'lodash';
import getDatabase from '../database';
@@ -10,7 +10,6 @@ import { RolesService } from '../services/roles';
import { getCache } from '../cache';
import hash from 'object-hash';
import env from '../env';
import { SchemaOverview } from '../types';
export async function getPermissions(accountability: Accountability, schema: SchemaOverview) {
const database = getDatabase();

View File

@@ -1,4 +1,4 @@
import { Relation } from '../types';
import { Relation } from '@directus/shared/types';
export function getRelationType(getRelationOptions: {
relation: Relation;

View File

@@ -5,8 +5,7 @@ import { systemCollectionRows } from '../database/system-data/collections';
import { systemFieldRows } from '../database/system-data/fields';
import logger from '../logger';
import { RelationsService } from '../services';
import { SchemaOverview } from '../types';
import { Accountability } from '@directus/shared/types';
import { Accountability, SchemaOverview } from '@directus/shared/types';
import { toArray } from '@directus/shared/utils';
import getDefaultValue from './get-default-value';
import getLocalType from './get-local-type';

View File

@@ -2,9 +2,10 @@ import getDatabase from '../database';
import { getSchema } from './get-schema';
import { CollectionsService, FieldsService, RelationsService } from '../services';
import { version } from '../../package.json';
import { SchemaOverview, Snapshot, SnapshotField, SnapshotRelation } from '../types';
import { Snapshot, SnapshotField, SnapshotRelation } from '../types';
import { Knex } from 'knex';
import { omit } from 'lodash';
import { SchemaOverview } from '@directus/shared/types';
export async function getSnapshot(options?: { database?: Knex; schema?: SchemaOverview }): Promise<Snapshot> {
const database = options?.database ?? getDatabase();

View File

@@ -1,5 +1,5 @@
import { Permission, Accountability, Filter } from '@directus/shared/types';
import { SchemaOverview } from '../types';
import { Permission, Accountability, Filter, SchemaOverview } from '@directus/shared/types';
import { assign, set, uniq } from 'lodash';
import { mergePermissions } from './merge-permissions';
import { schemaPermissions } from '../database/system-data/app-access-permissions';

View File

@@ -1,6 +1,6 @@
import { uniq } from 'lodash';
import { SchemaOverview } from '../types';
import { Permission, PermissionsAction } from '@directus/shared/types';
import { Permission, PermissionsAction, SchemaOverview } from '@directus/shared/types';
/**
* Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only