mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
[@types/epilogue] Create type definition for Epilogue
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import * as epilogue from 'epilogue';
|
||||
import * as express from 'express';
|
||||
import * as Sequelize from 'sequelize';
|
||||
|
||||
const database = new Sequelize({ });
|
||||
|
||||
epilogue.initialize({
|
||||
app: express(),
|
||||
sequelize: database
|
||||
});
|
||||
|
||||
epilogue.initialize({
|
||||
app: express(),
|
||||
sequelize: database,
|
||||
base: ''
|
||||
});
|
||||
|
||||
epilogue.initialize({
|
||||
app: express(),
|
||||
sequelize: database,
|
||||
base: '',
|
||||
updateMethod: ''
|
||||
});
|
||||
|
||||
const User = database.define('User', {
|
||||
username: Sequelize.STRING,
|
||||
birthday: Sequelize.DATE
|
||||
});
|
||||
|
||||
epilogue.resource({
|
||||
model: User,
|
||||
endpoints: ['/users', '/users/:id']
|
||||
});
|
||||
Vendored
+191
@@ -0,0 +1,191 @@
|
||||
// Type definitions for epilogue 0.7
|
||||
// Project: https://github.com/dchester/epilogue
|
||||
// Definitions by: Satana Charuwichitratana <https://github.com/micksatana>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4.1
|
||||
|
||||
/// <reference types="sequelize"/>
|
||||
/// <reference types="express"/>
|
||||
|
||||
declare module 'epilogue' {
|
||||
import {
|
||||
Sequelize,
|
||||
AssociationOptions,
|
||||
DataTypeAbstract,
|
||||
DataTypeString,
|
||||
DataTypeChar,
|
||||
DataTypeText,
|
||||
DataTypeNumber,
|
||||
DataTypeInteger,
|
||||
DataTypeBigInt,
|
||||
DataTypeFloat,
|
||||
DataTypeTime,
|
||||
DataTypeDate,
|
||||
DataTypeDateOnly,
|
||||
DataTypeBoolean,
|
||||
DataTypeNow,
|
||||
DataTypeBlob,
|
||||
DataTypeDecimal,
|
||||
DataTypeUUID,
|
||||
DataTypeUUIDv1,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeHStore,
|
||||
DataTypeJSONType,
|
||||
DataTypeJSONB,
|
||||
DataTypeVirtual,
|
||||
DataTypeArray,
|
||||
DataTypeEnum,
|
||||
DataTypeRange,
|
||||
DataTypeReal,
|
||||
DataTypeDouble,
|
||||
DataTypeGeometry
|
||||
} from 'sequelize';
|
||||
import { Express, Request, Response } from 'express';
|
||||
|
||||
export class Endpoint {
|
||||
constructor(endpoint: string);
|
||||
string: string;
|
||||
attributes: string[];
|
||||
}
|
||||
|
||||
export class Resource {
|
||||
constructor(options: ResourceOptions);
|
||||
app: Express;
|
||||
sequelize: Sequelize;
|
||||
model: any;
|
||||
include: Array<{ model: any } | any | string>;
|
||||
associationOptions: ResourceAssociationOptions;
|
||||
readOnlyAttributes: string[];
|
||||
excludeAttributes: string[];
|
||||
attributes: string[];
|
||||
actions: string[];
|
||||
endpoints: {
|
||||
singular: string;
|
||||
plural: string;
|
||||
};
|
||||
updateMethod: string;
|
||||
pagination: boolean;
|
||||
search: ResourceSearchOption;
|
||||
sort: ResourceSortOption;
|
||||
reloadInstances: boolean;
|
||||
controllers: Controllers;
|
||||
}
|
||||
|
||||
export interface Controllers {
|
||||
base: BaseController;
|
||||
create: CreateController;
|
||||
read: ReadController;
|
||||
update: UpdateController;
|
||||
delete: DeleteController;
|
||||
list: ListController;
|
||||
}
|
||||
|
||||
export interface Errors {
|
||||
NotFoundError: EpilogueError;
|
||||
BadRequestError: EpilogueError;
|
||||
EpilogueError: EpilogueError;
|
||||
ForbiddenError: EpilogueError;
|
||||
RequestCompleted: EpilogueError;
|
||||
}
|
||||
|
||||
export interface ResourceAssociationOptions extends AssociationOptions {
|
||||
removeForeignKeys: boolean;
|
||||
}
|
||||
|
||||
export interface ResourceSearchOption {
|
||||
param: string;
|
||||
operator: string;
|
||||
attributes: string[];
|
||||
}
|
||||
|
||||
export interface ResourceSortOption {
|
||||
param: string;
|
||||
default: string;
|
||||
}
|
||||
|
||||
export interface InitializeOptions {
|
||||
app: Express;
|
||||
sequelize: Sequelize;
|
||||
base?: string;
|
||||
updateMethod?: string;
|
||||
}
|
||||
|
||||
export interface BaseContollerOptions {
|
||||
endpoint: string;
|
||||
model: any;
|
||||
app: Express;
|
||||
resource: Resource;
|
||||
include: Array<any | string>;
|
||||
}
|
||||
|
||||
export interface Context {
|
||||
instance: Resource;
|
||||
criteria: any;
|
||||
attributes: any;
|
||||
options: any;
|
||||
continue: () => void;
|
||||
skip: () => void;
|
||||
stop: () => void;
|
||||
error: (status: number | EpilogueError, message?: string, errorList?: string[], cause?: Error) => void;
|
||||
}
|
||||
|
||||
export class BaseController {
|
||||
constructor(options: BaseContollerOptions);
|
||||
endpoint: Endpoint;
|
||||
model: any;
|
||||
}
|
||||
|
||||
export class CreateController extends BaseController {
|
||||
write: (req: Request, res: Response, context: Context) => Promise<() => void>;
|
||||
}
|
||||
|
||||
export class ReadController extends BaseController {
|
||||
fetch: (req: Request, res: Response, context: Context) => Promise<() => void>;
|
||||
}
|
||||
|
||||
export class UpdateController extends BaseController {
|
||||
fetch: (req: Request, res: Response, context: Context) => Promise<() => void>;
|
||||
write: (req: Request, res: Response, context: Context) => Promise<() => void>;
|
||||
}
|
||||
|
||||
export class DeleteController extends BaseController {
|
||||
fetch: (req: Request, res: Response, context: Context) => Promise<() => void>;
|
||||
write: (req: Request, res: Response, context: Context) => Promise<() => void>;
|
||||
}
|
||||
|
||||
export class ListController extends BaseController {
|
||||
fetch: (req: Request, res: Response, context: Context) => Promise<() => void>;
|
||||
_safeishParse: (value: any, type: DataTypeAbstract | DataTypeString | DataTypeChar | DataTypeText | DataTypeNumber |
|
||||
DataTypeInteger | DataTypeBigInt | DataTypeFloat | DataTypeTime | DataTypeDate | DataTypeDateOnly |
|
||||
DataTypeBoolean | DataTypeNow | DataTypeBlob | DataTypeDecimal | DataTypeUUID | DataTypeUUIDv1 |
|
||||
DataTypeUUIDv4 | DataTypeHStore | DataTypeJSONType | DataTypeJSONB | DataTypeVirtual |
|
||||
DataTypeArray | DataTypeEnum | DataTypeRange | DataTypeReal | DataTypeDouble | DataTypeGeometry,
|
||||
sequelize: Sequelize) => any;
|
||||
}
|
||||
|
||||
export interface ResourceOptions {
|
||||
model: any;
|
||||
endpoints: string[];
|
||||
actions?: string[];
|
||||
include?: Array<any | string>;
|
||||
pagination?: boolean;
|
||||
search?: ResourceSearchOption;
|
||||
sort?: ResourceSortOption;
|
||||
reloadInstances?: boolean;
|
||||
associations?: AssociationOptions;
|
||||
excludeAttributes?: string[];
|
||||
readOnlyAttributes?: string[];
|
||||
updateMethod?: string;
|
||||
}
|
||||
|
||||
export class EpilogueError extends Error {
|
||||
name: string;
|
||||
message: string;
|
||||
errors: string[];
|
||||
status: EpilogueError | number;
|
||||
cause: Error;
|
||||
}
|
||||
|
||||
function initialize(options: InitializeOptions): undefined;
|
||||
function resource(options: ResourceOptions): Resource;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"epilogue-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {}
|
||||
}
|
||||
Reference in New Issue
Block a user