feat: builds plugin infrastructure (#149)
This commit is contained in:
@@ -137,9 +137,10 @@ export type PayloadCollectionConfig = {
|
||||
timestamps?: boolean
|
||||
};
|
||||
|
||||
export interface CollectionConfig extends Omit<DeepRequired<PayloadCollectionConfig>, 'auth' | 'upload'> {
|
||||
export interface CollectionConfig extends Omit<DeepRequired<PayloadCollectionConfig>, 'auth' | 'upload' | 'fields'> {
|
||||
auth: Auth;
|
||||
upload: Upload;
|
||||
fields: Field[];
|
||||
}
|
||||
|
||||
export type Collection = {
|
||||
|
||||
@@ -9,5 +9,9 @@ import sanitize from './sanitize';
|
||||
export function buildConfig(config: PayloadConfig): Config {
|
||||
const sanitized = sanitize(config);
|
||||
|
||||
if (Array.isArray(config.plugins)) {
|
||||
return sanitized.plugins.reduce((configWithPlugins, plugin) => plugin(configWithPlugins), sanitized);
|
||||
}
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export default joi.object({
|
||||
.keys({
|
||||
json: joi.object(),
|
||||
compression: joi.object(),
|
||||
middleware: joi.array().items(joi.object()),
|
||||
middleware: joi.array().items(joi.func()),
|
||||
}),
|
||||
local: joi.boolean(),
|
||||
upload: joi.object()
|
||||
@@ -116,4 +116,7 @@ export default joi.object({
|
||||
hooks: joi.object().keys({
|
||||
afterError: joi.func(),
|
||||
}),
|
||||
plugins: joi.array().items(
|
||||
joi.func(),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -9,7 +9,6 @@ import { Payload } from '..';
|
||||
import { AfterErrorHook, PayloadCollectionConfig, CollectionConfig } from '../collections/config/types';
|
||||
import { PayloadGlobalConfig, GlobalConfig } from '../globals/config/types';
|
||||
import { PayloadRequest } from '../express/types';
|
||||
import InitializeGraphQL from '../graphql';
|
||||
import { Where } from '../types';
|
||||
|
||||
type Email = {
|
||||
@@ -17,6 +16,9 @@ type Email = {
|
||||
fromAddress: string;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
type Plugin = (config: Config) => Config;
|
||||
|
||||
export type EmailTransport = Email & {
|
||||
transport: Transporter;
|
||||
transportOptions?: SMTPConnection.Options;
|
||||
@@ -99,7 +101,7 @@ export type PayloadConfig = {
|
||||
};
|
||||
debug?: boolean
|
||||
express?: {
|
||||
json: {
|
||||
json?: {
|
||||
limit?: number
|
||||
},
|
||||
compression?: {
|
||||
@@ -126,8 +128,8 @@ export type PayloadConfig = {
|
||||
fallback?: boolean
|
||||
};
|
||||
graphQL?: {
|
||||
mutations?: ((graphQL: typeof GraphQL, payload: InitializeGraphQL) => any),
|
||||
queries?: ((graphQL: typeof GraphQL, payload: InitializeGraphQL) => any),
|
||||
mutations?: ((graphQL: typeof GraphQL, payload: Payload) => Record<string, unknown>),
|
||||
queries?: ((graphQL: typeof GraphQL, payload: Payload) => Record<string, unknown>),
|
||||
maxComplexity?: number;
|
||||
disablePlaygroundInProduction?: boolean;
|
||||
disable?: boolean;
|
||||
@@ -136,9 +138,10 @@ export type PayloadConfig = {
|
||||
hooks?: {
|
||||
afterError?: AfterErrorHook;
|
||||
};
|
||||
plugins?: Plugin[]
|
||||
};
|
||||
|
||||
export type Config = Omit<DeepRequired<PayloadConfig>, 'collections'> & {
|
||||
export type Config = Omit<DeepRequired<PayloadConfig>, 'collections' | 'globals'> & {
|
||||
collections: CollectionConfig[]
|
||||
globals: GlobalConfig[]
|
||||
paths: { [key: string]: string };
|
||||
|
||||
@@ -62,7 +62,9 @@ export type PayloadGlobalConfig = {
|
||||
}
|
||||
}
|
||||
|
||||
export type GlobalConfig = DeepRequired<PayloadGlobalConfig>
|
||||
export interface GlobalConfig extends Omit<DeepRequired<PayloadGlobalConfig>, 'fields'> {
|
||||
fields: Field[]
|
||||
}
|
||||
|
||||
export type Globals = {
|
||||
Model: GlobalModel
|
||||
|
||||
@@ -99,7 +99,7 @@ class InitializeGraphQL {
|
||||
};
|
||||
|
||||
if (typeof this.config.graphQL.queries === 'function') {
|
||||
const customQueries = this.config.graphQL.queries(GraphQL, this);
|
||||
const customQueries = this.config.graphQL.queries(GraphQL, init);
|
||||
this.Query = {
|
||||
...this.Query,
|
||||
fields: {
|
||||
@@ -110,7 +110,7 @@ class InitializeGraphQL {
|
||||
}
|
||||
|
||||
if (typeof this.config.graphQL.mutations === 'function') {
|
||||
const customMutations = this.config.graphQL.mutations(GraphQL, this);
|
||||
const customMutations = this.config.graphQL.mutations(GraphQL, init);
|
||||
this.Mutation = {
|
||||
...this.Mutation,
|
||||
fields: {
|
||||
|
||||
Reference in New Issue
Block a user