more typing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const findConfig = () => {
|
||||
const findConfig = (): string => {
|
||||
// If the developer has specified a config path,
|
||||
// format it if relative and use it directly if absolute
|
||||
if (process.env.PAYLOAD_CONFIG_PATH) {
|
||||
|
||||
@@ -60,7 +60,7 @@ export type Config = {
|
||||
cookiePrefix?: string;
|
||||
csrf?: string[];
|
||||
cors?: string[];
|
||||
publicENV: { [key: string]: string };
|
||||
publicENV?: { [key: string]: string };
|
||||
routes?: {
|
||||
api?: string;
|
||||
admin?: string;
|
||||
@@ -102,7 +102,7 @@ export type Config = {
|
||||
maxComplexity?: number;
|
||||
disablePlaygroundInProduction?: boolean;
|
||||
};
|
||||
components: { [key: string]: JSX.Element | (() => JSX.Element) };
|
||||
components?: { [key: string]: JSX.Element | (() => JSX.Element) };
|
||||
paths?: { [key: string]: string };
|
||||
hooks?: {
|
||||
afterError?: () => void;
|
||||
|
||||
@@ -9,11 +9,10 @@ export type Message = {
|
||||
html: string
|
||||
}
|
||||
|
||||
export type MockEmailHandler = { account: TestAccount; transport: Transporter };
|
||||
export type BuildEmailResult = Promise<{
|
||||
transport: Mail,
|
||||
transportOptions?: SMTPConnection.Options,
|
||||
fromName: string,
|
||||
fromAddress: string,
|
||||
}>
|
||||
|
||||
export type MockEmailHandler = { account: TestAccount; transport: Transporter };
|
||||
} | MockEmailHandler>
|
||||
|
||||
17
src/index.ts
17
src/index.ts
@@ -1,9 +1,10 @@
|
||||
import express, { Express, Router } from 'express';
|
||||
import express, { Express, Request, Router } from 'express';
|
||||
import crypto from 'crypto';
|
||||
|
||||
import { TestAccount } from 'nodemailer';
|
||||
import {
|
||||
Config,
|
||||
EmailOptions,
|
||||
InitOptions,
|
||||
} from './config/types';
|
||||
import {
|
||||
@@ -18,7 +19,7 @@ import {
|
||||
UpdateOptions,
|
||||
DeleteOptions,
|
||||
} from './types';
|
||||
import Logger from './utilities/logger';
|
||||
import Logger, { PayloadLogger } from './utilities/logger';
|
||||
import bindOperations from './init/bindOperations';
|
||||
import bindRequestHandlers from './init/bindRequestHandlers';
|
||||
import bindResolvers from './init/bindResolvers';
|
||||
@@ -44,18 +45,18 @@ import { MockEmailHandler, BuildEmailResult, Message } from './email/types';
|
||||
|
||||
require('isomorphic-fetch');
|
||||
|
||||
class Payload {
|
||||
export class Payload {
|
||||
config: Config;
|
||||
|
||||
collections: Collection[] = [];
|
||||
|
||||
logger: typeof Logger;
|
||||
logger: PayloadLogger;
|
||||
|
||||
express: Express
|
||||
|
||||
router: Router;
|
||||
|
||||
emailOptions: any;
|
||||
emailOptions: EmailOptions;
|
||||
|
||||
email: BuildEmailResult;
|
||||
|
||||
@@ -84,6 +85,7 @@ class Payload {
|
||||
initAdmin: typeof initAdmin;
|
||||
|
||||
performFieldOperations: typeof performFieldOperations;
|
||||
// requestHandlers: { collections: { create: any; find: any; findByID: any; update: any; delete: any; auth: { access: any; forgotPassword: any; init: any; login: any; logout: any; me: any; refresh: any; registerFirstUser: any; resetPassword: any; verifyEmail: any; unlock: any; }; }; globals: { ...; }; };
|
||||
|
||||
init(options: InitOptions) {
|
||||
this.logger = Logger();
|
||||
@@ -153,7 +155,7 @@ class Payload {
|
||||
}
|
||||
|
||||
// Configure email service
|
||||
this.email = buildEmail(this.emailOptions);
|
||||
this.email = buildEmail(this.config.email);
|
||||
|
||||
// Initialize collections & globals
|
||||
this.initCollections();
|
||||
@@ -162,7 +164,8 @@ class Payload {
|
||||
// Connect to database
|
||||
connectMongoose(this.mongoURL);
|
||||
|
||||
options.express.use((req, res, next) => {
|
||||
type PayloadReq = Request & { payload: Payload }; // TODO: move this out and add more
|
||||
options.express.use((req: PayloadReq, res, next) => {
|
||||
req.payload = this;
|
||||
next();
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ import deleteHandler from '../collections/requestHandlers/delete';
|
||||
import findOne from '../globals/requestHandlers/findOne';
|
||||
import globalUpdate from '../globals/requestHandlers/update';
|
||||
|
||||
function bindRequestHandlers(ctx) {
|
||||
function bindRequestHandlers(ctx): void {
|
||||
const payload = ctx;
|
||||
|
||||
payload.requestHandlers = {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import falsey from 'falsey';
|
||||
import pino from 'pino';
|
||||
import memoize from 'micro-memoize';
|
||||
import { PayloadLogger } from '../types';
|
||||
|
||||
export type PayloadLogger = pino.Logger;
|
||||
|
||||
export default memoize((name = 'payload') => pino({
|
||||
name,
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
"dist",
|
||||
"src/admin",
|
||||
"src/tests",
|
||||
"src/tests/*",
|
||||
"src/tests/**/*.spec.ts",
|
||||
// "**/*.d.ts",
|
||||
// "node_modules/"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user