@prestizni-software/server-dem 0.5.16 → 0.5.18
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/dist/AutoUpdateManagerClass.d.ts +11 -12
- package/dist/AutoUpdateManagerClass.js +13 -8
- package/dist/AutoUpdateManagerClass.js.map +1 -1
- package/dist/AutoUpdateServerManagerClass.d.ts +28 -36
- package/dist/AutoUpdateServerManagerClass.js +160 -89
- package/dist/AutoUpdateServerManagerClass.js.map +1 -1
- package/dist/AutoUpdatedClientObjectClass.d.ts +32 -34
- package/dist/AutoUpdatedClientObjectClass.js +91 -48
- package/dist/AutoUpdatedClientObjectClass.js.map +1 -1
- package/dist/AutoUpdatedServerObjectClass.d.ts +12 -17
- package/dist/AutoUpdatedServerObjectClass.js +106 -98
- package/dist/AutoUpdatedServerObjectClass.js.map +1 -1
- package/dist/CommonTypes.d.ts +78 -32
- package/dist/CommonTypes.js +8 -0
- package/dist/CommonTypes.js.map +1 -1
- package/dist/CommonTypes_server.d.ts +3 -3
- package/dist/server.d.ts +5 -6
- package/dist/server.js +5 -6
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Constructor, EventEmitter3, LoggersType, Cache } from "./CommonTypes";
|
|
1
|
+
import { IAutoUpdatedClientObjectBase, MongoId, IsData, IAutoUpdateManager, Constructor, EventEmitter3, LoggersType, DEMCache } from "./CommonTypes.js";
|
|
3
2
|
import "reflect-metadata";
|
|
4
|
-
export declare abstract class AutoUpdateManager<T extends
|
|
3
|
+
export declare abstract class AutoUpdateManager<T extends IAutoUpdatedClientObjectBase, M extends Record<string, IAutoUpdateManager<any>> = Record<string, IAutoUpdateManager<any>>> implements IAutoUpdateManager<T> {
|
|
5
4
|
protected abstract objects_: {
|
|
6
5
|
[_id: string]: T;
|
|
7
6
|
};
|
|
8
7
|
protected isLoaded_: boolean;
|
|
9
|
-
readonly socket:
|
|
8
|
+
readonly socket: unknown;
|
|
10
9
|
protected classParam: Constructor<T>;
|
|
11
|
-
protected properties:
|
|
10
|
+
protected properties: string[];
|
|
12
11
|
readonly className: string;
|
|
13
|
-
readonly cache:
|
|
14
|
-
readonly managers:
|
|
12
|
+
readonly cache: DEMCache;
|
|
13
|
+
readonly managers: M;
|
|
15
14
|
protected preloaded: boolean;
|
|
16
15
|
protected waitingToResolveReferences: {
|
|
17
16
|
[_id: string]: string;
|
|
18
17
|
};
|
|
19
18
|
protected loggers: LoggersType;
|
|
20
19
|
protected emitter: EventEmitter3;
|
|
21
|
-
constructor(classParam: Constructor<T>, className: string, socket:
|
|
20
|
+
constructor(classParam: Constructor<T>, className: string, socket: unknown, loggers: LoggersType, managers: M, emitter: EventEmitter3);
|
|
22
21
|
get isLoaded(): boolean;
|
|
23
22
|
close(): void;
|
|
24
23
|
loadReferences(): Promise<void>;
|
|
25
|
-
deleteObject(_id:
|
|
24
|
+
deleteObject(_id: MongoId): Promise<{
|
|
26
25
|
success: boolean;
|
|
27
26
|
message: string;
|
|
28
27
|
}>;
|
|
29
28
|
get objectIDs(): string[];
|
|
30
|
-
abstract handleGetMissingObject(_id:
|
|
31
|
-
abstract createObject(data: Omit<
|
|
32
|
-
abstract getObject(_id?:
|
|
29
|
+
abstract handleGetMissingObject(_id: MongoId): Promise<T>;
|
|
30
|
+
abstract createObject(data: Omit<IsData<T>, "_id">): Promise<T>;
|
|
31
|
+
abstract getObject(_id?: MongoId): T | null | undefined;
|
|
33
32
|
abstract get objects(): {
|
|
34
33
|
[_id: string]: T;
|
|
35
34
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { globalCache, } from "./CommonTypes";
|
|
1
|
+
import { globalCache, } from "./CommonTypes.js";
|
|
2
2
|
import "reflect-metadata";
|
|
3
3
|
export class AutoUpdateManager {
|
|
4
4
|
isLoaded_ = false;
|
|
@@ -20,13 +20,16 @@ export class AutoUpdateManager {
|
|
|
20
20
|
};
|
|
21
21
|
emitter;
|
|
22
22
|
constructor(classParam, className, socket, loggers, managers, emitter) {
|
|
23
|
-
console.log("DEBUG: AutoUpdateManager constructor, className=" +
|
|
23
|
+
console.log("DEBUG: AutoUpdateManager constructor, className=" +
|
|
24
|
+
className +
|
|
25
|
+
", socket keys=" +
|
|
26
|
+
Object.keys(socket || {}).join(","));
|
|
24
27
|
this.className = className;
|
|
25
28
|
this.managers = managers;
|
|
26
29
|
this.emitter = emitter;
|
|
27
30
|
this.socket = socket;
|
|
28
31
|
this.classParam = classParam;
|
|
29
|
-
this.properties = Reflect.getMetadata("props", classParam.prototype);
|
|
32
|
+
this.properties = Reflect.getMetadata("props", classParam.prototype) || [];
|
|
30
33
|
this.loggers.debug = (s) => loggers.debug?.("[DEM - " + className + " MANAGER] " + s);
|
|
31
34
|
this.loggers.info = (s) => loggers.info?.("[DEM - " + className + " MANAGER] " + s);
|
|
32
35
|
this.loggers.error = (s) => loggers.error?.("[DEM - " + className + " MANAGER] " + s);
|
|
@@ -40,7 +43,8 @@ export class AutoUpdateManager {
|
|
|
40
43
|
delete this.objects_[id];
|
|
41
44
|
delete globalCache.objects[id];
|
|
42
45
|
}
|
|
43
|
-
this.socket.disconnect?.() ??
|
|
46
|
+
this.socket.disconnect?.() ??
|
|
47
|
+
this.socket.disconnectSockets?.(true);
|
|
44
48
|
this.loggers.info("Goodbye, see you next time!");
|
|
45
49
|
}
|
|
46
50
|
async loadReferences() {
|
|
@@ -50,13 +54,14 @@ export class AutoUpdateManager {
|
|
|
50
54
|
this.isLoaded_ = true;
|
|
51
55
|
}
|
|
52
56
|
async deleteObject(_id) {
|
|
53
|
-
const
|
|
57
|
+
const _idStr = _id.toString();
|
|
58
|
+
const o = this.objects_[_idStr];
|
|
54
59
|
const res = await o?.destroy(true);
|
|
55
60
|
if (res?.success) {
|
|
56
|
-
delete this.objects_[
|
|
57
|
-
delete globalCache.objects[
|
|
61
|
+
delete this.objects_[_idStr];
|
|
62
|
+
delete globalCache.objects[_idStr];
|
|
58
63
|
}
|
|
59
|
-
|
|
64
|
+
o?.callbacks?.delete?.(this);
|
|
60
65
|
return res ?? { success: true, message: "Already gone" };
|
|
61
66
|
}
|
|
62
67
|
get objectIDs() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoUpdateManagerClass.js","sourceRoot":"","sources":["../AutoUpdateManagerClass.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AutoUpdateManagerClass.js","sourceRoot":"","sources":["../AutoUpdateManagerClass.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,kBAAkB,CAAC;AAE1B,MAAM,OAAgB,iBAAiB;IAQ3B,SAAS,GAAG,KAAK,CAAC;IACZ,MAAM,CAAU;IACtB,UAAU,CAAiB;IAC3B,UAAU,CAAW;IACf,SAAS,CAAS;IAClB,KAAK,GAAa;QAChC,UAAU,EAAE,EAAE;KACf,CAAC;IACc,QAAQ,CAAI;IAClB,SAAS,GAAG,KAAK,CAAC;IAClB,0BAA0B,GAA8B,EAAE,CAAC;IAC3D,OAAO,GAAgB;QAC/B,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;KACf,CAAC;IACQ,OAAO,CAAgB;IAEjC,YACE,UAA0B,EAC1B,SAAiB,EACjB,MAAe,EACf,OAAoB,EACpB,QAAW,EACX,OAAsB;QAEtB,OAAO,CAAC,GAAG,CACT,kDAAkD;YAChD,SAAS;YACT,gBAAgB;YAChB,MAAM,CAAC,IAAI,CAAE,MAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAClD,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI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,CAAC,MAIN,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,cAAc;QACzB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtC,MAAM,GAAG,CAAC,qBAAqB,EAAE,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,YAAY,CACvB,GAAY;QAEZ,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC9B,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAChC,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,GAAG,EAAE,OAAO,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7B,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;QACD,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;QAC7B,OAAO,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAC3D,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;CAWF"}
|
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
import { Server, Socket } from "socket.io";
|
|
2
|
-
import { AutoUpdateManager } from "./AutoUpdateManagerClass";
|
|
3
|
-
import {
|
|
4
|
-
import { Constructor, EventEmitter3, IsData, LoggersType, Pure } from "./CommonTypes";
|
|
2
|
+
import { AutoUpdateManager } from "./AutoUpdateManagerClass.js";
|
|
3
|
+
import { Constructor, IsData, LoggersType, IAutoUpdatedClientObject, EventEmitter3, MongoId, IAutoUpdateManager } from "./CommonTypes.js";
|
|
5
4
|
import { BeAnObject, ReturnModelType } from "@typegoose/typegoose/lib/types";
|
|
6
|
-
|
|
7
|
-
export type WrappedInstances<T extends Record<string, AutoUpdatedServerObject<any>>> = {
|
|
5
|
+
export type WrappedInstances<T extends Record<string, IAutoUpdatedClientObject<any>>> = {
|
|
8
6
|
[K in keyof T]: AutoUpdateServerManager<T[K]>;
|
|
9
7
|
};
|
|
10
|
-
export type AUSDefinitions<T extends Record<string,
|
|
8
|
+
export type AUSDefinitions<T extends Record<string, IAutoUpdatedClientObject<any>>> = {
|
|
11
9
|
[K in keyof T]: ServerManagerDefinition<T[K], T>;
|
|
12
10
|
};
|
|
13
|
-
export type EventMiddlewareFunction<T extends Record<string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export type StartupMiddlewareFunction<T extends Record<string, AutoUpdatedServerObject<any>>, C extends AutoUpdatedServerObject<any>> = (ids: C[], managers: {
|
|
17
|
-
[K in keyof T]: AutoUpdateServerManager<T[K]>;
|
|
18
|
-
}, socket: Socket) => Promise<C[]>;
|
|
19
|
-
export type AccessMiddleware<T extends Record<string, AutoUpdatedServerObject<any>>, C extends AutoUpdatedServerObject<any>> = {
|
|
11
|
+
export type EventMiddlewareFunction<T extends Record<string, IAutoUpdatedClientObject<any>>, C extends IAutoUpdatedClientObject<any>> = (event: DEMEvent<C>, managers: WrappedInstances<T>, socket: Socket) => Promise<void>;
|
|
12
|
+
export type StartupMiddlewareFunction<T extends Record<string, IAutoUpdatedClientObject<any>>, C extends IAutoUpdatedClientObject<any>> = (ids: C[], managers: WrappedInstances<T>, socket: Socket) => Promise<C[]>;
|
|
13
|
+
export type AccessMiddleware<T extends Record<string, IAutoUpdatedClientObject<any>>, C extends IAutoUpdatedClientObject<any>> = {
|
|
20
14
|
eventMiddleware?: EventMiddlewareFunction<T, C>;
|
|
21
15
|
startupMiddleware?: StartupMiddlewareFunction<T, C>;
|
|
22
16
|
};
|
|
23
|
-
export type AUSOption<C extends
|
|
17
|
+
export type AUSOption<C extends IAutoUpdatedClientObject<any>, T extends Record<string, IAutoUpdatedClientObject<any>>> = {
|
|
24
18
|
accessDefinitions?: AccessMiddleware<T, C>;
|
|
25
|
-
onUpdate?: (obj: C, set:
|
|
19
|
+
onUpdate?: (obj: C, set: (key: string, val: any) => Promise<{
|
|
26
20
|
success: boolean;
|
|
27
21
|
msg: string;
|
|
28
22
|
}>) => Promise<void>;
|
|
29
23
|
};
|
|
30
|
-
export type ServerManagerDefinition<C extends
|
|
24
|
+
export type ServerManagerDefinition<C extends IAutoUpdatedClientObject<any>, T extends Record<string, IAutoUpdatedClientObject<any>>> = {
|
|
31
25
|
class: Constructor<C>;
|
|
32
26
|
options?: AUSOption<C, T>;
|
|
33
27
|
};
|
|
34
|
-
export type BaseManagers = Record<string,
|
|
28
|
+
export type BaseManagers = Record<string, IAutoUpdateManager<any>>;
|
|
35
29
|
export declare enum DEMEventTypes {
|
|
36
30
|
"new" = "new",
|
|
37
31
|
"update" = "update",
|
|
@@ -39,48 +33,46 @@ export declare enum DEMEventTypes {
|
|
|
39
33
|
"get" = "get",
|
|
40
34
|
"startup" = "startup"
|
|
41
35
|
}
|
|
42
|
-
export type DEMEvent<C extends
|
|
36
|
+
export type DEMEvent<C extends IAutoUpdatedClientObject<any>> = {
|
|
43
37
|
type: DEMEventTypes.delete | DEMEventTypes.get;
|
|
44
|
-
manager:
|
|
38
|
+
manager: IAutoUpdateManager<C>;
|
|
45
39
|
object: C;
|
|
46
40
|
data: never;
|
|
47
41
|
} | {
|
|
48
42
|
type: DEMEventTypes.update;
|
|
49
|
-
manager:
|
|
43
|
+
manager: IAutoUpdateManager<C>;
|
|
50
44
|
object: C;
|
|
51
45
|
data: {
|
|
52
46
|
_id: string;
|
|
53
|
-
key:
|
|
54
|
-
value:
|
|
47
|
+
key: string;
|
|
48
|
+
value: unknown;
|
|
55
49
|
};
|
|
56
50
|
} | {
|
|
57
51
|
type: DEMEventTypes.startup;
|
|
58
|
-
manager:
|
|
52
|
+
manager: IAutoUpdateManager<C>;
|
|
59
53
|
object: never;
|
|
60
54
|
data: never;
|
|
61
55
|
} | {
|
|
62
56
|
type: DEMEventTypes.new;
|
|
63
|
-
manager:
|
|
57
|
+
manager: IAutoUpdateManager<C>;
|
|
64
58
|
object: never;
|
|
65
|
-
data: IsData<C>;
|
|
59
|
+
data: Omit<IsData<C>, "_id">;
|
|
66
60
|
};
|
|
67
|
-
export declare function AUSManagerFactory<T extends Record<string,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
export declare class AutoUpdateServerManager<T extends AutoUpdatedServerObject<any>> extends AutoUpdateManager<T> {
|
|
71
|
-
readonly model: ReturnModelType<Constructor<T>, BeAnObject>;
|
|
61
|
+
export declare function AUSManagerFactory<T extends Record<string, IAutoUpdatedClientObject<any>>>(defs: AUSDefinitions<T>, loggers_: LoggersType, socket: Server, doDebug?: boolean, emitter?: EventEmitter3, models?: unknown): Promise<WrappedInstances<T>>;
|
|
62
|
+
export declare class AutoUpdateServerManager<T extends IAutoUpdatedClientObject<T>, M extends Record<string, IAutoUpdateManager<any>> = any> extends AutoUpdateManager<T, M> {
|
|
63
|
+
readonly model: ReturnModelType<any, BeAnObject>;
|
|
72
64
|
private readonly clientSockets;
|
|
73
|
-
readonly options?: AUSOption<T, any
|
|
65
|
+
readonly options?: AUSOption<T, Record<string, IAutoUpdatedClientObject<any>>>;
|
|
74
66
|
protected objects_: {
|
|
75
67
|
[_id: string]: T;
|
|
76
68
|
};
|
|
77
|
-
readonly managers:
|
|
78
|
-
constructor(classParam: Constructor<T>, className: string, socket: Server, loggers: LoggersType, model: ReturnModelType<
|
|
69
|
+
readonly managers: M;
|
|
70
|
+
constructor(classParam: Constructor<T>, className: string, socket: Server, loggers: LoggersType, model: ReturnModelType<any, BeAnObject>, managers: M, emitter: EventEmitter3, options?: AUSOption<T, Record<string, IAutoUpdatedClientObject<any>>>);
|
|
79
71
|
preLoad(): Promise<void>;
|
|
80
72
|
registerSocket(socket: Socket): void;
|
|
81
|
-
getObject(_id
|
|
73
|
+
getObject(_id?: MongoId): T | null | undefined;
|
|
82
74
|
get objects(): Record<string, T>;
|
|
83
75
|
get objectsAsArray(): T[];
|
|
84
|
-
handleGetMissingObject(_id:
|
|
85
|
-
createObject(data: Omit<IsData<
|
|
76
|
+
handleGetMissingObject(_id: MongoId): Promise<T>;
|
|
77
|
+
createObject(data: Omit<IsData<T>, "_id">): Promise<T>;
|
|
86
78
|
}
|