0.14.7 • Published 6 months ago

@types/json-server v0.14.7

Weekly downloads
13,288
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/json-server

Summary

This package contains type definitions for json-server (https://github.com/typicode/json-server).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/json-server.

index.d.ts

// Type definitions for json-server 0.14
// Project: https://github.com/typicode/json-server
// Definitions by: Jeremy Bensimon <https://github.com/jeremyben>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

import { NextHandleFunction } from 'connect';
import { Application, RequestHandler, Router } from 'express';
import { LowdbSync } from 'lowdb';

export interface JsonServerRouter<T> extends Router {
    db: LowdbSync<T>;
}

/**
 * Returns an Express server.
 */
export function create(): Application;

/**
 * Returns middlewares used by JSON Server.
 */
export function defaults(options?: MiddlewaresOptions): RequestHandler[];

/**
 * Returns JSON Server router.
 * @param source Either a path to a json file (e.g. `'db.json'`) or an object in memory.
 * This object will then be wrapped by lowdb, but you can also just pass in your own lowdb
 * instance that will then not be wrapped.
 * @param options Set foreign key suffix (default: `'Id'`)
 */
export function router<T extends object>(source: LowdbSync<T> | T | string, options?: { foreignKeySuffix: string }): JsonServerRouter<T>;

/**
 * Add custom rewrite rules.
 */
export function rewriter(rules: { [rule: string]: string }): Router;

/**
 * Returns body-parser middleware used by JSON Server router.
 *
 * @returns
 * ```
 * [bodyParser.json({ limit: '10mb', extended: false }), bodyParser.urlencoded({ extended: false })]
 * ```
 */
export const bodyParser: [NextHandleFunction, NextHandleFunction];

export interface MiddlewaresOptions {
    /**
     * Path to static files
     * @default "public" (if folder exists)
     */
    static?: string | undefined;

    /**
     * Enable logger middleware
     * @default true
     */
    logger?: boolean | undefined;

    /**
     * Enable body-parser middleware
     * @default true
     */
    bodyParser?: boolean | undefined;

    /**
     * Disable compression
     * @default false
     */
    noGzip?: boolean | undefined;

    /**
     * Disable CORS
     * @default false
     */
    noCors?: boolean | undefined;

    /**
     * Accept only GET requests
     * @default false
     */
    readOnly?: boolean | undefined;
}

Additional Details

Credits

These definitions were written by Jeremy Bensimon.

0.14.5

8 months ago

0.14.6

7 months ago

0.14.7

6 months ago

0.14.4

3 years ago

0.14.3

3 years ago

0.14.2

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago