@prestizni-software/server-dem 0.5.6 → 0.5.8

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.
@@ -1,54 +1,89 @@
1
1
  import { EventEmitter } from "eventemitter3";
2
2
  import { ObjectId, ObjectIdLike } from "bson";
3
3
  import "reflect-metadata";
4
- export type Pretty<T> = {
5
- [K in keyof T]: T[K];
6
- } & {};
7
- export type BaseObjectKeys = "preLoad" | "registerSocket" | "readyLoggers" | "loadFromDB" | "isLoaded" | "isPreLoadedAsync" | "loadMissingReferences" | "getValue" | "setValue" | "destroy" | "destroyImmediate" | "contactChildren" | "extractedData" | "onUpdate" | "properties" | "classParam" | "className" | "parentManager" | "callbacks" | "waitForPreloaded" | "loadFromDocument" | "socket" | "data" | "isServer" | "emitter" | "toChangeOnParents" | "checkedMissingRefs" | "isLoading" | "isLoadingReferences" | "EmitterID" | "loadShit" | "openSockets" | "handleUpdateRequest" | "generateSettersAndGetters" | "findReference" | "setValueInternal" | "makeUpdate" | "resolveReference" | "findAndLoadReferences" | "wipeSelf" | "loadForceReferences" | "handleLoad" | "createdWithParent" | "checkForMissingRefs" | "findMissingObjectReference" | "loadReferencesAsync";
8
- export type MongoId = string | ObjectId | ObjectIdLike;
4
+ type RefType = string | ObjectId;
5
+ export type MongoId = RefType;
9
6
  export type EventEmitter3 = EventEmitter;
10
- export interface IDEMSocket {
11
- on(event: string, fn: (...args: any[]) => void): void;
12
- emit(event: string, ...args: any[]): void;
13
- onAny?(fn: (event: string, ...args: any[]) => void): void;
14
- disconnect?(): void;
15
- disconnectSockets?(once: boolean): void;
16
- removeAllListeners?(event?: string): void;
7
+ export interface IAutoUpdateManager<T extends IAutoUpdatedClientObjectBase> {
8
+ readonly className: string;
9
+ readonly cache: DEMCache;
10
+ readonly managers: Record<string, IAutoUpdateManager<IAutoUpdatedClientObjectBase>>;
11
+ getObject(_id?: MongoId): T | null | undefined;
12
+ deleteObject(_id: MongoId): Promise<{
13
+ success: boolean;
14
+ message: string;
15
+ }>;
16
+ readonly objectsAsArray: T[];
17
+ readonly isLoaded: boolean;
18
+ }
19
+ export interface IAutoUpdatedClientObjectBase {
20
+ readonly _id: MongoId;
21
+ readonly properties: string[];
22
+ readonly className: string;
23
+ readonly isLoaded: boolean;
24
+ loadMissingReferences(): Promise<void>;
25
+ waitForPreloaded(): Promise<void>;
26
+ destroy(once?: boolean): Promise<{
27
+ success: boolean;
28
+ message: string;
29
+ }>;
30
+ isPreLoadedAsync(): Promise<boolean>;
31
+ contactChildren(): Promise<void>;
32
+ onUpdate(): Promise<void>;
33
+ getValue(key: string): any;
34
+ setValue(key: string, val: any): Promise<{
35
+ success: boolean;
36
+ msg: string;
37
+ }>;
38
+ readonly parentManager: IAutoUpdateManager<IAutoUpdatedClientObjectBase>;
39
+ readonly callbacks: any;
40
+ readonly classParam: any;
41
+ }
42
+ export interface IAutoUpdatedClientObject<T extends object = any> extends IAutoUpdatedClientObjectBase {
43
+ readonly extractedData: ExtractedData<T, IAutoUpdatedClientObject<any>>;
44
+ getValue<K extends Paths<T, IAutoUpdatedClientObject<any>>>(key: K): PathValueOf<T, K>;
45
+ setValue<K extends Paths<T, IAutoUpdatedClientObject<any>>>(key: K, val: PathValueOf<IsData<T>, K>): Promise<{
46
+ success: boolean;
47
+ msg: string;
48
+ }>;
49
+ }
50
+ export interface IAutoUpdatedServerObject<T extends object = any> extends IAutoUpdatedClientObject<T> {
51
+ loadFromDB(): Promise<void>;
52
+ loadFromDocument(document: unknown): Promise<void>;
17
53
  }
18
- /**
19
- * Extracts data properties from a class, omitting base object methods and properties.
20
- */
21
- export type Pure<T> = 0 extends (1 & T) ? Record<string, unknown> : Pretty<{
22
- [K in keyof T as K extends BaseObjectKeys ? never : K]: T[K];
23
- }>;
24
- export type InstanceOf<T> = T extends Constructor<infer I> ? I : T;
54
+ export type AutoProps<T> = {
55
+ readonly [K in keyof T]: T[K];
56
+ };
25
57
  export type Constructor<T> = new (...args: any[]) => T;
58
+ export type UnboxConstructor<T> = T extends new (...args: any[]) => infer I ? I : T;
26
59
  export type LoggersType = {
27
60
  info: (s: string) => void;
28
61
  debug: (s: string) => void;
29
62
  error: (s: string) => void;
30
63
  warn: (s: string) => void;
31
64
  };
32
- type IsAUCO<T> = T extends {
65
+ type IsAUCOBase<T> = T extends {
33
66
  className: string;
67
+ _id: any;
34
68
  } ? true : false;
35
- type AllowStringForRefs<V> = 0 extends 1 & V ? V : NonNullable<V> extends Array<infer U> ? IsAUCO<NonNullable<U>> extends true ? (U | string | ObjectIdLike)[] : V : IsAUCO<NonNullable<V>> extends true ? V | string | ObjectIdLike : V;
36
- /**
37
- * Checks if a type is 'any'. Returns 'unknown' if it is, otherwise returns the type itself.
38
- */
39
- export type AnnihilateAny<T> = 0 extends (1 & T) ? unknown : T;
40
- type OnlyStringForRefs<V> = 0 extends 1 & V ? V : NonNullable<V> extends Array<infer U> ? IsAUCO<NonNullable<U>> extends true ? string[] : V : IsAUCO<NonNullable<V>> extends true ? string : V;
41
- export type Cache<T> = {
69
+ type AllowStringForRefs<V> = NonNullable<V> extends Array<infer U> ? IsAUCOBase<NonNullable<U>> extends true ? (U | string | ObjectIdLike)[] : V : IsAUCOBase<NonNullable<V>> extends true ? V | string | ObjectIdLike : V;
70
+ type OnlyStringForRefs<V> = V extends any ? (V extends Array<infer U> ? OnlyStringForRefs<U>[] : V extends IAutoUpdatedClientObjectBase ? string : V extends Date ? V : V extends ObjectId | ObjectIdLike ? string : V extends object ? {
71
+ [K in keyof V as V[K] extends Function ? never : K]: K extends "_id" ? string : OnlyStringForRefs<V[K]>;
72
+ } : V) : never;
73
+ export type DEMCache = {
42
74
  references: Record<string, any>;
43
75
  };
44
- export type IsData<T> = 0 extends (1 & T) ? Record<string, unknown> : Pretty<{
45
- [K in keyof Pure<T>]: AllowStringForRefs<Pure<T>[K]>;
76
+ export type Pure<T extends object, Base = IAutoUpdatedClientObject<any>> = Omit<T, keyof Base | "parentManager" | "callbacks" | "classParam" | "className" | "properties" | "isLoaded" | "extractedData" | "getValue" | "setValue" | "loadFromDB" | "setValue_">;
77
+ export type IsData<T extends object> = {
78
+ [K in keyof Pure<T> as T[K] extends Function ? never : K]: AllowStringForRefs<T[K]>;
46
79
  } & {
47
80
  _id: MongoId;
48
- }>;
49
- export type ExtractedData<T, Filter = never> = 0 extends (1 & T) ? Record<string, unknown> : Pretty<{
50
- [K in keyof Omit<Pure<T>, keyof Filter>]: OnlyStringForRefs<Pure<T>[K]>;
51
- }>;
81
+ };
82
+ export type ExtractedData<T extends object, Base = IAutoUpdatedClientObject<any>> = {
83
+ [K in keyof IsData<T> as K extends "_id" ? never : K]: OnlyStringForRefs<IsData<T>[K]>;
84
+ } & {
85
+ _id: string;
86
+ };
52
87
  export type SocketEvent = [string, unknown, (res: ServerResponse<unknown>) => void];
53
88
  export type ServerResponse<T> = {
54
89
  data: T;
@@ -59,14 +94,32 @@ export type ServerResponse<T> = {
59
94
  success: false;
60
95
  };
61
96
  export type ServerUpdateRequest<T> = {
62
- _id: MongoId;
97
+ _id: RefType;
63
98
  key: string;
64
99
  value: unknown;
65
100
  };
66
101
  export declare function classProp(target: object, propertyKey: string): void;
67
102
  export declare function populatedRef(where: string): (target: object, propertyKey: string) => void;
68
103
  export declare function classRef(): (target: object, propertyKey: string) => void;
69
- export type PathValueOf<T, P extends string> = P extends keyof T ? T[P] : never;
104
+ export type Pretty<T> = {
105
+ [K in keyof T]: T[K];
106
+ };
107
+ export type StripPrototypePrefix<P extends string> = P extends "prototype" ? never : P extends `prototype.${infer Rest}` ? Rest : P;
108
+ export type Recurseable<T> = T extends object ? T extends Array<unknown> | Function ? never : T : never;
109
+ export type OnlyClassKeys<T> = {
110
+ [K in keyof T]: K;
111
+ }[keyof T] & string;
112
+ export type Split<S extends string> = S extends `${infer L}.${infer R}` ? [L, ...Split<R>] : [S];
113
+ export type NonOptional<T> = Exclude<T, null | undefined>;
114
+ export type DeAutoUpdate<T> = T extends IAutoUpdatedClientObject<any> ? unknown : T;
115
+ export type RecursiveDeAutoUpdate<T extends IAutoUpdatedClientObject<any>> = T extends IAutoUpdatedClientObject<any> ? unknown : T;
116
+ export type OnlyAddedKeys<Sub, Parent> = Pick<Sub, Exclude<keyof Sub, keyof Omit<Parent, "_id">>>;
117
+ export type Prev = [never, 0, 1, 2, 3];
118
+ export type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${"" extends P ? "" : "."}${P}` : never : never;
119
+ export type Paths<T, Base, D extends number = 3> = 0 extends (1 & T) ? string : [D] extends [never] ? never : NonNullable<T> extends object ? {
120
+ [K in keyof OnlyAddedKeys<NonNullable<T>, Base> & string]-?: NonNullable<NonNullable<T>[K]> extends Function ? never : NonNullable<NonNullable<T>[K]> extends Array<unknown> | Date | ObjectId ? K : NonNullable<NonNullable<T>[K]> extends object ? K | Join<K, Paths<NonNullable<NonNullable<T>[K]>, Base, Prev[D]>> : K;
121
+ }[keyof OnlyAddedKeys<NonNullable<T>, Base> & string] : never;
122
+ export type PathValueOf<T, P extends string> = 0 extends (1 & T) ? any : P extends `${infer K}.${infer Rest}` ? K extends keyof NonNullable<T> ? PathValueOf<NonNullable<NonNullable<T>[K]>, Rest> : never : P extends keyof NonNullable<T> ? NonNullable<T>[P] : never;
70
123
  export declare const EVENT_INTERNAL_PRE_LOADED = "pre-loaded";
71
124
  export declare const EVENT_UPDATE = "update";
72
125
  export declare const EVENT_DELETE = "delete";
@@ -76,7 +129,7 @@ export declare const EVENT_STARTUP = "startup";
76
129
  export type GlobalCache = {
77
130
  objects: Record<string, {
78
131
  className: string;
79
- object: unknown;
132
+ object: IAutoUpdatedClientObjectBase;
80
133
  }>;
81
134
  };
82
135
  export declare const globalCache: GlobalCache;
@@ -15,9 +15,7 @@ export function classRef() {
15
15
  Reflect.defineMetadata("isRef", true, target, propertyKey);
16
16
  };
17
17
  }
18
- // Internal client events
19
18
  export const EVENT_INTERNAL_PRE_LOADED = "pre-loaded";
20
- // Server socket events
21
19
  export const EVENT_UPDATE = "update";
22
20
  export const EVENT_DELETE = "delete";
23
21
  export const EVENT_NEW = "new";
@@ -1 +1 @@
1
- {"version":3,"file":"CommonTypes.js","sourceRoot":"","sources":["../CommonTypes.ts"],"names":[],"mappings":"AAEA,OAAO,kBAAkB,CAAC;AA6I1B,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,WAAmB;IAC3D,MAAM,KAAK,GAAI,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAA0B,IAAI,EAAE,CAAC;IACtF,MAAM,QAAQ,GAAG,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC,CAAC;IACzC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,UAAU,MAAc,EAAE,WAAmB;QAClD,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAChC,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC/D,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,OAAO,UAAU,MAAc,EAAE,WAAmB;QAClD,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7D,CAAC,CAAC;AACJ,CAAC;AAOD,yBAAyB;AACzB,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CAAC;AAEtD,uBAAuB;AACvB,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AACrC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC;AAC/B,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC;AAC/B,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAMvC,MAAM,CAAC,MAAM,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}
@@ -0,0 +1,9 @@
1
+ import { Join, OnlyAddedKeys, Prev } from "./CommonTypes";
2
+ import { ObjectId, Types } from "mongoose";
3
+ export type NonOptional<T> = Exclude<T, null | undefined>;
4
+ export type Paths<T, Base, D extends number = 3> = [D] extends [never] ? never : NonNullable<T> extends object ? {
5
+ [K in keyof OnlyAddedKeys<NonNullable<T>, Base> & string]-?: NonNullable<NonNullable<T>[K]> extends Function ? never : NonNullable<NonNullable<T>[K]> extends Array<unknown> | Date | ObjectId | Types.ObjectId ? K : NonNullable<NonNullable<T>[K]> extends object ? K | Join<K, Paths<NonNullable<NonNullable<T>[K]>, Base, Prev[D]>> : K;
6
+ }[keyof OnlyAddedKeys<NonNullable<T>, Base> & string] : never;
7
+ type SafeGet<T, K extends string> = T extends unknown ? K extends keyof NonNullable<T> ? NonNullable<T>[K] : never : never;
8
+ export type PathValueOf<T, P extends string> = P extends `${infer K}.${infer Rest}` ? PathValueOf<SafeGet<T, K>, Rest> : SafeGet<T, P>;
9
+ export {};
@@ -1,2 +1,2 @@
1
- "use strict";
1
+ export {};
2
2
  //# sourceMappingURL=CommonTypes_server.js.map
package/dist/server.d.ts CHANGED
@@ -1 +1,6 @@
1
- export {};
1
+ import * as AutoUpdateServerManagerClass from "./AutoUpdateServerManagerClass";
2
+ import * as AutoUpdateManagerClass from "./AutoUpdateManagerClass";
3
+ import * as AutoUpdatedClientObjectClass from "./AutoUpdatedClientObjectClass";
4
+ import * as AutoUpdatedServerObjectClass from "./AutoUpdatedServerObjectClass";
5
+ import * as CommonTypes from "./CommonTypes_server";
6
+ export { AutoUpdateServerManagerClass, AutoUpdateManagerClass, AutoUpdatedClientObjectClass, AutoUpdatedServerObjectClass, CommonTypes, };
package/dist/server.js CHANGED
@@ -1,11 +1,7 @@
1
- import * as AutoUpdateServerManagerClass from "./AutoUpdateServerManagerClass.js";
2
- import * as AutoUpdateManagerClass from "./AutoUpdateManagerClass.js";
3
- import * as AutoUpdatedClientObjectClass from "./AutoUpdatedClientObjectClass.js";
4
- import * as AutoUpdatedServerObjectClass from "./AutoUpdatedServerObjectClass.js";
5
- module.exports = {
6
- AutoUpdateServerManagerClass,
7
- AutoUpdateManagerClass,
8
- AutoUpdatedClientObjectClass,
9
- AutoUpdatedServerObjectClass,
10
- };
1
+ import * as AutoUpdateServerManagerClass from "./AutoUpdateServerManagerClass";
2
+ import * as AutoUpdateManagerClass from "./AutoUpdateManagerClass";
3
+ import * as AutoUpdatedClientObjectClass from "./AutoUpdatedClientObjectClass";
4
+ import * as AutoUpdatedServerObjectClass from "./AutoUpdatedServerObjectClass";
5
+ import * as CommonTypes from "./CommonTypes_server";
6
+ export { AutoUpdateServerManagerClass, AutoUpdateManagerClass, AutoUpdatedClientObjectClass, AutoUpdatedServerObjectClass, CommonTypes, };
11
7
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,4BAA4B,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,4BAA4B,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,4BAA4B,MAAM,mCAAmC,CAAC;AAGlF,MAAM,CAAC,OAAO,GAAG;IACf,4BAA4B;IAC5B,sBAAsB;IACtB,4BAA4B;IAC5B,4BAA4B;CAC7B,CAAC"}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,4BAA4B,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,4BAA4B,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,4BAA4B,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,WAAW,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,WAAW,GACZ,CAAC"}