UNPKG

5.95 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2import 'rxjs/add/observable/fromEvent';
3/**
4 * @private
5 */
6export interface PluginConfig {
7 /**
8 * Plugin name, this should match the class name
9 */
10 pluginName: string;
11 /**
12 * Plugin NPM package name
13 */
14 plugin: string;
15 /**
16 * Plugin object reference
17 */
18 pluginRef: string;
19 /**
20 * Github repository URL
21 */
22 repo: string;
23 /**
24 * Custom install command
25 */
26 install?: string;
27 /**
28 * Supported platforms
29 */
30 platforms?: string[];
31}
32/**
33 * @private
34 */
35export interface CordovaOptions {
36 /**
37 * Set to true if the wrapped method is a sync function
38 */
39 sync?: boolean;
40 /**
41 * Callback order. Set to reverse if the success/error callbacks are the first 2 arguments that the wrapped method takes.
42 */
43 callbackOrder?: 'reverse';
44 /**
45 * Callback style
46 */
47 callbackStyle?: 'node' | 'object';
48 /**
49 * Set a custom index for the success callback function. This doesn't work if callbackOrder or callbackStyle are set.
50 */
51 successIndex?: number;
52 /**
53 * Set a custom index for the error callback function. This doesn't work if callbackOrder or callbackStyle are set.
54 */
55 errorIndex?: number;
56 /**
57 * Success function property name. This must be set if callbackStyle is set to object.
58 */
59 successName?: string;
60 /**
61 * Error function property name. This must be set if callbackStyle is set to object.
62 */
63 errorName?: string;
64 /**
65 * Set to true to return an observable
66 */
67 observable?: boolean;
68 /**
69 * If observable is set to true, this can be set to a different function name that will cancel the observable.
70 */
71 clearFunction?: string;
72 /**
73 * This can be used if clearFunction is set. Set this to true to call the clearFunction with the same arguments used in the initial function.
74 */
75 clearWithArgs?: boolean;
76 /**
77 * Creates an observable that wraps a global event. Replaces document.addEventListener
78 */
79 eventObservable?: boolean;
80 /**
81 * Event name, this must be set if eventObservable is set to true
82 */
83 event?: string;
84 /**
85 * Element to attach the event listener to, this is optional, defaults to `window`
86 */
87 element?: any;
88 /**
89 * Set to true if the wrapped method returns a promise
90 */
91 otherPromise?: boolean;
92 /**
93 * Supported platforms
94 */
95 platforms?: string[];
96}
97/**
98 * @private
99 * @param pluginRef
100 * @returns {null|*}
101 */
102export declare const getPlugin: (pluginRef: string) => any;
103/**
104 * @private
105 * @param pluginObj
106 * @param method
107 */
108export declare const pluginWarn: (pluginObj: any, method?: string) => void;
109/**
110 * @private
111 * @param pluginName
112 * @param method
113 */
114export declare const cordovaWarn: (pluginName: string, method: string) => void;
115/**
116 * @private
117 */
118export declare function getPromise(cb: any): any;
119/**
120 * @private
121 * @param pluginObj
122 * @param methodName
123 * @param opts
124 * @returns {function(...[any]): (undefined|*|Observable|*|*)}
125 */
126export declare const wrap: (pluginObj: any, methodName: string, opts?: CordovaOptions) => (...args: any[]) => any;
127/**
128 * @private
129 *
130 * Class decorator specifying Plugin metadata. Required for all plugins.
131 *
132 * @usage
133 * ```typescript
134 * @Plugin({
135 * pluginName: 'MyPlugin',
136 * plugin: 'cordova-plugin-myplugin',
137 * pluginRef: 'window.myplugin'
138 * })
139 * export class MyPlugin {
140 *
141 * // Plugin wrappers, properties, and functions go here ...
142 *
143 * }
144 * ```
145 */
146export declare function Plugin(config: PluginConfig): (cls: any) => any;
147/**
148 * @private
149 *
150 * Wrap a stub function in a call to a Cordova plugin, checking if both Cordova
151 * and the required plugin are installed.
152 */
153export declare function Cordova(opts?: CordovaOptions): (target: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => {
154 value: (...args: any[]) => any;
155};
156/**
157 * @private
158 *
159 * Wrap an instance method
160 */
161export declare function CordovaInstance(opts?: any): (target: Object, methodName: string) => {
162 value: (...args: any[]) => any;
163};
164/**
165 * @private
166 *
167 *
168 * Before calling the original method, ensure Cordova and the plugin are installed.
169 */
170export declare function CordovaProperty(target: any, key: string): void;
171/**
172 * @private
173 * @param target
174 * @param key
175 * @constructor
176 */
177export declare function InstanceProperty(target: any, key: string): void;
178/**
179 * @private
180 *
181 * Wrap a stub function in a call to a Cordova plugin, checking if both Cordova
182 * and the required plugin are installed.
183 */
184export declare function CordovaFunctionOverride(opts?: any): (target: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => {
185 value: (...args: any[]) => Observable<any>;
186};
187/**
188 * @private
189 */
190export interface CordovaFiniteObservableOptions extends CordovaOptions {
191 /**
192 * Function that gets a result returned from plugin's success callback, and decides whether it is last value and observable should complete.
193 */
194 resultFinalPredicate?: (result: any) => boolean;
195 /**
196 * Function that gets called after resultFinalPredicate, and removes service data that indicates end of stream from the result.
197 */
198 resultTransform?: (result: any) => any;
199}
200/**
201 * @private
202 *
203 * Wraps method that returns an observable that can be completed. Provided opts.resultFinalPredicate dictates when the observable completes.
204 *
205 */
206export declare function CordovaFiniteObservable(opts?: CordovaFiniteObservableOptions): (target: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => {
207 value: (...args: any[]) => Observable<any>;
208};