@zenflux/core 0.0.1-dev.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/package.json +29 -29
  2. package/src/bases/controller-base.ts +4 -4
  3. package/src/clients/http.ts +5 -7
  4. package/src/command-bases/command-base.ts +5 -3
  5. package/src/errors/command-already-registered.ts +1 -1
  6. package/src/errors/controller-already-registered.ts +1 -1
  7. package/src/errors/controller-already-set.ts +1 -1
  8. package/src/errors/force-method-implementation.ts +1 -1
  9. package/src/exports-index.ts +13 -0
  10. package/src/exports.ts +47 -27
  11. package/src/index.ts +12 -2
  12. package/src/managers/commands.ts +7 -8
  13. package/src/managers/controllers.ts +3 -2
  14. package/src/managers/export.ts +1 -1
  15. package/src/managers/restful.ts +8 -6
  16. package/dist/es/src/bases/controller-base.d.ts +0 -55
  17. package/dist/es/src/bases/controller-base.d.ts.map +0 -1
  18. package/dist/es/src/bases/index.d.ts +0 -3
  19. package/dist/es/src/bases/index.d.ts.map +0 -1
  20. package/dist/es/src/bases/object-base.d.ts +0 -32
  21. package/dist/es/src/bases/object-base.d.ts.map +0 -1
  22. package/dist/es/src/clients/http.d.ts +0 -40
  23. package/dist/es/src/clients/http.d.ts.map +0 -1
  24. package/dist/es/src/command-bases/command-base.d.ts +0 -29
  25. package/dist/es/src/command-bases/command-base.d.ts.map +0 -1
  26. package/dist/es/src/command-bases/command-internal.d.ts +0 -9
  27. package/dist/es/src/command-bases/command-internal.d.ts.map +0 -1
  28. package/dist/es/src/command-bases/command-public.d.ts +0 -9
  29. package/dist/es/src/command-bases/command-public.d.ts.map +0 -1
  30. package/dist/es/src/command-bases/command-restful.d.ts +0 -22
  31. package/dist/es/src/command-bases/command-restful.d.ts.map +0 -1
  32. package/dist/es/src/command-bases/index.d.ts +0 -8
  33. package/dist/es/src/command-bases/index.d.ts.map +0 -1
  34. package/dist/es/src/errors/command-already-registered.d.ts +0 -11
  35. package/dist/es/src/errors/command-already-registered.d.ts.map +0 -1
  36. package/dist/es/src/errors/command-not-found.d.ts +0 -10
  37. package/dist/es/src/errors/command-not-found.d.ts.map +0 -1
  38. package/dist/es/src/errors/controller-already-registered.d.ts +0 -11
  39. package/dist/es/src/errors/controller-already-registered.d.ts.map +0 -1
  40. package/dist/es/src/errors/controller-already-set.d.ts +0 -11
  41. package/dist/es/src/errors/controller-already-set.d.ts.map +0 -1
  42. package/dist/es/src/errors/force-method-implementation.d.ts +0 -14
  43. package/dist/es/src/errors/force-method-implementation.d.ts.map +0 -1
  44. package/dist/es/src/errors/index-public.d.ts +0 -2
  45. package/dist/es/src/errors/index-public.d.ts.map +0 -1
  46. package/dist/es/src/errors/index.d.ts +0 -6
  47. package/dist/es/src/errors/index.d.ts.map +0 -1
  48. package/dist/es/src/exports.d.ts +0 -37
  49. package/dist/es/src/exports.d.ts.map +0 -1
  50. package/dist/es/src/index.d.ts +0 -6
  51. package/dist/es/src/index.d.ts.map +0 -1
  52. package/dist/es/src/initializer.d.ts +0 -36
  53. package/dist/es/src/initializer.d.ts.map +0 -1
  54. package/dist/es/src/interfaces/commands.d.ts +0 -14
  55. package/dist/es/src/interfaces/commands.d.ts.map +0 -1
  56. package/dist/es/src/interfaces/config.d.ts +0 -21
  57. package/dist/es/src/interfaces/config.d.ts.map +0 -1
  58. package/dist/es/src/interfaces/index.d.ts +0 -8
  59. package/dist/es/src/interfaces/index.d.ts.map +0 -1
  60. package/dist/es/src/interfaces/logger.d.ts +0 -20
  61. package/dist/es/src/interfaces/logger.d.ts.map +0 -1
  62. package/dist/es/src/interfaces/restful.d.ts +0 -19
  63. package/dist/es/src/interfaces/restful.d.ts.map +0 -1
  64. package/dist/es/src/managers/commands.d.ts +0 -68
  65. package/dist/es/src/managers/commands.d.ts.map +0 -1
  66. package/dist/es/src/managers/controllers.d.ts +0 -17
  67. package/dist/es/src/managers/controllers.d.ts.map +0 -1
  68. package/dist/es/src/managers/export.d.ts +0 -16
  69. package/dist/es/src/managers/export.d.ts.map +0 -1
  70. package/dist/es/src/managers/index.d.ts +0 -8
  71. package/dist/es/src/managers/index.d.ts.map +0 -1
  72. package/dist/es/src/managers/internal.d.ts +0 -9
  73. package/dist/es/src/managers/internal.d.ts.map +0 -1
  74. package/dist/es/src/managers/restful.d.ts +0 -25
  75. package/dist/es/src/managers/restful.d.ts.map +0 -1
  76. package/dist/es/tsdoc-metadata.json +0 -11
  77. package/dist/es/zenflux-core.d.ts +0 -470
  78. package/dist/es/zenflux-core.js +0 -1922
  79. package/src/initializer.ts +0 -56
@@ -1,470 +0,0 @@
1
- declare const afterInitializeCallbacks: (() => void)[];
2
-
3
- declare namespace bases {
4
- export {
5
- ControllerBase,
6
- ObjectBase
7
- }
8
- }
9
- export { bases }
10
-
11
- export declare const classes: {
12
- Logger: {
13
- new (owner: typeof bases.ObjectBase, params?: any): {
14
- log(caller: TCaller, message: string, ...params: any[]): void;
15
- warn(caller: TCaller, message: string, ...params: any[]): void;
16
- error(caller: TCaller, message: string, ...params: any[]): void;
17
- info(caller: TCaller, message: string, ...params: any[]): void;
18
- debug(caller: TCaller, message: string, ...params: any[]): void;
19
- startsEmpty(caller: TCaller): void;
20
- startsWith(caller: TCaller, params: object): void;
21
- dump(caller: TCaller, data: any): void;
22
- drop(caller: TCaller, according: {
23
- [key: string]: string;
24
- }, data: any): void;
25
- };
26
- };
27
- };
28
-
29
- declare abstract class CommandBase extends ObjectBase {
30
- private static controller;
31
- protected args: ICommandArgsInterface;
32
- protected options: ICommandOptionsInterface;
33
- private readonly logger;
34
- static getName(): string;
35
- static setController(controller: ControllerBase): void;
36
- static getController(): ControllerBase;
37
- constructor(args?: ICommandArgsInterface, options?: {});
38
- protected initialize(args: ICommandArgsInterface, options: ICommandOptionsInterface): void;
39
- /**
40
- * TODO: Maybe abstract, currently not sure about parameters initialization.
41
- */
42
- protected apply(args?: ICommandArgsInterface, options?: ICommandOptionsInterface): any;
43
- protected onBeforeApply?(): void;
44
- protected onAfterApply?(): void;
45
- run(): Promise<any>;
46
- private runInternal;
47
- }
48
-
49
- declare namespace commandBases {
50
- export {
51
- CommandPublic,
52
- CommandRestful,
53
- CommandBase,
54
- CommandInternal
55
- }
56
- }
57
- export { commandBases }
58
-
59
- declare class CommandInternal extends CommandBase {
60
- static getName(): string;
61
- }
62
-
63
- declare class CommandPublic extends CommandBase {
64
- static getName(): string;
65
- }
66
-
67
- declare abstract class CommandRestful extends CommandBase {
68
- static getName(): string;
69
- /**
70
- * Override this method is required to determine endpoint and magic query params.
71
- *
72
- * @example
73
- * ```
74
- * args = { query: { id: 1 } };
75
- * getEndpoint() = '/api/v1/users/{id}';
76
- * result = '/api/v1/users/1';
77
- * ```
78
- */
79
- getEndpoint(): string;
80
- protected apply(args?: ICommandArgsInterface, options?: ICommandOptionsInterface): Promise<any>;
81
- private applyEndpointFormat;
82
- }
83
-
84
- declare class Commands extends ObjectBase {
85
- static readonly trace: string[];
86
- private current;
87
- private currentArgs;
88
- private trace;
89
- private commands;
90
- private onBeforeHooks;
91
- private onBeforeUIHooks;
92
- private onAfterHooks;
93
- private onAfterOnceHooks;
94
- private onAfterUIHooks;
95
- private onAfterAffectHooks;
96
- private readonly logger;
97
- static getName(): string;
98
- private static runCallbacks;
99
- private static hookCommand;
100
- constructor();
101
- run(command: string | CommandBase, args?: ICommandArgsInterface, options?: any): Promise<any>;
102
- register(commands: {
103
- [key: string]: typeof CommandBase;
104
- }, controller: ControllerBase): {
105
- [key: string]: typeof CommandBase;
106
- };
107
- getAll(): {
108
- [key: string]: typeof CommandBase;
109
- };
110
- getByName(name: string): typeof CommandBase;
111
- getLogger(): ILogger;
112
- getCommandInstance(name: string, args?: ICommandArgsInterface, options?: {}): CommandBase;
113
- /**
114
- * Used to set hooks that effects only data and not UI.
115
- */
116
- onBefore(hookCommand: string, callback: TCommandCallbackType): void;
117
- /**
118
- * Used to set hooks that effects only UI.
119
- */
120
- onBeforeUI(hookCommand: string, callback: TCommandCallbackType): void;
121
- /**
122
- * Used to set hooks that effects only data and not UI.
123
- */
124
- onAfter(hookCommand: string, callback: TCommandCallbackType): void;
125
- /**
126
- * Used to set hooks that effects only UI.
127
- */
128
- onAfterUI(command: string, callback: TCommandCallbackType): void;
129
- /**
130
- * Used to set hooks that effects only data and not UI.
131
- */
132
- onAfterOnce(command: string, callback: TCommandCallbackType): void;
133
- /**
134
- * Used to register a trigger that runs command after `hookCommand` run's.
135
- */
136
- onAfterAffect(hookCommand: string, affectCommand: string): void;
137
- protected onBeforeRun(command: CommandBase, args?: ICommandArgsInterface, options?: {}): void;
138
- protected runInstance(command: CommandBase, args?: ICommandArgsInterface, options?: {}): Promise<any>;
139
- protected onAfterRun(command: CommandBase, args: ICommandArgsInterface, options: {}, result: any): Promise<any>;
140
- protected attachCurrent(command: CommandBase, args?: any): void;
141
- protected detachCurrent(command: CommandBase): void;
142
- }
143
-
144
- declare let commands: Commands;
145
-
146
- declare abstract class ControllerBase extends ObjectBase {
147
- private commands;
148
- private restful;
149
- private internal;
150
- static getName(): string;
151
- /**
152
- * Constructor for `ControllerBase` instances.
153
- * Initializes the base class and invokes the `initialize()` method.
154
- */
155
- constructor();
156
- /**
157
- * Initializes the controller by calling the `register()` method and optionally the `setupHooks()` method.
158
- */
159
- protected initialize(): void;
160
- /**
161
- * Registers commands and command types by calling manager functions.
162
- */
163
- protected register(): void;
164
- /**
165
- * Retrieve the public commands associated with this controller.
166
- * Derived classes can override this method to specify their own commands.
167
- */
168
- protected getCommands(): {
169
- [key: string]: typeof CommandPublic;
170
- };
171
- /**
172
- * Retrieve the RESTful commands associated with this controller.
173
- * Derived classes can override this method to specify their own RESTful commands.
174
- */
175
- protected getRestful(): {
176
- [key: string]: typeof CommandRestful;
177
- };
178
- /**
179
- * Retrieve the internal commands associated with this controller.
180
- * Derived classes can override this method to specify their own internal commands.
181
- */
182
- protected getInternal(): {
183
- [key: string]: typeof CommandInternal;
184
- };
185
- /**
186
- * A hook method that can be optionally overridden in derived classes to set up hooks or event listeners.
187
- */
188
- protected setupHooks?(): void;
189
- }
190
-
191
- declare class Controllers extends ObjectBase {
192
- private controllers;
193
- constructor();
194
- static getName(): string;
195
- get(name: string): ControllerBase;
196
- getAll(): {
197
- [key: string]: ControllerBase;
198
- };
199
- register(controller: ControllerBase): ControllerBase;
200
- }
201
-
202
- declare let controllers: Controllers;
203
-
204
- declare const CoreAPI: {
205
- classes: {
206
- Logger: {
207
- new (owner: typeof exported.bases.ObjectBase, params?: any): {
208
- log(caller: exported.interfaces.TCaller, message: string, ...params: any[]): void;
209
- warn(caller: exported.interfaces.TCaller, message: string, ...params: any[]): void;
210
- error(caller: exported.interfaces.TCaller, message: string, ...params: any[]): void;
211
- info(caller: exported.interfaces.TCaller, message: string, ...params: any[]): void;
212
- debug(caller: exported.interfaces.TCaller, message: string, ...params: any[]): void;
213
- startsEmpty(caller: exported.interfaces.TCaller): void;
214
- startsWith(caller: exported.interfaces.TCaller, params: object): void;
215
- dump(caller: exported.interfaces.TCaller, data: any): void;
216
- drop(caller: exported.interfaces.TCaller, according: {
217
- [key: string]: string;
218
- }, data: any): void;
219
- };
220
- };
221
- };
222
- bases: typeof exported.bases;
223
- commandBases: typeof exported.commandBases;
224
- errors: typeof exported.errors;
225
- interfaces: typeof exported.interfaces;
226
- managers: typeof exported.managers;
227
- initialize: (configuration?: Partial<IAPIConfig>) => void;
228
- destroy: () => void;
229
- onAfterInitialize: (callback: () => void) => void;
230
- config: IAPIConfig;
231
- };
232
- export default CoreAPI;
233
-
234
- declare function destroy(): void;
235
-
236
- declare enum E_HTTP_METHOD_TYPE {
237
- DELETE = "DELETE",
238
- GET = "GET",
239
- OPTIONS = "OPTIONS",
240
- PATCH = "PATCH",
241
- POST = "POST",
242
- PUT = "PUT",
243
- "__EMPTY__" = ""
244
- }
245
-
246
- declare enum E_RESPONSE_HANDLER_TYPE {
247
- ERROR_HANDLER = "error_handler",
248
- RESPONSE_FILTER = "response_filter",
249
- RESPONSE_HANDLER = "response_handler"
250
- }
251
-
252
- declare namespace errors {
253
- export {
254
- ForceMethodImplementation
255
- }
256
- }
257
- export { errors }
258
-
259
- declare namespace exported {
260
- export {
261
- classes,
262
- bases,
263
- commandBases,
264
- errors,
265
- interfaces,
266
- managers
267
- }
268
- }
269
-
270
- /**
271
- * @public
272
- */
273
- declare class ForceMethodImplementation extends Error {
274
- constructor(context: ObjectBase | typeof ObjectBase | string, methodName: string);
275
- }
276
-
277
- declare class Http extends ObjectBase {
278
- private readonly logger;
279
- private readonly apiBaseUrl;
280
- private readonly requestInit;
281
- private errorHandler?;
282
- private responseFilter?;
283
- private responseHandler?;
284
- static getName(): string;
285
- /**
286
- * Initializes the base class and sets up configuration parameters.
287
- */
288
- constructor(apiBaseUrl?: string, requestInit?: RequestInit);
289
- /**
290
- * Fetches data from the specified path using the given HTTP method and optional request body.
291
- */
292
- fetch(path: string, method: E_HTTP_METHOD_TYPE, body?: any): Promise<any>;
293
- /**
294
- * Sets the error handler callback for handling errors during fetch requests.
295
- */
296
- setErrorHandler(callback: TErrorHandlerCallbackType): void;
297
- /**
298
- * Sets the response filter callback for filtering the response text.
299
- */
300
- setResponseFilter(callback: TResponseFilterCallbackType): void;
301
- /**
302
- * Sets the response handler callback for handling the response data.
303
- */
304
- setResponseHandler(callback: TResponseHandlerCallbackType): void;
305
- private applyErrorHandler;
306
- private applyResponseFilter;
307
- private applyResponseHandler;
308
- }
309
-
310
- /**
311
- * @author Leonid Vinikov <leonidvinikov@gmail.com>
312
- */
313
- /**
314
- *
315
- */
316
- declare interface IAPIConfig {
317
- /**
318
- * @description API version, from `package.json`
319
- */
320
- version: string;
321
- /**
322
- * @description API base url for http requests.
323
- */
324
- baseURL?: string;
325
- /**
326
- * @description Request Init for fetch API.
327
- */
328
- requestInit?: RequestInit;
329
- }
330
-
331
- declare interface ICommandArgsInterface {
332
- [key: string]: any;
333
- }
334
-
335
- declare interface ICommandOptionsInterface {
336
- [key: string]: any;
337
- }
338
-
339
- declare interface ILogger {
340
- log(caller: TCaller, message: string, ...params: any[]): void;
341
- warn(caller: TCaller, message: string, ...params: any[]): void;
342
- error(caller: TCaller, message: string, ...params: any[]): void;
343
- info(caller: TCaller, message: string, ...params: any[]): void;
344
- debug(caller: TCaller, message: string, ...params: any[]): void;
345
- startsEmpty(caller: TCaller): void;
346
- startsWith(caller: TCaller, params: object): void;
347
- dump(caller: TCaller, params: {
348
- [key: string]: object | string;
349
- }): void;
350
- drop(caller: TCaller, according: {
351
- [key: string]: string;
352
- }, data: any): void;
353
- }
354
-
355
- declare function initialize(config: IAPIConfig): void;
356
-
357
- declare namespace interfaces {
358
- export {
359
- TCommandCallbackType,
360
- ICommandArgsInterface,
361
- ICommandOptionsInterface,
362
- IOnHookAffectInterface,
363
- IOnHookInterface,
364
- IAPIConfig,
365
- TCaller,
366
- ILogger,
367
- TErrorHandlerCallbackType,
368
- TResponseFilterCallbackType,
369
- TResponseHandlerCallbackType,
370
- TPossibleHandlersType,
371
- E_RESPONSE_HANDLER_TYPE,
372
- E_HTTP_METHOD_TYPE
373
- }
374
- }
375
- export { interfaces }
376
-
377
- declare class Internal extends Commands {
378
- static getName(): string;
379
- }
380
-
381
- declare let internal: Internal;
382
-
383
- declare interface IOnHookAffectInterface {
384
- [key: string]: Array<string>;
385
- }
386
-
387
- declare interface IOnHookInterface {
388
- [key: string]: Array<TCommandCallbackType>;
389
- }
390
-
391
- declare namespace managers {
392
- export {
393
- initialize,
394
- destroy,
395
- afterInitializeCallbacks,
396
- commands,
397
- controllers,
398
- restful,
399
- internal
400
- }
401
- }
402
- export { managers }
403
-
404
- declare abstract class ObjectBase {
405
- private readonly _id;
406
- private readonly name;
407
- /**
408
- * Initializes the name and unique identifier for the instance.
409
- */
410
- protected constructor();
411
- /**
412
- * Static method to retrieve the name of the class. This method is abstract and must be implemented
413
- * by derived classes.
414
- */
415
- static getName(): string;
416
- /**
417
- * Retrieves the name of the current instance by calling the static `getName()` method of the
418
- * constructor (derived class).
419
- */
420
- getName(): string;
421
- /**
422
- * Retrieves the unique identifier of the current instance.
423
- */
424
- getUniqueId(): string;
425
- /**
426
- * Retrieves the initial name that was set during construction. This name may be "__UNDEFINED_NAME__"
427
- * if the `getName()` method of the derived class does not provide a valid name.
428
- */
429
- getInitialName(): string;
430
- /**
431
- * Retrieves an array of hierarchical class names from the current instance up to the `ObjectBase` class.
432
- */
433
- getHierarchyNames(): string[];
434
- }
435
-
436
- declare class Restful extends Commands {
437
- private static client;
438
- currentHttpMethod: E_HTTP_METHOD_TYPE;
439
- static getName(): string;
440
- constructor(Config: IAPIConfig);
441
- getClient(): Http;
442
- get(command: string, args?: ICommandArgsInterface, options?: ICommandOptionsInterface): Promise<any>;
443
- update(command: string, args?: ICommandArgsInterface, options?: {}): Promise<any>;
444
- delete(command: string, args?: ICommandArgsInterface, options?: {}): Promise<any>;
445
- create(command: string, args?: ICommandArgsInterface, options?: {}): Promise<any>;
446
- protected runInstance(command: CommandRestful, args?: ICommandArgsInterface, options?: {}): Promise<any>;
447
- /**
448
- * Handlers on return true will swallow the request.
449
- */
450
- setHandler(type: E_RESPONSE_HANDLER_TYPE, callback: TPossibleHandlersType): void;
451
- }
452
-
453
- declare let restful: Restful;
454
-
455
- /**
456
- * @author Leonid Vinikov <leonidvinikov@gmail.com>
457
- */
458
- declare type TCaller = string | Function;
459
-
460
- declare type TCommandCallbackType = (args?: any, options?: any) => any;
461
-
462
- declare type TErrorHandlerCallbackType = (data: any) => boolean;
463
-
464
- declare type TPossibleHandlersType = TErrorHandlerCallbackType | TResponseFilterCallbackType | TResponseHandlerCallbackType;
465
-
466
- declare type TResponseFilterCallbackType = (text: string) => string;
467
-
468
- declare type TResponseHandlerCallbackType = (text: string) => boolean;
469
-
470
- export { }