mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Remove API extension types from the API (#11191)
There is little value in keeping these types inside the API package. We should instead focus on improving the types in shared.
This commit is contained in:
committed by
GitHub
parent
a19fc451fa
commit
889668f972
@@ -1,6 +1,6 @@
|
||||
import { ActionHandler, EventContext, FilterHandler, InitHandler } from '@directus/shared/types';
|
||||
import { EventEmitter2 } from 'eventemitter2';
|
||||
import logger from './logger';
|
||||
import { ActionHandler, FilterHandler, HookContext, InitHandler } from './types';
|
||||
|
||||
export class Emitter {
|
||||
private filterEmitter;
|
||||
@@ -26,7 +26,7 @@ export class Emitter {
|
||||
event: string | string[],
|
||||
payload: T,
|
||||
meta: Record<string, any>,
|
||||
context: HookContext
|
||||
context: EventContext
|
||||
): Promise<T> {
|
||||
const events = Array.isArray(event) ? event : [event];
|
||||
const listeners: FilterHandler[] = events.flatMap((event) => this.filterEmitter.listeners(event));
|
||||
@@ -43,7 +43,7 @@ export class Emitter {
|
||||
return updatedPayload;
|
||||
}
|
||||
|
||||
public emitAction(event: string | string[], meta: Record<string, any>, context: HookContext): void {
|
||||
public emitAction(event: string | string[], meta: Record<string, any>, context: EventContext): void {
|
||||
const events = Array.isArray(event) ? event : [event];
|
||||
|
||||
for (const event of events) {
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
import express, { Router } from 'express';
|
||||
import path from 'path';
|
||||
import { AppExtensionType, Extension, ExtensionType } from '@directus/shared/types';
|
||||
import {
|
||||
ActionHandler,
|
||||
AppExtensionType,
|
||||
EndpointConfig,
|
||||
Extension,
|
||||
ExtensionType,
|
||||
FilterHandler,
|
||||
HookConfig,
|
||||
InitHandler,
|
||||
ScheduleHandler,
|
||||
} from '@directus/shared/types';
|
||||
import {
|
||||
ensureExtensionDirs,
|
||||
generateExtensionsEntry,
|
||||
@@ -22,7 +32,6 @@ import env from './env';
|
||||
import * as exceptions from './exceptions';
|
||||
import * as sharedExceptions from '@directus/shared/exceptions';
|
||||
import logger from './logger';
|
||||
import { HookConfig, EndpointConfig, FilterHandler, ActionHandler, InitHandler, ScheduleHandler } from './types';
|
||||
import fse from 'fs-extra';
|
||||
import { getSchema } from './utils/get-schema';
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import { Accountability, SchemaOverview } from '@directus/shared/types';
|
||||
import { Router } from 'express';
|
||||
import { Knex } from 'knex';
|
||||
import { Logger } from 'pino';
|
||||
import env from '../env';
|
||||
import * as exceptions from '../exceptions';
|
||||
import * as services from '../services';
|
||||
import { Emitter } from '../emitter';
|
||||
import { getSchema } from '../utils/get-schema';
|
||||
|
||||
export type ExtensionContext = {
|
||||
services: typeof services;
|
||||
exceptions: typeof exceptions;
|
||||
database: Knex;
|
||||
env: typeof env;
|
||||
emitter: Emitter;
|
||||
logger: Logger;
|
||||
getSchema: typeof getSchema;
|
||||
};
|
||||
|
||||
export type HookContext = {
|
||||
database: Knex;
|
||||
schema: SchemaOverview | null;
|
||||
accountability: Accountability | null;
|
||||
};
|
||||
|
||||
export type FilterHandler = (payload: any, meta: Record<string, any>, context: HookContext) => any | Promise<any>;
|
||||
export type ActionHandler = (meta: Record<string, any>, context: HookContext) => void | Promise<void>;
|
||||
export type InitHandler = (meta: Record<string, any>) => void | Promise<void>;
|
||||
export type ScheduleHandler = () => void | Promise<void>;
|
||||
|
||||
type RegisterFunctions = {
|
||||
filter: (event: string, handler: FilterHandler) => void;
|
||||
action: (event: string, handler: ActionHandler) => void;
|
||||
init: (event: string, handler: InitHandler) => void;
|
||||
schedule: (cron: string, handler: ScheduleHandler) => void;
|
||||
};
|
||||
|
||||
type HookHandlerFunction = (register: RegisterFunctions, context: ExtensionContext) => void;
|
||||
|
||||
export type HookConfig = HookHandlerFunction;
|
||||
|
||||
type EndpointHandlerFunction = (router: Router, context: ExtensionContext) => void;
|
||||
interface EndpointAdvancedConfig {
|
||||
id: string;
|
||||
handler: EndpointHandlerFunction;
|
||||
}
|
||||
|
||||
export type EndpointConfig = EndpointHandlerFunction | EndpointAdvancedConfig;
|
||||
@@ -3,7 +3,6 @@ export * from './assets';
|
||||
export * from './ast';
|
||||
export * from './auth';
|
||||
export * from './collection';
|
||||
export * from './extensions';
|
||||
export * from './files';
|
||||
export * from './graphql';
|
||||
export * from './items';
|
||||
|
||||
@@ -2,9 +2,10 @@ import axios from 'axios';
|
||||
import getDatabase from './database';
|
||||
import emitter from './emitter';
|
||||
import logger from './logger';
|
||||
import { ActionHandler, Webhook, WebhookHeader } from './types';
|
||||
import { Webhook, WebhookHeader } from './types';
|
||||
import { WebhooksService } from './services';
|
||||
import { getSchema } from './utils/get-schema';
|
||||
import { ActionHandler } from '@directus/shared/types';
|
||||
|
||||
let registered: { event: string; handler: ActionHandler }[] = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user