taon 21.0.3 → 21.0.6

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 (200) hide show
  1. package/browser/fesm2022/taon.mjs +1953 -1238
  2. package/browser/fesm2022/taon.mjs.map +1 -1
  3. package/browser/package.json +1 -1
  4. package/browser/types/taon.d.ts +2152 -0
  5. package/lib/base-classes/base-abstract-entity.d.ts +1 -1
  6. package/lib/base-classes/base-abstract-entity.js +12 -12
  7. package/lib/base-classes/base-abstract-entity.js.map +1 -1
  8. package/lib/base-classes/base-angular-service.d.ts +1 -1
  9. package/lib/base-classes/base-angular-service.js +6 -3
  10. package/lib/base-classes/base-angular-service.js.map +1 -1
  11. package/lib/base-classes/base-context.d.ts +2 -2
  12. package/lib/base-classes/base-controller.js +7 -1
  13. package/lib/base-classes/base-controller.js.map +1 -1
  14. package/lib/base-classes/base-crud-controller.js +52 -12
  15. package/lib/base-classes/base-crud-controller.js.map +1 -1
  16. package/lib/base-classes/base-entity.js +2 -6
  17. package/lib/base-classes/base-entity.js.map +1 -1
  18. package/lib/base-classes/base-repository.d.ts +3 -3
  19. package/lib/base-classes/base-repository.js +15 -10
  20. package/lib/base-classes/base-repository.js.map +1 -1
  21. package/lib/base-classes/base.d.ts +1 -46
  22. package/lib/base-classes/base.js +17 -30
  23. package/lib/base-classes/base.js.map +1 -1
  24. package/lib/build-info._auto-generated_.d.ts +1 -1
  25. package/lib/build-info._auto-generated_.js +1 -1
  26. package/lib/context-db-migrations.d.ts +2 -1
  27. package/lib/create-context.d.ts +4 -4
  28. package/lib/decorators/classes/entity-decorator.js +1 -1
  29. package/lib/decorators/classes/entity-decorator.js.map +1 -1
  30. package/lib/decorators/http/http-decorators.d.ts +1 -19
  31. package/lib/decorators/http/http-decorators.js +20 -22
  32. package/lib/decorators/http/http-decorators.js.map +1 -1
  33. package/lib/endpoint-context.d.ts +3 -2
  34. package/lib/formly/{formly-group-wrapper-component.d.ts → formly-group-wrapper.component.d.ts} +1 -1
  35. package/lib/formly/{formly-repeat-component.d.ts → formly-repeat.component.d.ts} +1 -1
  36. package/lib/formly/fromly.js +24 -24
  37. package/lib/formly/fromly.js.map +1 -1
  38. package/lib/index.d.ts +146 -45
  39. package/lib/index.js +166 -55
  40. package/lib/index.js.map +1 -1
  41. package/lib/orm/columns.d.ts +28 -0
  42. package/lib/orm/columns.js +102 -0
  43. package/lib/orm/columns.js.map +1 -0
  44. package/lib/orm/index.d.ts +1 -0
  45. package/lib/orm/index.js +73 -0
  46. package/lib/orm/index.js.map +1 -0
  47. package/lib/realtime/realtime-core.d.ts +1 -1
  48. package/lib/realtime/realtime-strategy/realtime-strategy-socket-io.d.ts +1 -2
  49. package/lib/realtime/realtime-strategy/realtime-strategy-socket-io.js.map +1 -1
  50. package/lib/realtime/realtime-strategy/realtime-strategy.d.ts +1 -1
  51. package/lib/realtime/realtime-subs-manager.d.ts +1 -1
  52. package/lib/symbols.d.ts +31 -31
  53. package/lib/symbols.js +59 -59
  54. package/lib/symbols.js.map +1 -1
  55. package/lib/ui/index.js +2 -2
  56. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  57. package/package.json +1 -1
  58. package/websql/fesm2022/taon.mjs +1316 -648
  59. package/websql/fesm2022/taon.mjs.map +1 -1
  60. package/websql/package.json +1 -1
  61. package/websql/types/taon.d.ts +2161 -0
  62. package/browser/index.d.ts +0 -6
  63. package/browser/lib/base-classes/base-abstract-entity.d.ts +0 -8
  64. package/browser/lib/base-classes/base-angular-service.d.ts +0 -34
  65. package/browser/lib/base-classes/base-class.d.ts +0 -16
  66. package/browser/lib/base-classes/base-context.d.ts +0 -21
  67. package/browser/lib/base-classes/base-controller.d.ts +0 -83
  68. package/browser/lib/base-classes/base-crud-controller.d.ts +0 -29
  69. package/browser/lib/base-classes/base-custom-repository.d.ts +0 -4
  70. package/browser/lib/base-classes/base-entity.d.ts +0 -17
  71. package/browser/lib/base-classes/base-file-upload.middleware.d.ts +0 -15
  72. package/browser/lib/base-classes/base-injector.d.ts +0 -68
  73. package/browser/lib/base-classes/base-middleware.d.ts +0 -39
  74. package/browser/lib/base-classes/base-migration.d.ts +0 -12
  75. package/browser/lib/base-classes/base-provider.d.ts +0 -9
  76. package/browser/lib/base-classes/base-repository.d.ts +0 -267
  77. package/browser/lib/base-classes/base-subscriber-for-entity.d.ts +0 -82
  78. package/browser/lib/base-classes/base.d.ts +0 -47
  79. package/browser/lib/config/controller-config.d.ts +0 -22
  80. package/browser/lib/config/controller-options.d.ts +0 -17
  81. package/browser/lib/config/method-config.d.ts +0 -40
  82. package/browser/lib/config/param-config.d.ts +0 -9
  83. package/browser/lib/constants.d.ts +0 -10
  84. package/browser/lib/context-db-migrations.d.ts +0 -18
  85. package/browser/lib/create-context.d.ts +0 -79
  86. package/browser/lib/decorators/classes/controller-decorator.d.ts +0 -6
  87. package/browser/lib/decorators/classes/entity-decorator.d.ts +0 -20
  88. package/browser/lib/decorators/classes/middleware-decorator.d.ts +0 -8
  89. package/browser/lib/decorators/classes/migration-decorator.d.ts +0 -8
  90. package/browser/lib/decorators/classes/provider-decorator.d.ts +0 -8
  91. package/browser/lib/decorators/classes/repository-decorator.d.ts +0 -8
  92. package/browser/lib/decorators/classes/subscriber-decorator.d.ts +0 -9
  93. package/browser/lib/decorators/decorator-abstract-opt.d.ts +0 -4
  94. package/browser/lib/decorators/http/http-decorators.d.ts +0 -21
  95. package/browser/lib/decorators/http/http-methods-decorators.d.ts +0 -71
  96. package/browser/lib/decorators/http/http-params-decorators.d.ts +0 -9
  97. package/browser/lib/dependency-injection/di-container.d.ts +0 -6
  98. package/browser/lib/endpoint-context-storage.d.ts +0 -12
  99. package/browser/lib/endpoint-context.d.ts +0 -198
  100. package/browser/lib/entity-process.d.ts +0 -40
  101. package/browser/lib/get-response-value.d.ts +0 -7
  102. package/browser/lib/helpers/class-helpers.d.ts +0 -25
  103. package/browser/lib/helpers/clone-obj.d.ts +0 -2
  104. package/browser/lib/helpers/taon-helpers.d.ts +0 -19
  105. package/browser/lib/index.d.ts +0 -129
  106. package/browser/lib/inject.d.ts +0 -5
  107. package/browser/lib/models.d.ts +0 -257
  108. package/browser/lib/orm.d.ts +0 -3
  109. package/browser/lib/realtime/realtime-client.d.ts +0 -42
  110. package/browser/lib/realtime/realtime-core.d.ts +0 -41
  111. package/browser/lib/realtime/realtime-server.d.ts +0 -44
  112. package/browser/lib/realtime/realtime-strategy/index.d.ts +0 -5
  113. package/browser/lib/realtime/realtime-strategy/realtime-strategy-ipc.d.ts +0 -82
  114. package/browser/lib/realtime/realtime-strategy/realtime-strategy-mock.d.ts +0 -15
  115. package/browser/lib/realtime/realtime-strategy/realtime-strategy-socket-io.d.ts +0 -16
  116. package/browser/lib/realtime/realtime-strategy/realtime-strategy.d.ts +0 -12
  117. package/browser/lib/realtime/realtime-subs-manager.d.ts +0 -15
  118. package/browser/lib/realtime/realtime.models.d.ts +0 -28
  119. package/browser/lib/symbols.d.ts +0 -66
  120. package/browser/lib/ui/index.d.ts +0 -2
  121. package/browser/lib/ui/taon-admin-mode-configuration/index.d.ts +0 -2
  122. package/browser/lib/ui/taon-admin-mode-configuration/taon-admin.service.d.ts +0 -22
  123. package/browser/lib/validators.d.ts +0 -8
  124. package/browser/public-api.d.ts +0 -2
  125. package/lib/decorators/classes/controller-config.d.ts +0 -20
  126. package/lib/decorators/classes/controller-config.js +0 -21
  127. package/lib/decorators/classes/controller-config.js.map +0 -1
  128. package/lib/decorators/classes/controller-options.d.ts +0 -16
  129. package/lib/decorators/classes/controller-options.js +0 -20
  130. package/lib/decorators/classes/controller-options.js.map +0 -1
  131. package/lib/formly/formly-group-wrapper-component.js +0 -51
  132. package/lib/formly/formly-group-wrapper-component.js.map +0 -1
  133. package/lib/formly/formly-repeat-component.js +0 -95
  134. package/lib/formly/formly-repeat-component.js.map +0 -1
  135. package/lib/orm.d.ts +0 -68
  136. package/lib/orm.js +0 -112
  137. package/lib/orm.js.map +0 -1
  138. package/websql/index.d.ts +0 -6
  139. package/websql/lib/base-classes/base-abstract-entity.d.ts +0 -8
  140. package/websql/lib/base-classes/base-angular-service.d.ts +0 -34
  141. package/websql/lib/base-classes/base-class.d.ts +0 -16
  142. package/websql/lib/base-classes/base-context.d.ts +0 -21
  143. package/websql/lib/base-classes/base-controller.d.ts +0 -83
  144. package/websql/lib/base-classes/base-crud-controller.d.ts +0 -29
  145. package/websql/lib/base-classes/base-custom-repository.d.ts +0 -4
  146. package/websql/lib/base-classes/base-entity.d.ts +0 -17
  147. package/websql/lib/base-classes/base-file-upload.middleware.d.ts +0 -15
  148. package/websql/lib/base-classes/base-injector.d.ts +0 -68
  149. package/websql/lib/base-classes/base-middleware.d.ts +0 -39
  150. package/websql/lib/base-classes/base-migration.d.ts +0 -12
  151. package/websql/lib/base-classes/base-provider.d.ts +0 -9
  152. package/websql/lib/base-classes/base-repository.d.ts +0 -272
  153. package/websql/lib/base-classes/base-subscriber-for-entity.d.ts +0 -82
  154. package/websql/lib/base-classes/base.d.ts +0 -47
  155. package/websql/lib/config/controller-config.d.ts +0 -22
  156. package/websql/lib/config/controller-options.d.ts +0 -17
  157. package/websql/lib/config/method-config.d.ts +0 -40
  158. package/websql/lib/config/param-config.d.ts +0 -9
  159. package/websql/lib/constants.d.ts +0 -10
  160. package/websql/lib/context-db-migrations.d.ts +0 -18
  161. package/websql/lib/create-context.d.ts +0 -79
  162. package/websql/lib/decorators/classes/controller-decorator.d.ts +0 -6
  163. package/websql/lib/decorators/classes/entity-decorator.d.ts +0 -20
  164. package/websql/lib/decorators/classes/middleware-decorator.d.ts +0 -8
  165. package/websql/lib/decorators/classes/migration-decorator.d.ts +0 -8
  166. package/websql/lib/decorators/classes/provider-decorator.d.ts +0 -8
  167. package/websql/lib/decorators/classes/repository-decorator.d.ts +0 -8
  168. package/websql/lib/decorators/classes/subscriber-decorator.d.ts +0 -9
  169. package/websql/lib/decorators/decorator-abstract-opt.d.ts +0 -4
  170. package/websql/lib/decorators/http/http-decorators.d.ts +0 -21
  171. package/websql/lib/decorators/http/http-methods-decorators.d.ts +0 -71
  172. package/websql/lib/decorators/http/http-params-decorators.d.ts +0 -9
  173. package/websql/lib/dependency-injection/di-container.d.ts +0 -6
  174. package/websql/lib/endpoint-context-storage.d.ts +0 -12
  175. package/websql/lib/endpoint-context.d.ts +0 -200
  176. package/websql/lib/entity-process.d.ts +0 -40
  177. package/websql/lib/get-response-value.d.ts +0 -7
  178. package/websql/lib/helpers/class-helpers.d.ts +0 -25
  179. package/websql/lib/helpers/clone-obj.d.ts +0 -2
  180. package/websql/lib/helpers/taon-helpers.d.ts +0 -19
  181. package/websql/lib/index.d.ts +0 -129
  182. package/websql/lib/inject.d.ts +0 -5
  183. package/websql/lib/models.d.ts +0 -261
  184. package/websql/lib/orm.d.ts +0 -69
  185. package/websql/lib/realtime/realtime-client.d.ts +0 -42
  186. package/websql/lib/realtime/realtime-core.d.ts +0 -41
  187. package/websql/lib/realtime/realtime-server.d.ts +0 -44
  188. package/websql/lib/realtime/realtime-strategy/index.d.ts +0 -5
  189. package/websql/lib/realtime/realtime-strategy/realtime-strategy-ipc.d.ts +0 -82
  190. package/websql/lib/realtime/realtime-strategy/realtime-strategy-mock.d.ts +0 -15
  191. package/websql/lib/realtime/realtime-strategy/realtime-strategy-socket-io.d.ts +0 -16
  192. package/websql/lib/realtime/realtime-strategy/realtime-strategy.d.ts +0 -12
  193. package/websql/lib/realtime/realtime-subs-manager.d.ts +0 -15
  194. package/websql/lib/realtime/realtime.models.d.ts +0 -28
  195. package/websql/lib/symbols.d.ts +0 -66
  196. package/websql/lib/ui/index.d.ts +0 -2
  197. package/websql/lib/ui/taon-admin-mode-configuration/index.d.ts +0 -2
  198. package/websql/lib/ui/taon-admin-mode-configuration/taon-admin.service.d.ts +0 -22
  199. package/websql/lib/validators.d.ts +0 -8
  200. package/websql/public-api.d.ts +0 -2
@@ -1,1231 +1,1000 @@
1
1
  import 'reflect-metadata';
2
2
  import * as coreHelpers from 'tnp-core/browser';
3
3
  import { _, Utils, Helpers, UtilsOs, config, CoreModels, crossPlatformPath, UtilsTerminal } from 'tnp-core/browser';
4
- import { __decorate, __metadata, __param } from 'tslib';
5
- import { SYMBOL, CLASS } from 'typescript-class-helpers/browser';
6
- import { OrignalClassKey, Table } from 'taon-typeorm/browser';
7
- import { walk } from 'lodash-walk-object/browser';
8
- import * as i0 from '@angular/core';
9
- import { InjectionToken, inject as inject$1, Injectable } from '@angular/core';
10
4
  import axios from 'axios';
11
5
  import { JSON10 } from 'json10/browser';
6
+ import { walk } from 'lodash-walk-object/browser';
12
7
  import { RestResponseWrapper, Models as Models$1, Resource, RestHeaders, Mapping, HttpResponseError } from 'ng2-rest/browser';
13
8
  import { Observable, from, Subject } from 'rxjs';
9
+ import * as i0 from '@angular/core';
10
+ import { InjectionToken, inject as inject$1, Injectable, ViewContainerRef, ViewChild, Component } from '@angular/core';
11
+ import { Table, OrignalClassKey, Column } from 'taon-typeorm/browser';
12
+ export { AfterInsert, AfterLoad, AfterRecover, AfterRemove, AfterSoftRemove, AfterUpdate, BeforeInsert, BeforeRecover, BeforeRemove, BeforeSoftRemove, BeforeUpdate, Column, Connection, CreateDateColumn, Column as CustomColumn, DeleteDateColumn, Generated, Generated as GeneratedColumn, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryColumn, PrimaryGeneratedColumn, Repository, TreeChildren, TreeParent, UpdateDateColumn, VersionColumn, VirtualColumn } from 'taon-typeorm/browser';
13
+ import { SYMBOL, CLASS } from 'typescript-class-helpers/browser';
14
14
  import * as JSON5 from 'json5';
15
15
  import { io } from 'socket.io-client';
16
+ import { __decorate, __metadata, __param } from 'tslib';
17
+ import * as i1 from '@ngx-formly/core';
18
+ import { FieldWrapper, FieldArrayType } from '@ngx-formly/core';
16
19
 
17
- class DecoratorAbstractOpt {
18
- }
19
-
20
- class TaonControllerOptions extends DecoratorAbstractOpt {
21
- }
22
-
23
- // import { cloneObj } from '../helpers/clone-obj';
24
- // import { ParamConfig } from './param-config';
25
- class ControllerConfig extends TaonControllerOptions {
26
- }
27
- const controllerConfigFrom = (partial) => {
28
- const newObj = partial || {};
29
- newObj.methods = newObj.methods || {};
30
- for (const methodName in newObj.methods) {
31
- if (newObj.methods.hasOwnProperty(methodName)) {
32
- // newObj.methods[methodName] = new MethodConfig().clone(
33
- // newObj.methods[methodName],
34
- // );
35
- newObj.methods[methodName] = newObj.methods[methodName] || {};
36
- const params = newObj.methods[methodName].parameters || {};
37
- newObj.methods[methodName].parameters = params
38
- ? params
39
- : {};
40
- for (const paramName in params) {
41
- if (params.hasOwnProperty(paramName)) {
42
- params[paramName] = params[paramName] || {};
43
- // params[paramName] = new ParamConfig().clone(params[paramName]);
44
- }
45
- }
46
- }
47
- }
48
- return newObj;
49
- };
20
+ const TaonEntityKeysToOmitArr = [
21
+ 'ctrl',
22
+ 'clone',
23
+ '__endpoint_context__',
24
+ 'ctx',
25
+ 'inject',
26
+ '_',
27
+ 'relation',
28
+ 'relations',
29
+ 'inject',
30
+ 'injectRepo',
31
+ 'injectCustomRepository',
32
+ 'injectCustomRepo',
33
+ 'injectController',
34
+ 'injectCtrl',
35
+ 'injectProvider',
36
+ 'injectMiddleware',
37
+ ];
38
+ let TAON_CONTEXT;
39
+ //#region @browser
40
+ TAON_CONTEXT = new InjectionToken('TAON_CONTEXT');
41
+ //#endregion
42
+ let CURRENT_HOST_BACKEND_PORT;
43
+ //#region @browser
44
+ CURRENT_HOST_BACKEND_PORT = new InjectionToken('CURRENT_HOST_BACKEND_PORT');
45
+ //#endregion
46
+ let CURRENT_HOST_URL;
47
+ //#region @browser
48
+ CURRENT_HOST_URL = new InjectionToken('CURRENT_HOST_URL');
49
+ const apiPrefix = 'api';
50
50
 
51
- var Symbols;
52
- (function (Symbols) {
53
- Symbols.ctxInClassOrClassObj = Symbol();
54
- Symbols.classNameStaticProperty = SYMBOL.ClassNameStaticProperty;
55
- Symbols.fullClassNameStaticProperty = `$$fullclassName$$`;
56
- Symbols.orignalClass = OrignalClassKey;
57
- Symbols.orignalClassClonesObj = `$$originalClassClonesObj$$`;
58
- Symbols.classMethodsNames = `$$classMethodsNames$$`;
59
- /**
60
- * for backendSocket.in(ROOM_NAME).emit(EVENT)
61
- *
62
- * Room names are uniqe..
63
- * here I am limiting number of event for clients.
64
- */
65
- class Realtime {
66
- constructor() {
67
- this.KEYroomSubscribe = `roomSubscribe`;
68
- this.KEYroomUnsubscribe = `roomUnsubscribe`;
69
- //#endregion
70
- }
71
- NAMESPACE(contextName) {
72
- return `${contextName}-taonRealtimeNsp`;
73
- }
74
- TABLE_CHANGE(contextName, tableName) {
75
- return `${contextName}:listentablename${tableName}`;
76
- }
77
- // /**
78
- // * TODO use it or not?
79
- // * @deprecated
80
- // */
81
- // ROOM_NAME_SUBSCRIBER_EVENT(
82
- // contextName: string,
83
- // className: string,
84
- // propertyName: string,
85
- // ) {
86
- // return `${contextName}:room${_.camelCase(className)}${propertyName}`.toLowerCase();
87
- // }
88
- //#region custom events in rooms
89
- ROOM_NAME_CUSTOM(contextName, customEvent) {
90
- return `${contextName}:CustomRoomEvent${customEvent}`;
91
- }
92
- ROOM_SUBSCRIBE_CUSTOM(contextName) {
93
- return `${contextName}:${this.KEYroomSubscribe}CustomRoomEvent`;
94
- }
95
- ROOM_UNSUBSCRIBE_CUSTOM(contextName) {
96
- return `${contextName}:${this.KEYroomUnsubscribe}CustomRoomEvent`;
97
- }
51
+ class ContextDbMigrations {
52
+ //#endregion
53
+ //#endregion
54
+ //#region constructor
55
+ constructor(ctx) {
56
+ this.ctx = ctx;
57
+ //#region fields
58
+ //#region fields / migration table name
59
+ this.DEFAULT_MIGRATION_TABLE_NAME = 'TAON_MIGRATION_META';
98
60
  //#endregion
99
- //#region entity events
100
- ROOM_NAME_UPDATE_ENTITY(contextName, className, entityId) {
101
- return `${contextName}:room${_.camelCase(className)}${entityId}`.toLowerCase();
102
- }
103
- ROOM_SUBSCRIBE_ENTITY_UPDATE_EVENTS(contextName) {
104
- return `${contextName}:${this.KEYroomSubscribe}EntityEvents`;
105
- }
106
- ROOM_UNSUBSCRIBE_ENTITY_UPDATE_EVENTS(contextName) {
107
- return `${contextName}:${this.KEYroomUnsubscribe}EntityEvents`;
108
- }
61
+ //#region fields / migration statuses
62
+ this.MIGRATION_STATUS_COMPLETED = 'completed';
63
+ this.MIGRATION_STATUS_PENDING = 'pending';
109
64
  //#endregion
110
- //#region entity property events
111
- ROOM_NAME_UPDATE_ENTITY_PROPERTY(contextName, className, property, entityId) {
112
- return `${contextName}:room${_.camelCase(className)}${_.camelCase(property)}${entityId}`.toLowerCase();
113
- }
114
- ROOM_SUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(contextName) {
115
- return `${contextName}:${this.KEYroomSubscribe}EntityPropertyEvents`;
116
- }
117
- ROOM_UNSUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(contextName) {
118
- return `${contextName}:${this.KEYroomUnsubscribe}EntityPropertyEvents`;
119
- }
120
- }
121
- Symbols.REALTIME = new Realtime();
122
- Symbols.metadata = {
123
- className: `class:realname`,
124
- options: {
125
- controller: `controller:options`,
126
- entity: `entity:options`,
127
- repository: `repository:options`,
128
- provider: `provider:options`,
129
- subscriber: `subscriber:options`,
130
- migration: `migration:options`,
131
- },
132
- };
133
- Symbols.old = {
134
- HAS_TABLE_IN_DB: Symbol(),
135
- MDC_KEY: `modeldataconfig`,
136
- WEBSQL_REST_PROGRESS_FUN: Symbol(),
137
- WEBSQL_REST_PROGRESS_FUN_START: Symbol(),
138
- WEBSQL_REST_PROGRESS_FUN_DONE: Symbol(),
139
- WEBSQL_REST_PROGRESS_TIMEOUT: Symbol(),
140
- X_TOTAL_COUNT: `x-total-count`,
141
- CIRCURAL_OBJECTS_MAP_BODY: `circuralmapbody`,
142
- CIRCURAL_OBJECTS_MAP_QUERY_PARAM: `circuralmapbody`,
143
- MAPPING_CONFIG_HEADER: `mappingheader`,
144
- MAPPING_CONFIG_HEADER_BODY_PARAMS: `mhbodyparams`,
145
- MAPPING_CONFIG_HEADER_QUERY_PARAMS: `mhqueryparams`,
146
- ENDPOINT_META_CONFIG: `ng2_rest_endpoint_config`,
147
- CLASS_DECORATOR_CONTEXT: `$$ng2_rest_class_context`,
148
- SOCKET_MSG: `socketmessageng2rest`,
149
- ANGULAR: {
150
- INPUT_NAMES: Symbol(),
151
- },
152
- ERROR_MESSAGES: {
153
- CLASS_NAME_MATCH: `Please check if your "class name" matches @Controller( className ) or @Entity( className )`,
154
- },
155
- };
156
- })(Symbols || (Symbols = {}));
157
-
158
- var Validators;
159
- (function (Validators) {
160
- //#region vlidate class name
161
- Validators.classNameVlidation = (className, target) => {
162
- setTimeout(() => {
163
- // console.log(`check after timeout ${className} , production mode: ${FrameworkContext.isProductionMode}`)
164
- if (_.isUndefined(className)) {
165
- throw `[Taon]
166
- Please provide "className" property for each Controller and Entity:
167
-
168
- @Taon.Controller({ className: 'MyExampleCtrl' })
169
- class MyExampleCtrl {
170
- ...
171
- }
172
-
173
- @Taon.Entity({ className: 'MyExampleEntity' })
174
- class MyExampleEntity {
175
- ...
176
- }
177
-
178
- Notice that minified javascript code does not preserve
179
- Functions/Classes names -this is only solution to preserve classes names.
180
-
181
- `;
182
- }
65
+ //#region fields / migration table schema
66
+ this.table = new Table({
67
+ name: this.DEFAULT_MIGRATION_TABLE_NAME,
68
+ columns: [
69
+ {
70
+ name: 'id',
71
+ type: 'integer',
72
+ isPrimary: true, // Mark it as the primary key
73
+ isGenerated: true, // Enable auto-generation
74
+ generationStrategy: 'increment', // Use auto-increment strategy
75
+ },
76
+ {
77
+ name: 'name',
78
+ type: 'varchar',
79
+ length: '255',
80
+ isUnique: true, // Ensure the name is unique
81
+ isNullable: false, // Ensure this field is required
82
+ },
83
+ {
84
+ // context is a part of name
85
+ name: 'context',
86
+ type: 'varchar',
87
+ length: '255',
88
+ isNullable: false, // Optional context for migrations (e.g., tenant or module name)
89
+ },
90
+ {
91
+ name: 'applied_at',
92
+ type: 'timestamp',
93
+ default: 'CURRENT_TIMESTAMP', // Automatically set the timestamp
94
+ isNullable: true,
95
+ },
96
+ {
97
+ name: 'status',
98
+ type: 'varchar',
99
+ length: '50',
100
+ default: `'${this.MIGRATION_STATUS_COMPLETED}'`,
101
+ isNullable: false,
102
+ },
103
+ // { // TODO not needed for now
104
+ // name: 'checksum',
105
+ // type: 'varchar',
106
+ // length: '64',
107
+ // isNullable: true, // Optional field to store a hash/checksum of migration file
108
+ // },
109
+ ],
183
110
  });
184
- return _.isUndefined(className) ? target.name : className;
185
- };
186
- //#endregion
187
- //#region validate method config
188
- Validators.checkIfMethodsWithReponseTYpeAlowed = (methods, current) => {
189
- const defaultResponseType = 'text or JSON';
190
- if (!current.responseType) {
191
- return;
192
- }
193
- for (let index = 0; index < methods.length; index++) {
194
- const m = methods[index];
195
- if (m.path === current.path && m.responseType !== current.responseType) {
196
- throw new Error(`
197
- [taon] you can have 2 methods with same path but differetn reponseType-s
198
-
199
- ${m.methodName}( ... path: ${m.path} ) -> responseType: ${m.responseType || defaultResponseType}
200
- ${current.methodName}( ... path: ${current.path} ) -> responseType: ${current.responseType}
201
-
202
- Please change path name on of the methods.
203
-
204
- `);
205
- }
206
- }
207
- };
111
+ }
208
112
  //#endregion
209
- //#region validate class functions
210
- // TODO
211
- Validators.validateClassFunctions = (controllers, entities, proviers, repositories) => {
212
- if (_.isArray(controllers) &&
213
- controllers.filter(f => !_.isFunction(f)).length > 0) {
214
- console.error('controllers', controllers);
215
- throw `
216
-
217
- Incorect value for property "controllers" inside Taon.Init(...)
218
-
219
- `;
220
- }
221
- if (_.isArray(entities) &&
222
- entities.filter(f => !_.isFunction(f)).length > 0) {
223
- console.error('entites', entities);
224
- throw `
225
-
226
- Incorect value for property "entities" inside Taon.Init(...)
227
-
228
- `;
229
- }
230
- };
231
- //#endregion
232
- Validators.preventUndefinedModel = (model, id) => {
233
- if (_.isUndefined(model)) {
234
- throw `Bad update by id, config, id: ${id}`;
235
- }
236
- };
237
- })(Validators || (Validators = {}));
238
-
239
- //#region imports
240
- /* */
241
- //#endregion
242
- var ClassHelpers;
243
- (function (ClassHelpers) {
244
- //#region get class from name
245
- /**
246
- * TODO - repalce in every place when getting class fn from object
247
- */
248
- ClassHelpers.getClassFnFromObject = (json) => {
249
- if (_.isUndefined(json) || _.isNull(json)) {
250
- return;
251
- }
252
- if (json.constructor) {
253
- return json.constructor;
254
- }
255
- const p = Object.getPrototypeOf(json);
256
- return p && p.constructor && p.constructor.name !== 'Object'
257
- ? p.constructor
258
- : void 0;
259
- };
260
- //#endregion
261
- //#region get name
262
- ClassHelpers.getName = (classFnOrObject) => {
263
- // exception for FormData
264
- if (classFnOrObject instanceof FormData) {
265
- return 'FormData';
266
- }
267
- if (!classFnOrObject) {
268
- console.error('OBJECT OR CLASS', classFnOrObject);
269
- throw new Error(`Cannot get name from this object or class.`);
270
- }
271
- return ((classFnOrObject[Symbols.classNameStaticProperty]
272
- ? classFnOrObject[Symbols.classNameStaticProperty]
273
- : classFnOrObject?.constructor[Symbols.classNameStaticProperty]) ||
274
- (_.isFunction(classFnOrObject) ? CLASS.getName(classFnOrObject) : void 0));
275
- };
113
+ //#region methods & getters / make sure migration table exists
114
+ async ensureMigrationTableExists() {
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
+ return (void 0);
160
+ }
276
161
  //#endregion
277
- ClassHelpers.getOrginalClass = (classFnOrObject) => {
278
- const org = classFnOrObject[Symbols.orignalClass];
279
- if (!org) {
280
- return classFnOrObject;
281
- }
282
- return ClassHelpers.getOrginalClass(org);
283
- };
284
- //#region get full internal name
285
- ClassHelpers.getFullInternalName = (classFnOrObject) => {
286
- // exception for FormData
287
- if (!classFnOrObject) {
288
- throw new Error(`Cannot get name from: ${classFnOrObject}`);
289
- }
290
- return ((classFnOrObject[Symbols.fullClassNameStaticProperty]
291
- ? classFnOrObject[Symbols.fullClassNameStaticProperty]
292
- : classFnOrObject?.constructor[Symbols.fullClassNameStaticProperty]) ||
293
- void 0);
294
- };
162
+ //#region methods & getters / revert migration to timestamp
163
+ async logSelectALl(name, queryRunner) {
164
+ console.log(name, (await queryRunner.query(`SELECT * FROM ${this.DEFAULT_MIGRATION_TABLE_NAME} WHERE context = $1`, [this.ctx.contextName])).map(m => m.name));
165
+ }
166
+ async revertMigrationToTimestamp(timestamp) {
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
+ return (void 0);
263
+ }
295
264
  //#endregion
296
- //#region get unique key
297
- ClassHelpers.getUniqueKey = (classFnOrObject) => {
298
- const classFn = _.isFunction(classFnOrObject)
299
- ? classFnOrObject
300
- : classFnOrObject.constructor;
301
- const config = Reflect.getMetadata(Symbols.metadata.options.entity, classFn);
302
- return config.uniqueKeyProp;
303
- };
265
+ //#region methods & getters / clear migration table
266
+ async clearMigrationTable() {
267
+ /* */
268
+ /* */
269
+ /* */
270
+ /* */
271
+ /* */
272
+ /* */
273
+ /* */
274
+ /* */
275
+ /* */
276
+ /* */
277
+ /* */
278
+ /* */
279
+ /* */
280
+ /* */
281
+ /* */
282
+ /* */
283
+ /* */
284
+ /* */
285
+ return (void 0);
286
+ }
304
287
  //#endregion
305
- //#region is class object
306
- ClassHelpers.isContextClassObject = (obj) => {
307
- if (!_.isObject(obj) ||
308
- _.isArray(obj) ||
309
- _.isRegExp(obj) ||
310
- _.isBuffer(obj) ||
311
- _.isArrayBuffer(obj)) {
312
- return false;
313
- }
314
- if (_.isDate(obj)) {
315
- return true;
316
- }
317
- const className = ClassHelpers.getName(obj);
318
- return _.isString(className) && className !== 'Object';
319
- };
320
- //#endregion
321
- //#region get name
322
- ClassHelpers.setName = (target, className) => {
323
- // console.log('setName', className, target.name)
324
- Validators.classNameVlidation(className, target);
325
- target[Symbols.classNameStaticProperty] = className;
326
- };
288
+ //#region methods & getters / mark all migrations as applied
289
+ async markAllMigrationsAsApplied() {
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
+ return (void 0);
362
+ }
327
363
  //#endregion
328
- //#region has parent with class name
329
- ClassHelpers.hasParentClassWithName = (target, className, targets = []) => {
330
- if (!target) {
331
- return false;
332
- }
333
- targets.push(target);
334
- let targetProto = Object.getPrototypeOf(target);
335
- if (_.isFunction(targetProto) &&
336
- ClassHelpers.getName(targetProto) === className) {
337
- // console.log(`true "${_.first(targets).name}" for ${targets.map(d => d.name).join(',')}`)
338
- return true;
364
+ //#region methods & getters / run all migrations
365
+ async runAllNotCompletedMigrations() {
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
+ /* */
447
+ /* */
448
+ /* */
449
+ /* */
450
+ /* */
451
+ /* */
452
+ /* */
453
+ /* */
454
+ /* */
455
+ /* */
456
+ /* */
457
+ /* */
458
+ /* */
459
+ /* */
460
+ /* */
461
+ /* */
462
+ /* */
463
+ /* */
464
+ /* */
465
+ /* */
466
+ /* */
467
+ /* */
468
+ /* */
469
+ /* */
470
+ /* */
471
+ /* */
472
+ /* */
473
+ /* */
474
+ /* */
475
+ /* */
476
+ /* */
477
+ /* */
478
+ /* */
479
+ /* */
480
+ /* */
481
+ /* */
482
+ /* */
483
+ /* */
484
+ /* */
485
+ /* */
486
+ /* */
487
+ /* */
488
+ /* */
489
+ /* */
490
+ /* */
491
+ /* */
492
+ /* */
493
+ /* */
494
+ /* */
495
+ return (void 0);
496
+ }
497
+ }
498
+
499
+ class DITaonContainer {
500
+ static { this.instances = new Map(); }
501
+ static resolve(target) {
502
+ if (DITaonContainer.instances.has(target)) {
503
+ return DITaonContainer.instances.get(target);
339
504
  }
340
- return ClassHelpers.hasParentClassWithName(targetProto, className, targets);
341
- };
342
- //#endregion
343
- //#region get methods name
344
- //#region not allowed as method name
345
- const notAllowedAsMethodName = [
346
- 'length',
347
- 'name',
348
- 'arguments',
349
- 'caller',
350
- 'constructor',
351
- 'apply',
352
- 'bind',
353
- 'call',
354
- 'toString',
355
- '__defineGetter__',
356
- '__defineSetter__',
357
- 'hasOwnProperty',
358
- '__lookupGetter__',
359
- '__lookupSetter__',
360
- 'isPrototypeOf',
361
- 'propertyIsEnumerable',
362
- 'valueOf',
363
- '__proto__',
364
- 'toLocaleString',
365
- ];
366
- //#endregion
367
- /**
368
- * Express async handler for middleware functions.
369
- */
370
- ClassHelpers.asyncHandler = fn => (req, res, next) => {
371
- Promise.resolve(fn(req, res, next)).catch(next);
372
- };
373
- ClassHelpers.getMethodsNames = (classOrClassInstance, allMethodsNames = []) => {
374
- if (!classOrClassInstance) {
375
- return Utils.uniqArray(allMethodsNames);
376
- }
377
- const isClassFunction = _.isFunction(classOrClassInstance);
378
- const classFun = isClassFunction
379
- ? classOrClassInstance
380
- : Object.getPrototypeOf(classOrClassInstance);
381
- const objectToCheck = isClassFunction
382
- ? classOrClassInstance?.prototype
383
- : classOrClassInstance;
384
- const prototypeObj = Object.getPrototypeOf(objectToCheck || {});
385
- const properties = _.uniq([
386
- ...Object.getOwnPropertyNames(objectToCheck || {}),
387
- ...Object.getOwnPropertyNames(prototypeObj || {}),
388
- ...Object.keys(objectToCheck || {}),
389
- ...Object.keys(prototypeObj || {}),
390
- ]).filter(f => !!f && !notAllowedAsMethodName.includes(f));
391
- properties
392
- .filter(methodName => typeof objectToCheck[methodName] === 'function')
393
- .forEach(p => allMethodsNames.push(p));
394
- if (!classFun ||
395
- !classFun.constructor ||
396
- classFun?.constructor?.name === 'Object') {
397
- return Utils.uniqArray(allMethodsNames);
398
- }
399
- return ClassHelpers.getMethodsNames(Object.getPrototypeOf(classFun), allMethodsNames);
400
- };
401
- //#endregion
402
- //#region get controller configs
403
- ClassHelpers.getControllerConfigs = (target, configs = [], callerTarget) => {
404
- if (!_.isFunction(target)) {
405
- throw `[typescript-class-helper][getControllerConfigs] Cannot get class config from: ${target}`;
406
- }
407
- let config;
408
- const parentClass = Object.getPrototypeOf(target);
409
- const parentName = parentClass ? ClassHelpers.getName(parentClass) : void 0;
410
- const isValidParent = _.isFunction(parentClass) && parentName !== '';
411
- config = controllerConfigFrom(ClassHelpers.getClassConfig(target));
412
- configs.push(config);
413
- return isValidParent
414
- ? ClassHelpers.getControllerConfigs(parentClass, configs, target)
415
- : configs;
416
- };
417
- //#endregion
418
- //#region ensure configs
419
- // Ensure ClassConfig on constructor, clone parent if needed
420
- ClassHelpers.ensureClassConfig = (target) => {
421
- let cfg = Reflect.getOwnMetadata(Symbols.metadata.options.controller, // META_KEYS.class,
422
- target);
423
- if (!cfg) {
424
- cfg = { methods: {} };
425
- const parent = Object.getPrototypeOf(target);
426
- if (parent && parent !== Function.prototype) {
427
- const parentCfg = Reflect.getMetadata(Symbols.metadata.options.controller, // META_KEYS.class,
428
- parent);
429
- if (parentCfg) {
430
- // Deep copy each method config so child gets its own objects
431
- const clonedMethods = {};
432
- for (const [k, v] of Object.entries(parentCfg.methods)) {
433
- clonedMethods[k] = {
434
- ...v,
435
- parameters: { ...v.parameters }, // shallow clone parameters too
436
- };
437
- }
438
- cfg = {
439
- ...parentCfg,
440
- methods: clonedMethods,
441
- };
505
+ // const tokens = Reflect.getMetadata('design:paramtypes', target) || [];
506
+ const injections = []; // tokens.map(token => Container.inject<any>(token));
507
+ const instance = new target(...injections);
508
+ DITaonContainer.instances.set(target, instance);
509
+ return instance;
510
+ }
511
+ static inject(target) {
512
+ return new Proxy({}, {
513
+ get: (_, propName) => {
514
+ let instance = DITaonContainer.instances.get(target) ||
515
+ DITaonContainer.resolve(target);
516
+ return typeof instance[propName] === 'function'
517
+ ? instance[propName].bind(instance)
518
+ : instance[propName];
519
+ },
520
+ set: (_, propName, value) => {
521
+ let instance = DITaonContainer.instances.get(target) ||
522
+ DITaonContainer.resolve(target);
523
+ instance[propName] = value;
524
+ return true;
525
+ },
526
+ });
527
+ }
528
+ }
529
+
530
+ const getResponseValue = (response, options) => {
531
+ /* */
532
+ /* */
533
+ /* */
534
+ /* */
535
+ /* */
536
+ /* */
537
+ /* */
538
+ /* */
539
+ /* */
540
+ /* */
541
+ /* */
542
+ /* */
543
+ /* */
544
+ /* */
545
+ /* */
546
+ /* */
547
+ /* */
548
+ /* */
549
+ return (void 0);
550
+ };
551
+
552
+ class DecoratorAbstractOpt {
553
+ }
554
+
555
+ class TaonControllerOptions extends DecoratorAbstractOpt {
556
+ }
557
+
558
+ // import { cloneObj } from '../helpers/clone-obj';
559
+ // import { ParamConfig } from './param-config';
560
+ class ControllerConfig extends TaonControllerOptions {
561
+ }
562
+ const controllerConfigFrom = (partial) => {
563
+ const newObj = partial || {};
564
+ newObj.methods = newObj.methods || {};
565
+ for (const methodName in newObj.methods) {
566
+ if (newObj.methods.hasOwnProperty(methodName)) {
567
+ // newObj.methods[methodName] = new MethodConfig().clone(
568
+ // newObj.methods[methodName],
569
+ // );
570
+ newObj.methods[methodName] = newObj.methods[methodName] || {};
571
+ const params = newObj.methods[methodName].parameters || {};
572
+ newObj.methods[methodName].parameters = params
573
+ ? params
574
+ : {};
575
+ for (const paramName in params) {
576
+ if (params.hasOwnProperty(paramName)) {
577
+ params[paramName] = params[paramName] || {};
578
+ // params[paramName] = new ParamConfig().clone(params[paramName]);
442
579
  }
443
580
  }
444
- Reflect.defineMetadata(Symbols.metadata.options.controller, cfg, target);
445
- }
446
- return cfg;
447
- };
448
- // Ensure MethodConfig inside ClassConfig
449
- ClassHelpers.ensureMethodConfig = (target, propertyKey) => {
450
- const classCfg = ClassHelpers.ensureClassConfig(target.constructor);
451
- let methodCfg = classCfg.methods[propertyKey?.toString()];
452
- if (!methodCfg) {
453
- methodCfg = { methodName: propertyKey?.toString(), parameters: {} };
454
- classCfg.methods[propertyKey?.toString()] = methodCfg;
455
- }
456
- return methodCfg;
457
- };
458
- ClassHelpers.getClassConfig = (constructor) => {
459
- return Reflect.getMetadata(Symbols.metadata.options.controller, constructor);
460
- };
461
- //#endregion
462
- })(ClassHelpers || (ClassHelpers = {}));
463
-
464
- const cloneObj = (override, classFn) => {
465
- const result = _.merge(new classFn(), _.cloneDeep(this));
466
- walk.Object(override || {}, (value, lodashPath) => {
467
- if (_.isNil(value) || _.isFunction(value) || _.isObject(value)) {
468
- // skipping
469
- }
470
- else {
471
- _.set(result, lodashPath, value);
472
581
  }
473
- }, {
474
- walkGetters: false,
475
- });
476
- // console.log({result})
477
- return result;
582
+ }
583
+ return newObj;
478
584
  };
479
585
 
480
- //#endregion
481
- class TaonBaseClass {
482
- //#region class initialization hook
483
- /**
484
- * class initialization hook
485
- * taon after class instance creation
486
- */
487
- async _() { }
586
+ /**
587
+ * for backendSocket.in(ROOM_NAME).emit(EVENT)
588
+ *
589
+ * Room names are uniqe..
590
+ * here I am limiting number of event for clients.
591
+ */
592
+ class Realtime {
593
+ constructor() {
594
+ this.KEYroomSubscribe = `roomSubscribe`;
595
+ this.KEYroomUnsubscribe = `roomUnsubscribe`;
596
+ //#endregion
597
+ }
598
+ NAMESPACE(contextName) {
599
+ return `${contextName}-taonRealtimeNsp`;
600
+ }
601
+ TABLE_CHANGE(contextName, tableName) {
602
+ return `${contextName}:listentablename${tableName}`;
603
+ }
604
+ // /**
605
+ // * TODO use it or not?
606
+ // * @deprecated
607
+ // */
608
+ // ROOM_NAME_SUBSCRIBER_EVENT(
609
+ // contextName: string,
610
+ // className: string,
611
+ // propertyName: string,
612
+ // ) {
613
+ // return `${contextName}:room${_.camelCase(className)}${propertyName}`.toLowerCase();
614
+ // }
615
+ //#region custom events in rooms
616
+ ROOM_NAME_CUSTOM(contextName, customEvent) {
617
+ return `${contextName}:CustomRoomEvent${customEvent}`;
618
+ }
619
+ ROOM_SUBSCRIBE_CUSTOM(contextName) {
620
+ return `${contextName}:${this.KEYroomSubscribe}CustomRoomEvent`;
621
+ }
622
+ ROOM_UNSUBSCRIBE_CUSTOM(contextName) {
623
+ return `${contextName}:${this.KEYroomUnsubscribe}CustomRoomEvent`;
624
+ }
488
625
  //#endregion
489
- //#region clone
490
- /**
491
- *
492
- * @param overrideObjOrFn if object is provided it will override values in cloned object,
493
- * if function is provided it will be called with old cloned values and should return
494
- * object with values to override
495
- * @returns cloned instance of the class
496
- */
497
- clone(overrideObjOrFn) {
498
- if (_.isString(overrideObjOrFn)) {
499
- console.log(overrideObjOrFn);
500
- throw new Error('String is not supported as .clone() method argument');
501
- }
502
- const classFn = ClassHelpers.getClassFnFromObject(this);
503
- if (_.isFunction(overrideObjOrFn)) {
504
- // console.log('clone with fn');
505
- const oldValues = (_.cloneDeep(this) || {});
506
- return cloneObj(overrideObjOrFn(oldValues), classFn);
507
- }
508
- // console.log('clone normal');
509
- return cloneObj(overrideObjOrFn, classFn);
626
+ //#region entity events
627
+ ROOM_NAME_UPDATE_ENTITY(contextName, className, entityId) {
628
+ return `${contextName}:room${_.camelCase(className)}${entityId}`.toLowerCase();
510
629
  }
511
- }
512
-
513
- let EntityDecorator$1 = () => {
514
- return (target) => { };
515
- };
516
- /* */
517
- /* */
518
- let TaonBaseEntity = class TaonBaseEntity extends TaonBaseClass {
519
- /**
520
- * simple check if relation is ok
521
- */
522
- relation(relationName) {
523
- return relationName;
630
+ ROOM_SUBSCRIBE_ENTITY_UPDATE_EVENTS(contextName) {
631
+ return `${contextName}:${this.KEYroomSubscribe}EntityEvents`;
524
632
  }
525
- /**
526
- * simple check if relation is ok
527
- */
528
- relations(relationNames) {
529
- return relationNames;
633
+ ROOM_UNSUBSCRIBE_ENTITY_UPDATE_EVENTS(contextName) {
634
+ return `${contextName}:${this.KEYroomUnsubscribe}EntityEvents`;
530
635
  }
531
- };
532
- TaonBaseEntity = __decorate([
533
- EntityDecorator$1()
534
- ], TaonBaseEntity);
535
-
536
- /* */
537
- /* */
538
- // empty decorator
539
- let EntityDecorator = () => {
540
- return (target) => { };
541
- };
542
- /* */
543
- /* */
544
- let TaonBaseAbstractEntity = class TaonBaseAbstractEntity extends TaonBaseEntity {
545
- };
546
- TaonBaseAbstractEntity = __decorate([
547
- EntityDecorator()
548
- ], TaonBaseAbstractEntity);
549
-
550
- const TaonEntityKeysToOmitArr = [
551
- 'ctrl',
552
- 'clone',
553
- '__endpoint_context__',
554
- 'ctx',
555
- 'inject',
556
- '_',
557
- 'relation',
558
- 'relations',
559
- 'inject',
560
- 'injectRepo',
561
- 'injectCustomRepository',
562
- 'injectCustomRepo',
563
- 'injectController',
564
- 'injectCtrl',
565
- 'injectProvider',
566
- 'injectMiddleware',
567
- ];
568
- let TAON_CONTEXT;
569
- //#region @browser
570
- TAON_CONTEXT = new InjectionToken('TAON_CONTEXT');
571
- //#endregion
572
- let CURRENT_HOST_BACKEND_PORT;
573
- //#region @browser
574
- CURRENT_HOST_BACKEND_PORT = new InjectionToken('CURRENT_HOST_BACKEND_PORT');
575
- //#endregion
576
- let CURRENT_HOST_URL;
577
- //#region @browser
578
- CURRENT_HOST_URL = new InjectionToken('CURRENT_HOST_URL');
579
- const apiPrefix = 'api';
580
-
581
- const inject = (entity) => {
582
- return new Proxy({}, {
583
- get: (_, propName) => {
584
- if (propName === 'hasOwnProperty') {
585
- return () => false;
586
- }
587
- const ctor = entity();
588
- const contextFromClass = ctor[Symbols.ctxInClassOrClassObj];
589
- const resultContext = contextFromClass;
590
- if (resultContext) {
591
- let instance = resultContext.inject(ctor, {
592
- parentInstanceThatWillGetInjectedStuff: this,
593
- });
594
- // console.log('instance', instance);
595
- if (propName === 'getOriginalPrototype') {
596
- return () => Object.getPrototypeOf(instance);
597
- }
598
- if (propName === 'getOriginalConstructor') {
599
- return () => instance.constructor;
600
- }
601
- const methods = ctor[Symbols.classMethodsNames] || [];
602
- const isMethods = methods.includes(propName);
603
- const methodOrProperty = isMethods
604
- ? instance[propName].bind(instance)
605
- : instance[propName];
606
- // console.log(
607
- // `methodOrProperty from proxy ${propName?.toString()} = isMethods:${isMethods}`,
608
- // methods,
609
- // );
610
- return methodOrProperty;
611
- }
612
- },
613
- });
614
- };
615
- // export const injectController = inject;
616
- // export type SubscriptionEvent<T> = {
617
- // name: keyof T;
618
- // data: any;
619
- // };
620
- /**
621
- * TODO
622
- */
623
- // export const injectEntityEvents = <T>(
624
- // subscriberClassResolveFn: () => new (...args: any[]) => T,
625
- // eventName?: keyof Omit<EntitySubscriberInterface,'listenTo'> ,
626
- // ): Observable<SubscriptionEvent<T>> => {
627
- // const eventsSrc = new Subject<SubscriptionEvent<T>>();
628
- // const obs = eventsSrc.asObservable();
629
- // let isFirstSubscription = true;
630
- // const proxyObservable = new Proxy(obs, {
631
- // get(target, prop, receiver) {
632
- // if (prop === 'subscribe') {
633
- // return (...args: any[]) => {
634
- // if (isFirstSubscription) {
635
- // isFirstSubscription = false;
636
- // const subscriberClassFN: typeof TaonBaseClass =
637
- // subscriberClassResolveFn() as any;
638
- // const ctx = subscriberClassFN[
639
- // Symbols.ctxInClassOrClassObj
640
- // ] as EndpointContext;
641
- // if (!ctx) {
642
- // throw new Error(
643
- // `You are trying to inject class without context. Use context like this:
644
- // class MyClassSubscriber extends BaseSubscriber {
645
- // ${eventName as any}() {
646
- // \/\/ your code here
647
- // }
648
- // }
649
- // Taon.injectSubscriberEvents( MyContext.getInstance(()=> MyClassSubscriber), '${eventName as any}' )
650
- // `,
651
- // );
652
- // }
653
- // const subscriberInstance = ctx.getInstanceBy(subscriberClassFN);
654
- // // subscriberInstance TODO @LAST subscriber event from instance
655
- // // const entity = subscriberClassFN.prototype.listenTo();
656
- // console.log('First subscription, you can access arguments here:', {
657
- // subscriberClassFN,
658
- // eventName,
659
- // });
660
- // }
661
- // return target.subscribe(...args);
662
- // };
663
- // }
664
- // return Reflect.get(target, prop, receiver);
665
- // },
666
- // });
667
- // return proxyObservable as Observable<SubscriptionEvent<T>>;
668
- // };
669
-
670
- /**
671
- * TODO prevent calling methods when not initialized
672
- * with init(ctx)
673
- */
674
- //#region @browser
675
- //#endregion
676
- class BaseAngularsService {
677
636
  //#endregion
678
- constructor() {
679
- //#region @browser
680
- this.currentContext = inject$1(TAON_CONTEXT);
681
- //#region @browser
682
- this.CURRENT_HOST_BACKEND_PORT = inject$1(CURRENT_HOST_BACKEND_PORT, {
683
- optional: true,
684
- });
685
- this.CURRENT_HOST_URL = inject$1(CURRENT_HOST_URL, {
686
- optional: true,
687
- });
688
- // #endregion
637
+ //#region entity property events
638
+ ROOM_NAME_UPDATE_ENTITY_PROPERTY(contextName, className, property, entityId) {
639
+ return `${contextName}:room${_.camelCase(className)}${_.camelCase(property)}${entityId}`.toLowerCase();
689
640
  }
690
- /**
691
- * @deprecated
692
- * Returns the host URL for the backend service
693
- * that is running on localhost (normal NodeJS/ExpressJS mode).
694
- */
695
- get host() {
696
- //#region @browser
697
- if (this.CURRENT_HOST_URL) {
698
- return this.CURRENT_HOST_URL;
699
- }
700
- return `http://localhost:${this.CURRENT_HOST_BACKEND_PORT}`;
701
- //#endregion
702
- return void 0;
641
+ ROOM_SUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(contextName) {
642
+ return `${contextName}:${this.KEYroomSubscribe}EntityPropertyEvents`;
703
643
  }
704
- injectController(ctor,
705
- /**
706
- * optional override context
707
- */
708
- overrideCurrentContext) {
709
- return inject(() => {
710
- let currentContext;
711
- //#region @browser
712
- currentContext = overrideCurrentContext
713
- ? overrideCurrentContext
714
- : this.currentContext;
715
- //#endregion
716
- if (!currentContext) {
717
- throw new Error('No context available. Make sure to initialize the context before injecting controllers.');
718
- }
719
- return currentContext ? currentContext.getClass(ctor) : void 0;
720
- });
644
+ ROOM_UNSUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(contextName) {
645
+ return `${contextName}:${this.KEYroomUnsubscribe}EntityPropertyEvents`;
721
646
  }
722
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
723
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService }); }
724
647
  }
725
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService, decorators: [{
726
- type: Injectable
727
- }], ctorParameters: () => [] });
648
+ var Symbols;
649
+ (function (Symbols) {
650
+ Symbols.ctxInClassOrClassObj = Symbol();
651
+ Symbols.classNameStaticProperty = SYMBOL.ClassNameStaticProperty;
652
+ Symbols.fullClassNameStaticProperty = `$$fullclassName$$`;
653
+ Symbols.orignalClass = OrignalClassKey;
654
+ Symbols.orignalClassClonesObj = `$$originalClassClonesObj$$`;
655
+ Symbols.classMethodsNames = `$$classMethodsNames$$`;
656
+ Symbols.REALTIME = new Realtime();
657
+ Symbols.metadata = {
658
+ className: `class:realname`,
659
+ options: {
660
+ controller: `controller:options`,
661
+ entity: `entity:options`,
662
+ repository: `repository:options`,
663
+ provider: `provider:options`,
664
+ subscriber: `subscriber:options`,
665
+ migration: `migration:options`,
666
+ },
667
+ };
668
+ Symbols.old = {
669
+ HAS_TABLE_IN_DB: Symbol(),
670
+ MDC_KEY: `modeldataconfig`,
671
+ WEBSQL_REST_PROGRESS_FUN: Symbol(),
672
+ WEBSQL_REST_PROGRESS_FUN_START: Symbol(),
673
+ WEBSQL_REST_PROGRESS_FUN_DONE: Symbol(),
674
+ WEBSQL_REST_PROGRESS_TIMEOUT: Symbol(),
675
+ X_TOTAL_COUNT: `x-total-count`,
676
+ CIRCURAL_OBJECTS_MAP_BODY: `circuralmapbody`,
677
+ CIRCURAL_OBJECTS_MAP_QUERY_PARAM: `circuralmapbody`,
678
+ MAPPING_CONFIG_HEADER: `mappingheader`,
679
+ MAPPING_CONFIG_HEADER_BODY_PARAMS: `mhbodyparams`,
680
+ MAPPING_CONFIG_HEADER_QUERY_PARAMS: `mhqueryparams`,
681
+ ENDPOINT_META_CONFIG: `ng2_rest_endpoint_config`,
682
+ CLASS_DECORATOR_CONTEXT: `$$ng2_rest_class_context`,
683
+ SOCKET_MSG: `socketmessageng2rest`,
684
+ ANGULAR: {
685
+ INPUT_NAMES: Symbol(),
686
+ },
687
+ ERROR_MESSAGES: {
688
+ CLASS_NAME_MATCH: `Please check if your "class name" matches @Controller( className ) or @Entity( className )`,
689
+ },
690
+ };
691
+ })(Symbols || (Symbols = {}));
728
692
 
729
- class ContextDbMigrations {
730
- //#endregion
693
+ var Validators;
694
+ (function (Validators) {
695
+ //#region vlidate class name
696
+ Validators.classNameVlidation = (className, target) => {
697
+ setTimeout(() => {
698
+ // console.log(`check after timeout ${className} , production mode: ${FrameworkContext.isProductionMode}`)
699
+ if (_.isUndefined(className)) {
700
+ throw `[Taon]
701
+ Please provide "className" property for each Controller and Entity:
702
+
703
+ @Taon.Controller({ className: 'MyExampleCtrl' })
704
+ class MyExampleCtrl {
705
+ ...
706
+ }
707
+
708
+ @Taon.Entity({ className: 'MyExampleEntity' })
709
+ class MyExampleEntity {
710
+ ...
711
+ }
712
+
713
+ Notice that minified javascript code does not preserve
714
+ Functions/Classes names -this is only solution to preserve classes names.
715
+
716
+ `;
717
+ }
718
+ });
719
+ return _.isUndefined(className) ? target.name : className;
720
+ };
731
721
  //#endregion
732
- //#region constructor
733
- constructor(ctx) {
734
- this.ctx = ctx;
735
- //#region fields
736
- //#region fields / migration table name
737
- this.DEFAULT_MIGRATION_TABLE_NAME = 'TAON_MIGRATION_META';
738
- //#endregion
739
- //#region fields / migration statuses
740
- this.MIGRATION_STATUS_COMPLETED = 'completed';
741
- this.MIGRATION_STATUS_PENDING = 'pending';
742
- //#endregion
743
- //#region fields / migration table schema
744
- this.table = new Table({
745
- name: this.DEFAULT_MIGRATION_TABLE_NAME,
746
- columns: [
747
- {
748
- name: 'id',
749
- type: 'integer',
750
- isPrimary: true, // Mark it as the primary key
751
- isGenerated: true, // Enable auto-generation
752
- generationStrategy: 'increment', // Use auto-increment strategy
753
- },
754
- {
755
- name: 'name',
756
- type: 'varchar',
757
- length: '255',
758
- isUnique: true, // Ensure the name is unique
759
- isNullable: false, // Ensure this field is required
760
- },
761
- {
762
- // context is a part of name
763
- name: 'context',
764
- type: 'varchar',
765
- length: '255',
766
- isNullable: false, // Optional context for migrations (e.g., tenant or module name)
767
- },
768
- {
769
- name: 'applied_at',
770
- type: 'timestamp',
771
- default: 'CURRENT_TIMESTAMP', // Automatically set the timestamp
772
- isNullable: true,
773
- },
774
- {
775
- name: 'status',
776
- type: 'varchar',
777
- length: '50',
778
- default: `'${this.MIGRATION_STATUS_COMPLETED}'`,
779
- isNullable: false,
780
- },
781
- // { // TODO not needed for now
782
- // name: 'checksum',
783
- // type: 'varchar',
784
- // length: '64',
785
- // isNullable: true, // Optional field to store a hash/checksum of migration file
786
- // },
787
- ],
788
- });
789
- }
790
- //#endregion
791
- //#region methods & getters / make sure migration table exists
792
- async ensureMigrationTableExists() {
793
- /* */
794
- /* */
795
- /* */
796
- /* */
797
- /* */
798
- /* */
799
- /* */
800
- /* */
801
- /* */
802
- /* */
803
- /* */
804
- /* */
805
- /* */
806
- /* */
807
- /* */
808
- /* */
809
- /* */
810
- /* */
811
- /* */
812
- /* */
813
- /* */
814
- /* */
815
- /* */
816
- /* */
817
- /* */
818
- /* */
819
- /* */
820
- /* */
821
- /* */
822
- /* */
823
- /* */
824
- /* */
825
- /* */
826
- /* */
827
- /* */
828
- /* */
829
- /* */
830
- /* */
831
- /* */
832
- /* */
833
- /* */
834
- /* */
835
- /* */
836
- /* */
837
- return (void 0);
838
- }
722
+ //#region validate method config
723
+ Validators.checkIfMethodsWithReponseTYpeAlowed = (methods, current) => {
724
+ const defaultResponseType = 'text or JSON';
725
+ if (!current.responseType) {
726
+ return;
727
+ }
728
+ for (let index = 0; index < methods.length; index++) {
729
+ const m = methods[index];
730
+ if (m.path === current.path && m.responseType !== current.responseType) {
731
+ throw new Error(`
732
+ [taon] you can have 2 methods with same path but differetn reponseType-s
733
+
734
+ ${m.methodName}( ... path: ${m.path} ) -> responseType: ${m.responseType || defaultResponseType}
735
+ ${current.methodName}( ... path: ${current.path} ) -> responseType: ${current.responseType}
736
+
737
+ Please change path name on of the methods.
738
+
739
+ `);
740
+ }
741
+ }
742
+ };
839
743
  //#endregion
840
- //#region methods & getters / revert migration to timestamp
841
- async logSelectALl(name, queryRunner) {
842
- console.log(name, (await queryRunner.query(`SELECT * FROM ${this.DEFAULT_MIGRATION_TABLE_NAME} WHERE context = $1`, [this.ctx.contextName])).map(m => m.name));
843
- }
844
- async revertMigrationToTimestamp(timestamp) {
845
- /* */
846
- /* */
847
- /* */
848
- /* */
849
- /* */
850
- /* */
851
- /* */
852
- /* */
853
- /* */
854
- /* */
855
- /* */
856
- /* */
857
- /* */
858
- /* */
859
- /* */
860
- /* */
861
- /* */
862
- /* */
863
- /* */
864
- /* */
865
- /* */
866
- /* */
867
- /* */
868
- /* */
869
- /* */
870
- /* */
871
- /* */
872
- /* */
873
- /* */
874
- /* */
875
- /* */
876
- /* */
877
- /* */
878
- /* */
879
- /* */
880
- /* */
881
- /* */
882
- /* */
883
- /* */
884
- /* */
885
- /* */
886
- /* */
887
- /* */
888
- /* */
889
- /* */
890
- /* */
891
- /* */
892
- /* */
893
- /* */
894
- /* */
895
- /* */
896
- /* */
897
- /* */
898
- /* */
899
- /* */
900
- /* */
901
- /* */
902
- /* */
903
- /* */
904
- /* */
905
- /* */
906
- /* */
907
- /* */
908
- /* */
909
- /* */
910
- /* */
911
- /* */
912
- /* */
913
- /* */
914
- /* */
915
- /* */
916
- /* */
917
- /* */
918
- /* */
919
- /* */
920
- /* */
921
- /* */
922
- /* */
923
- /* */
924
- /* */
925
- /* */
926
- /* */
927
- /* */
928
- /* */
929
- /* */
930
- /* */
931
- /* */
932
- /* */
933
- /* */
934
- /* */
935
- /* */
936
- /* */
937
- /* */
938
- /* */
939
- /* */
940
- return (void 0);
941
- }
744
+ //#region validate class functions
745
+ // TODO
746
+ Validators.validateClassFunctions = (controllers, entities, proviers, repositories) => {
747
+ if (_.isArray(controllers) &&
748
+ controllers.filter(f => !_.isFunction(f)).length > 0) {
749
+ console.error('controllers', controllers);
750
+ throw `
751
+
752
+ Incorect value for property "controllers" inside Taon.Init(...)
753
+
754
+ `;
755
+ }
756
+ if (_.isArray(entities) &&
757
+ entities.filter(f => !_.isFunction(f)).length > 0) {
758
+ console.error('entites', entities);
759
+ throw `
760
+
761
+ Incorect value for property "entities" inside Taon.Init(...)
762
+
763
+ `;
764
+ }
765
+ };
942
766
  //#endregion
943
- //#region methods & getters / clear migration table
944
- async clearMigrationTable() {
945
- /* */
946
- /* */
947
- /* */
948
- /* */
949
- /* */
950
- /* */
951
- /* */
952
- /* */
953
- /* */
954
- /* */
955
- /* */
956
- /* */
957
- /* */
958
- /* */
959
- /* */
960
- /* */
961
- /* */
962
- /* */
963
- return (void 0);
964
- }
767
+ Validators.preventUndefinedModel = (model, id) => {
768
+ if (_.isUndefined(model)) {
769
+ throw `Bad update by id, config, id: ${id}`;
770
+ }
771
+ };
772
+ })(Validators || (Validators = {}));
773
+
774
+ //#region imports
775
+ /* */
776
+ //#endregion
777
+ var ClassHelpers;
778
+ (function (ClassHelpers) {
779
+ //#region get class from name
780
+ /**
781
+ * TODO - repalce in every place when getting class fn from object
782
+ */
783
+ ClassHelpers.getClassFnFromObject = (json) => {
784
+ if (_.isUndefined(json) || _.isNull(json)) {
785
+ return;
786
+ }
787
+ if (json.constructor) {
788
+ return json.constructor;
789
+ }
790
+ const p = Object.getPrototypeOf(json);
791
+ return p && p.constructor && p.constructor.name !== 'Object'
792
+ ? p.constructor
793
+ : void 0;
794
+ };
965
795
  //#endregion
966
- //#region methods & getters / mark all migrations as applied
967
- async markAllMigrationsAsApplied() {
968
- /* */
969
- /* */
970
- /* */
971
- /* */
972
- /* */
973
- /* */
974
- /* */
975
- /* */
976
- /* */
977
- /* */
978
- /* */
979
- /* */
980
- /* */
981
- /* */
982
- /* */
983
- /* */
984
- /* */
985
- /* */
986
- /* */
987
- /* */
988
- /* */
989
- /* */
990
- /* */
991
- /* */
992
- /* */
993
- /* */
994
- /* */
995
- /* */
996
- /* */
997
- /* */
998
- /* */
999
- /* */
1000
- /* */
1001
- /* */
1002
- /* */
1003
- /* */
1004
- /* */
1005
- /* */
1006
- /* */
1007
- /* */
1008
- /* */
1009
- /* */
1010
- /* */
1011
- /* */
1012
- /* */
1013
- /* */
1014
- /* */
1015
- /* */
1016
- /* */
1017
- /* */
1018
- /* */
1019
- /* */
1020
- /* */
1021
- /* */
1022
- /* */
1023
- /* */
1024
- /* */
1025
- /* */
1026
- /* */
1027
- /* */
1028
- /* */
1029
- /* */
1030
- /* */
1031
- /* */
1032
- /* */
1033
- /* */
1034
- /* */
1035
- /* */
1036
- /* */
1037
- /* */
1038
- /* */
1039
- return (void 0);
1040
- }
796
+ //#region get name
797
+ ClassHelpers.getName = (classFnOrObject) => {
798
+ // exception for FormData
799
+ if (classFnOrObject instanceof FormData) {
800
+ return 'FormData';
801
+ }
802
+ if (!classFnOrObject) {
803
+ console.error('OBJECT OR CLASS', classFnOrObject);
804
+ throw new Error(`Cannot get name from this object or class.`);
805
+ }
806
+ return ((classFnOrObject[Symbols.classNameStaticProperty]
807
+ ? classFnOrObject[Symbols.classNameStaticProperty]
808
+ : classFnOrObject?.constructor[Symbols.classNameStaticProperty]) ||
809
+ (_.isFunction(classFnOrObject) ? CLASS.getName(classFnOrObject) : void 0));
810
+ };
1041
811
  //#endregion
1042
- //#region methods & getters / run all migrations
1043
- async runAllNotCompletedMigrations() {
1044
- /* */
1045
- /* */
1046
- /* */
1047
- /* */
1048
- /* */
1049
- /* */
1050
- /* */
1051
- /* */
1052
- /* */
1053
- /* */
1054
- /* */
1055
- /* */
1056
- /* */
1057
- /* */
1058
- /* */
1059
- /* */
1060
- /* */
1061
- /* */
1062
- /* */
1063
- /* */
1064
- /* */
1065
- /* */
1066
- /* */
1067
- /* */
1068
- /* */
1069
- /* */
1070
- /* */
1071
- /* */
1072
- /* */
1073
- /* */
1074
- /* */
1075
- /* */
1076
- /* */
1077
- /* */
1078
- /* */
1079
- /* */
1080
- /* */
1081
- /* */
1082
- /* */
1083
- /* */
1084
- /* */
1085
- /* */
1086
- /* */
1087
- /* */
1088
- /* */
1089
- /* */
1090
- /* */
1091
- /* */
1092
- /* */
1093
- /* */
1094
- /* */
1095
- /* */
1096
- /* */
1097
- /* */
1098
- /* */
1099
- /* */
1100
- /* */
1101
- /* */
1102
- /* */
1103
- /* */
1104
- /* */
1105
- /* */
1106
- /* */
1107
- /* */
1108
- /* */
1109
- /* */
1110
- /* */
1111
- /* */
1112
- /* */
1113
- /* */
1114
- /* */
1115
- /* */
1116
- /* */
1117
- /* */
1118
- /* */
1119
- /* */
1120
- /* */
1121
- /* */
1122
- /* */
1123
- /* */
1124
- /* */
1125
- /* */
1126
- /* */
1127
- /* */
1128
- /* */
1129
- /* */
1130
- /* */
1131
- /* */
1132
- /* */
1133
- /* */
1134
- /* */
1135
- /* */
1136
- /* */
1137
- /* */
1138
- /* */
1139
- /* */
1140
- /* */
1141
- /* */
1142
- /* */
1143
- /* */
1144
- /* */
1145
- /* */
1146
- /* */
1147
- /* */
1148
- /* */
1149
- /* */
1150
- /* */
1151
- /* */
1152
- /* */
1153
- /* */
1154
- /* */
1155
- /* */
1156
- /* */
1157
- /* */
1158
- /* */
1159
- /* */
1160
- /* */
1161
- /* */
1162
- /* */
1163
- /* */
1164
- /* */
1165
- /* */
1166
- /* */
1167
- /* */
1168
- /* */
1169
- /* */
1170
- /* */
1171
- /* */
1172
- /* */
1173
- return (void 0);
1174
- }
1175
- }
1176
-
1177
- class DITaonContainer {
1178
- static { this.instances = new Map(); }
1179
- static resolve(target) {
1180
- if (DITaonContainer.instances.has(target)) {
1181
- return DITaonContainer.instances.get(target);
812
+ ClassHelpers.getOrginalClass = (classFnOrObject) => {
813
+ const org = classFnOrObject[Symbols.orignalClass];
814
+ if (!org) {
815
+ return classFnOrObject;
816
+ }
817
+ return ClassHelpers.getOrginalClass(org);
818
+ };
819
+ //#region get full internal name
820
+ ClassHelpers.getFullInternalName = (classFnOrObject) => {
821
+ // exception for FormData
822
+ if (!classFnOrObject) {
823
+ throw new Error(`Cannot get name from: ${classFnOrObject}`);
824
+ }
825
+ return ((classFnOrObject[Symbols.fullClassNameStaticProperty]
826
+ ? classFnOrObject[Symbols.fullClassNameStaticProperty]
827
+ : classFnOrObject?.constructor[Symbols.fullClassNameStaticProperty]) ||
828
+ void 0);
829
+ };
830
+ //#endregion
831
+ //#region get unique key
832
+ ClassHelpers.getUniqueKey = (classFnOrObject) => {
833
+ const classFn = _.isFunction(classFnOrObject)
834
+ ? classFnOrObject
835
+ : classFnOrObject.constructor;
836
+ const config = Reflect.getMetadata(Symbols.metadata.options.entity, classFn);
837
+ return config.uniqueKeyProp;
838
+ };
839
+ //#endregion
840
+ //#region is class object
841
+ ClassHelpers.isContextClassObject = (obj) => {
842
+ if (!_.isObject(obj) ||
843
+ _.isArray(obj) ||
844
+ _.isRegExp(obj) ||
845
+ _.isBuffer(obj) ||
846
+ _.isArrayBuffer(obj)) {
847
+ return false;
848
+ }
849
+ if (_.isDate(obj)) {
850
+ return true;
851
+ }
852
+ const className = ClassHelpers.getName(obj);
853
+ return _.isString(className) && className !== 'Object';
854
+ };
855
+ //#endregion
856
+ //#region get name
857
+ ClassHelpers.setName = (target, className) => {
858
+ // console.log('setName', className, target.name)
859
+ Validators.classNameVlidation(className, target);
860
+ target[Symbols.classNameStaticProperty] = className;
861
+ };
862
+ //#endregion
863
+ //#region has parent with class name
864
+ ClassHelpers.hasParentClassWithName = (target, className, targets = []) => {
865
+ if (!target) {
866
+ return false;
867
+ }
868
+ targets.push(target);
869
+ let targetProto = Object.getPrototypeOf(target);
870
+ if (_.isFunction(targetProto) &&
871
+ ClassHelpers.getName(targetProto) === className) {
872
+ // console.log(`true "${_.first(targets).name}" for ${targets.map(d => d.name).join(',')}`)
873
+ return true;
874
+ }
875
+ return ClassHelpers.hasParentClassWithName(targetProto, className, targets);
876
+ };
877
+ //#endregion
878
+ //#region get methods name
879
+ //#region not allowed as method name
880
+ const notAllowedAsMethodName = [
881
+ 'length',
882
+ 'name',
883
+ 'arguments',
884
+ 'caller',
885
+ 'constructor',
886
+ 'apply',
887
+ 'bind',
888
+ 'call',
889
+ 'toString',
890
+ '__defineGetter__',
891
+ '__defineSetter__',
892
+ 'hasOwnProperty',
893
+ '__lookupGetter__',
894
+ '__lookupSetter__',
895
+ 'isPrototypeOf',
896
+ 'propertyIsEnumerable',
897
+ 'valueOf',
898
+ '__proto__',
899
+ 'toLocaleString',
900
+ ];
901
+ //#endregion
902
+ /**
903
+ * Express async handler for middleware functions.
904
+ */
905
+ ClassHelpers.asyncHandler = fn => (req, res, next) => {
906
+ Promise.resolve(fn(req, res, next)).catch(next);
907
+ };
908
+ ClassHelpers.getMethodsNames = (classOrClassInstance, allMethodsNames = []) => {
909
+ if (!classOrClassInstance) {
910
+ return Utils.uniqArray(allMethodsNames);
911
+ }
912
+ const isClassFunction = _.isFunction(classOrClassInstance);
913
+ const classFun = isClassFunction
914
+ ? classOrClassInstance
915
+ : Object.getPrototypeOf(classOrClassInstance);
916
+ const objectToCheck = isClassFunction
917
+ ? classOrClassInstance?.prototype
918
+ : classOrClassInstance;
919
+ const prototypeObj = Object.getPrototypeOf(objectToCheck || {});
920
+ const properties = _.uniq([
921
+ ...Object.getOwnPropertyNames(objectToCheck || {}),
922
+ ...Object.getOwnPropertyNames(prototypeObj || {}),
923
+ ...Object.keys(objectToCheck || {}),
924
+ ...Object.keys(prototypeObj || {}),
925
+ ]).filter(f => !!f && !notAllowedAsMethodName.includes(f));
926
+ properties
927
+ .filter(methodName => typeof objectToCheck[methodName] === 'function')
928
+ .forEach(p => allMethodsNames.push(p));
929
+ if (!classFun ||
930
+ !classFun.constructor ||
931
+ classFun?.constructor?.name === 'Object') {
932
+ return Utils.uniqArray(allMethodsNames);
933
+ }
934
+ return ClassHelpers.getMethodsNames(Object.getPrototypeOf(classFun), allMethodsNames);
935
+ };
936
+ //#endregion
937
+ //#region get controller configs
938
+ ClassHelpers.getControllerConfigs = (target, configs = [], callerTarget) => {
939
+ if (!_.isFunction(target)) {
940
+ throw `[typescript-class-helper][getControllerConfigs] Cannot get class config from: ${target}`;
1182
941
  }
1183
- // const tokens = Reflect.getMetadata('design:paramtypes', target) || [];
1184
- const injections = []; // tokens.map(token => Container.inject<any>(token));
1185
- const instance = new target(...injections);
1186
- DITaonContainer.instances.set(target, instance);
1187
- return instance;
1188
- }
1189
- static inject(target) {
1190
- return new Proxy({}, {
1191
- get: (_, propName) => {
1192
- let instance = DITaonContainer.instances.get(target) ||
1193
- DITaonContainer.resolve(target);
1194
- return typeof instance[propName] === 'function'
1195
- ? instance[propName].bind(instance)
1196
- : instance[propName];
1197
- },
1198
- set: (_, propName, value) => {
1199
- let instance = DITaonContainer.instances.get(target) ||
1200
- DITaonContainer.resolve(target);
1201
- instance[propName] = value;
1202
- return true;
1203
- },
1204
- });
1205
- }
1206
- }
1207
-
1208
- const getResponseValue = (response, options) => {
1209
- /* */
1210
- /* */
1211
- /* */
1212
- /* */
1213
- /* */
1214
- /* */
1215
- /* */
1216
- /* */
1217
- /* */
1218
- /* */
1219
- /* */
1220
- /* */
1221
- /* */
1222
- /* */
1223
- /* */
1224
- /* */
1225
- /* */
1226
- /* */
1227
- return (void 0);
1228
- };
942
+ let config;
943
+ const parentClass = Object.getPrototypeOf(target);
944
+ const parentName = parentClass ? ClassHelpers.getName(parentClass) : void 0;
945
+ const isValidParent = _.isFunction(parentClass) && parentName !== '';
946
+ config = controllerConfigFrom(ClassHelpers.getClassConfig(target));
947
+ configs.push(config);
948
+ return isValidParent
949
+ ? ClassHelpers.getControllerConfigs(parentClass, configs, target)
950
+ : configs;
951
+ };
952
+ //#endregion
953
+ //#region ensure configs
954
+ // Ensure ClassConfig on constructor, clone parent if needed
955
+ ClassHelpers.ensureClassConfig = (target) => {
956
+ let cfg = Reflect.getOwnMetadata(Symbols.metadata.options.controller, // META_KEYS.class,
957
+ target);
958
+ if (!cfg) {
959
+ cfg = { methods: {} };
960
+ const parent = Object.getPrototypeOf(target);
961
+ if (parent && parent !== Function.prototype) {
962
+ const parentCfg = Reflect.getMetadata(Symbols.metadata.options.controller, // META_KEYS.class,
963
+ parent);
964
+ if (parentCfg) {
965
+ // Deep copy each method config so child gets its own objects
966
+ const clonedMethods = {};
967
+ for (const [k, v] of Object.entries(parentCfg.methods)) {
968
+ clonedMethods[k] = {
969
+ ...v,
970
+ parameters: { ...v.parameters }, // shallow clone parameters too
971
+ };
972
+ }
973
+ cfg = {
974
+ ...parentCfg,
975
+ methods: clonedMethods,
976
+ };
977
+ }
978
+ }
979
+ Reflect.defineMetadata(Symbols.metadata.options.controller, cfg, target);
980
+ }
981
+ return cfg;
982
+ };
983
+ // Ensure MethodConfig inside ClassConfig
984
+ ClassHelpers.ensureMethodConfig = (target, propertyKey) => {
985
+ const classCfg = ClassHelpers.ensureClassConfig(target.constructor);
986
+ let methodCfg = classCfg.methods[propertyKey?.toString()];
987
+ if (!methodCfg) {
988
+ methodCfg = { methodName: propertyKey?.toString(), parameters: {} };
989
+ classCfg.methods[propertyKey?.toString()] = methodCfg;
990
+ }
991
+ return methodCfg;
992
+ };
993
+ ClassHelpers.getClassConfig = (constructor) => {
994
+ return Reflect.getMetadata(Symbols.metadata.options.controller, constructor);
995
+ };
996
+ //#endregion
997
+ })(ClassHelpers || (ClassHelpers = {}));
1229
998
 
1230
999
  var TaonHelpers;
1231
1000
  (function (TaonHelpers) {
@@ -5556,11 +5325,451 @@ const createContextFn = (configFn, cloneOptions) => {
5556
5325
  return res;
5557
5326
  };
5558
5327
  //#endregion
5559
- const createContext = (configFn) => {
5560
- return createContextFn(configFn, { useAsRemoteContext: false });
5561
- };
5562
- // const AA = createContext(() => ({ contextName: 'aa' }));
5563
- // const BB = AA.cloneAsRemoteContext();
5328
+ const createContext = (configFn) => {
5329
+ return createContextFn(configFn, { useAsRemoteContext: false });
5330
+ };
5331
+ // const AA = createContext(() => ({ contextName: 'aa' }));
5332
+ // const BB = AA.cloneAsRemoteContext();
5333
+
5334
+ const inject = (entity) => {
5335
+ return new Proxy({}, {
5336
+ get: (_, propName) => {
5337
+ if (propName === 'hasOwnProperty') {
5338
+ return () => false;
5339
+ }
5340
+ const ctor = entity();
5341
+ const contextFromClass = ctor[Symbols.ctxInClassOrClassObj];
5342
+ const resultContext = contextFromClass;
5343
+ if (resultContext) {
5344
+ let instance = resultContext.inject(ctor, {
5345
+ parentInstanceThatWillGetInjectedStuff: this,
5346
+ });
5347
+ // console.log('instance', instance);
5348
+ if (propName === 'getOriginalPrototype') {
5349
+ return () => Object.getPrototypeOf(instance);
5350
+ }
5351
+ if (propName === 'getOriginalConstructor') {
5352
+ return () => instance.constructor;
5353
+ }
5354
+ const methods = ctor[Symbols.classMethodsNames] || [];
5355
+ const isMethods = methods.includes(propName);
5356
+ const methodOrProperty = isMethods
5357
+ ? instance[propName].bind(instance)
5358
+ : instance[propName];
5359
+ // console.log(
5360
+ // `methodOrProperty from proxy ${propName?.toString()} = isMethods:${isMethods}`,
5361
+ // methods,
5362
+ // );
5363
+ return methodOrProperty;
5364
+ }
5365
+ },
5366
+ });
5367
+ };
5368
+ // export const injectController = inject;
5369
+ // export type SubscriptionEvent<T> = {
5370
+ // name: keyof T;
5371
+ // data: any;
5372
+ // };
5373
+ /**
5374
+ * TODO
5375
+ */
5376
+ // export const injectEntityEvents = <T>(
5377
+ // subscriberClassResolveFn: () => new (...args: any[]) => T,
5378
+ // eventName?: keyof Omit<EntitySubscriberInterface,'listenTo'> ,
5379
+ // ): Observable<SubscriptionEvent<T>> => {
5380
+ // const eventsSrc = new Subject<SubscriptionEvent<T>>();
5381
+ // const obs = eventsSrc.asObservable();
5382
+ // let isFirstSubscription = true;
5383
+ // const proxyObservable = new Proxy(obs, {
5384
+ // get(target, prop, receiver) {
5385
+ // if (prop === 'subscribe') {
5386
+ // return (...args: any[]) => {
5387
+ // if (isFirstSubscription) {
5388
+ // isFirstSubscription = false;
5389
+ // const subscriberClassFN: typeof TaonBaseClass =
5390
+ // subscriberClassResolveFn() as any;
5391
+ // const ctx = subscriberClassFN[
5392
+ // Symbols.ctxInClassOrClassObj
5393
+ // ] as EndpointContext;
5394
+ // if (!ctx) {
5395
+ // throw new Error(
5396
+ // `You are trying to inject class without context. Use context like this:
5397
+ // class MyClassSubscriber extends BaseSubscriber {
5398
+ // ${eventName as any}() {
5399
+ // \/\/ your code here
5400
+ // }
5401
+ // }
5402
+ // Taon.injectSubscriberEvents( MyContext.getInstance(()=> MyClassSubscriber), '${eventName as any}' )
5403
+ // `,
5404
+ // );
5405
+ // }
5406
+ // const subscriberInstance = ctx.getInstanceBy(subscriberClassFN);
5407
+ // // subscriberInstance TODO @LAST subscriber event from instance
5408
+ // // const entity = subscriberClassFN.prototype.listenTo();
5409
+ // console.log('First subscription, you can access arguments here:', {
5410
+ // subscriberClassFN,
5411
+ // eventName,
5412
+ // });
5413
+ // }
5414
+ // return target.subscribe(...args);
5415
+ // };
5416
+ // }
5417
+ // return Reflect.get(target, prop, receiver);
5418
+ // },
5419
+ // });
5420
+ // return proxyObservable as Observable<SubscriptionEvent<T>>;
5421
+ // };
5422
+
5423
+ //#region imports
5424
+ //#endregion
5425
+ //#region get transform function
5426
+ /**
5427
+ * @deprecated
5428
+ */
5429
+ const getTransformFunction = (target) => {
5430
+ if (!target) {
5431
+ return;
5432
+ }
5433
+ // const className = ClassHelpers.getName(target)
5434
+ // target = ClassHelpers.getBy(className);
5435
+ if (!target) {
5436
+ return void 0;
5437
+ }
5438
+ const configs = ClassHelpers.getControllerConfigs(target);
5439
+ // console.log(`CONFIGS TO CHECK`, configs)
5440
+ const functions = configs
5441
+ .map(c => {
5442
+ if (_.isFunction(c.browserTransformFn)) {
5443
+ return c.browserTransformFn;
5444
+ }
5445
+ })
5446
+ .filter(f => _.isFunction(f));
5447
+ return functions.length === 0
5448
+ ? void 0
5449
+ : function (entity) {
5450
+ for (let index = functions.length - 1; index >= 0; index--) {
5451
+ const transformFun = functions[index];
5452
+ transformFun(entity);
5453
+ }
5454
+ return entity;
5455
+ };
5456
+ };
5457
+ //#endregion
5458
+ //#region single transform
5459
+ /**
5460
+ * @deprecated
5461
+ */
5462
+ const singleTransform = (json) => {
5463
+ let ptarget = ClassHelpers.getClassFnFromObject(json);
5464
+ let pbrowserTransformFn = getTransformFunction(ptarget);
5465
+ if (pbrowserTransformFn) {
5466
+ const newValue = pbrowserTransformFn(json);
5467
+ if (!_.isObject(newValue)) {
5468
+ console.error(`Please return object in transform function for class: ` +
5469
+ `${ClassHelpers.getName(json)}`);
5470
+ }
5471
+ else {
5472
+ json = newValue;
5473
+ }
5474
+ }
5475
+ return json;
5476
+ };
5477
+ //#endregion
5478
+ class EntityProcess {
5479
+ //#region init
5480
+ static async init(result, response) {
5481
+ return await new EntityProcess(result, response).run();
5482
+ }
5483
+ //#endregion
5484
+ //#region constructor
5485
+ constructor(
5486
+ /**
5487
+ * Data from backend
5488
+ */
5489
+ result, response) {
5490
+ this.result = result;
5491
+ this.response = response;
5492
+ /**
5493
+ * Say yes to:
5494
+ * - circural object
5495
+ * - transform browser fn in decorator
5496
+ */
5497
+ this.advancedManipulation = false;
5498
+ this.circural = [];
5499
+ }
5500
+ //#endregion
5501
+ //#region check advanced manipulation
5502
+ checkAdvancedManiupulation() {
5503
+ if (_.isFunction(this.result)) {
5504
+ this.advancedManipulation = true;
5505
+ this.result = this.result();
5506
+ }
5507
+ }
5508
+ //#endregion
5509
+ //#region run
5510
+ async run() {
5511
+ this.checkAdvancedManiupulation();
5512
+ this.data = this.result;
5513
+ if (_.isObject(this.result)) {
5514
+ if (this.advancedManipulation) {
5515
+ this.applayTransformFn();
5516
+ }
5517
+ this.setHeaders();
5518
+ }
5519
+ this.send();
5520
+ }
5521
+ //#endregion
5522
+ //#region apply transform function
5523
+ applayTransformFn() {
5524
+ if (_.isObject(this.data) && !_.isArray(this.data)) {
5525
+ this.data = singleTransform(this.data);
5526
+ }
5527
+ const { include } = { include: [] };
5528
+ walk.Object(this.data, (value, lodashPath, changeValue, { skipObject, isCircural }) => {
5529
+ // console.log(`${isCircural ? 'CIR' : 'NOT'} : ${lodashPath}`)
5530
+ if (!isCircural) {
5531
+ if (!_.isArray(value) && _.isObject(value)) {
5532
+ changeValue(singleTransform(value));
5533
+ }
5534
+ }
5535
+ }, { checkCircural: true, breadthWalk: true, include });
5536
+ const { circs } = walk.Object(this.data, void 0, {
5537
+ checkCircural: true,
5538
+ breadthWalk: true,
5539
+ include,
5540
+ });
5541
+ this.circural = circs;
5542
+ }
5543
+ //#endregion
5544
+ //#region set headers
5545
+ setHeaders() {
5546
+ const { include } = { include: [] };
5547
+ const className = ClassHelpers.getName(this.data);
5548
+ const doNothing = _.isNil(this.data) ||
5549
+ [
5550
+ 'Object',
5551
+ '',
5552
+ // void 0, null // TODO not sure about commenting this
5553
+ ].includes(className);
5554
+ // console.log('doNothing', doNothing)
5555
+ if (!doNothing) {
5556
+ const cleaned = JSON10.cleaned(this.data, void 0, {
5557
+ breadthWalk: true,
5558
+ include,
5559
+ });
5560
+ this.entityMapping = Mapping.decode(cleaned, !this.advancedManipulation);
5561
+ this.response.set(Symbols.old.MAPPING_CONFIG_HEADER, JSON.stringify(this.entityMapping));
5562
+ if (this.advancedManipulation) {
5563
+ this.response.set(Symbols.old.CIRCURAL_OBJECTS_MAP_BODY, JSON.stringify(this.circural));
5564
+ }
5565
+ }
5566
+ }
5567
+ //#endregion
5568
+ //#region send
5569
+ send() {
5570
+ if (this.advancedManipulation) {
5571
+ const browserKey = config.folder.browser;
5572
+ let toSend = _.isArray(this.data) ? [] : {};
5573
+ const { include = [], exclude = [] } = { include: [], exclude: [] };
5574
+ walk.Object(this.data, (value, lodashPath, changeVAlue, { isCircural, skipObject }) => {
5575
+ // console.log(`${isCircural ? 'CIR' : 'NOT'} ${lodashPath}`)
5576
+ if (isCircural) {
5577
+ _.set(toSend, lodashPath, null);
5578
+ }
5579
+ else {
5580
+ const fun = getTransformFunction(ClassHelpers.getClassFnFromObject(value));
5581
+ if (_.isFunction(fun)) {
5582
+ _.set(toSend, `${lodashPath}.${browserKey}`, value[browserKey]);
5583
+ const indexProp = ClassHelpers.getUniqueKey(value);
5584
+ _.set(toSend, `${lodashPath}.${indexProp}`, value[indexProp]);
5585
+ // skipObject()
5586
+ }
5587
+ else {
5588
+ _.set(toSend, lodashPath, value);
5589
+ }
5590
+ }
5591
+ }, { checkCircural: true, breadthWalk: true, include });
5592
+ if (!_.isArray(this.data)) {
5593
+ let funParent = getTransformFunction(ClassHelpers.getClassFnFromObject(this.data));
5594
+ // if (this.mdc && this.mdc.exclude && this.mdc.exclude.length > 0) {
5595
+ // console.log(`funParent !!! have fun? ${!!funParent} `)
5596
+ // }
5597
+ if (_.isFunction(funParent)) {
5598
+ toSend = {
5599
+ [browserKey]: toSend[browserKey],
5600
+ };
5601
+ }
5602
+ Object.keys(this.data).forEach(prop => {
5603
+ if (prop !== browserKey) {
5604
+ const v = this.data[prop];
5605
+ if (!((include.length > 0 && !include.includes(prop)) ||
5606
+ (exclude.length > 0 && exclude.includes(prop)))) {
5607
+ if (ClassHelpers.isContextClassObject(v) &&
5608
+ _.isFunction(getTransformFunction(ClassHelpers.getClassFnFromObject(v)))) {
5609
+ toSend[prop] = {
5610
+ [browserKey]: v[browserKey],
5611
+ };
5612
+ const indexProp = ClassHelpers.getUniqueKey(v);
5613
+ toSend[prop][indexProp] = this.data[prop][indexProp];
5614
+ for (const key in v) {
5615
+ if (_.isObject(v) &&
5616
+ v.hasOwnProperty(key) &&
5617
+ ![indexProp, config.folder.browser].includes(key) &&
5618
+ (_.isString(v[key]) ||
5619
+ _.isNumber(v[key]) ||
5620
+ _.isDate(v[key]) ||
5621
+ _.isNull(v[key]) ||
5622
+ _.isBoolean(v[key]))) {
5623
+ toSend[prop][key] = v[key];
5624
+ }
5625
+ }
5626
+ }
5627
+ else {
5628
+ toSend[prop] = v;
5629
+ }
5630
+ }
5631
+ }
5632
+ });
5633
+ }
5634
+ // toSend = Helpers.JSON.cleaned(toSend, void 0, { breadthWalk: true })
5635
+ this.response.json(toSend);
5636
+ }
5637
+ else {
5638
+ this.response.json(this.data);
5639
+ }
5640
+ }
5641
+ }
5642
+
5643
+ const cloneObj = (override, classFn) => {
5644
+ const result = _.merge(new classFn(), _.cloneDeep(this));
5645
+ walk.Object(override || {}, (value, lodashPath) => {
5646
+ if (_.isNil(value) || _.isFunction(value) || _.isObject(value)) {
5647
+ // skipping
5648
+ }
5649
+ else {
5650
+ _.set(result, lodashPath, value);
5651
+ }
5652
+ }, {
5653
+ walkGetters: false,
5654
+ });
5655
+ // console.log({result})
5656
+ return result;
5657
+ };
5658
+
5659
+ //#endregion
5660
+ class TaonBaseClass {
5661
+ //#region class initialization hook
5662
+ /**
5663
+ * class initialization hook
5664
+ * taon after class instance creation
5665
+ */
5666
+ async _() { }
5667
+ //#endregion
5668
+ //#region clone
5669
+ /**
5670
+ *
5671
+ * @param overrideObjOrFn if object is provided it will override values in cloned object,
5672
+ * if function is provided it will be called with old cloned values and should return
5673
+ * object with values to override
5674
+ * @returns cloned instance of the class
5675
+ */
5676
+ clone(overrideObjOrFn) {
5677
+ if (_.isString(overrideObjOrFn)) {
5678
+ console.log(overrideObjOrFn);
5679
+ throw new Error('String is not supported as .clone() method argument');
5680
+ }
5681
+ const classFn = ClassHelpers.getClassFnFromObject(this);
5682
+ if (_.isFunction(overrideObjOrFn)) {
5683
+ // console.log('clone with fn');
5684
+ const oldValues = (_.cloneDeep(this) || {});
5685
+ return cloneObj(overrideObjOrFn(oldValues), classFn);
5686
+ }
5687
+ // console.log('clone normal');
5688
+ return cloneObj(overrideObjOrFn, classFn);
5689
+ }
5690
+ }
5691
+
5692
+ /* */
5693
+ /* */
5694
+ class TaonBaseEntity extends TaonBaseClass {
5695
+ /**
5696
+ * simple check if relation is ok
5697
+ */
5698
+ relation(relationName) {
5699
+ return relationName;
5700
+ }
5701
+ /**
5702
+ * simple check if relation is ok
5703
+ */
5704
+ relations(relationNames) {
5705
+ return relationNames;
5706
+ }
5707
+ }
5708
+
5709
+ /* */
5710
+ /* */
5711
+ /* */
5712
+ class TaonBaseAbstractEntity extends TaonBaseEntity {
5713
+ }
5714
+
5715
+ /**
5716
+ * TODO prevent calling methods when not initialized
5717
+ * with init(ctx)
5718
+ */
5719
+ //#region @browser
5720
+ //#endregion
5721
+ class TaonBaseAngularService {
5722
+ //#endregion
5723
+ constructor() {
5724
+ //#region @browser
5725
+ this.currentContext = inject$1(TAON_CONTEXT);
5726
+ //#region @browser
5727
+ this.CURRENT_HOST_BACKEND_PORT = inject$1(CURRENT_HOST_BACKEND_PORT, {
5728
+ optional: true,
5729
+ });
5730
+ this.CURRENT_HOST_URL = inject$1(CURRENT_HOST_URL, {
5731
+ optional: true,
5732
+ });
5733
+ // #endregion
5734
+ }
5735
+ /**
5736
+ * @deprecated
5737
+ * Returns the host URL for the backend service
5738
+ * that is running on localhost (normal NodeJS/ExpressJS mode).
5739
+ */
5740
+ get host() {
5741
+ //#region @browser
5742
+ if (this.CURRENT_HOST_URL) {
5743
+ return this.CURRENT_HOST_URL;
5744
+ }
5745
+ return `http://localhost:${this.CURRENT_HOST_BACKEND_PORT}`;
5746
+ //#endregion
5747
+ return void 0;
5748
+ }
5749
+ injectController(ctor,
5750
+ /**
5751
+ * optional override context
5752
+ */
5753
+ overrideCurrentContext) {
5754
+ return inject(() => {
5755
+ let currentContext;
5756
+ //#region @browser
5757
+ currentContext = overrideCurrentContext
5758
+ ? overrideCurrentContext
5759
+ : this.currentContext;
5760
+ //#endregion
5761
+ if (!currentContext) {
5762
+ throw new Error('No context available. Make sure to initialize the context before injecting controllers.');
5763
+ }
5764
+ return currentContext ? currentContext.getClass(ctor) : void 0;
5765
+ });
5766
+ }
5767
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: TaonBaseAngularService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5768
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: TaonBaseAngularService }); }
5769
+ }
5770
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: TaonBaseAngularService, decorators: [{
5771
+ type: Injectable
5772
+ }], ctorParameters: () => [] });
5564
5773
 
5565
5774
  /**
5566
5775
  * Provider decorator
@@ -7287,22 +7496,452 @@ TaonBaseSubscriberForEntity = __decorate([
7287
7496
  })
7288
7497
  ], TaonBaseSubscriberForEntity);
7289
7498
 
7290
- var Base;
7291
- (function (Base) {
7292
- Base.Controller = TaonBaseController;
7293
- Base.CrudController = TaonBaseCrudController;
7294
- Base.Entity = TaonBaseEntity;
7295
- Base.AbstractEntity = TaonBaseAbstractEntity;
7296
- Base.Provider = TaonBaseProvider;
7297
- Base.Class = TaonBaseClass;
7298
- Base.Repository = TaonBaseRepository;
7299
- Base.CustomRepository = TaonBaseCustomRepository;
7300
- Base.SubscriberForEntity = TaonBaseSubscriberForEntity;
7301
- Base.Migration = TaonBaseMigration;
7302
- Base.Middleware = TaonBaseMiddleware;
7303
- Base.AngularService = BaseAngularsService;
7304
- Base.Context = TaonBaseContext;
7305
- })(Base || (Base = {}));
7499
+ //#region models / method config
7500
+ /**
7501
+ * @link './decorators/http/http-methods-decorators.ts' TaonHttpDecoratorOptions
7502
+ */
7503
+ class MethodConfig {
7504
+ }
7505
+ //#endregion
7506
+
7507
+ // import { cloneObj } from '../helpers/clone-obj';
7508
+ class ParamConfig {
7509
+ }
7510
+
7511
+ class FormlyHorizontalWrapper extends FieldWrapper {
7512
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: FormlyHorizontalWrapper, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
7513
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.6", type: FormlyHorizontalWrapper, isStandalone: false, selector: "formly-horizontal-wrapper", viewQueries: [{ propertyName: "fieldComponent", first: true, predicate: ["fieldComponent"], descendants: true, read: ViewContainerRef }], usesInheritance: true, ngImport: i0, template: `
7514
+ <div class="form-group row">
7515
+ <label
7516
+ [attr.for]="id"
7517
+ class="col-sm-2 col-form-label"
7518
+ *ngIf="to.label">
7519
+ {{ to.label }}
7520
+ <ng-container *ngIf="to.required && to.hideRequiredMarker !== true"
7521
+ >*</ng-container
7522
+ >
7523
+ </label>
7524
+ <div class="col-sm-10">
7525
+ <ng-template #fieldComponent></ng-template>
7526
+ </div>
7527
+ </div>
7528
+ `, isInline: true, styles: [":host{display:block;padding:5px;margin-bottom:5px;border:1px dotted gray}\n"] }); }
7529
+ }
7530
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: FormlyHorizontalWrapper, decorators: [{
7531
+ type: Component,
7532
+ args: [{ selector: 'formly-horizontal-wrapper', standalone: false, template: `
7533
+ <div class="form-group row">
7534
+ <label
7535
+ [attr.for]="id"
7536
+ class="col-sm-2 col-form-label"
7537
+ *ngIf="to.label">
7538
+ {{ to.label }}
7539
+ <ng-container *ngIf="to.required && to.hideRequiredMarker !== true"
7540
+ >*</ng-container
7541
+ >
7542
+ </label>
7543
+ <div class="col-sm-10">
7544
+ <ng-template #fieldComponent></ng-template>
7545
+ </div>
7546
+ </div>
7547
+ `, styles: [":host{display:block;padding:5px;margin-bottom:5px;border:1px dotted gray}\n"] }]
7548
+ }], propDecorators: { fieldComponent: [{
7549
+ type: ViewChild,
7550
+ args: ['fieldComponent', { read: ViewContainerRef }]
7551
+ }] } });
7552
+
7553
+ /*
7554
+
7555
+ DON'T FORGET
7556
+ ...
7557
+ FormlyModule.forRoot({
7558
+ types: [
7559
+ { name: 'repeat', component: RepeatTypeComponent },
7560
+ ],
7561
+ }),
7562
+ ...
7563
+
7564
+ */
7565
+ class RepeatTypeComponent extends FieldArrayType {
7566
+ get labelTemplate() {
7567
+ // @ts-ignore
7568
+ return this.field.fieldArray.templateOptions.label; // TODO QUICK_FIX
7569
+ }
7570
+ constructor(builder) {
7571
+ // TODO QUICK_FIX
7572
+ // @ts-ignore
7573
+ super(builder);
7574
+ }
7575
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RepeatTypeComponent, deps: [{ token: i1.FormlyFormBuilder }], target: i0.ɵɵFactoryTarget.Component }); }
7576
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.6", type: RepeatTypeComponent, isStandalone: false, selector: "formly-repeat-section", usesInheritance: true, ngImport: i0, template: `
7577
+ <div *ngIf="field.fieldGroup && field.fieldGroup.length === 0">
7578
+ Press button to add new element...
7579
+ </div>
7580
+ <div
7581
+ *ngFor="let field of field.fieldGroup; let i = index"
7582
+ class="taon-formly-array">
7583
+ <formly-group
7584
+ [model]="model[i]"
7585
+ [field]="field"
7586
+ [options]="options"
7587
+ [form]="formControl">
7588
+ <div>
7589
+ <button
7590
+ class="btn btn-danger"
7591
+ type="button"
7592
+ (click)="remove(i)">
7593
+ Remove
7594
+ </button>
7595
+ </div>
7596
+ </formly-group>
7597
+ </div>
7598
+ <div>
7599
+ <button
7600
+ class="btn btn-primary"
7601
+ type="button"
7602
+ (click)="add()">
7603
+ {{ labelTemplate }}
7604
+ </button>
7605
+ </div>
7606
+ `, isInline: true, styles: [":host{display:block;padding:5px;margin-bottom:5px;border:1px solid gray}formly-group{display:block;border:1px dashed gray;margin-bottom:5px;padding:5px}.taon-formly-array{padding:5px;background:#fff}\n"] }); }
7607
+ }
7608
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RepeatTypeComponent, decorators: [{
7609
+ type: Component,
7610
+ args: [{ selector: 'formly-repeat-section', standalone: false, template: `
7611
+ <div *ngIf="field.fieldGroup && field.fieldGroup.length === 0">
7612
+ Press button to add new element...
7613
+ </div>
7614
+ <div
7615
+ *ngFor="let field of field.fieldGroup; let i = index"
7616
+ class="taon-formly-array">
7617
+ <formly-group
7618
+ [model]="model[i]"
7619
+ [field]="field"
7620
+ [options]="options"
7621
+ [form]="formControl">
7622
+ <div>
7623
+ <button
7624
+ class="btn btn-danger"
7625
+ type="button"
7626
+ (click)="remove(i)">
7627
+ Remove
7628
+ </button>
7629
+ </div>
7630
+ </formly-group>
7631
+ </div>
7632
+ <div>
7633
+ <button
7634
+ class="btn btn-primary"
7635
+ type="button"
7636
+ (click)="add()">
7637
+ {{ labelTemplate }}
7638
+ </button>
7639
+ </div>
7640
+ `, styles: [":host{display:block;padding:5px;margin-bottom:5px;border:1px solid gray}formly-group{display:block;border:1px dashed gray;margin-bottom:5px;padding:5px}.taon-formly-array{padding:5px;background:#fff}\n"] }]
7641
+ }], ctorParameters: () => [{ type: i1.FormlyFormBuilder }] });
7642
+
7643
+ function findTypeForEntity(entity, isArray = false) {
7644
+ if (!_.isArray(RegisterComponentType.prototype.types)) {
7645
+ RegisterComponentType.prototype.types = [];
7646
+ }
7647
+ return getRegisteredComponents().find(c => c.entity === entity && c.isArray === isArray);
7648
+ }
7649
+ function typeFromEntity(component, entity) {
7650
+ const isArray = _.isArray(entity);
7651
+ if (isArray) {
7652
+ entity = _.first(entity);
7653
+ }
7654
+ let name = ClassHelpers.getName(component);
7655
+ let res = { name, component, entity, isArray };
7656
+ // console.log(res);
7657
+ return res;
7658
+ }
7659
+ function typeFromName(component, name) {
7660
+ let res = { name, component };
7661
+ return res;
7662
+ }
7663
+ function RegisterComponentTypeForEntity(entity) {
7664
+ if (!_.isArray(RegisterComponentType.prototype.types)) {
7665
+ RegisterComponentType.prototype.types = [];
7666
+ }
7667
+ return function (target, propertyKey, descriptor) {
7668
+ RegisterComponentType.prototype.types.push(typeFromEntity(target, entity));
7669
+ };
7670
+ }
7671
+ function RegisterComponentType(className, ...optionslNames) {
7672
+ if (!_.isArray(RegisterComponentType.prototype.types)) {
7673
+ RegisterComponentType.prototype.types = [];
7674
+ }
7675
+ return function (target, propertyKey, descriptor) {
7676
+ ClassHelpers.setName(target, className);
7677
+ RegisterComponentType.prototype.types.push(typeFromEntity(target));
7678
+ optionslNames.forEach(name => {
7679
+ RegisterComponentType.prototype.types.push(typeFromName(target, name));
7680
+ });
7681
+ };
7682
+ }
7683
+ // RegisterComponentType.prototype.types = []
7684
+ function getRegisteredComponents() {
7685
+ let registered = RegisterComponentType.prototype.types;
7686
+ if (!Array.isArray(registered)) {
7687
+ return [];
7688
+ }
7689
+ // console.log(registered)
7690
+ return registered;
7691
+ }
7692
+
7693
+ function getFromlyConfigFor(target, options = {}) {
7694
+ const { formType = 'material', keysPathesToExclude = [], keysPathesToInclude = [], parentModel, relativePath = '', level = 0, maxLevel = 4, } = options;
7695
+ if (level === maxLevel) {
7696
+ return [];
7697
+ }
7698
+ const mapping = Mapping.getModelsMapping(target);
7699
+ // console.log('mapping', mapping)
7700
+ const fieldNames = CLASS.describeProperites(target);
7701
+ const checkExclude = _.isArray(keysPathesToExclude) && keysPathesToExclude.length > 0;
7702
+ const checkInclude = _.isArray(keysPathesToInclude) && keysPathesToInclude.length > 0;
7703
+ if (checkExclude && checkInclude) {
7704
+ throw new Error(`In Taon function getFromlyConfigFor(...) please use keysPathesToInclude or keysPathesToExclude, `);
7705
+ }
7706
+ // if (checkInclude) {
7707
+ // console.log('check include', keysPathesToExclude)
7708
+ // }
7709
+ // if (checkExclude) {
7710
+ // console.log('check exclude', keysPathesToExclude)
7711
+ // }
7712
+ let fields = [];
7713
+ //#region input to push
7714
+ function inputToPush(key, type, model, inptToPushOptions) {
7715
+ const { targetChild, selectOptions } = inptToPushOptions || {};
7716
+ // console.log(`key(${key}) type: ${type} | model: ${model} targetChild: ${targetChild && targetChild.name}`)
7717
+ let res;
7718
+ if (type === 'repeat') {
7719
+ const fieldGroup = getFromlyConfigFor(targetChild, {
7720
+ formType,
7721
+ keysPathesToInclude,
7722
+ keysPathesToExclude,
7723
+ relativePath: `${relativePath}.${key}`,
7724
+ level: level + 1,
7725
+ maxLevel,
7726
+ });
7727
+ if (fieldGroup.length > 0) {
7728
+ res = {
7729
+ key,
7730
+ type,
7731
+ defaultValue: [],
7732
+ fieldArray: {
7733
+ fieldGroupClassName: 'row',
7734
+ templateOptions: {
7735
+ label: `Add new ${_.startCase(key)}`,
7736
+ },
7737
+ fieldGroup,
7738
+ },
7739
+ };
7740
+ }
7741
+ }
7742
+ else if (type === 'group') {
7743
+ const fieldGroup = getFromlyConfigFor(targetChild, {
7744
+ formType,
7745
+ keysPathesToInclude,
7746
+ keysPathesToExclude,
7747
+ parentModel: model,
7748
+ relativePath: `${relativePath}.${key}`,
7749
+ level: level + 1,
7750
+ maxLevel,
7751
+ });
7752
+ if (fieldGroup.length > 0) {
7753
+ res = {
7754
+ fieldGroupClassName: 'row',
7755
+ templateOptions: {
7756
+ label: `${_.startCase(key)}`,
7757
+ },
7758
+ wrappers: ['groupwrap'],
7759
+ fieldGroup,
7760
+ };
7761
+ }
7762
+ }
7763
+ else {
7764
+ res = {
7765
+ key,
7766
+ model,
7767
+ type,
7768
+ defaultValue: !_.isUndefined(target.prototype[key])
7769
+ ? target.prototype[key]
7770
+ : undefined,
7771
+ templateOptions: {
7772
+ label: _.isString(model)
7773
+ ? `${model
7774
+ .split('.')
7775
+ .map(l => _.startCase(l))
7776
+ .join(' / ')} / ${_.startCase(key)}`
7777
+ : _.startCase(key),
7778
+ options: selectOptions,
7779
+ },
7780
+ };
7781
+ }
7782
+ if (res) {
7783
+ Object.keys(res).forEach(key => res[key] === undefined ? delete res[key] : '');
7784
+ }
7785
+ return res;
7786
+ }
7787
+ //#endregion
7788
+ //#region is allowed path
7789
+ function isAlowedPath(key) {
7790
+ let isAlowed = true;
7791
+ const matchPath = relativePath === '' ? key : `${relativePath}:${key}`;
7792
+ if (checkExclude) {
7793
+ if (keysPathesToExclude.includes(matchPath)) {
7794
+ // console.log(`Not allowed key: ${key}`)
7795
+ isAlowed = false;
7796
+ }
7797
+ else {
7798
+ isAlowed = true;
7799
+ }
7800
+ }
7801
+ else if (checkInclude) {
7802
+ if (keysPathesToInclude.includes(matchPath)) {
7803
+ // console.log(`Allowed key: ${key}`)
7804
+ isAlowed = true;
7805
+ }
7806
+ else {
7807
+ isAlowed = false;
7808
+ }
7809
+ }
7810
+ // console.log(`Is allowed;${matchPath} `, isAlowed)
7811
+ return isAlowed;
7812
+ }
7813
+ //#endregion
7814
+ const simpleResolved = [];
7815
+ //#region resolve simple types
7816
+ function resolveSimpleTypes() {
7817
+ for (const key in target.prototype) {
7818
+ if (target.prototype.hasOwnProperty(key) &&
7819
+ !_.isFunction(target.prototype[key])) {
7820
+ if (!isAlowedPath(key)) {
7821
+ continue;
7822
+ }
7823
+ if (!_.isUndefined(mapping[key])) {
7824
+ continue;
7825
+ }
7826
+ const element = target.prototype[key];
7827
+ let type = 'input';
7828
+ if (_.isBoolean(element)) {
7829
+ type = 'switch';
7830
+ }
7831
+ else if (_.isDate(element)) {
7832
+ type = 'datepicker';
7833
+ }
7834
+ else if (_.isFunction(target['getOptionsFor'])) {
7835
+ var selectOptions = target['getOptionsFor'](key);
7836
+ if (!_.isUndefined(selectOptions)) {
7837
+ type = 'select';
7838
+ }
7839
+ }
7840
+ else if (_.isFunction(target.prototype?.getOptionsFor)) {
7841
+ var selectOptions = target.prototype?.getOptionsFor(key);
7842
+ if (!_.isUndefined(selectOptions)) {
7843
+ type = 'select';
7844
+ }
7845
+ }
7846
+ fields.push(inputToPush(key, type, parentModel, { selectOptions }));
7847
+ simpleResolved.push(key);
7848
+ }
7849
+ }
7850
+ }
7851
+ //#endregion
7852
+ //#region resolve complex types
7853
+ function resolveComplexTypes() {
7854
+ fieldNames
7855
+ .filter(key => !simpleResolved.includes(key))
7856
+ .forEach(key => {
7857
+ if (isAlowedPath(key) && !_.isUndefined(mapping[key])) {
7858
+ let className = mapping[key];
7859
+ const isArray = _.isArray(className);
7860
+ className = isArray ? _.first(className) : className;
7861
+ if (className === 'Date') {
7862
+ fields.push(inputToPush(key, 'datepicker', parentModel));
7863
+ }
7864
+ else {
7865
+ const targetChild = CLASS.getBy(className);
7866
+ if (targetChild) {
7867
+ const ftype = findTypeForEntity(targetChild, isArray);
7868
+ if (ftype) {
7869
+ fields = fields.concat(inputToPush(key, ftype.name, key));
7870
+ }
7871
+ else {
7872
+ if (isArray) {
7873
+ fields = fields.concat(inputToPush(key, 'repeat', key, { targetChild }));
7874
+ }
7875
+ else {
7876
+ fields = fields.concat(inputToPush(key, 'group', key, { targetChild }));
7877
+ }
7878
+ }
7879
+ }
7880
+ }
7881
+ }
7882
+ });
7883
+ }
7884
+ //#endregion
7885
+ function generate() {
7886
+ resolveSimpleTypes();
7887
+ // console.log('after simple', fields);
7888
+ resolveComplexTypes();
7889
+ // console.log('after complext', fields);
7890
+ }
7891
+ generate();
7892
+ return fields.filter(f => !!f);
7893
+ }
7894
+
7895
+ /**
7896
+ * 100 default characters varchar
7897
+ */
7898
+ const StringColumn = (defaultValue = null, length = 100) => Column({
7899
+ type: 'varchar',
7900
+ length,
7901
+ nullable: _.isNil(defaultValue),
7902
+ default: defaultValue,
7903
+ });
7904
+ /**
7905
+ * 100 characters varchar
7906
+ */
7907
+ const String100Column = (defaultValue = null) => Column({
7908
+ type: 'varchar',
7909
+ length: 100,
7910
+ nullable: _.isNil(defaultValue),
7911
+ default: defaultValue,
7912
+ });
7913
+ /**
7914
+ * 100 characters varchar
7915
+ */
7916
+ const String45Column = (defaultValue = null) => Column({
7917
+ type: 'varchar',
7918
+ length: 45,
7919
+ nullable: _.isNil(defaultValue),
7920
+ default: defaultValue,
7921
+ });
7922
+ /**
7923
+ * 500 characters varchar
7924
+ */
7925
+ const String500Column = (defaultValue = null) => Column({
7926
+ type: 'varchar',
7927
+ length: 500,
7928
+ nullable: _.isNil(defaultValue),
7929
+ default: defaultValue,
7930
+ });
7931
+ /**
7932
+ * 200 characters varchar
7933
+ */
7934
+ const String200Column = (defaultValue = null) => Column({
7935
+ type: 'varchar',
7936
+ length: 200,
7937
+ nullable: _.isNil(defaultValue),
7938
+ default: defaultValue,
7939
+ });
7940
+ const NumberColumn = () => Column({ type: 'int', nullable: true });
7941
+ const DecimalNumberColumn = () => Column({ type: 'float', nullable: true });
7942
+ const SimpleJsonColumn = () => Column({ type: 'simple-json', nullable: true });
7943
+ const BooleanColumn = (defaultValue) => Column({ type: 'boolean', nullable: true, default: defaultValue });
7944
+ const DateTImeColumn = (defaultValue = null) => Column({ type: 'datetime', nullable: true, default: defaultValue });
7306
7945
 
7307
7946
  /**
7308
7947
  * Entity decorator
@@ -7351,26 +7990,6 @@ function TaonProvider(options) {
7351
7990
  class TaonProviderOptions extends DecoratorAbstractOpt {
7352
7991
  }
7353
7992
 
7354
- var Http;
7355
- (function (Http) {
7356
- Http.GET = GET;
7357
- Http.POST = POST;
7358
- Http.PUT = PUT;
7359
- Http.DELETE = DELETE;
7360
- Http.PATCH = PATCH;
7361
- Http.HEAD = HEAD;
7362
- Http.HTML = HTML;
7363
- Http.Response = Models$1.HttpResponse;
7364
- let Param;
7365
- (function (Param) {
7366
- Param.Query = Query;
7367
- Param.Path = Path;
7368
- Param.Body = Body;
7369
- Param.Cookie = Cookie;
7370
- Param.Header = Header;
7371
- })(Param = Http.Param || (Http.Param = {}));
7372
- })(Http || (Http = {}));
7373
-
7374
7993
  // TODO export all things
7375
7994
  var Taon;
7376
7995
  (function (Taon) {
@@ -7384,17 +8003,16 @@ var Taon;
7384
8003
  return opt;
7385
8004
  };
7386
8005
  };
7387
- Taon.Http = Http;
7388
- Taon.Base = Base;
7389
8006
  Taon.getResponseValue = getResponseValue;
7390
8007
  //#region class decorators
7391
- Taon.Controller = TaonController;
7392
- Taon.Entity = TaonEntity;
7393
- Taon.Provider = TaonProvider;
7394
- Taon.Repository = TaonRepository;
7395
- Taon.Subscriber = TaonSubscriber;
7396
- Taon.Migration = TaonMigration;
7397
- Taon.Middleware = TaonMiddleware;
8008
+ // TODO new 5.8 typescript is not allowing this
8009
+ // export import Controller = controllerDecorator.TaonController;
8010
+ // export import Entity = entityDecorator.TaonEntity;
8011
+ // export import Provider = providerDecorator.TaonProvider;
8012
+ // export import Repository = repositoryDecorator.TaonRepository;
8013
+ // export import Subscriber = subscriberDecorator.TaonSubscriber;
8014
+ // export import Migration = migrationDecorator.TaonMigration;
8015
+ // export import Middleware = middlewareDecorator.TaonMiddleware;
7398
8016
  //#endregion
7399
8017
  //#region aliases to helpers
7400
8018
  Taon.isBrowser = coreHelpers.Helpers.isBrowser;
@@ -7431,10 +8049,107 @@ var Taon;
7431
8049
  return context;
7432
8050
  };
7433
8051
  })(Taon || (Taon = {}));
8052
+ //#region taon flattening map
8053
+ const TAON_FLATTEN_MAPPING = {
8054
+ 'taon/src': {
8055
+ // =====================
8056
+ // Taon.Http.*
8057
+ // =====================
8058
+ 'Taon.Http.GET': 'GET',
8059
+ 'Taon.Http.POST': 'POST',
8060
+ 'Taon.Http.PUT': 'PUT',
8061
+ 'Taon.Http.DELETE': 'DELETE',
8062
+ 'Taon.Http.PATCH': 'PATCH',
8063
+ 'Taon.Http.HEAD': 'HEAD',
8064
+ 'Taon.Http.HTML': 'HTML',
8065
+ 'Taon.Http.Response': 'HttpResponse',
8066
+ 'Taon.Http.Param.Query': 'Query',
8067
+ 'Taon.Http.Param.Path': 'Path',
8068
+ 'Taon.Http.Param.Body': 'Body',
8069
+ 'Taon.Http.Param.Cookie': 'Cookie',
8070
+ 'Taon.Http.Param.Header': 'Header',
8071
+ // =====================
8072
+ // Taon.Base.*
8073
+ // =====================
8074
+ 'Taon.Base.Controller': 'TaonBaseController',
8075
+ 'Taon.Base.CrudController': 'TaonBaseCrudController',
8076
+ 'Taon.Base.Entity': 'TaonBaseEntity',
8077
+ 'Taon.Base.AbstractEntity': 'TaonBaseAbstractEntity',
8078
+ 'Taon.Base.AbstractEntityOmitKeys': 'AbstractEntityOmitKeys',
8079
+ 'Taon.Base.Provider': 'TaonBaseProvider',
8080
+ 'Taon.Base.Class': 'TaonBaseClass',
8081
+ 'Taon.Base.Repository': 'TaonBaseRepository',
8082
+ 'Taon.Base.CustomRepository': 'TaonBaseCustomRepository',
8083
+ 'Taon.Base.SubscriberForEntity': 'TaonBaseSubscriberForEntity',
8084
+ 'Taon.Base.Migration': 'TaonBaseMigration',
8085
+ 'Taon.Base.Middleware': 'TaonBaseMiddleware',
8086
+ 'Taon.Base.AngularService': 'TaonBaseAngularService',
8087
+ 'Taon.Base.Context': 'TaonBaseContext',
8088
+ // =====================
8089
+ // Taon.Controller.* (decorators)
8090
+ // =====================
8091
+ 'Taon.Controller': 'TaonController',
8092
+ 'Taon.Entity': 'TaonEntity',
8093
+ 'Taon.Provider': 'TaonProvider',
8094
+ 'Taon.Repository': 'TaonRepository',
8095
+ 'Taon.Subscriber': 'TaonSubscriber',
8096
+ 'Taon.Migration': 'TaonMigration',
8097
+ 'Taon.Middleware': 'TaonMiddleware',
8098
+ // =====================
8099
+ // Taon.Orm.*
8100
+ // =====================
8101
+ 'Taon.Orm.Repository': 'Repository',
8102
+ 'Taon.Orm.Connection': 'Connection',
8103
+ // ListenEvent
8104
+ 'Taon.Orm.ListenEvent.AfterInsert': 'AfterInsert',
8105
+ 'Taon.Orm.ListenEvent.AfterLoad': 'AfterLoad',
8106
+ 'Taon.Orm.ListenEvent.AfterRecover': 'AfterRecover',
8107
+ 'Taon.Orm.ListenEvent.AfterRemove': 'AfterRemove',
8108
+ 'Taon.Orm.ListenEvent.AfterSoftRemove': 'AfterSoftRemove',
8109
+ 'Taon.Orm.ListenEvent.AfterUpdate': 'AfterUpdate',
8110
+ 'Taon.Orm.ListenEvent.BeforeInsert': 'BeforeInsert',
8111
+ 'Taon.Orm.ListenEvent.BeforeRecover': 'BeforeRecover',
8112
+ 'Taon.Orm.ListenEvent.BeforeRemove': 'BeforeRemove',
8113
+ 'Taon.Orm.ListenEvent.BeforeSoftRemove': 'BeforeSoftRemove',
8114
+ 'Taon.Orm.ListenEvent.BeforeUpdate': 'BeforeUpdate',
8115
+ // Tree
8116
+ 'Taon.Orm.Tree.Children': 'TreeChildren',
8117
+ 'Taon.Orm.Tree.Parent': 'TreeParent',
8118
+ // Column
8119
+ 'Taon.Orm.Column.Generated': 'Generated',
8120
+ 'Taon.Orm.Column.Primary': 'PrimaryColumn',
8121
+ 'Taon.Orm.Column.Index': 'Index',
8122
+ 'Taon.Orm.Column.CreateDate': 'CreateDateColumn',
8123
+ 'Taon.Orm.Column.UpdateDate': 'UpdateDateColumn',
8124
+ 'Taon.Orm.Column.DeleteDate': 'DeleteDateColumn',
8125
+ 'Taon.Orm.Column.Custom': 'Column',
8126
+ 'Taon.Orm.Column.String': 'StringColumn',
8127
+ 'Taon.Orm.Column.String100': 'String100Column',
8128
+ 'Taon.Orm.Column.String45': 'String45Column',
8129
+ 'Taon.Orm.Column.String500': 'String500Column',
8130
+ 'Taon.Orm.Column.String200': 'String200Column',
8131
+ 'Taon.Orm.Column.Number': 'NumberColumn',
8132
+ 'Taon.Orm.Column.DecimalNumber': 'DecimalNumberColumn',
8133
+ 'Taon.Orm.Column.SimpleJson': 'SimpleJsonColumn',
8134
+ 'Taon.Orm.Column.Boolean': 'BooleanColumn',
8135
+ 'Taon.Orm.Column.DateTIme': 'DateTimeColumn',
8136
+ 'Taon.Orm.Column.Version': 'VersionColumn',
8137
+ 'Taon.Orm.Column.Virtual': 'VirtualColumn',
8138
+ // Join
8139
+ 'Taon.Orm.Join.Table': 'JoinTable',
8140
+ 'Taon.Orm.Join.Column': 'JoinColumn',
8141
+ // Relation
8142
+ 'Taon.Orm.Relation.OneToMany': 'OneToMany',
8143
+ 'Taon.Orm.Relation.OneToOne': 'OneToOne',
8144
+ 'Taon.Orm.Relation.ManyToMany': 'ManyToMany',
8145
+ 'Taon.Orm.Relation.ManyToOne': 'ManyToOne',
8146
+ },
8147
+ };
8148
+ //#endregion
7434
8149
 
7435
8150
  /**
7436
8151
  * Generated bundle index. Do not edit.
7437
8152
  */
7438
8153
 
7439
- export { BaseTaonClassesNames, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL, ClassHelpers, ContextsEndpointStorage, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonBaseClass, TaonBaseContext, TaonBaseController, TaonBaseCustomRepository, TaonBaseEntity, TaonBaseFileUploadMiddleware, TaonBaseMigration, TaonBaseProvider, TaonBaseRepository, TaonEntityKeysToOmitArr, TaonTempDatabasesFolder, TaonTempRoutesFolder, apiPrefix, createContext, inject };
8154
+ export { BaseTaonClassesNames, Body, BooleanColumn, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL, ClassHelpers, ContextDbMigrations, ContextsEndpointStorage, ControllerConfig, Cookie, DELETE, DITaonContainer, DateTImeColumn, DecimalNumberColumn, DecoratorAbstractOpt, EndpointContext, EntityProcess, FormlyHorizontalWrapper, GET, HEAD, HTML, Header, MethodConfig, MockNamespaceIpc, MockServerIpc, MockSocketIpc, Models, NumberColumn, PATCH, POST, PUT, ParamConfig, Path, Query, RealtimeClient, RealtimeCore, RealtimeServer, RealtimeStrategy, RealtimeStrategyIpc, RealtimeStrategyMock, RealtimeStrategySocketIO, RealtimeSubsManager, RegisterComponentType, RegisterComponentTypeForEntity, RepeatTypeComponent, SimpleJsonColumn, String100Column, String200Column, String45Column, String500Column, StringColumn, Symbols, TAON_CONTEXT, TAON_FLATTEN_MAPPING, Taon, TaonAdminService, TaonBaseAbstractEntity, TaonBaseAngularService, TaonBaseClass, TaonBaseContext, TaonBaseController, TaonBaseCrudController, TaonBaseCustomRepository, TaonBaseEntity, TaonBaseFileUploadMiddleware, TaonBaseInjector, TaonBaseMiddleware, TaonBaseMigration, TaonBaseProvider, TaonBaseRepository, TaonBaseSubscriberForEntity, TaonController, TaonControllerOptions, TaonEntity, TaonEntityKeysToOmitArr, TaonEntityOptions, TaonHelpers, TaonMiddleware, TaonMiddlewareOptions, TaonMigration, TaonMigrationOptions, TaonProvider, TaonProviderOptions, TaonRepository, TaonRepositoryOptions, TaonRestResponseWrapper, TaonSubscriber, TaonSubscriberOptions, TaonTempDatabasesFolder, TaonTempRoutesFolder, Validators, apiPrefix, cloneObj, controllerConfigFrom, createContext, createContextTemplate, findTypeForEntity, getFromlyConfigFor, getRegisteredComponents, getResponseValue, getTransformFunction, inject, singleTransform, typeFromEntity, typeFromName };
7440
8155
  //# sourceMappingURL=taon.mjs.map