taon 21.0.52 → 21.0.54
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.
- package/browser/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/icon-menu-taon.svg +15 -15
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib-prod/base-classes/base-abstract-entity.js +19 -0
- package/lib-prod/base-classes/base-angular-service.js +84 -0
- package/lib-prod/base-classes/base-class.js +35 -0
- package/lib-prod/base-classes/{base-context.ts → base-context.js} +13 -15
- package/lib-prod/base-classes/base-controller.js +154 -0
- package/lib-prod/base-classes/base-crud-controller.js +264 -0
- package/lib-prod/base-classes/base-custom-repository.js +9 -0
- package/lib-prod/base-classes/{base-electron-service.ts → base-electron-service.js} +1 -12
- package/lib-prod/base-classes/base-entity.js +22 -0
- package/lib-prod/base-classes/base-file-upload.middleware.js +75 -0
- package/lib-prod/base-classes/base-injector.js +184 -0
- package/lib-prod/base-classes/base-middleware.js +9 -0
- package/lib-prod/base-classes/base-migration.js +20 -0
- package/lib-prod/base-classes/{base-provider.ts → base-provider.js} +2 -2
- package/lib-prod/base-classes/base-repository.js +617 -0
- package/lib-prod/base-classes/base-subscriber-for-entity.js +145 -0
- package/lib-prod/base-classes/{base.ts → base.js} +2 -15
- package/lib-prod/{build-info._auto-generated_.ts → build-info._auto-generated_.js} +1 -2
- package/lib-prod/config/controller-config.js +28 -0
- package/lib-prod/config/controller-options.js +3 -0
- package/lib-prod/config/method-config.js +7 -0
- package/lib-prod/config/param-config.js +3 -0
- package/lib-prod/constants.js +33 -0
- package/lib-prod/context-db-migrations.js +342 -0
- package/lib-prod/create-context.js +217 -0
- package/lib-prod/decorators/classes/controller-decorator.js +17 -0
- package/lib-prod/decorators/classes/entity-decorator.js +28 -0
- package/lib-prod/decorators/classes/middleware-decorator.js +16 -0
- package/lib-prod/decorators/classes/migration-decorator.js +15 -0
- package/lib-prod/decorators/classes/provider-decorator.js +15 -0
- package/lib-prod/decorators/classes/repository-decorator.js +15 -0
- package/lib-prod/decorators/classes/subscriber-decorator.js +15 -0
- package/lib-prod/decorators/decorator-abstract-opt.js +2 -0
- package/lib-prod/decorators/http/http-decorators.js +20 -0
- package/lib-prod/decorators/http/http-methods-decorators.js +102 -0
- package/lib-prod/decorators/http/http-params-decorators.js +42 -0
- package/lib-prod/dependency-injection/di-container.js +30 -0
- package/lib-prod/endpoint-context-storage.js +31 -0
- package/lib-prod/endpoint-context.js +2397 -0
- package/lib-prod/entity-process.js +225 -0
- package/lib-prod/env/{env.angular-node-app.ts → env.angular-node-app.js} +1 -1
- package/lib-prod/env/{env.docs-webapp.ts → env.docs-webapp.js} +1 -1
- package/lib-prod/env/{env.electron-app.ts → env.electron-app.js} +1 -1
- package/lib-prod/env/{env.mobile-app.ts → env.mobile-app.js} +1 -1
- package/lib-prod/env/{env.npm-lib-and-cli-tool.ts → env.npm-lib-and-cli-tool.js} +1 -1
- package/lib-prod/env/{env.vscode-plugin.ts → env.vscode-plugin.js} +1 -1
- package/lib-prod/express-types.js +1 -0
- package/lib-prod/formly/formly.models.js +1 -0
- package/lib-prod/formly/fromly.js +205 -0
- package/lib-prod/formly/type-from-entity.js +51 -0
- package/lib-prod/get-response-value.js +22 -0
- package/lib-prod/global-state/taon-global-state/{index.ts → index.js} +2 -2
- package/lib-prod/global-state/taon-global-state/{taon-global-state.abstract.context.ts → taon-global-state.abstract.context.js} +9 -11
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +7 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +42 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +35 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +12 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +44 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +12 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +46 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +22 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.js +11 -0
- package/lib-prod/global-state/taon-transaction-registry/{index.ts → index.js} +2 -2
- package/lib-prod/global-state/taon-transaction-registry/{taon-transaction-registry.abstract.context.ts → taon-transaction-registry.abstract.context.js} +10 -12
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +5 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +36 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +36 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +12 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +7 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +12 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +31 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +5 -0
- package/lib-prod/helpers/class-helpers.js +228 -0
- package/lib-prod/helpers/clone-obj.js +17 -0
- package/lib-prod/helpers/taon-helpers.js +147 -0
- package/lib-prod/{index._auto-generated_.ts → index._auto-generated_.js} +1 -1
- package/lib-prod/index.js +252 -0
- package/lib-prod/{inject.ts → inject.js} +35 -57
- package/lib-prod/migrations/index.js +2 -0
- package/lib-prod/migrations/{migrations_index._auto-generated_.ts → migrations_index._auto-generated_.js} +0 -2
- package/lib-prod/models.js +78 -0
- package/lib-prod/orm/columns.js +64 -0
- package/lib-prod/orm/index.js +56 -0
- package/lib-prod/package.json +1 -1
- package/lib-prod/realtime/realtime-client.js +198 -0
- package/lib-prod/realtime/realtime-core.js +81 -0
- package/lib-prod/realtime/realtime-server.js +237 -0
- package/lib-prod/realtime/realtime-strategy/{index.ts → index.js} +1 -1
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +280 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +289 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +27 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +11 -0
- package/lib-prod/realtime/realtime-subs-manager.js +88 -0
- package/lib-prod/realtime/realtime.models.js +2 -0
- package/lib-prod/symbols.js +108 -0
- package/lib-prod/ui/index.js +1 -0
- package/lib-prod/ui/taon-admin-mode-configuration/index.js +1 -0
- package/lib-prod/validators.js +80 -0
- package/lib-prod.split-namespaces.json +31 -91
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
- package/lib-prod/base-classes/base-abstract-entity.ts +0 -34
- package/lib-prod/base-classes/base-angular-service.ts +0 -107
- package/lib-prod/base-classes/base-class.ts +0 -46
- package/lib-prod/base-classes/base-controller.ts +0 -240
- package/lib-prod/base-classes/base-crud-controller.ts +0 -298
- package/lib-prod/base-classes/base-custom-repository.ts +0 -10
- package/lib-prod/base-classes/base-entity.ts +0 -28
- package/lib-prod/base-classes/base-file-upload.middleware.ts +0 -92
- package/lib-prod/base-classes/base-injector.ts +0 -278
- package/lib-prod/base-classes/base-middleware.ts +0 -71
- package/lib-prod/base-classes/base-migration.ts +0 -26
- package/lib-prod/base-classes/base-repository.ts +0 -942
- package/lib-prod/base-classes/base-subscriber-for-entity.ts +0 -196
- package/lib-prod/config/controller-config.ts +0 -58
- package/lib-prod/config/controller-options.ts +0 -19
- package/lib-prod/config/method-config.ts +0 -55
- package/lib-prod/config/param-config.ts +0 -16
- package/lib-prod/constants.ts +0 -63
- package/lib-prod/context-db-migrations.ts +0 -488
- package/lib-prod/create-context.ts +0 -345
- package/lib-prod/decorators/classes/controller-decorator.ts +0 -25
- package/lib-prod/decorators/classes/entity-decorator.ts +0 -57
- package/lib-prod/decorators/classes/middleware-decorator.ts +0 -29
- package/lib-prod/decorators/classes/migration-decorator.ts +0 -27
- package/lib-prod/decorators/classes/provider-decorator.ts +0 -28
- package/lib-prod/decorators/classes/repository-decorator.ts +0 -26
- package/lib-prod/decorators/classes/subscriber-decorator.ts +0 -28
- package/lib-prod/decorators/decorator-abstract-opt.ts +0 -4
- package/lib-prod/decorators/http/http-decorators.ts +0 -26
- package/lib-prod/decorators/http/http-methods-decorators.ts +0 -275
- package/lib-prod/decorators/http/http-params-decorators.ts +0 -105
- package/lib-prod/dependency-injection/di-container.ts +0 -39
- package/lib-prod/endpoint-context-storage.ts +0 -47
- package/lib-prod/endpoint-context.ts +0 -3110
- package/lib-prod/entity-process.ts +0 -286
- package/lib-prod/express-types.ts +0 -4
- package/lib-prod/formly/formly.models.ts +0 -7
- package/lib-prod/formly/fromly.ts +0 -261
- package/lib-prod/formly/type-from-entity.ts +0 -80
- package/lib-prod/get-response-value.ts +0 -30
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.ts +0 -9
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.ts +0 -44
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.ts +0 -40
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.ts +0 -12
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.ts +0 -48
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.ts +0 -16
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.ts +0 -47
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.ts +0 -18
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.ts +0 -21
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.ts +0 -7
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.ts +0 -38
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.ts +0 -54
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.ts +0 -12
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.ts +0 -6
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.ts +0 -16
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.ts +0 -29
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.ts +0 -20
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.ts +0 -9
- package/lib-prod/helpers/class-helpers.ts +0 -315
- package/lib-prod/helpers/clone-obj.ts +0 -24
- package/lib-prod/helpers/taon-helpers.ts +0 -181
- package/lib-prod/index.ts +0 -323
- package/lib-prod/lib-info.md +0 -8
- package/lib-prod/migrations/index.ts +0 -2
- package/lib-prod/migrations/migrations-info.md +0 -6
- package/lib-prod/models.ts +0 -427
- package/lib-prod/orm/columns.ts +0 -121
- package/lib-prod/orm/index.ts +0 -62
- package/lib-prod/realtime/realtime-client.ts +0 -288
- package/lib-prod/realtime/realtime-core.ts +0 -134
- package/lib-prod/realtime/realtime-server.ts +0 -398
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.ts +0 -344
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.ts +0 -349
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.ts +0 -30
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.ts +0 -21
- package/lib-prod/realtime/realtime-subs-manager.ts +0 -127
- package/lib-prod/realtime/realtime.models.ts +0 -33
- package/lib-prod/symbols.ts +0 -136
- package/lib-prod/ui/index.ts +0 -1
- package/lib-prod/ui/taon-admin-mode-configuration/index.ts +0 -1
- package/lib-prod/validators.ts +0 -103
- /package/lib-prod/env/{index.ts → index.js} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { TaonBaseInjector } from './base-injector';
|
|
2
|
+
import { TaonSubscriber } from '../decorators/classes/subscriber-decorator';
|
|
3
|
+
let TaonBaseSubscriberForEntity = class TaonBaseSubscriberForEntity extends TaonBaseInjector {
|
|
4
|
+
/**
|
|
5
|
+
* Called after entity is loaded.
|
|
6
|
+
*/
|
|
7
|
+
afterLoad(entity) {
|
|
8
|
+
this.ctx.logDb &&
|
|
9
|
+
console.log(`AFTER ENTITY LOADED: `, entity);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Called before query execution.
|
|
13
|
+
*/
|
|
14
|
+
beforeQuery(event) {
|
|
15
|
+
// BeforeQueryEvent<any>
|
|
16
|
+
this.ctx.logDb &&
|
|
17
|
+
console.log(`BEFORE QUERY: `, event.query);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Called after query execution.
|
|
21
|
+
*/
|
|
22
|
+
afterQuery(event) {
|
|
23
|
+
// AfterQueryEvent<any>
|
|
24
|
+
this.ctx.logDb &&
|
|
25
|
+
console.log(`AFTER QUERY: `, event.query);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Called before entity insertion.
|
|
29
|
+
*/
|
|
30
|
+
beforeInsert(event) {
|
|
31
|
+
this.ctx.logDb &&
|
|
32
|
+
console.log(`BEFORE ENTITY INSERTED: `, event.entity);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Called after entity insertion.
|
|
36
|
+
*/
|
|
37
|
+
afterInsert(event) {
|
|
38
|
+
this.ctx.logDb &&
|
|
39
|
+
console.log(`AFTER ENTITY INSERTED: `, event.entity);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Called before entity update.
|
|
43
|
+
*/
|
|
44
|
+
beforeUpdate(event) {
|
|
45
|
+
this.ctx.logDb &&
|
|
46
|
+
console.log(`BEFORE ENTITY UPDATED: `, event.entity);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Called after entity update.
|
|
50
|
+
*/
|
|
51
|
+
afterUpdate(event) {
|
|
52
|
+
this.ctx.logDb &&
|
|
53
|
+
console.log(`AFTER ENTITY UPDATED: `, event.entity);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Called before entity removal.
|
|
57
|
+
*/
|
|
58
|
+
beforeRemove(event) {
|
|
59
|
+
this.ctx.logDb &&
|
|
60
|
+
console.log(`BEFORE ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Called after entity removal.
|
|
64
|
+
*/
|
|
65
|
+
afterRemove(event) {
|
|
66
|
+
this.ctx.logDb &&
|
|
67
|
+
console.log(`AFTER ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Called before entity removal.
|
|
71
|
+
*/
|
|
72
|
+
beforeSoftRemove(event) {
|
|
73
|
+
this.ctx.logDb &&
|
|
74
|
+
console.log(`BEFORE ENTITY WITH ID ${event.entityId} SOFT REMOVED: `, event.entity);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Called after entity removal.
|
|
78
|
+
*/
|
|
79
|
+
afterSoftRemove(event) {
|
|
80
|
+
this.ctx.logDb &&
|
|
81
|
+
console.log(`AFTER ENTITY WITH ID ${event.entityId} SOFT REMOVED: `, event.entity);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Called before entity recovery.
|
|
85
|
+
*/
|
|
86
|
+
beforeRecover(event) {
|
|
87
|
+
this.ctx.logDb &&
|
|
88
|
+
console.log(`BEFORE ENTITY WITH ID ${event.entityId} RECOVERED: `, event.entity);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Called after entity recovery.
|
|
92
|
+
*/
|
|
93
|
+
afterRecover(event) {
|
|
94
|
+
this.ctx.logDb &&
|
|
95
|
+
console.log(`AFTER ENTITY WITH ID ${event.entityId} RECOVERED: `, event.entity);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Called before transaction start.
|
|
99
|
+
*/
|
|
100
|
+
beforeTransactionStart(event) {
|
|
101
|
+
this.ctx.logDb &&
|
|
102
|
+
console.log(`BEFORE TRANSACTION STARTED: `, event);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Called after transaction start.
|
|
106
|
+
*/
|
|
107
|
+
afterTransactionStart(event) {
|
|
108
|
+
this.ctx.logDb &&
|
|
109
|
+
console.log(`AFTER TRANSACTION STARTED: `, event);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Called before transaction commit.
|
|
113
|
+
*/
|
|
114
|
+
beforeTransactionCommit(event) {
|
|
115
|
+
this.ctx.logDb &&
|
|
116
|
+
console.log(`BEFORE TRANSACTION COMMITTED: `, event);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Called after transaction commit.
|
|
120
|
+
*/
|
|
121
|
+
afterTransactionCommit(event) {
|
|
122
|
+
this.ctx.logDb &&
|
|
123
|
+
console.log(`AFTER TRANSACTION COMMITTED: `, event);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Called before transaction rollback.
|
|
127
|
+
*/
|
|
128
|
+
beforeTransactionRollback(event) {
|
|
129
|
+
this.ctx.logDb &&
|
|
130
|
+
console.log(`BEFORE TRANSACTION ROLLBACK: `, event);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Called after transaction rollback.
|
|
134
|
+
*/
|
|
135
|
+
afterTransactionRollback(event) {
|
|
136
|
+
this.ctx.logDb &&
|
|
137
|
+
console.log(`AFTER TRANSACTION ROLLBACK: `, event);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
TaonBaseSubscriberForEntity = __decorate([
|
|
141
|
+
TaonSubscriber({
|
|
142
|
+
className: 'TaonBaseSubscriberForEntity',
|
|
143
|
+
})
|
|
144
|
+
], TaonBaseSubscriberForEntity);
|
|
145
|
+
export { TaonBaseSubscriberForEntity };
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import * as baseService from './base-angular-service';
|
|
3
|
-
import * as baseClass from './base-class';
|
|
4
|
-
import * as baseContext from './base-context';
|
|
5
|
-
import * as controller from './base-controller';
|
|
6
|
-
import * as crudController from './base-crud-controller';
|
|
7
|
-
import * as customRepository from './base-custom-repository';
|
|
8
|
-
import * as entity from './base-entity';
|
|
9
|
-
import * as baseMiddleware from './base-middleware';
|
|
10
|
-
import * as baseMigration from './base-migration';
|
|
11
|
-
import * as provider from './base-provider';
|
|
12
|
-
import * as repository from './base-repository';
|
|
13
|
-
import * as baseSubscriberEntity from './base-subscriber-for-entity';
|
|
14
|
-
|
|
1
|
+
export {};
|
|
15
2
|
// TODO new 5.8 typescript is not allowing this
|
|
16
3
|
// export namespace Base {
|
|
17
4
|
// export import Controller = controller.TaonBaseController;
|
|
@@ -28,4 +15,4 @@ import * as baseSubscriberEntity from './base-subscriber-for-entity';
|
|
|
28
15
|
// export import Middleware = baseMiddleware.TaonBaseMiddleware;
|
|
29
16
|
// export import AngularService = baseService.TaonBaseAngularService;
|
|
30
17
|
// export const Context = baseContext.TaonBaseContext;
|
|
31
|
-
// }
|
|
18
|
+
// }
|
|
@@ -22,6 +22,5 @@ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
|
22
22
|
/**
|
|
23
23
|
* Autogenerated by current cli tool. Use *tnp release* to bump version.
|
|
24
24
|
*/
|
|
25
|
-
export const CURRENT_PACKAGE_VERSION = '21.0.
|
|
25
|
+
export const CURRENT_PACKAGE_VERSION = '21.0.54';
|
|
26
26
|
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
27
|
-
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// import { cloneObj } from '../helpers/clone-obj';
|
|
2
|
+
import { TaonControllerOptions } from './controller-options';
|
|
3
|
+
// import { ParamConfig } from './param-config';
|
|
4
|
+
export class ControllerConfig extends TaonControllerOptions {
|
|
5
|
+
}
|
|
6
|
+
export const controllerConfigFrom = (partial) => {
|
|
7
|
+
const newObj = partial || {};
|
|
8
|
+
newObj.methods = newObj.methods || {};
|
|
9
|
+
for (const methodName in newObj.methods) {
|
|
10
|
+
if (newObj.methods.hasOwnProperty(methodName)) {
|
|
11
|
+
// newObj.methods[methodName] = new MethodConfig().clone(
|
|
12
|
+
// newObj.methods[methodName],
|
|
13
|
+
// );
|
|
14
|
+
newObj.methods[methodName] = newObj.methods[methodName] || {};
|
|
15
|
+
const params = newObj.methods[methodName].parameters || {};
|
|
16
|
+
newObj.methods[methodName].parameters = params
|
|
17
|
+
? params
|
|
18
|
+
: {};
|
|
19
|
+
for (const paramName in params) {
|
|
20
|
+
if (params.hasOwnProperty(paramName)) {
|
|
21
|
+
params[paramName] = params[paramName] || {};
|
|
22
|
+
// params[paramName] = new ParamConfig().clone(params[paramName]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return newObj;
|
|
28
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const TaonEntityKeysToOmitArr = [
|
|
2
|
+
'ctrl',
|
|
3
|
+
'clone',
|
|
4
|
+
'__endpoint_context__',
|
|
5
|
+
'ctx',
|
|
6
|
+
'inject',
|
|
7
|
+
'_',
|
|
8
|
+
'relation',
|
|
9
|
+
'relations',
|
|
10
|
+
'inject',
|
|
11
|
+
'injectRepo',
|
|
12
|
+
'injectCustomRepository',
|
|
13
|
+
'injectCustomRepo',
|
|
14
|
+
'injectController',
|
|
15
|
+
'injectCtrl',
|
|
16
|
+
'injectProvider',
|
|
17
|
+
'injectMiddleware',
|
|
18
|
+
];
|
|
19
|
+
let TAON_CONTEXT;
|
|
20
|
+
/* */
|
|
21
|
+
/* */
|
|
22
|
+
let CURRENT_HOST_BACKEND_PORT;
|
|
23
|
+
/* */
|
|
24
|
+
/* */
|
|
25
|
+
/* */
|
|
26
|
+
/* */
|
|
27
|
+
let CURRENT_HOST_URL;
|
|
28
|
+
/* */
|
|
29
|
+
/* */
|
|
30
|
+
/* */
|
|
31
|
+
/* */
|
|
32
|
+
export { TAON_CONTEXT, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL };
|
|
33
|
+
export const apiPrefix = 'api';
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
//#region imports
|
|
2
|
+
import { Helpers__NS__throwError, UtilsMigrations__NS__getTimestampFromClassName, UtilsMigrations__NS__isValidTimestamp } from 'tnp-core/lib-prod';
|
|
3
|
+
import { ClassHelpers__NS__getName } from './helpers/class-helpers';
|
|
4
|
+
import { Table, TableIndex, } from 'taon-typeorm/lib-prod';
|
|
5
|
+
export class ContextDbMigrations {
|
|
6
|
+
//#endregion
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region constructor
|
|
9
|
+
constructor(ctx) {
|
|
10
|
+
this.ctx = ctx;
|
|
11
|
+
//#region fields
|
|
12
|
+
//#region fields / migration table name
|
|
13
|
+
this.DEFAULT_MIGRATION_TABLE_NAME = 'TAON_MIGRATION_META';
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region fields / migration statuses
|
|
16
|
+
this.MIGRATION_STATUS_COMPLETED = 'completed';
|
|
17
|
+
this.MIGRATION_STATUS_PENDING = 'pending';
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region fields / migration table schema
|
|
20
|
+
this.table = new Table({
|
|
21
|
+
name: this.DEFAULT_MIGRATION_TABLE_NAME,
|
|
22
|
+
columns: [
|
|
23
|
+
{
|
|
24
|
+
name: 'id',
|
|
25
|
+
type: 'integer',
|
|
26
|
+
isPrimary: true, // Mark it as the primary key
|
|
27
|
+
isGenerated: true, // Enable auto-generation
|
|
28
|
+
generationStrategy: 'increment', // Use auto-increment strategy
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'name',
|
|
32
|
+
type: 'varchar',
|
|
33
|
+
length: '255',
|
|
34
|
+
isUnique: true, // Ensure the name is unique
|
|
35
|
+
isNullable: false, // Ensure this field is required
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
// context is a part of name
|
|
39
|
+
name: 'context',
|
|
40
|
+
type: 'varchar',
|
|
41
|
+
length: '255',
|
|
42
|
+
isNullable: false, // Optional context for migrations (e.g., tenant or module name)
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'applied_at',
|
|
46
|
+
type: 'timestamp',
|
|
47
|
+
default: 'CURRENT_TIMESTAMP', // Automatically set the timestamp
|
|
48
|
+
isNullable: true,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'status',
|
|
52
|
+
type: 'varchar',
|
|
53
|
+
length: '50',
|
|
54
|
+
default: `'${this.MIGRATION_STATUS_COMPLETED}'`,
|
|
55
|
+
isNullable: false,
|
|
56
|
+
},
|
|
57
|
+
// { // TODO not needed for now
|
|
58
|
+
// name: 'checksum',
|
|
59
|
+
// type: 'varchar',
|
|
60
|
+
// length: '64',
|
|
61
|
+
// isNullable: true, // Optional field to store a hash/checksum of migration file
|
|
62
|
+
// },
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region methods & getters / make sure migration table exists
|
|
68
|
+
async ensureMigrationTableExists() {
|
|
69
|
+
//#region @websqlFunc
|
|
70
|
+
if (this.ctx.isRemoteHost || !this.ctx.connection) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const queryRunner = this.ctx.connection.createQueryRunner();
|
|
74
|
+
await queryRunner.connect();
|
|
75
|
+
await queryRunner.startTransaction();
|
|
76
|
+
// Check if the table already exists
|
|
77
|
+
const hasTable = await queryRunner.hasTable(this.DEFAULT_MIGRATION_TABLE_NAME);
|
|
78
|
+
if (hasTable) {
|
|
79
|
+
this.ctx.logMigrations &&
|
|
80
|
+
console.log(`Table ${this.DEFAULT_MIGRATION_TABLE_NAME} already exists.`);
|
|
81
|
+
await queryRunner.commitTransaction();
|
|
82
|
+
await queryRunner.release();
|
|
83
|
+
return; // Exit early if the table exists
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await queryRunner.createTable(this.table);
|
|
87
|
+
await queryRunner.createIndex(this.DEFAULT_MIGRATION_TABLE_NAME, new TableIndex({
|
|
88
|
+
name: 'IDX_NAME',
|
|
89
|
+
columnNames: ['name'],
|
|
90
|
+
}));
|
|
91
|
+
await queryRunner.commitTransaction();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
this.ctx.logMigrations &&
|
|
95
|
+
console.error(`Transaction failed [ensureMigrationTableExists]` + `, rolling back:`, error);
|
|
96
|
+
await queryRunner.rollbackTransaction();
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
await queryRunner.release();
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region methods & getters / revert migration to timestamp
|
|
105
|
+
async logSelectALl(name, queryRunner) {
|
|
106
|
+
console.log(name, (await queryRunner.query(`SELECT * FROM ${this.DEFAULT_MIGRATION_TABLE_NAME} WHERE context = $1`, [this.ctx.contextName])).map(m => m.name));
|
|
107
|
+
}
|
|
108
|
+
async revertMigrationToTimestamp(timestamp) {
|
|
109
|
+
//#region @websqlFunc
|
|
110
|
+
if (this.ctx.isRemoteHost || !this.ctx.connection) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!UtilsMigrations__NS__isValidTimestamp(timestamp)) {
|
|
114
|
+
Helpers__NS__throwError(`Invalid timestamp provided for migration revert: ${timestamp}`);
|
|
115
|
+
}
|
|
116
|
+
// Get all migration class functions and reverse the order
|
|
117
|
+
const migrationsClassFns = this.ctx
|
|
118
|
+
.getClassFunByArr(Models.ClassType.MIGRATION)
|
|
119
|
+
.reverse();
|
|
120
|
+
// Filter migrations that need to be reverted
|
|
121
|
+
const migrationClassesInstancesToRevert = migrationsClassFns
|
|
122
|
+
.map(classFn => {
|
|
123
|
+
const timestampFromClassName = Number(UtilsMigrations__NS__getTimestampFromClassName(ClassHelpers__NS__getName(classFn)));
|
|
124
|
+
if (timestampFromClassName <= timestamp) {
|
|
125
|
+
// this.ctx.logMigrations &&
|
|
126
|
+
// console.log(
|
|
127
|
+
// `Stopping migration filter at: ${ClassHelpers__NS__getName(classFn)} ` +
|
|
128
|
+
// `with timestamp ${timestampFromClassName}`,
|
|
129
|
+
// );
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return this.ctx.getInstanceBy(classFn);
|
|
133
|
+
})
|
|
134
|
+
.filter(f => !!f)
|
|
135
|
+
.map(f => f)
|
|
136
|
+
.filter(migrationInstance => migrationInstance.isReadyToRun());
|
|
137
|
+
const queryRunner = this.ctx.connection.createQueryRunner();
|
|
138
|
+
await queryRunner.connect();
|
|
139
|
+
try {
|
|
140
|
+
await queryRunner.startTransaction();
|
|
141
|
+
// Fetch applied migrations from the database
|
|
142
|
+
const appliedMigrationsForContext = await queryRunner.query(`SELECT name FROM ${this.DEFAULT_MIGRATION_TABLE_NAME}
|
|
143
|
+
WHERE status = $1 AND context = $2`, [this.MIGRATION_STATUS_COMPLETED, this.ctx.contextName]);
|
|
144
|
+
const appliedMigrationsForContextNames = appliedMigrationsForContext.map(m => m.name);
|
|
145
|
+
// console.log({ appliedMigrationsForContextNames });
|
|
146
|
+
for (const migrationClassInstance of migrationClassesInstancesToRevert) {
|
|
147
|
+
const migrationName = ClassHelpers__NS__getName(migrationClassInstance);
|
|
148
|
+
if (!appliedMigrationsForContextNames.includes(migrationName)) {
|
|
149
|
+
this.ctx.logMigrations &&
|
|
150
|
+
console.warn(`Skipping migration not marked as applied: ${migrationName}`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
this.ctx.logMigrations &&
|
|
154
|
+
console.log(`Reverting migration: ${migrationName} , context: ${this.ctx.contextName}`);
|
|
155
|
+
await migrationClassInstance.down(queryRunner);
|
|
156
|
+
// Remove the reverted migration from the tracking table
|
|
157
|
+
await queryRunner.query(`DELETE FROM ${this.DEFAULT_MIGRATION_TABLE_NAME} WHERE name = $1`, [migrationName]);
|
|
158
|
+
}
|
|
159
|
+
await queryRunner.commitTransaction();
|
|
160
|
+
this.ctx.logMigrations &&
|
|
161
|
+
console.log(`Migrations successfully reverted ` +
|
|
162
|
+
`to the specified timestamp ${timestamp} .`);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
this.ctx.logMigrations &&
|
|
166
|
+
console.error('Transaction failed, rolling back:', error);
|
|
167
|
+
await queryRunner.rollbackTransaction();
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
await queryRunner.release();
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region methods & getters / clear migration table
|
|
176
|
+
async clearMigrationTable() {
|
|
177
|
+
//#region @websqlFunc
|
|
178
|
+
if (this.ctx.isRemoteHost || !this.ctx.connection) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const queryRunner = this.ctx.connection.createQueryRunner();
|
|
182
|
+
await queryRunner.connect();
|
|
183
|
+
await queryRunner.startTransaction();
|
|
184
|
+
try {
|
|
185
|
+
await queryRunner.clearTable(this.DEFAULT_MIGRATION_TABLE_NAME);
|
|
186
|
+
await queryRunner.commitTransaction();
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
this.ctx.logMigrations &&
|
|
190
|
+
console.error('Transaction failed, rolling back:', error);
|
|
191
|
+
await queryRunner.rollbackTransaction();
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
await queryRunner.release();
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region methods & getters / mark all migrations as applied
|
|
200
|
+
async markAllMigrationsAsApplied() {
|
|
201
|
+
//#region @websqlFunc
|
|
202
|
+
if (this.ctx.isRemoteHost || !this.ctx.connection) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const migrationsClassFns = this.ctx.getClassFunByArr(Models.ClassType.MIGRATION);
|
|
206
|
+
const migrationClassesInstances = migrationsClassFns
|
|
207
|
+
.map(classFn => this.ctx.getInstanceBy(classFn))
|
|
208
|
+
.map(f => f)
|
|
209
|
+
.filter(migrationInstance => migrationInstance.isReadyToRun());
|
|
210
|
+
const queryRunner = this.ctx.connection.createQueryRunner();
|
|
211
|
+
await queryRunner.connect();
|
|
212
|
+
try {
|
|
213
|
+
await queryRunner.startTransaction();
|
|
214
|
+
// Fetch already applied migrations from the database
|
|
215
|
+
const allMigrationsInDb = await queryRunner.query(`SELECT name FROM ${this.DEFAULT_MIGRATION_TABLE_NAME}`);
|
|
216
|
+
const allMigrationInDBNames = allMigrationsInDb.map(m => m.name);
|
|
217
|
+
for (const instance of migrationClassesInstances) {
|
|
218
|
+
const migrationName = ClassHelpers__NS__getName(instance);
|
|
219
|
+
if (allMigrationInDBNames.includes(migrationName)) {
|
|
220
|
+
this.ctx.logMigrations &&
|
|
221
|
+
console.log(`Skipping already applied migration: ${migrationName}`);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
this.ctx.logMigrations &&
|
|
225
|
+
console.log(`Marking migration as applied: ${migrationName}`);
|
|
226
|
+
// Insert migration as 'complete' without running
|
|
227
|
+
await queryRunner.query(`INSERT INTO ${this.DEFAULT_MIGRATION_TABLE_NAME} (name, status, context, applied_at) ` +
|
|
228
|
+
`VALUES ($1, $2, $3, CURRENT_TIMESTAMP)`, [
|
|
229
|
+
migrationName,
|
|
230
|
+
this.MIGRATION_STATUS_COMPLETED,
|
|
231
|
+
instance.ctx.contextName,
|
|
232
|
+
]);
|
|
233
|
+
}
|
|
234
|
+
// update all pending migrations to completed
|
|
235
|
+
await queryRunner.query(`UPDATE ${this.DEFAULT_MIGRATION_TABLE_NAME}
|
|
236
|
+
SET status = $1, applied_at = CURRENT_TIMESTAMP
|
|
237
|
+
WHERE status = $2`, [this.MIGRATION_STATUS_COMPLETED, this.MIGRATION_STATUS_PENDING]);
|
|
238
|
+
await queryRunner.commitTransaction();
|
|
239
|
+
this.ctx.logMigrations &&
|
|
240
|
+
console.log('All migrations marked as applied.');
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
this.ctx.logMigrations &&
|
|
244
|
+
console.error('Failed to mark all migrations as applied, rolling back:', error);
|
|
245
|
+
await queryRunner.rollbackTransaction();
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
await queryRunner.release();
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region methods & getters / run all migrations
|
|
254
|
+
async runAllNotCompletedMigrations() {
|
|
255
|
+
//#region @websqlFunc
|
|
256
|
+
if (this.ctx.isRemoteHost || !this.ctx.connection) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const migrationsClassFns = this.ctx.getClassFunByArr(Models.ClassType.MIGRATION);
|
|
260
|
+
// console.log({
|
|
261
|
+
// migrationClassesALl: migrationsClassFns.map(f => ClassHelpers__NS__getName(f)),
|
|
262
|
+
// });
|
|
263
|
+
const migrationClassesInstances = migrationsClassFns
|
|
264
|
+
.map(classFn => this.ctx.getInstanceBy(classFn))
|
|
265
|
+
.map(f => f)
|
|
266
|
+
.filter(migrationInstance => migrationInstance.isReadyToRun());
|
|
267
|
+
// console.log({
|
|
268
|
+
// migrationClassesInstances: migrationsClassFns.map(f =>
|
|
269
|
+
// ClassHelpers__NS__getName(f),
|
|
270
|
+
// ),
|
|
271
|
+
// });
|
|
272
|
+
const queryRunner = this.ctx.connection.createQueryRunner();
|
|
273
|
+
await queryRunner.connect();
|
|
274
|
+
try {
|
|
275
|
+
await queryRunner.startTransaction();
|
|
276
|
+
// Check if the migrations table exists
|
|
277
|
+
// TODO: Implement check for migrations table existence here
|
|
278
|
+
// Fetch applied migrations from the database
|
|
279
|
+
const appliedMigrationsForContext = await queryRunner.query(`SELECT name, status FROM ${this.DEFAULT_MIGRATION_TABLE_NAME} ` +
|
|
280
|
+
`WHERE context = $1`, [this.ctx.contextName]);
|
|
281
|
+
//#region check and update pending migrations
|
|
282
|
+
const pendingMigrationsForContext = appliedMigrationsForContext.filter(m => m.status === this.MIGRATION_STATUS_PENDING);
|
|
283
|
+
// Run pending migrations first
|
|
284
|
+
for (const pendingContextMigration of pendingMigrationsForContext) {
|
|
285
|
+
const migrationInstance = migrationClassesInstances.find(instance => ClassHelpers__NS__getName(instance) === pendingContextMigration.name);
|
|
286
|
+
if (!migrationInstance) {
|
|
287
|
+
this.ctx.logMigrations &&
|
|
288
|
+
console.warn(`Pending migration ${pendingContextMigration.name} not found in loaded migrations.`);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
this.ctx.logMigrations &&
|
|
292
|
+
console.log(`Completing pending migration: ${pendingContextMigration.name}`);
|
|
293
|
+
await migrationInstance.up(queryRunner);
|
|
294
|
+
// Update migration status to 'complete'
|
|
295
|
+
await queryRunner.query(`UPDATE ${this.DEFAULT_MIGRATION_TABLE_NAME}
|
|
296
|
+
SET status = $1, applied_at = CURRENT_TIMESTAMP
|
|
297
|
+
WHERE name = $2`, [this.MIGRATION_STATUS_COMPLETED, pendingContextMigration.name]);
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region run new migrations
|
|
301
|
+
for (const instance of migrationClassesInstances) {
|
|
302
|
+
const migrationName = ClassHelpers__NS__getName(instance);
|
|
303
|
+
if (appliedMigrationsForContext.some(m => m.name === migrationName)) {
|
|
304
|
+
this.ctx.logMigrations &&
|
|
305
|
+
console.log(`Skipping already applied migration: ${migrationName}`);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
this.ctx.logMigrations &&
|
|
309
|
+
console.log(`Applying new migration: ${migrationName}`);
|
|
310
|
+
// Insert migration as 'pending' before execution
|
|
311
|
+
await queryRunner.query(`INSERT INTO ${this.DEFAULT_MIGRATION_TABLE_NAME} (name, status, context, applied_at) ` +
|
|
312
|
+
`VALUES ($1, $2, $3, NULL)`, [migrationName, this.MIGRATION_STATUS_PENDING, this.ctx.contextName]);
|
|
313
|
+
try {
|
|
314
|
+
// Apply migration
|
|
315
|
+
await instance.up(queryRunner);
|
|
316
|
+
// Update migration to 'complete' after successful execution
|
|
317
|
+
await queryRunner.query(`UPDATE ${this.DEFAULT_MIGRATION_TABLE_NAME} ` +
|
|
318
|
+
`SET status = '${this.MIGRATION_STATUS_COMPLETED}', applied_at = CURRENT_TIMESTAMP ` +
|
|
319
|
+
`WHERE name = $1`, [migrationName]);
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
this.ctx.logMigrations &&
|
|
323
|
+
console.error(`Failed to apply migration: ${migrationName}`, error);
|
|
324
|
+
// Rollback pending migration entry
|
|
325
|
+
await queryRunner.query(`DELETE FROM ${this.DEFAULT_MIGRATION_TABLE_NAME} WHERE name = $1`, [migrationName]);
|
|
326
|
+
throw error; // Rethrow to ensure the transaction is rolled back
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
//#endregion
|
|
330
|
+
await queryRunner.commitTransaction();
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
this.ctx.logMigrations &&
|
|
334
|
+
console.error('Transaction failed, rolling back:', error);
|
|
335
|
+
await queryRunner.rollbackTransaction();
|
|
336
|
+
}
|
|
337
|
+
finally {
|
|
338
|
+
await queryRunner.release();
|
|
339
|
+
}
|
|
340
|
+
//#endregion
|
|
341
|
+
}
|
|
342
|
+
}
|