UNPKG

16.3 kBTypeScriptView Raw
1// Capitalization is intentional: this makes it much easier to re-export RSVP on
2// the Ember namespace.
3import Rsvp from "rsvp";
4
5import { Registry as ControllerRegistry } from "@ember/controller";
6import * as EmberStringNs from "@ember/string";
7import * as EmberTemplateNs from "@ember/template";
8import * as EmberTemplateHandlebarsNs from "@ember/template/-private/handlebars";
9// eslint-disable-next-line no-duplicate-imports
10import * as EmberObjectNs from "@ember/object";
11import * as EmberObjectComputedNs from "@ember/object/computed";
12import * as EmberObjectEventedNs from "@ember/object/evented";
13import * as EmberObjectEventsNs from "@ember/object/events";
14import * as EmberObjectInternalsNs from "@ember/object/internals";
15import * as EmberObjectObserversNs from "@ember/object/observers";
16import * as EmberObjectPromiseProxyNs from "@ember/object/promise-proxy-mixin";
17import * as EmberObjectProxyNs from "@ember/object/proxy";
18import * as EmberPolyfillsNs from "@ember/polyfills";
19import * as EmberRunloopNs from "@ember/runloop";
20import * as EmberServiceNs from "@ember/service";
21import * as EmberUtilsNs from "@ember/utils";
22// @ember/debug
23import * as EmberDebugNs from "@ember/debug";
24import _ContainerDebugAdapter from "@ember/debug/container-debug-adapter";
25import EmberDataAdapter from "@ember/debug/data-adapter";
26// @ember/engine
27import * as EmberApplicationNs from "@ember/application";
28import * as EmberApplicationInstanceNs from "@ember/application/instance";
29import * as EmberEngineNs from "@ember/engine";
30import _ContainerProxyMixin from "@ember/engine/-private/container-proxy-mixin";
31import _RegistryProxyMixin from "@ember/engine/-private/registry-proxy-mixin";
32import * as EmberEngineInstanceNs from "@ember/engine/instance";
33import EmberCoreObject from "@ember/object/core";
34import * as EmberTestNs from "@ember/test";
35// eslint-disable-next-line no-duplicate-imports
36import * as EmberControllerNs from "@ember/controller";
37// eslint-disable-next-line no-duplicate-imports
38import EmberMixin from "@ember/object/mixin";
39import EmberObservable from "@ember/object/observable";
40// @ember/array
41import * as EmberArrayNs from "@ember/array";
42import EmberEnumerable from "@ember/array/-private/enumerable";
43import EmberMutableEnumerable from "@ember/array/-private/mutable-enumerable";
44import EmberNativeArray from "@ember/array/-private/native-array";
45import EmberMutableArray from "@ember/array/mutable";
46import EmberArrayProxy from "@ember/array/proxy";
47import EmberArrayProtoExtensions from "@ember/array/types/prototype-extensions";
48// @ember/error
49import EmberError from "@ember/error";
50
51type EmberArray<T> = EmberArrayNs.default<T>;
52import EmberComponent from "@ember/component";
53import EmberHelper from "@ember/component/helper";
54import EmberActionHandler from "@ember/object/-private/action-handler";
55// @ember/routing
56import EmberRoutingHashLocation from "@ember/routing/hash-location";
57import EmberRoutingHistoryLocation from "@ember/routing/history-location";
58import EmberRoutingNoneLocation from "@ember/routing/none-location";
59import EmberRoutingRoute from "@ember/routing/route";
60import EmberRoutingRouter from "@ember/routing/router";
61// @ember/application
62import EmberEventDispatcher from "@ember/application/-private/event-dispatcher";
63import EmberRegistry from "@ember/application/-private/registry";
64// @ember/test
65import EmberTestAdapter from "@ember/test/adapter";
66
67export namespace Ember {
68 const A: typeof EmberArrayNs.A;
69 const isArray: typeof EmberArrayNs.isArray;
70 type Enumerable<T> = EmberEnumerable<T>;
71 const Enumerable: typeof EmberEnumerable;
72 class ArrayProxy<T> extends EmberArrayProxy<T> {}
73 type Array<T> = EmberArray<T>;
74 const Array: typeof EmberArrayNs.default;
75 type MutableArray<T> = EmberMutableArray<T>;
76 const MutableArray: typeof EmberMutableArray;
77 type NativeArray<T> = EmberNativeArray<T>;
78 const NativeArray: typeof EmberNativeArray;
79 type MutableEnumerable<T> = EmberMutableEnumerable<T>;
80 const MutableEnumerable: typeof EmberMutableEnumerable;
81 class Router extends EmberRoutingRouter {}
82 class Route extends EmberRoutingRoute {}
83 const ActionHandler: typeof EmberActionHandler;
84 class Controller extends EmberControllerNs.default {}
85 class Component extends EmberComponent {}
86 class Helper extends EmberHelper {}
87
88 class HashLocation extends EmberRoutingHashLocation {}
89 class NoneLocation extends EmberRoutingNoneLocation {}
90 class HistoryLocation extends EmberRoutingHistoryLocation {}
91 const deprecate: typeof EmberDebugNs.deprecate;
92 const getOwner: typeof EmberApplicationNs.getOwner;
93 const setOwner: typeof EmberApplicationNs.setOwner;
94 class EventDispatcher extends EmberEventDispatcher {}
95 class Registry extends EmberRegistry {}
96 interface ArrayPrototypeExtensions<T> extends EmberArrayProtoExtensions<T> {}
97
98 /**
99 * Implements some standard methods for comparing objects. Add this mixin to
100 * any class you create that can compare its instances.
101 */
102 interface Comparable {
103 compare(a: unknown, b: unknown): number;
104 }
105 const Comparable: EmberMixin<Comparable>;
106 class ComputedProperty<Get, Set = Get> extends EmberObjectComputedNs.default<Get, Set> {}
107 /**
108 * A container used to instantiate and cache objects.
109 */
110 class Container {
111 /**
112 * Given a fullName, return the corresponding factory. The consumer of the factory
113 * is responsible for the destruction of any factory instances, as there is no
114 * way for the container to ensure instances are destroyed when it itself is
115 * destroyed.
116 */
117 factoryFor(fullName: string, options?: {}): unknown;
118 }
119 class ContainerDebugAdapter extends _ContainerDebugAdapter {}
120
121 // TODO: replace with a proper ES6 reexport once we remove declare module 'ember' {}
122 class Object extends EmberObjectNs.default {}
123 class ObjectProxy extends EmberObjectProxyNs.default {}
124 const Observable: typeof EmberObservable;
125 const PromiseProxyMixin: typeof EmberObjectPromiseProxyNs.default;
126 class CoreObject extends EmberCoreObject {}
127 class DataAdapter extends EmberDataAdapter {}
128 const Debug: {
129 registerDeprecationHandler: typeof EmberDebugNs.registerDeprecationHandler;
130 registerWarnHandler: typeof EmberDebugNs.registerWarnHandler;
131 };
132 class EngineInstance extends EmberEngineInstanceNs.default {}
133 class Engine extends EmberEngineNs.default {}
134
135 /**
136 * A subclass of the JavaScript Error object for use in Ember.
137 */
138 const Error: typeof EmberError;
139
140 const Evented: typeof EmberObjectEventedNs.default;
141
142 class Mixin<T, Base = EmberObjectNs.default> extends EmberMixin<T, Base> {}
143
144 /**
145 * A Namespace is an object usually used to contain other objects or methods
146 * such as an application or framework. Create a namespace anytime you want
147 * to define one of these new containers.
148 */
149 class Namespace extends Object {}
150
151 class Service extends Object {}
152
153 interface ViewTargetActionSupport {
154 target: unknown;
155 actionContext: unknown;
156 }
157 const ViewTargetActionSupport: Mixin<ViewTargetActionSupport>;
158 const ViewUtils: {
159 isSimpleClick(event: Event): boolean;
160 };
161
162 // FYI - RSVP source comes from https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp/promise.js
163 const RSVP: typeof Rsvp;
164 namespace RSVP {
165 type Promise<T> = Rsvp.Promise<T>;
166 }
167 class Application extends EmberApplicationNs.default {}
168 class ApplicationInstance extends EmberApplicationInstanceNs.default {}
169 /**
170 * This is a container for an assortment of testing related functionality
171 */
172 namespace Test {
173 class Adapter extends EmberTestAdapter {}
174 const registerHelper: typeof EmberTestNs.registerHelper;
175 const unregisterHelper: typeof EmberTestNs.unregisterHelper;
176 const registerWaiter: typeof EmberTestNs.registerWaiter;
177 const unregisterWaiter: typeof EmberTestNs.unregisterWaiter;
178 const registerAsyncHelper: typeof EmberTestNs.registerAsyncHelper;
179 /**
180 * Used to register callbacks to be fired whenever `App.injectTestHelpers`
181 * is called.
182 */
183 function onInjectHelpers(callback: (app: Application) => void): void;
184 /**
185 * This returns a thenable tailored for testing. It catches failed
186 * `onSuccess` callbacks and invokes the `Ember.Test.adapter.exception`
187 * callback in the last chained then.
188 */
189 function promise<T>(
190 resolver: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void,
191 label?: string,
192 ): Promise<T>;
193 /**
194 * Replacement for `Ember.RSVP.resolve`
195 * The only difference is this uses
196 * an instance of `Ember.Test.Promise`
197 */
198 function resolve<T>(value?: T | PromiseLike<T>, label?: string): Promise<T>;
199
200 /**
201 * Iterates through each registered test waiter, and invokes
202 * its callback. If any waiter returns false, this method will return
203 * true indicating that the waiters have not settled yet.
204 */
205 function checkWaiters(): boolean;
206 /**
207 * Used to allow ember-testing to communicate with a specific testing
208 * framework.
209 */
210 const adapter: EmberTestAdapter;
211
212 /**
213 * This class implements the methods defined by Ember.Test.Adapter for the
214 * QUnit testing framework.
215 */
216 class QUnitAdapter extends EmberTestAdapter {}
217 class Promise<T> extends Rsvp.Promise<T> {
218 constructor(
219 executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void,
220 );
221 }
222 }
223 /**
224 * Namespace for injection helper methods.
225 */
226 namespace inject {
227 /**
228 * Creates a property that lazily looks up another controller in the container.
229 * Can only be used when defining another controller.
230 */
231 function controller(): ComputedProperty<Controller>;
232 function controller<K extends keyof ControllerRegistry>(name: K): ComputedProperty<ControllerRegistry[K]>;
233 const service: typeof EmberServiceNs.inject;
234 }
235 namespace ENV {
236 const EXTEND_PROTOTYPES: {
237 Array: boolean;
238 Function: boolean;
239 String: boolean;
240 };
241 const LOG_BINDINGS: boolean;
242 const LOG_STACKTRACE_ON_DEPRECATION: boolean;
243 const LOG_VERSION: boolean;
244 const MODEL_FACTORY_INJECTIONS: boolean;
245 const RAISE_ON_DEPRECATION: boolean;
246 }
247 namespace Handlebars {
248 function compile(string: string): (...args: any[]) => any;
249 function compile(environment: any, options?: any, context?: any, asObject?: any): any;
250 function precompile(string: string, options: any): void;
251 class Compiler {}
252 class JavaScriptCompiler {}
253 function registerPartial(name: string, str: any): void;
254 function createFrame(objec: any): any;
255 function Exception(message: string): void;
256 class SafeString extends EmberTemplateHandlebarsNs.SafeString {}
257 function parse(string: string): any;
258 function print(ast: any): void;
259 function log(level: string, str: string): void;
260 function registerHelper(name: string, helper: any): void;
261 }
262 namespace String {
263 const camelize: typeof EmberStringNs.camelize;
264 const capitalize: typeof EmberStringNs.capitalize;
265 const classify: typeof EmberStringNs.classify;
266 const dasherize: typeof EmberStringNs.dasherize;
267 const decamelize: typeof EmberStringNs.decamelize;
268 function fmt(...args: string[]): string;
269 const htmlSafe: typeof EmberTemplateNs.htmlSafe;
270 const isHTMLSafe: typeof EmberTemplateNs.isHTMLSafe;
271 const underscore: typeof EmberStringNs.underscore;
272 const w: typeof EmberStringNs.w;
273 }
274 namespace Template {
275 const htmlSafe: typeof EmberTemplateNs.htmlSafe;
276 const isHTMLSafe: typeof EmberTemplateNs.isHTMLSafe;
277 }
278 const computed: typeof EmberObjectNs.computed & typeof EmberObjectComputedNs;
279
280 // Shenanigans to make `run` both callable and a namespace safely, while not
281 // making the `run.bind` call resolve to `Function.prototype.bind`. (Yes,
282 // insert :upside-down-smiley: here.)
283 // 1. Get the type side of the namespace.
284 type EmberRunloop = typeof EmberRunloopNs;
285 // 2. Use it to get an interface representing the callable side of `run`.
286 type RunFn = EmberRunloop["run"];
287 // type RunFn = Pick<EmberRunloop, 'run'>['run'];
288 // 3. Merge the two together so that the public-facing type of `run` is both
289 // the plucked-off run type *and* the namespace.
290 interface Run extends RunFn, EmberRunloop {}
291 const run: Run;
292
293 const platform: {
294 defineProperty: boolean;
295 hasPropertyAccessors: boolean;
296 };
297
298 /**
299 * `getEngineParent` retrieves an engine instance's parent instance.
300 */
301 function getEngineParent(engine: EngineInstance): EngineInstance;
302
303 const assert: typeof EmberDebugNs.assert;
304 const debug: typeof EmberDebugNs.debug;
305 const defineProperty: typeof EmberObjectNs.defineProperty;
306
307 const runInDebug: typeof EmberDebugNs.runInDebug;
308 const warn: typeof EmberDebugNs.warn;
309 const cacheFor: typeof EmberObjectInternalsNs.cacheFor;
310 const addListener: typeof EmberObjectEventsNs.addListener;
311 const removeListener: typeof EmberObjectEventsNs.removeListener;
312 const sendEvent: typeof EmberObjectEventsNs.sendEvent;
313 const on: typeof EmberObjectEventedNs.on;
314
315 const htmlSafe: typeof EmberTemplateNs.htmlSafe;
316 const isHTMLSafe: typeof EmberTemplateNs.isHTMLSafe;
317
318 const isBlank: typeof EmberUtilsNs.isBlank;
319 const isEmpty: typeof EmberUtilsNs.isEmpty;
320 const isNone: typeof EmberUtilsNs.isNone;
321 const isPresent: typeof EmberUtilsNs.isPresent;
322
323 const observer: typeof EmberObjectNs.observer;
324 const addObserver: typeof EmberObjectObserversNs.addObserver;
325 const removeObserver: typeof EmberObjectObserversNs.removeObserver;
326 const get: typeof EmberObjectNs.get;
327 const notifyPropertyChange: typeof EmberObjectNs.notifyPropertyChange;
328 const getProperties: typeof EmberObjectNs.getProperties;
329 const setProperties: typeof EmberObjectNs.setProperties;
330 const set: typeof EmberObjectNs.set;
331 const trySet: typeof EmberObjectNs.trySet;
332 const compare: typeof EmberUtilsNs.compare;
333 /**
334 * Creates a shallow copy of the passed object. A deep copy of the object is
335 * returned if the optional `deep` argument is `true`.
336 */
337 const isEqual: typeof EmberUtilsNs.isEqual;
338 const typeOf: typeof EmberUtilsNs.typeOf;
339 // TODO: replace with an es6 reexport when declare module 'ember' is removed
340 /**
341 * Copy properties from a source object to a target object.
342 * @deprecated until v5.0. You should replace any calls to `Ember.assign`
343 * with `Object.assign` or use the object spread operator.
344 */
345 const assign: typeof EmberPolyfillsNs.assign;
346 const guidFor: typeof EmberObjectInternalsNs.guidFor;
347
348 /**
349 * A function may be assigned to `Ember.onerror` to be called when Ember
350 * internals encounter an error. This is useful for specialized error handling
351 * and reporting code.
352 */
353 let onerror: ((error: Error) => void) | undefined;
354
355 /**
356 * The semantic version
357 */
358 const VERSION: string;
359 /**
360 * This property indicates whether or not this application is currently in
361 * testing mode. This is set when `setupForTesting` is called on the current
362 * application.
363 */
364 const testing: boolean;
365
366 const expandProperties: typeof EmberObjectComputedNs.expandProperties;
367}
368
369export default Ember;
370
371declare module "htmlbars-inline-precompile" {
372 interface TemplateFactory {
373 __htmlbars_inline_precompile_template_factory: any;
374 }
375 export default function hbs(tagged: TemplateStringsArray): TemplateFactory;
376}
377
\No newline at end of file