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,64 @@
|
|
|
1
|
+
import { Column } from 'taon-typeorm/lib-prod';
|
|
2
|
+
import { ___NS__isNil } from 'tnp-core/lib-prod';
|
|
3
|
+
export { Repository, Connection, Generated, AfterInsert, AfterLoad, AfterRecover, AfterRemove, AfterSoftRemove, AfterUpdate, BeforeInsert, BeforeRecover, BeforeRemove, BeforeSoftRemove, BeforeUpdate, TreeChildren, TreeParent, PrimaryGeneratedColumn, PrimaryColumn, Index, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Column, VersionColumn, VirtualColumn, JoinTable, JoinColumn, OneToMany, OneToOne, ManyToMany, ManyToOne, } from 'taon-typeorm/lib-prod';
|
|
4
|
+
export { Column as CustomColumn } from 'taon-typeorm/lib-prod';
|
|
5
|
+
export { Generated as GeneratedColumn } from 'taon-typeorm/lib-prod';
|
|
6
|
+
/**
|
|
7
|
+
* 100 default characters varchar
|
|
8
|
+
*/
|
|
9
|
+
export const StringColumn = (defaultValue = null, length = 100) => Column({
|
|
10
|
+
type: 'varchar',
|
|
11
|
+
length,
|
|
12
|
+
nullable: ___NS__isNil(defaultValue),
|
|
13
|
+
default: defaultValue,
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* 100 characters varchar
|
|
17
|
+
*/
|
|
18
|
+
export const String100Column = (defaultValue = null) => Column({
|
|
19
|
+
type: 'varchar',
|
|
20
|
+
length: 100,
|
|
21
|
+
nullable: ___NS__isNil(defaultValue),
|
|
22
|
+
default: defaultValue,
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* 20 characters varchar
|
|
26
|
+
*/
|
|
27
|
+
export const String20Column = (defaultValue = null) => Column({
|
|
28
|
+
type: 'varchar',
|
|
29
|
+
length: 20,
|
|
30
|
+
nullable: ___NS__isNil(defaultValue),
|
|
31
|
+
default: defaultValue,
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* 45 characters varchar
|
|
35
|
+
*/
|
|
36
|
+
export const String45Column = (defaultValue = null) => Column({
|
|
37
|
+
type: 'varchar',
|
|
38
|
+
length: 45,
|
|
39
|
+
nullable: ___NS__isNil(defaultValue),
|
|
40
|
+
default: defaultValue,
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* 500 characters varchar
|
|
44
|
+
*/
|
|
45
|
+
export const String500Column = (defaultValue = null) => Column({
|
|
46
|
+
type: 'varchar',
|
|
47
|
+
length: 500,
|
|
48
|
+
nullable: ___NS__isNil(defaultValue),
|
|
49
|
+
default: defaultValue,
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* 200 characters varchar
|
|
53
|
+
*/
|
|
54
|
+
export const String200Column = (defaultValue = null) => Column({
|
|
55
|
+
type: 'varchar',
|
|
56
|
+
length: 200,
|
|
57
|
+
nullable: ___NS__isNil(defaultValue),
|
|
58
|
+
default: defaultValue,
|
|
59
|
+
});
|
|
60
|
+
export const NumberColumn = () => Column({ type: 'int', nullable: true });
|
|
61
|
+
export const DecimalNumberColumn = () => Column({ type: 'float', nullable: true });
|
|
62
|
+
export const SimpleJsonColumn = () => Column({ type: 'simple-json', nullable: true });
|
|
63
|
+
export const BooleanColumn = (defaultValue) => Column({ type: 'boolean', nullable: true, default: defaultValue });
|
|
64
|
+
export const DateTimeColumn = (defaultValue = null) => Column({ type: 'datetime', nullable: true, default: defaultValue });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export * from './columns';
|
|
2
|
+
// TODO new 5.8 typescript is not allowing this
|
|
3
|
+
// export namespace Orm {
|
|
4
|
+
// export const Repository = tsorm.Repository;
|
|
5
|
+
// export import Connection = tsorm.Connection;
|
|
6
|
+
// export namespace ListenEvent {
|
|
7
|
+
// export import AfterInsert = tsorm.AfterInsert;
|
|
8
|
+
// export import AfterLoad = tsorm.AfterLoad;
|
|
9
|
+
// export import AfterRecover = tsorm.AfterRecover;
|
|
10
|
+
// export import AfterRemove = tsorm.AfterRemove;
|
|
11
|
+
// export import AfterSoftRemove = tsorm.AfterSoftRemove;
|
|
12
|
+
// export import AfterUpdate = tsorm.AfterUpdate;
|
|
13
|
+
// export import BeforeInsert = tsorm.BeforeInsert;
|
|
14
|
+
// export import BeforeRecover = tsorm.BeforeRecover;
|
|
15
|
+
// export import BeforeRemove = tsorm.BeforeRemove;
|
|
16
|
+
// export import BeforeSoftRemove = tsorm.BeforeSoftRemove;
|
|
17
|
+
// export import BeforeUpdate = tsorm.BeforeUpdate;
|
|
18
|
+
// }
|
|
19
|
+
// export namespace Tree {
|
|
20
|
+
// export import Children = tsorm.TreeChildren;
|
|
21
|
+
// export import Parent = tsorm.TreeParent;
|
|
22
|
+
// }
|
|
23
|
+
// export namespace Column {
|
|
24
|
+
// export import Generated = tsorm.PrimaryGeneratedColumn;
|
|
25
|
+
// export import Primary = tsorm.PrimaryColumn;
|
|
26
|
+
// export import Index = tsorm.Index;
|
|
27
|
+
// export import CreateDate = tsorm.CreateDateColumn;
|
|
28
|
+
// export import UpdateDate = tsorm.UpdateDateColumn;
|
|
29
|
+
// export import DeleteDate = tsorm.DeleteDateColumn;
|
|
30
|
+
// export import Custom = tsorm.Column;
|
|
31
|
+
// export import String = additionalColumns.StringColumn;
|
|
32
|
+
// export import String100 = additionalColumns.String100Column;
|
|
33
|
+
// export import String45 = additionalColumns.String45Column;
|
|
34
|
+
// export import String500 = additionalColumns.String500Column;
|
|
35
|
+
// export import String200 = additionalColumns.String200Column;
|
|
36
|
+
// export import Number = additionalColumns.NumberColumn;
|
|
37
|
+
// export import DecimalNumber = additionalColumns.DecimalNumberColumn;
|
|
38
|
+
// export import SimpleJson = additionalColumns.SimpleJsonColumn;
|
|
39
|
+
// export import Boolean = additionalColumns.BooleanColumn;
|
|
40
|
+
// export import DateTIme = additionalColumns.DateTImeColumn;
|
|
41
|
+
// // TODO has limitation => comma in name
|
|
42
|
+
// // export const SimpleArray = () => tsorm.Column({ type: 'simple-array', nullable: true });
|
|
43
|
+
// export import Version = tsorm.VersionColumn;
|
|
44
|
+
// export import Virtual = tsorm.VirtualColumn;
|
|
45
|
+
// }
|
|
46
|
+
// export namespace Join {
|
|
47
|
+
// export import Table = tsorm.JoinTable;
|
|
48
|
+
// export import Column = tsorm.JoinColumn;
|
|
49
|
+
// }
|
|
50
|
+
// export namespace Relation {
|
|
51
|
+
// export import OneToMany = tsorm.OneToMany;
|
|
52
|
+
// export import OneToOne = tsorm.OneToOne;
|
|
53
|
+
// export import ManyToMany = tsorm.ManyToMany;
|
|
54
|
+
// export import ManyToOne = tsorm.ManyToOne;
|
|
55
|
+
// }
|
|
56
|
+
// }
|
package/lib-prod/package.json
CHANGED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
//#region imports
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ___NS__isObject, ___NS__isString } from 'tnp-core/lib-prod';
|
|
4
|
+
import { Helpers__NS__logInfo } from 'tnp-core/lib-prod';
|
|
5
|
+
import { ClassHelpers__NS__getClassFnFromObject, ClassHelpers__NS__getName, ClassHelpers__NS__getUniqueKey } from '../helpers/class-helpers';
|
|
6
|
+
import { Symbols__NS__REALTIME } from '../symbols';
|
|
7
|
+
import { RealtimeSubsManager } from './realtime-subs-manager';
|
|
8
|
+
//#endregion
|
|
9
|
+
/**
|
|
10
|
+
* Client for realtime communication
|
|
11
|
+
* you can listen to:
|
|
12
|
+
* - entity changes (any property in table changed)
|
|
13
|
+
* - entity custom property changes (specific property changed)
|
|
14
|
+
* - entity table changes (new instance added, instance removed)
|
|
15
|
+
* - custom events
|
|
16
|
+
*/
|
|
17
|
+
export class RealtimeClient {
|
|
18
|
+
constructor(core) {
|
|
19
|
+
this.core = core;
|
|
20
|
+
this.subsManagers = {};
|
|
21
|
+
this.core = core;
|
|
22
|
+
if (!core.ctx.disabledRealtime) {
|
|
23
|
+
// this.core.ctx.logRealtime &&
|
|
24
|
+
// Helpers__NS__info(`
|
|
25
|
+
// [ctx=${this.core.ctx.contextName}] init RealtimeClient (type: ${this.core.ctx.contextType})
|
|
26
|
+
// `);
|
|
27
|
+
this.init();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//#region methods & getters / init
|
|
31
|
+
init() {
|
|
32
|
+
//#region prepare naspaces pathes
|
|
33
|
+
const nspPath = {
|
|
34
|
+
global: this.core.pathFor(),
|
|
35
|
+
realtime: this.core.pathFor(Symbols__NS__REALTIME.NAMESPACE(this.core.ctx.contextName)),
|
|
36
|
+
};
|
|
37
|
+
// console.log('[browser] nspPath', nspPath);
|
|
38
|
+
if (this.core.ctx.config.frontendHost &&
|
|
39
|
+
this.core.ctx.config.frontendHost !== '' &&
|
|
40
|
+
this.core.ctx.isRunningInsideDocker) {
|
|
41
|
+
this.core.ctx.logRealtime &&
|
|
42
|
+
Helpers__NS__logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
|
|
43
|
+
` ${this.core.ctx.config.frontendHost} FOR REALTIME`);
|
|
44
|
+
nspPath.global = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.global.pathname}`);
|
|
45
|
+
nspPath.realtime = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.realtime.pathname}`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.core.ctx.logRealtime &&
|
|
49
|
+
Helpers__NS__logInfo(`[${this.core.ctx.contextName}] Not using frontend host for realtime`);
|
|
50
|
+
}
|
|
51
|
+
this.core.ctx.logRealtime &&
|
|
52
|
+
console.info('[CLIENT] NAMESPACE GLOBAL ', nspPath.global.href + ` host: ${this.core.ctx.host}`);
|
|
53
|
+
this.core.ctx.logRealtime &&
|
|
54
|
+
console.info('[CLIENT] NAMESPACE REALTIME', nspPath.realtime.href + ` host: ${this.core.ctx.host}`);
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region prepare globa FE socket
|
|
57
|
+
this.core.conectSocketFE = this.core.strategy.ioClient(nspPath.global.origin, {
|
|
58
|
+
path: nspPath.global.pathname,
|
|
59
|
+
});
|
|
60
|
+
if (this.core.conectSocketFE.on) {
|
|
61
|
+
this.core.conectSocketFE.on('connect', () => {
|
|
62
|
+
// console.info(
|
|
63
|
+
// `[CLIENT] connected to GLOBAL namespace ${global.nsp} of host: ${context.host}`,
|
|
64
|
+
// );
|
|
65
|
+
this.core.ctx.logRealtime &&
|
|
66
|
+
console.info(`[CLIENT] connected to GLOBAL namespace ${nspPath.global.pathname}` +
|
|
67
|
+
` of host: ${this.core.ctx.host}`);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region prepare realtime FE socket
|
|
72
|
+
this.core.socketFE = this.core.strategy.ioClient(nspPath.realtime.origin, {
|
|
73
|
+
path: nspPath.realtime.pathname,
|
|
74
|
+
});
|
|
75
|
+
if (this.core.socketFE.on) {
|
|
76
|
+
this.core.socketFE.on('connect', () => {
|
|
77
|
+
// console.info(
|
|
78
|
+
// `[CLIENT] connected to REALTIME namespace ${realtime.nsp} host: ${context.host}`,
|
|
79
|
+
// );
|
|
80
|
+
this.core.ctx.logRealtime &&
|
|
81
|
+
console.info(`[CLIENT] connected to REALTIME namespace ${nspPath.realtime.pathname}` +
|
|
82
|
+
` host: ${this.core.ctx.host}`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region methods & getters / listen changes entity
|
|
89
|
+
/**
|
|
90
|
+
* Usage:
|
|
91
|
+
* myContext.realtimeClient.listenChangesEntity(myEntityInstance);
|
|
92
|
+
*
|
|
93
|
+
*
|
|
94
|
+
* Changes trigger on backend needs to be done manually.. example code:
|
|
95
|
+
*
|
|
96
|
+
* myContext.realtimeServer.triggerEntityChanges(myEntityInstance);
|
|
97
|
+
* ...
|
|
98
|
+
*/
|
|
99
|
+
listenChangesEntity(entityClassFnOrObj, options) {
|
|
100
|
+
options = options || {};
|
|
101
|
+
if (___NS__isObject(entityClassFnOrObj)) {
|
|
102
|
+
const orgObj = entityClassFnOrObj;
|
|
103
|
+
entityClassFnOrObj =
|
|
104
|
+
ClassHelpers__NS__getClassFnFromObject(entityClassFnOrObj);
|
|
105
|
+
const uniqueKey = ClassHelpers__NS__getUniqueKey(entityClassFnOrObj);
|
|
106
|
+
if (uniqueKey) {
|
|
107
|
+
options.idOrUniqValue = orgObj[uniqueKey];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//#region parameters validation
|
|
111
|
+
const { property, customEvent } = options;
|
|
112
|
+
const className = !customEvent && ClassHelpers__NS__getName(entityClassFnOrObj);
|
|
113
|
+
if (___NS__isString(property)) {
|
|
114
|
+
if (property.trim() === '') {
|
|
115
|
+
throw new Error(`[Taon][listenChangesEntity.. incorrect property '' for ${className}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
return new Observable(observer => {
|
|
120
|
+
//#region prepare parameters for manager
|
|
121
|
+
if (this.core.ctx.disabledRealtime) {
|
|
122
|
+
console.error(`[Taon][realtime rxjs] remove taon config flag:
|
|
123
|
+
|
|
124
|
+
...
|
|
125
|
+
disabledRealtime: true
|
|
126
|
+
...
|
|
127
|
+
|
|
128
|
+
to use socket realtime connection;
|
|
129
|
+
`);
|
|
130
|
+
return () => {
|
|
131
|
+
// empty nothing to do
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
let roomName;
|
|
135
|
+
if (customEvent) {
|
|
136
|
+
roomName = Symbols__NS__REALTIME.ROOM_NAME_CUSTOM(this.core.ctx.contextName, customEvent);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
roomName = ___NS__isString(property)
|
|
140
|
+
? Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, className, property, options.idOrUniqValue)
|
|
141
|
+
: Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, className, options.idOrUniqValue);
|
|
142
|
+
}
|
|
143
|
+
const roomSubOptions = {
|
|
144
|
+
core: this.core,
|
|
145
|
+
property,
|
|
146
|
+
roomName,
|
|
147
|
+
customEvent,
|
|
148
|
+
};
|
|
149
|
+
//#endregion
|
|
150
|
+
const subManagerId = this.getUniqueIdentifierForConnection(roomSubOptions);
|
|
151
|
+
if (!this.subsManagers[subManagerId]) {
|
|
152
|
+
this.subsManagers[subManagerId] = new RealtimeSubsManager(roomSubOptions);
|
|
153
|
+
}
|
|
154
|
+
const inst = this.subsManagers[subManagerId];
|
|
155
|
+
inst.add(observer);
|
|
156
|
+
inst.startListenIfNotStarted(this.core.socketFE);
|
|
157
|
+
return () => {
|
|
158
|
+
inst.remove(observer);
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region listen changes entity table
|
|
164
|
+
/**
|
|
165
|
+
* Listen changes entity table
|
|
166
|
+
* Example: for pagination, lists update ...
|
|
167
|
+
*/
|
|
168
|
+
listenChangesEntityTable(entityClassFn) {
|
|
169
|
+
const className = ClassHelpers__NS__getName(entityClassFn);
|
|
170
|
+
return this.listenChangesEntity(entityClassFn, {
|
|
171
|
+
customEvent: Symbols__NS__REALTIME.TABLE_CHANGE(this.core.ctx.contextName, className),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region listen changes custom event
|
|
176
|
+
listenChangesCustomEvent(customEvent) {
|
|
177
|
+
return this.listenChangesEntity(void 0, {
|
|
178
|
+
customEvent,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region methods & getters / trigger custom event\
|
|
183
|
+
/**
|
|
184
|
+
* Trigger custom event on backend
|
|
185
|
+
* @param customEvent global event name
|
|
186
|
+
* @param dataToPush
|
|
187
|
+
*/
|
|
188
|
+
triggerCustomEvent(customEvent, dataToPush) {
|
|
189
|
+
this.core.socketFE.emit(customEvent, dataToPush);
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region methods & getters / get room id from
|
|
193
|
+
getUniqueIdentifierForConnection(options) {
|
|
194
|
+
let url = new URL(options.core.ctx.host);
|
|
195
|
+
let contextNameForCommunication = options.core.ctx.contextNameForCommunication;
|
|
196
|
+
return `${contextNameForCommunication}:${url.origin}|${options.roomName}|${options.property}|${options.customEvent}`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { UtilsOs__NS__isElectron, UtilsOs__NS__isWebSQL } from 'tnp-core/lib-prod';
|
|
2
|
+
import { apiPrefix } from '../constants';
|
|
3
|
+
import { RealtimeClient } from './realtime-client';
|
|
4
|
+
import { RealtimeServer } from './realtime-server';
|
|
5
|
+
import { RealtimeStrategyIpc, RealtimeStrategyMock, RealtimeStrategySocketIO, } from './realtime-strategy';
|
|
6
|
+
//#endregion
|
|
7
|
+
/**
|
|
8
|
+
* Realtime class
|
|
9
|
+
* - mock (when browser-browser)
|
|
10
|
+
* - sockets (from socket io when backend-browser)
|
|
11
|
+
* - ipc (when electron is used or between processes)
|
|
12
|
+
* - webworker (when webworker is used in browser or nodejs)
|
|
13
|
+
*/
|
|
14
|
+
export class RealtimeCore {
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region constructor
|
|
17
|
+
constructor(ctx) {
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
//#region fields
|
|
20
|
+
this.allHttpMethods = [
|
|
21
|
+
'GET',
|
|
22
|
+
'POST',
|
|
23
|
+
'PUT',
|
|
24
|
+
'DELETE',
|
|
25
|
+
'PATCH',
|
|
26
|
+
'OPTIONS',
|
|
27
|
+
'HEAD',
|
|
28
|
+
];
|
|
29
|
+
this.ctx = ctx;
|
|
30
|
+
this.strategy = this.resolveStrategy();
|
|
31
|
+
// this.ctx.logRealtime &&
|
|
32
|
+
// console.log(`
|
|
33
|
+
// [ctx=${this.ctx.contextName}] realtime strategy: ${this.strategy}, context type: ${this.ctx.contextType}
|
|
34
|
+
// `);
|
|
35
|
+
if (UtilsOs__NS__isWebSQL) {
|
|
36
|
+
this.server = new RealtimeServer(this);
|
|
37
|
+
// console.log('DONE INITING SERVER');
|
|
38
|
+
this.client = new RealtimeClient(this);
|
|
39
|
+
// console.log('DONE INITING CLIENT');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.client = new RealtimeClient(this);
|
|
43
|
+
this.server = new RealtimeServer(this);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region methods & getters / resovle staraegy
|
|
48
|
+
resolveStrategy() {
|
|
49
|
+
// console.log(`[taon] resolveStrategy for this.ctx.mode ${this.ctx.mode}`);
|
|
50
|
+
if (this.ctx.mode === 'backend-frontend(websql)' ||
|
|
51
|
+
this.ctx.mode === 'backend-frontend(websql-electron)') {
|
|
52
|
+
// debugger
|
|
53
|
+
return new RealtimeStrategyMock(this.ctx);
|
|
54
|
+
}
|
|
55
|
+
if (this.ctx.mode === 'backend-frontend(ipc-electron)') {
|
|
56
|
+
return new RealtimeStrategyIpc(this.ctx);
|
|
57
|
+
}
|
|
58
|
+
// if (this.ctx.mode === 'backend-frontend(tcp+udp)') {
|
|
59
|
+
// return new RealtimeStrategySocketIO(this.ctx);
|
|
60
|
+
// }
|
|
61
|
+
// if (this.ctx.mode === 'remote-backend(tcp+udp)') {
|
|
62
|
+
// return new RealtimeStrategySocketIO(this.ctx);
|
|
63
|
+
// }
|
|
64
|
+
return new RealtimeStrategySocketIO(this.ctx);
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region path for
|
|
68
|
+
pathFor(namespace) {
|
|
69
|
+
let nsp = namespace ? namespace : '';
|
|
70
|
+
nsp = nsp === '/' ? '' : nsp;
|
|
71
|
+
const contextNameForCommunication = this.ctx.contextNameForCommunication;
|
|
72
|
+
let prefix = `${apiPrefix}/${contextNameForCommunication}/udp`;
|
|
73
|
+
if (UtilsOs__NS__isElectron) {
|
|
74
|
+
prefix = ``;
|
|
75
|
+
}
|
|
76
|
+
const href = `${this.ctx.uriOrigin}${this.ctx.uriPathnameOrNothingIfRoot}` +
|
|
77
|
+
`/${prefix}${prefix && nsp ? '-' + nsp : nsp}`;
|
|
78
|
+
// console.log(`HREF: ${href}, nsp: ${nsp}`)
|
|
79
|
+
return new URL(href);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
import { ___NS__isArray, ___NS__isFunction, ___NS__isObject, ___NS__isString, Helpers__NS__error, UtilsOs__NS__isElectron, UtilsOs__NS__isWebSQL } from 'tnp-core/lib-prod';
|
|
3
|
+
import { ClassHelpers__NS__getClassFnFromObject, ClassHelpers__NS__getName, ClassHelpers__NS__getUniqueKey } from '../helpers/class-helpers';
|
|
4
|
+
import { Symbols__NS__REALTIME } from '../symbols';
|
|
5
|
+
//#endregion
|
|
6
|
+
/**
|
|
7
|
+
* Server for realtime communication
|
|
8
|
+
* you can trigger:
|
|
9
|
+
* - entity changes (any property in table changed)
|
|
10
|
+
* - entity custom property changes (specific property changed)
|
|
11
|
+
* - entity table changes (new instance added, instance removed)
|
|
12
|
+
* - custom events
|
|
13
|
+
*
|
|
14
|
+
* and also listen to:
|
|
15
|
+
* - custom events from yourself
|
|
16
|
+
*/
|
|
17
|
+
export class RealtimeServer {
|
|
18
|
+
// private jobs = {};
|
|
19
|
+
constructor(core) {
|
|
20
|
+
this.core = core;
|
|
21
|
+
this.core = core;
|
|
22
|
+
if (core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
//#region @websql
|
|
26
|
+
this.init();
|
|
27
|
+
//#endregion
|
|
28
|
+
}
|
|
29
|
+
//#region methods & getters / init
|
|
30
|
+
init() {
|
|
31
|
+
/* */
|
|
32
|
+
/* */
|
|
33
|
+
/* */
|
|
34
|
+
/* */
|
|
35
|
+
/* */
|
|
36
|
+
/* */
|
|
37
|
+
/* */
|
|
38
|
+
/* */
|
|
39
|
+
/* */
|
|
40
|
+
/* */
|
|
41
|
+
/* */
|
|
42
|
+
//#region @websql
|
|
43
|
+
//#region prepare namespaces pathes
|
|
44
|
+
const nspPathGlobal = this.core.pathFor();
|
|
45
|
+
const nspPathRealtime = this.core.pathFor(Symbols__NS__REALTIME.NAMESPACE(this.core.ctx.contextName));
|
|
46
|
+
//#endregion
|
|
47
|
+
// console.log('[backend] nspPath', nspPath);
|
|
48
|
+
const cors = {
|
|
49
|
+
origin: this.core.ctx.frontendHostUri.origin, // only origin needs to be set - pathname not needed
|
|
50
|
+
methods: this.core.allHttpMethods,
|
|
51
|
+
};
|
|
52
|
+
// console.log('frontendHost', this.core.ctx.config.frontendHost);
|
|
53
|
+
// console.log('cors', cors);
|
|
54
|
+
//#region prepare global BE socket
|
|
55
|
+
this.core.connectSocketBE = this.core.strategy.ioServer(UtilsOs__NS__isWebSQL ? this.core.ctx.uriOrigin : this.core.ctx.serverTcpUdp, {
|
|
56
|
+
path: nspPathGlobal.pathname,
|
|
57
|
+
cors,
|
|
58
|
+
}, // @ts-ignore
|
|
59
|
+
this.core.ctx);
|
|
60
|
+
this.core.ctx.logRealtime &&
|
|
61
|
+
console.info(`[backend] CREATE GLOBAL NAMESPACE: '${this.core.connectSocketBE.path()}'` +
|
|
62
|
+
` , path: '${nspPathGlobal.pathname}'`);
|
|
63
|
+
this.core.connectSocketBE.on('connection', clientSocket => {
|
|
64
|
+
this.core.ctx.logRealtime &&
|
|
65
|
+
console.info(`[backend] client connected to namespace "${nspPathGlobal.pathname}", ` +
|
|
66
|
+
` host: ${this.core.ctx.host}`);
|
|
67
|
+
});
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region prepare realtime BE socket
|
|
70
|
+
this.core.socketBE = this.core.strategy.ioServer(UtilsOs__NS__isWebSQL || UtilsOs__NS__isElectron
|
|
71
|
+
? this.core.ctx.uriOrigin
|
|
72
|
+
: this.core.ctx.serverTcpUdp, {
|
|
73
|
+
path: nspPathRealtime.pathname,
|
|
74
|
+
cors,
|
|
75
|
+
}, // @ts-ignore
|
|
76
|
+
this.core.ctx);
|
|
77
|
+
this.core.ctx.logRealtime &&
|
|
78
|
+
console.info(`[backend] CREATE REALTIME NAMESPACE: '${this.core.socketBE.path()}'` +
|
|
79
|
+
` , path: '${nspPathRealtime.pathname}' `);
|
|
80
|
+
this.core.socketBE.on('connection', backendSocketForClient => {
|
|
81
|
+
this.core.ctx.logRealtime &&
|
|
82
|
+
console.info(`[backend] client connected to namespace "${nspPathRealtime.pathname}", ` +
|
|
83
|
+
` host: ${this.core.ctx.host}`);
|
|
84
|
+
backendSocketForClient.on(Symbols__NS__REALTIME.ROOM_SUBSCRIBE_CUSTOM(this.core.ctx.contextName), roomName => {
|
|
85
|
+
this.core.ctx.logRealtime &&
|
|
86
|
+
console.info(`Joining room ${roomName} in namespace REALTIME` +
|
|
87
|
+
` host: ${this.core.ctx.contextName}/${this.core.ctx.host}`);
|
|
88
|
+
backendSocketForClient.join(roomName);
|
|
89
|
+
});
|
|
90
|
+
backendSocketForClient.on(Symbols__NS__REALTIME.ROOM_SUBSCRIBE_ENTITY_UPDATE_EVENTS(this.core.ctx.contextName), roomName => {
|
|
91
|
+
this.core.ctx.logRealtime &&
|
|
92
|
+
console.info(`[backend] Joining room ${roomName} in namespace REALTIME` +
|
|
93
|
+
` host: ${this.core.ctx.contextName}/${this.core.ctx.host}`);
|
|
94
|
+
backendSocketForClient.join(roomName);
|
|
95
|
+
});
|
|
96
|
+
backendSocketForClient.on(Symbols__NS__REALTIME.ROOM_SUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(this.core.ctx.contextName), roomName => {
|
|
97
|
+
this.core.ctx.logRealtime &&
|
|
98
|
+
console.info(`[backend] Joining room ${roomName} in namespace REALTIME ` +
|
|
99
|
+
` host: ${this.core.ctx.contextName}/${this.core.ctx.host}`);
|
|
100
|
+
backendSocketForClient.join(roomName);
|
|
101
|
+
});
|
|
102
|
+
backendSocketForClient.on(Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_CUSTOM(this.core.ctx.contextName), roomName => {
|
|
103
|
+
this.core.ctx.logRealtime &&
|
|
104
|
+
console.info(`[backend] Leaving room ${roomName} in namespace REALTIME` +
|
|
105
|
+
` host: ${this.core.ctx.contextName}/${this.core.ctx.host}`);
|
|
106
|
+
backendSocketForClient.leave(roomName);
|
|
107
|
+
});
|
|
108
|
+
backendSocketForClient.on(Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_ENTITY_UPDATE_EVENTS(this.core.ctx.contextName), roomName => {
|
|
109
|
+
this.core.ctx.logRealtime &&
|
|
110
|
+
console.info(`[backend] Leaving room ${roomName} in namespace REALTIME ` +
|
|
111
|
+
` host: ${this.core.ctx.contextName}/${this.core.ctx.host}`);
|
|
112
|
+
backendSocketForClient.leave(roomName);
|
|
113
|
+
});
|
|
114
|
+
backendSocketForClient.on(Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(this.core.ctx.contextName), roomName => {
|
|
115
|
+
this.core.ctx.logRealtime &&
|
|
116
|
+
console.info(`[backend] Leaving room ${roomName} in namespace REALTIME ` +
|
|
117
|
+
` host: ${this.core.ctx.contextName}/${this.core.ctx.host}`);
|
|
118
|
+
backendSocketForClient.leave(roomName);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
//#endregion
|
|
122
|
+
//#endregion
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region methods & getters / trigger changes
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
127
|
+
triggerChanges(entityObjOrClass, property, valueOfUniqueProperty, customEvent, customEventData) {
|
|
128
|
+
// console.log('customEventData', customEventData);
|
|
129
|
+
// console.info('__triger entity changes');
|
|
130
|
+
//#region @websql
|
|
131
|
+
let roomName;
|
|
132
|
+
if (this.core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (customEvent) {
|
|
136
|
+
roomName = Symbols__NS__REALTIME.ROOM_NAME_CUSTOM(this.core.ctx.contextName, customEvent);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
let entityFn = entityObjOrClass;
|
|
140
|
+
const entityIsObject = !___NS__isFunction(entityObjOrClass) && ___NS__isObject(entityObjOrClass);
|
|
141
|
+
if (entityIsObject) {
|
|
142
|
+
entityFn = ClassHelpers__NS__getClassFnFromObject(entityObjOrClass);
|
|
143
|
+
}
|
|
144
|
+
const uniqueKey = ClassHelpers__NS__getUniqueKey(entityFn);
|
|
145
|
+
if (entityIsObject) {
|
|
146
|
+
valueOfUniqueProperty = entityObjOrClass[uniqueKey];
|
|
147
|
+
}
|
|
148
|
+
if (!valueOfUniqueProperty) {
|
|
149
|
+
Helpers__NS__error(`[Taon][Realtime] Entity without iD ! ${ClassHelpers__NS__getName(entityFn)} `, true, true);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
roomName = ___NS__isString(property)
|
|
153
|
+
? Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, ClassHelpers__NS__getName(entityFn), property, valueOfUniqueProperty)
|
|
154
|
+
: Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, ClassHelpers__NS__getName(entityFn), valueOfUniqueProperty);
|
|
155
|
+
}
|
|
156
|
+
this.core.socketBE.in(roomName).emit(roomName, // roomName == eventName in room na
|
|
157
|
+
customEvent ? customEventData : '');
|
|
158
|
+
//#endregion
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region entity changes
|
|
162
|
+
//#region methods & getters / trigger entity changes
|
|
163
|
+
triggerEntityChanges(entityObjOrClass,
|
|
164
|
+
/**
|
|
165
|
+
* value of unique key property of entity instance
|
|
166
|
+
* (this value is not needed if entityObjOrClass is instance of entity)
|
|
167
|
+
*/
|
|
168
|
+
idToTrigger) {
|
|
169
|
+
if (this.core.ctx.disabledRealtime) {
|
|
170
|
+
const className = ClassHelpers__NS__getName(entityObjOrClass);
|
|
171
|
+
console.warn(`[Taon][TriggerEntityChanges] Entity "${className}' is not realtime`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.triggerChanges(entityObjOrClass, void 0, idToTrigger);
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region methods & getters / trigger entity property changes
|
|
178
|
+
triggerEntityPropertyChanges(entityObjOrClass,
|
|
179
|
+
/**
|
|
180
|
+
* property name or array of property names that changed
|
|
181
|
+
* for entity instance
|
|
182
|
+
*/
|
|
183
|
+
property,
|
|
184
|
+
/**
|
|
185
|
+
* value of unique key property of entity instance
|
|
186
|
+
* (this value is not needed if entityObjOrClass is instance of entity)
|
|
187
|
+
*/
|
|
188
|
+
idToTrigger) {
|
|
189
|
+
if (this.core.ctx.disabledRealtime) {
|
|
190
|
+
const className = ClassHelpers__NS__getName(entityObjOrClass);
|
|
191
|
+
console.warn(`[Taon][TriggerEntityPropertyChanges][property=${property}] Entity "${className}' is not realtime`);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (___NS__isArray(property)) {
|
|
195
|
+
property.forEach(propertyFromArr => {
|
|
196
|
+
this.triggerChanges(entityObjOrClass, propertyFromArr, idToTrigger);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
this.triggerChanges(entityObjOrClass, property, idToTrigger);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region methods & getters / trigger entity table changes
|
|
205
|
+
triggerEntityTableChanges(entityClassOrInstance) {
|
|
206
|
+
const className = ClassHelpers__NS__getName(entityClassOrInstance);
|
|
207
|
+
if (this.core.ctx.disabledRealtime) {
|
|
208
|
+
console.warn(`[Taon][TriggerEntityTableChanges] Entity "${className}' is not realtime`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this.triggerChanges(entityClassOrInstance, void 0, void 0, Symbols__NS__REALTIME.TABLE_CHANGE(this.core.ctx.contextName, className));
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region custom changes
|
|
216
|
+
//#region methods & getters / trigger custom event
|
|
217
|
+
triggerCustomEvent(customEvent, dataToPush) {
|
|
218
|
+
this.triggerChanges(void 0, void 0, void 0, customEvent, dataToPush);
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region methods & getters / listen custom events from users
|
|
222
|
+
/**
|
|
223
|
+
* Listen to custom events from users
|
|
224
|
+
* @param customEvent global event name
|
|
225
|
+
*/
|
|
226
|
+
listenChangesCustomEvent(customEvent) {
|
|
227
|
+
//#region @websqlFunc
|
|
228
|
+
const sub = new Subject();
|
|
229
|
+
this.core.socketBE.on('connection', backendSocketForClient => {
|
|
230
|
+
backendSocketForClient.on(customEvent, (data, ...args) => {
|
|
231
|
+
sub.next(data);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
return sub.asObservable();
|
|
235
|
+
//#endregion
|
|
236
|
+
}
|
|
237
|
+
}
|