Remove typings for universal-router

This commit is contained in:
Vladimir Kutepov
2019-01-15 22:27:08 +03:00
parent 945fd1a382
commit 793f824461
7 changed files with 6 additions and 245 deletions
+6
View File
@@ -1656,6 +1656,12 @@
"sourceRepoURL": "https://github.com/dpa99c/phonegap-launch-navigator",
"asOfVersion": "4.0.0"
},
{
"libraryName": "Universal Router",
"typingsPackageName": "universal-router",
"sourceRepoURL": "https://github.com/kriasoft/universal-router",
"asOfVersion": "8.0.0"
},
{
"libraryName": "upper-case",
"typingsPackageName": "upper-case",
-14
View File
@@ -1,14 +0,0 @@
import UniversalRouter, { Params } from ".";
import { PathFunctionOptions } from 'path-to-regexp';
export interface GenerateUrlsOptions extends PathFunctionOptions {
/**
* Provide a function to stringifyQueryParams option to generate URL with query string from unknown route params.
*/
stringifyQueryParams?: (params: Params) => string;
}
/**
* In most web applications it's much simpler to just use a string for hyperlinks.
*/
export default function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): (routeName: string, params?: Params) => string;
-122
View File
@@ -1,122 +0,0 @@
// Type definitions for universal-router 7.0
// Project: https://github.com/kriasoft/universal-router
// Definitions by: Jack Moore <https://github.com/jtmthf>
// Tomek Łaziuk <https://github.com/tlaziuk>
// Lodin <https://github.com/Lodin>
// acidghost <https://github.com/acidghost>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import pathToRegexp = require('path-to-regexp');
/**
* Params is a key/value object that represents extracted URL parameters.
* Each URL parameter resolves to a string.
*/
export interface Params {
[_: string]: any;
}
/**
* In addition to a URL path string, any arbitrary data can be passed to the `router.resolve()` method, that becomes available inside action functions.
*/
export interface Context {
[_: string]: any;
}
export interface PathnameContext extends Context {
/**
* URL which was transmitted to `router.resolve()`.
*/
pathname: string;
}
export interface ActionContext<C extends Context, R = any> extends PathnameContext {
/**
* Current router instance.
*/
router: UniversalRouter<C, R>;
/**
* Matched route object.
*/
route: Route;
/**
* Middleware style function which can continue resolving.
*/
next: (resume?: boolean, parent?: Route, prevResult?: any) => Promise<R>;
/**
* Base URL path relative to the path of the current route.
*/
baseUrl: string;
/**
* Matched path.
*/
path: string;
/**
* Matched path params.
*/
params: Params;
/**
* An array of keys found in the path, see `path-to-regexp` documentation for details.
* @see https://github.com/pillarjs/path-to-regexp
*/
keys: pathToRegexp.Key[];
}
/**
* A Route is a singular route in your application. It contains a path, an
* action function, and optional children which are an array of Route.
*
* @template C User context that is made union with ActionContext.
* @template R Result that every action function resolves to. If the action returns a Promise, R can be the type the Promise resolves to.
*/
export interface Route<C extends Context = any, R = any> {
path?: string | RegExp | Array<string | RegExp>;
/**
* unique string
*/
name?: string;
/**
* automatically filled by the router
*/
parent?: Route | null;
/**
* array of route objects
*/
children?: Routes<C, R> | null;
/**
* action method should return anything except `null` or `undefined` to be resolved by router
* otherwise router will throw `Page not found` error if all matched routes returned nothing
*/
action?: (context: ActionContext<C, R> & C, params: Params) => R | Promise<R> | void;
}
/**
* Routes in an array of type Route.
* @template C User context that is made union with ActionContext.
* @template R Result that every action function resolves to. If the action returns a Promise, R can be the type the Promise resolves to.
*/
export type Routes<C extends Context = Context, R = any> = Array<Route<C, R>>;
export interface Options<C extends Context = Context, R = any> {
context?: C;
baseUrl?: string;
resolveRoute?: (context: ActionContext<C, R> & C, params: Params) => any;
errorHandler?: (error: Error & { status: number }, context: C) => any;
}
/**
* @see https://github.com/kriasoft/universal-router/blob/v6.0.0/docs/api.md
*/
export default class UniversalRouter<C extends Context = Context, R = any> {
constructor(routes: Routes<C, R> | Route<C, R>, options?: Options<C>)
/**
* Traverses the list of routes in the order they are defined until it finds the first route that matches provided URL path string
* and whose action function returns anything other than null or undefined.
*/
resolve(pathnameOrContext: string | PathnameContext): Promise<R>;
/**
* `path-to-regexp` function
*/
static pathToRegexp: typeof pathToRegexp;
}
-6
View File
@@ -1,6 +0,0 @@
{
"private": true,
"dependencies": {
"path-to-regexp": "^2.2.0"
}
}
-26
View File
@@ -1,26 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"generateUrls.d.ts",
"universal-router-tests.ts"
]
}
-3
View File
@@ -1,3 +0,0 @@
{
"extends": "dtslint/dt.json"
}
@@ -1,74 +0,0 @@
import UniversalRouter from "universal-router";
import generateUrls from "universal-router/generateUrls";
new UniversalRouter(
{
path: '',
name: 'root',
action: (context) => context.path,
},
{
context: {
user: 'name',
},
baseUrl: '/base',
errorHandler: (error, context) => {
console.error(error);
console.dir(context);
return error.status === 404
? '<h1>Page Not Found</h1>'
: '<h1>Oops! Something went wrong</h1>';
},
},
).resolve('/').then(console.log);
new UniversalRouter({
path: '/admin',
children: [
{
path: '',
action: () => 'Admin Page',
},
{
path: '/users',
children: [
{
path: '',
action: () => 'User List',
},
{
path: '/:username',
action: () => 'User Profile',
},
],
},
],
}).resolve({ pathname: '/admin/users/john' })
.then(result => console.log(result));
new UniversalRouter({
path: '', // optional
async action({ next }) {
console.log('middleware: start');
const child = await next();
console.log('middleware: end');
return child;
},
children: [
{
path: '/hello',
action() {
console.log('route: return a result');
return 'Hello, world!';
},
},
],
});
const url = generateUrls(new UniversalRouter([
{ name: 'users', path: '/users' },
{ name: 'user', path: '/user/:username' },
], { baseUrl: '/base' }));
url('users'); // => '/base/users'
url('user', { username: 'john' }); // => '/base/user/john'