-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp-js-ui.d.ts
446 lines (366 loc) · 14.2 KB
/
esp-js-ui.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
import * as Rx from 'rx';
import * as esp from 'esp-js';
import { Router, DisposableBase } from 'esp-js';
import { Container, Resolver } from 'microdi-js';
import * as React from 'react';
declare module 'rx' {
export interface Observable<T> {
retryWithPolicy<T>(
policy: RetryPolicy,
onError?: (err: Error) => void,
scheduler?: Rx.IScheduler): Rx.Observable<T>;
subscribeWithRouter<T, TModel>(
router: esp.Router,
modelId: string,
onNext?: (value: T, model: TModel) => void,
onError?: (exception: any, model: TModel) => void,
onCompleted?: (model: TModel) => void): Rx.Disposable;
lazyConnect<T>(disposable: Rx.Disposable) : Rx.Observable<T>;
}
}
export class RetryPolicy {
static defaultPolicy(errorMessage: string): RetryPolicy;
static none(): RetryPolicy;
static createForUnlimitedRetry(description: string, retryAfterElapsedMs: number): RetryPolicy;
constructor(description: string, retryLimit: number, retryAfterElapsedMs: number, errorMessage: string | null);
readonly description: string;
readonly shouldRetry: boolean;
readonly errorMessage: string | null;
readonly retryAfterElapsedMs: number;
readonly retryCount: number;
readonly retryLimit: number;
incrementRetryCount(): void;
reset(): void;
}
export class Decimal {
static parse(value: any): Decimal;
constructor(unscaledValue: number, scale);
readonly unscaledValue: number;
readonly scale: number;
readonly value: number;
format(formatter?: (decimal: Decimal) => string): string;
}
export class DecimalFormat {
static ToString: (decimal: Decimal) => string;
static ToLocal: (decimal: Decimal) => string;
}
export class Environment {
static readonly isRunningOnTablet: boolean;
}
export class Unit {
static readonly default: Unit;
private constructor();
}
export class Guard {
static isDefined(value: any, message: string): void;
static isFalse(value: any, message: string): void;
static lengthIs<T>(array: Array<T>, expectedLength: number, message: string): void;
static lengthGreaterThan<T>(array: Array<T>, expectedLength: number, message: string): void;
static lengthIsAtLeast<T>(array: Array<T>, expectedLength: number, message: string): void;
static isString(value: any, message: string): void;
static stringIsNotEmpty(value: any, message: string): void;
static isTrue(item: any, message: string): void;
static isFunction(value: any, message: string): void;
static isNumber(value: any, message: string): void;
static isObject(value: any, message: string): void;
static isBoolean(value: any, message: string): void;
}
export declare enum Level {
verbose = 'verbose',
debug = 'debug',
info = 'info',
warn = 'warn',
error = 'error',
none = 'none'
}
export type Markers = {[key:string]: string};
export declare type LogEvent = {
timestamp: Date,
logger: string,
level: Level,
color: string,
message: string;
additionalDetails: any[];
markers: Markers;
};
export interface Sink {
log(logEvent:LogEvent): void;
}
export class ConsoleSink implements Sink {
log(logEvent:LogEvent): void;
}
export class CompositeSink implements Sink {
constructor(...sinks: Array<Sink>);
log(logEvent: LogEvent);
addSinks(...sinks:Array<Sink>);
}
export class LoggingConfig {
static setLevel(level: Level): void;
static addSinks(...sink: Sink[]): void;
static defaultLoggerConfig : LoggerConfig;
static getLoggerConfig(loggerName: string): LoggerConfig;
}
export interface LoggerConfig {
dumpAdditionalDetailsToConsole: boolean;
level: Level;
}
export class Logger {
constructor(name: string);
static create(name: string): Logger;
loggerConfig : LoggerConfig;
group(...args: any[]);
groupCollapsed(...args: any[]);
groupEnd();
verbose(message: string, additionalDetails?: any): void;
verbose(markers:Markers, message: string, additionalDetails?: any): void;
debug(message: string, additionalDetails?: any): void;
debug(markers:Markers, message: string, additionalDetails?: any): void;
info(message: string, additionalDetails?: any): void;
info(markers:Markers, message: string, additionalDetails?: any): void;
warn(message: string, additionalDetails?: any): void;
warn(markers:Markers, message: string, additionalDetails?: any): void;
error(message: string, additionalDetails?: any): void;
error(markers:Markers, message: string, additionalDetails?: any): void;
}
export interface ISchedulerService {
immediate: Rx.IScheduler;
async: Rx.IScheduler;
}
export class SchedulerService implements ISchedulerService {
readonly immediate: Rx.IScheduler;
readonly async: Rx.IScheduler;
}
export class Utils {
static parseBool(input: string): boolean;
static isString(value: any): boolean;
static isInt(n: number | string): boolean;
}
export function getComponentFactoryMetadata(target):ComponentFactoryMetadata;
export function componentFactory(componentKey:string, shortName:string);
export class ComponentFactoryMetadata {
constructor(componentKey:string, shortName:string);
readonly componentKey:string;
readonly shortName:string;
}
export interface ComponentStateSet {
componentFactoryKey: string;
componentsState: Array<any>;
}
export abstract class ComponentFactoryBase extends DisposableBase {
constructor(_container : Container);
readonly componentKey: string;
readonly shortName: string;
protected abstract _createComponent(childContainer: Container, state?: any): any;
public createComponent(state): void;
public getAllComponentsState(): ComponentStateSet;
public shutdownAllComponents(): void;
}
export interface ComponentMetadata {
componentFactoryKey: string;
shortName: string;
}
export interface FactoryEntry {
componentFactoryKey: string;
factory: ComponentFactoryBase;
shortName: string;
}
export class ComponentRegistryModel extends ModelBase {
public componentsMetadata: Array<ComponentMetadata>;
constructor(router:Router);
public getTitle() : string;
readonly componentFactories: Array<FactoryEntry>;
postProcess(): void;
registerComponentFactory(componentFactory:ComponentFactoryBase): void;
unregisterComponentFactory(componentFactory:ComponentFactoryBase): void;
getComponentFactory(componentFactoryKey:string): ComponentFactoryBase;
}
export class LiteralResolver<T> implements Resolver<T> {
public static readonly resolverName : string;
resolve<T>(container : Container, dependencyKey:{value:any}): T;
}
export class SystemContainerConfiguration {
public static configureContainer(rootContainer:Container);
}
export class SystemContainerConst {
static readonly router: string;
static readonly state_service: string;
static readonly components_registry_model: string;
static readonly region_manager: string;
static readonly scheduler_service: string;
static readonly module_loader: string;
}
export interface ComponentFactoryState {
componentFactoryKey:string;
componentsState: Array<any>;
}
export interface DefaultStateProvider {
getComponentFactoriesState(layoutMode:string):Array<ComponentFactoryState>;
}
export interface ModuleConstructor {
new (container: Container, stateService: StateService) : Module;
}
export interface Module extends DisposableBase {
initialise() : void;
configureContainer() : void ;
registerPrerequisites(registrar: PrerequisiteRegistrar): void;
registerComponents(componentRegistryModel:ComponentRegistryModel);
getComponentsFactories();
loadLayout(layoutMode:string);
unloadLayout() : void;
}
export abstract class ModuleBase extends DisposableBase implements Module {
protected container:Container;
constructor(moduleKey, container:Container, stateService:StateService, defaultStateProvider?:DefaultStateProvider);
abstract configureContainer();
abstract registerPrerequisites(registrar: PrerequisiteRegistrar): void;
registerComponents(componentRegistryModel:ComponentRegistryModel);
getComponentsFactories() : Array<ComponentFactoryBase>;
initialise() : void;
loadLayout(layoutMode:string);
unloadLayout();
}
export enum ModuleChangeType {
Change = 'Change',
Error = 'Error',
}
export interface ModuleLoadResult {
type: ModuleChangeType;
moduleName: string;
description?: string;
prerequisiteResult?: LoadResult;
errorMessage?: string;
}
interface ModuleDescriptor {
factory: ModuleConstructor;
moduleName: string;
permissions?: Array<string>;
}
export class ModuleLoader {
constructor(
_container: Container,
_componentRegistryModel: ComponentRegistryModel,
_stateService:StateService);
/**
* takes an array of modules class that will be new-ed up, i.e. constructor functions
*/
public loadModules(moduleDescriptors: Array<ModuleDescriptor>): Rx.Observable<ModuleLoadResult>;
public loadModule(moduleDescriptor: ModuleDescriptor): Rx.Observable<ModuleLoadResult>;
public unloadModule(moduleName: string): void;
public loadLayout(layoutMode:string): void;
}
export class MultiItemRegionEventConst {
static selectedItemChanged: string;
}
export interface SelectedItemChangedEvent {
selectedItem: RegionItem;
}
export class MultiItemRegionModel extends RegionModelBase {
public items: Array<RegionItem>;
public selectedItem: RegionItem;
constructor(regionName: string, router: Router, regionManager: RegionManager);
protected _addToRegion(title: string, modelId: string, displayContext?: string): void;
protected _removeFromRegion(modelId: string, displayContext?: string): void;
}
export interface ItemViewProps {
className?: string;
style?: any;
}
export default class ItemView extends React.Component<ItemViewProps, any> {
render(): JSX.Element;
}
export interface MultiItemRegionViewProps extends ViewBaseProps<MultiItemRegionModel> {
className?: string;
}
export class MultiItemRegionView extends ViewBase<MultiItemRegionView, MultiItemRegionModel, MultiItemRegionViewProps> {
}
export interface SelectableMultiItemViewProps extends ViewBaseProps<MultiItemRegionModel> {
className?: string;
}
export class SelectableMultiItemView extends ViewBase<SelectableMultiItemView, MultiItemRegionModel, SelectableMultiItemViewProps> {
}
export class SingleItemRegionModel extends RegionModelBase {
public item:RegionItem;
constructor(regionName : string, router, regionManager);
protected _addToRegion(title: string, modelId: string, displayContext?: string): void;
protected _removeFromRegion(modelId: string, displayContext?: string): void;
}
export interface SingleItemRegionViewProps extends ViewBaseProps<SingleItemRegionModel> {
className?: string;
}
export class SingleItemRegionView extends ViewBase<SingleItemRegionView, SingleItemRegionModel, SingleItemRegionViewProps> {
}
export class RegionItem {
public title:string;
public modelId:string;
public displayContext:string;
constructor(title: string, modelId:string, displayContext?:string);
public readonly itemKey;
public equals(modelId:string, displayContext?:string);
}
export type ViewCallBack = (model: ModelBase, viewKey?: string) => void;
export class RegionManager {// adds a region to the region manager
public registerRegion(regionName: string, onAddingViewToRegionCallback: ViewCallBack, onRemovingFromRegionCallback: ViewCallBack);
public unregisterRegion(regionName: string): void;
public addToRegion(regionName: string, model:ModelBase, displayContext?:string);
public removeFromRegion(regionName: string, model: ModelBase, displayContext?: string): void;
}
export abstract class RegionModelBase extends ModelBase {
constructor(_regionName : string, router: Router, _regionManager);
public observeEvents();
public getTitle(): string;
protected abstract _addToRegion(title:string, modelId:string, view:any, displayContext?:string);
protected abstract _removeFromRegion(modelId:string, view:any, displayContext?:string);
}
export class StateService {
public saveApplicationState<T>(moduleKey:string, layoutMode:string, state:T): void;
public getApplicationState<T>(moduleKey:string, layoutMode:string): T;
}
export class IdFactory {
public static createId(token);
}
export abstract class ModelBase extends DisposableBase {
protected _modelId: string;
protected _router: Router;
constructor(_modelId: string, _router: Router);
abstract getTitle(): string;
observeEvents(): void;
getState(): any;
/**
* Runs the given action on the dispatch loop for this model, ensures that any model observer will be notified of the change
* @param action
*/
ensureOnDispatchLoop(action: () => void): void;
readonly modelId: string;
readonly router: Router;
}
export interface ViewBaseProps<TModel> {
model:TModel;
router:Router;
}
export abstract class ViewBase<TComponent, TModel, TProps extends ViewBaseProps<TModel>>
extends React.Component<TProps, any> {
// This used to have all the model observation, that's now in esp-js-react's SmartComponent
// This view is doing something by way of the generic constraint it's putting on the props, but that's not exactly code reuse.
// Keeping this here for now, might delete at some point if we don't use it
}
export enum ResultStage {
Starting = 'Starting',
Completed = 'Completed',
Error = 'Error'
}
export interface LoadResult {
stage: ResultStage;
name: string;
errorMessage?: string;
}
export interface PrerequisiteRegistrar {
registerStreamFactory(factory: () => Rx.Observable<Unit>, name: string): void;
registerStream(stream: Rx.Observable<Unit>, name: string, errorMessage?: (e: Error) => string): void;
registerAction(action: () => void, name: string, errorMessage?: (e: Error) => string): void;
}
export class DefaultPrerequisiteRegistrar extends DisposableBase implements PrerequisiteRegistrar {
registerAction(action: () => void, name: string)
load(): Rx.Observable<LoadResult>;
registerStreamFactory(factory: () => Rx.Observable<Unit>, name: string): void;
registerStream(stream: Rx.Observable<Unit>, name: string): void;
}