Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Mar 16, 2018
1 parent ecd13de commit 1e5b3de
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 98 deletions.
96 changes: 2 additions & 94 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,2 @@
import _Vue = require('vue');

// augment typings of Vue.js
import './vue';

export interface HttpHeaders {
put?: { [key: string]: string };
post?: { [key: string]: string };
patch?: { [key: string]: string };
delete?: { [key: string]: string };
common?: { [key: string]: string };
custom?: { [key: string]: string };
[key: string]: any;
}

export interface HttpResponse {
data: any;
ok: boolean;
status: number;
statusText: string;
headers: Function;
text():string;
json():any;
blob():Blob;
}

export interface HttpOptions {
url?: string;
method?: string;
body?: any;
params?: any;
headers?: any;
before?(request: any): any;
progress?(event: any): any;
credentials?:boolean;
emulateHTTP?: boolean;
emulateJSON?: boolean;
}

export interface $http {
(url: string, data?: any, options?: HttpOptions): PromiseLike<HttpResponse>;
(url: string, options?: HttpOptions): PromiseLike<HttpResponse>;
}

export interface HttpInterceptor {
request?(request: HttpOptions): HttpOptions;
response?(response: HttpResponse): HttpResponse;
}

export interface Http {
options: HttpOptions & { root: string };
headers: HttpHeaders;
interceptors: (HttpInterceptor | (() => HttpInterceptor))[];
get: $http;
post: $http;
put: $http;
patch: $http;
delete: $http;
jsonp: $http;
}

export interface ResourceActions {
get: { method: string };
save: { method: string };
query: { method: string };
update: { method: string };
remove: { method: string };
delete: { method: string };
}

export interface ResourceMethod {
(params: any, data?: any, success?: Function, error?: Function): PromiseLike<HttpResponse>;
(params: any, success?: Function, error?: Function): PromiseLike<HttpResponse>;
(success?: Function, error?: Function): PromiseLike<HttpResponse>;
}

export interface ResourceMethods {
get: ResourceMethod;
save: ResourceMethod;
query: ResourceMethod;
update: ResourceMethod;
remove: ResourceMethod;
delete: ResourceMethod;
}

export interface $resource {
(url: string, params?: any, actions?: any, options?: HttpOptions): ResourceMethods;
}

export interface Resource extends $resource {
actions: ResourceActions;
}

export declare function install(vue: typeof _Vue): void;
import * as VueResource from './vue_resource';
export default VueResource
8 changes: 4 additions & 4 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*/

import Vue from "vue";
import { HttpHeaders, HttpOptions, HttpResponse, $http, $resource } from "./index";
import { HttpHeaders, HttpOptions, HttpResponse, $http, $resource } from "./vue_resource";

declare module "vue/types/options" {
interface ComponentOptions<V extends Vue> {
http?: (HttpOptions & { headers?: HttpHeaders } & { [key: string]: any })
}
interface ComponentOptions<V extends Vue> {
http?: (HttpOptions & { headers?: HttpHeaders } & { [key: string]: any })
}
}

declare module "vue/types/vue" {
Expand Down
94 changes: 94 additions & 0 deletions types/vue_resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import _Vue from 'vue';

// augment typings of Vue.js
import './vue';

export interface HttpHeaders {
put?: { [key: string]: string };
post?: { [key: string]: string };
patch?: { [key: string]: string };
delete?: { [key: string]: string };
common?: { [key: string]: string };
custom?: { [key: string]: string };
[key: string]: any;
}

export interface HttpResponse {
data: any;
ok: boolean;
status: number;
statusText: string;
headers: Function;
text(): string;
json(): any;
blob(): Blob;
}

export interface HttpOptions {
url?: string;
method?: string;
body?: any;
params?: any;
headers?: any;
before?(request: any): any;
progress?(event: any): any;
credentials?: boolean;
emulateHTTP?: boolean;
emulateJSON?: boolean;
}

export interface $http {
(url: string, data?: any, options?: HttpOptions): PromiseLike<HttpResponse>;
(url: string, options?: HttpOptions): PromiseLike<HttpResponse>;
}

export interface HttpInterceptor {
request?(request: HttpOptions): HttpOptions;
response?(response: HttpResponse): HttpResponse;
}

export interface Http {
options: HttpOptions & { root: string };
headers: HttpHeaders;
interceptors: (HttpInterceptor | (() => HttpInterceptor))[];
get: $http;
post: $http;
put: $http;
patch: $http;
delete: $http;
jsonp: $http;
}

export interface ResourceActions {
get: { method: string };
save: { method: string };
query: { method: string };
update: { method: string };
remove: { method: string };
delete: { method: string };
}

export interface ResourceMethod {
(params: any, data?: any, success?: Function, error?: Function): PromiseLike<HttpResponse>;
(params: any, success?: Function, error?: Function): PromiseLike<HttpResponse>;
(success?: Function, error?: Function): PromiseLike<HttpResponse>;
}

export interface ResourceMethods {
get: ResourceMethod;
save: ResourceMethod;
query: ResourceMethod;
update: ResourceMethod;
remove: ResourceMethod;
delete: ResourceMethod;
}

export interface $resource {
(url: string, params?: any, actions?: any, options?: HttpOptions): ResourceMethods;
}

export interface Resource extends $resource {
actions: ResourceActions;
}

export declare function install(vue: typeof _Vue): void;

0 comments on commit 1e5b3de

Please sign in to comment.