@prestizni-software/client-dem 0.2.5 → 0.2.7

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,76 +1,76 @@
1
- import { Socket } from "socket.io-client";
2
- import { AutoUpdateManager } from "./AutoUpdateManagerClass.js";
3
- import { createAutoUpdatedClass } from "./AutoUpdatedClientObjectClass.js";
4
- import { Constructor, IsData, LoggersType } from "./CommonTypes.js";
5
- export type WrappedInstances<T extends Record<string, Constructor<any>>> = {
6
- [K in keyof T]: AutoUpdateClientManager<T[K]>;
7
- };
8
- // ---------------------- Factory ----------------------
9
- export async function AUCManagerFactory<
10
- T extends Record<string, Constructor<any>>
11
- >(defs: T, loggers: LoggersType, socket: Socket): Promise<WrappedInstances<T>> {
12
- const classers = {} as WrappedInstances<T>;
13
-
14
- for (const key in defs) {
15
- const Model = defs[key];
16
- const c = new AutoUpdateClientManager(
17
- Model,
18
- loggers,
19
- socket,
20
- classers as any
21
- );
22
- classers[key] = c;
23
- }
24
-
25
- return classers;
26
- }
27
-
28
- export class AutoUpdateClientManager<
29
- T extends Constructor<any>
30
- > extends AutoUpdateManager<T> {
31
- constructor(
32
- classParam: T,
33
- loggers: LoggersType,
34
- socket: Socket,
35
- classers: Record<string, AutoUpdateManager<any>>
36
- ) {
37
- super(classParam, socket, loggers, classers);
38
- socket.emit("startup" + classParam.name, async (data: string[]) => {
39
- for (const id of data) {
40
- this.classes[id] = await this.handleGetMissingObject(id);
41
- this.classesAsArray.push(this.classes[id]);
42
- }
43
- });
44
- socket.on("new" + classParam.name, async (id: string) => {
45
- this.classes[id] = await this.handleGetMissingObject(id);
46
- this.classesAsArray.push(this.classes[id]);
47
- });
48
- socket.on("delete" + classParam.name, (id: string) => {
49
- this.deleteObject(id);
50
- });
51
- }
52
-
53
- protected async handleGetMissingObject(_id: string) {
54
- if (!this.classers) throw new Error(`No classers.`);
55
- return await createAutoUpdatedClass(
56
- this.classParam,
57
- this.socket,
58
- _id,
59
- this.loggers,
60
- this.classers
61
- );
62
- }
63
-
64
- public async createObject(data: IsData<InstanceType<T>>) {
65
- if (!this.classers) throw new Error(`No classers.`);
66
- const object = await createAutoUpdatedClass(
67
- this.classParam,
68
- this.socket,
69
- data,
70
- this.loggers,
71
- this.classers
72
- );
73
- this.classes[object._id as any] = object;
74
- return object;
75
- }
76
- }
1
+ import { Socket } from "socket.io-client";
2
+ import { AutoUpdateManager } from "./AutoUpdateManagerClass.ts";
3
+ import { createAutoUpdatedClass } from "./AutoUpdatedClientObjectClass.ts";
4
+ import { Constructor, IsData, LoggersType } from "./CommonTypes.ts";
5
+ export type WrappedInstances<T extends Record<string, Constructor<any>>> = {
6
+ [K in keyof T]: AutoUpdateClientManager<T[K]>;
7
+ };
8
+ // ---------------------- Factory ----------------------
9
+ export async function AUCManagerFactory<
10
+ T extends Record<string, Constructor<any>>
11
+ >(defs: T, loggers: LoggersType, socket: Socket): Promise<WrappedInstances<T>> {
12
+ const classers = {} as WrappedInstances<T>;
13
+
14
+ for (const key in defs) {
15
+ const Model = defs[key];
16
+ const c = new AutoUpdateClientManager(
17
+ Model,
18
+ loggers,
19
+ socket,
20
+ classers as any
21
+ );
22
+ classers[key] = c;
23
+ }
24
+
25
+ return classers;
26
+ }
27
+
28
+ export class AutoUpdateClientManager<
29
+ T extends Constructor<any>
30
+ > extends AutoUpdateManager<T> {
31
+ constructor(
32
+ classParam: T,
33
+ loggers: LoggersType,
34
+ socket: Socket,
35
+ classers: Record<string, AutoUpdateManager<any>>
36
+ ) {
37
+ super(classParam, socket, loggers, classers);
38
+ socket.emit("startup" + classParam.name, async (data: string[]) => {
39
+ for (const id of data) {
40
+ this.classes[id] = await this.handleGetMissingObject(id);
41
+ this.classesAsArray.push(this.classes[id]);
42
+ }
43
+ });
44
+ socket.on("new" + classParam.name, async (id: string) => {
45
+ this.classes[id] = await this.handleGetMissingObject(id);
46
+ this.classesAsArray.push(this.classes[id]);
47
+ });
48
+ socket.on("delete" + classParam.name, (id: string) => {
49
+ this.deleteObject(id);
50
+ });
51
+ }
52
+
53
+ protected async handleGetMissingObject(_id: string) {
54
+ if (!this.classers) throw new Error(`No classers.`);
55
+ return await createAutoUpdatedClass(
56
+ this.classParam,
57
+ this.socket,
58
+ _id,
59
+ this.loggers,
60
+ this.classers
61
+ );
62
+ }
63
+
64
+ public async createObject(data: IsData<InstanceType<T>>) {
65
+ if (!this.classers) throw new Error(`No classers.`);
66
+ const object = await createAutoUpdatedClass(
67
+ this.classParam,
68
+ this.socket,
69
+ data,
70
+ this.loggers,
71
+ this.classers
72
+ );
73
+ this.classes[object._id as any] = object;
74
+ return object;
75
+ }
76
+ }
@@ -1,71 +1,72 @@
1
- import { AutoUpdated } from "./AutoUpdatedClientObjectClass.js";
2
- import { Constructor, IsData, LoggersType, SocketType } from "./CommonTypes.js";
3
-
4
- export abstract class AutoUpdateManager<T extends Constructor<any>> {
5
- protected classes: { [_id: string]: AutoUpdated<T> } = {};
6
- public socket: SocketType;
7
- protected classParam: T;
8
- protected properties: (keyof T)[];
9
- protected classers: Record<string, AutoUpdateManager<any>>;
10
- protected loggers: LoggersType = {
11
- info: () => {},
12
- debug: () => {},
13
- error: () => {},
14
- warn: () => {},
15
- };
16
- protected classesAsArray: AutoUpdated<T>[] = [];
17
- constructor(
18
- classParam: T,
19
- socket: SocketType,
20
- loggers: LoggersType,
21
- classers: Record<string, AutoUpdateManager<any>>
22
- ) {
23
- this.classers = classers;
24
- this.socket = socket;
25
- this.classParam = classParam;
26
- this.properties = Reflect.getMetadata(
27
- "props",
28
- Object.getPrototypeOf(classParam)
29
- );
30
- loggers.warn = loggers.warn ?? loggers.info;
31
- this.loggers = loggers;
32
- }
33
-
34
-
35
- public getObject(
36
- _id: string
37
- ): AutoUpdated<T> | null {
38
- return this.classes[_id];
39
- }
40
-
41
- public async deleteObject(_id: string): Promise<void> {
42
- if (typeof this.classes[_id] === "string")
43
- this.classes[_id] = await this.handleGetMissingObject(this.classes[_id]);
44
- (this.classes[_id]).destroy();
45
- this.classesAsArray.splice(this.classesAsArray.indexOf(this.classes[_id]), 1);
46
- delete this.classes[_id];
47
- }
48
-
49
- public get objectIDs(): string[] {
50
- return Object.keys(this.classes);
51
- }
52
-
53
- public get objects(): { [_id: string]: AutoUpdated<T> | string } {
54
- return this.classes;
55
- }
56
-
57
- public get objectsAsArray(): AutoUpdated<T>[] {
58
- return this.classesAsArray;
59
- }
60
-
61
- public get className(): string {
62
- return this.classParam.name;
63
- }
64
-
65
- protected abstract handleGetMissingObject(
66
- _id: string
67
- ): Promise<AutoUpdated<T>>;
68
- public abstract createObject(
69
- data: IsData<InstanceType<T>>
70
- ): Promise<AutoUpdated<T>>;
71
- }
1
+ import { AutoUpdated } from "./AutoUpdatedClientObjectClass.ts";
2
+ import { Constructor, IsData, LoggersType, SocketType } from "./CommonTypes.ts";
3
+ import "reflect-metadata";
4
+
5
+ export abstract class AutoUpdateManager<T extends Constructor<any>> {
6
+ protected classes: { [_id: string]: AutoUpdated<T> } = {};
7
+ public socket: SocketType;
8
+ protected classParam: T;
9
+ protected properties: (keyof T)[];
10
+ protected classers: Record<string, AutoUpdateManager<any>>;
11
+ protected loggers: LoggersType = {
12
+ info: () => {},
13
+ debug: () => {},
14
+ error: () => {},
15
+ warn: () => {},
16
+ };
17
+ protected classesAsArray: AutoUpdated<T>[] = [];
18
+ constructor(
19
+ classParam: T,
20
+ socket: SocketType,
21
+ loggers: LoggersType,
22
+ classers: Record<string, AutoUpdateManager<any>>
23
+ ) {
24
+ this.classers = classers;
25
+ this.socket = socket;
26
+ this.classParam = classParam;
27
+ this.properties = Reflect.getMetadata(
28
+ "props",
29
+ Object.getPrototypeOf(classParam)
30
+ );
31
+ loggers.warn = loggers.warn ?? loggers.info;
32
+ this.loggers = loggers;
33
+ }
34
+
35
+
36
+ public getObject(
37
+ _id: string
38
+ ): AutoUpdated<T> | null {
39
+ return this.classes[_id];
40
+ }
41
+
42
+ public async deleteObject(_id: string): Promise<void> {
43
+ if (typeof this.classes[_id] === "string")
44
+ this.classes[_id] = await this.handleGetMissingObject(this.classes[_id]);
45
+ (this.classes[_id]).destroy();
46
+ this.classesAsArray.splice(this.classesAsArray.indexOf(this.classes[_id]), 1);
47
+ delete this.classes[_id];
48
+ }
49
+
50
+ public get objectIDs(): string[] {
51
+ return Object.keys(this.classes);
52
+ }
53
+
54
+ public get objects(): { [_id: string]: AutoUpdated<T> | string } {
55
+ return this.classes;
56
+ }
57
+
58
+ public get objectsAsArray(): AutoUpdated<T>[] {
59
+ return this.classesAsArray;
60
+ }
61
+
62
+ public get className(): string {
63
+ return this.classParam.name;
64
+ }
65
+
66
+ protected abstract handleGetMissingObject(
67
+ _id: string
68
+ ): Promise<AutoUpdated<T>>;
69
+ public abstract createObject(
70
+ data: IsData<InstanceType<T>>
71
+ ): Promise<AutoUpdated<T>>;
72
+ }
@@ -12,8 +12,8 @@ import {
12
12
  ServerResponse,
13
13
  ServerUpdateRequest,
14
14
  SocketType,
15
- } from "./CommonTypes.js";
16
- import { AutoUpdateManager } from "./AutoUpdateManagerClass.js";
15
+ } from "./CommonTypes.ts";
16
+ import { AutoUpdateManager } from "./AutoUpdateManagerClass.ts";
17
17
  import { ObjectId } from "bson";
18
18
 
19
19
  export type AutoUpdated<T extends Constructor<any>> =
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.2.7](https://github.com/Prestizni-Software/client-dem/compare/v0.2.6...v0.2.7) (2025-11-06)
6
+
7
+ ### [0.2.6](https://github.com/Prestizni-Software/client-dem/compare/v0.2.5...v0.2.6) (2025-11-06)
8
+
5
9
  ### [0.2.5](https://github.com/Prestizni-Software/client-dem/compare/v0.2.4...v0.2.5) (2025-11-06)
6
10
 
7
11
  ### [0.2.4](https://github.com/Prestizni-Software/client-dem/compare/v0.2.3...v0.2.4) (2025-11-06)
package/CommonTypes.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { DefaultEventsMap, Server } from "socket.io";
2
2
  import { Socket as SocketClient } from "socket.io-client";
3
3
  import { ObjectId } from "bson";
4
- import { AutoUpdated } from "./AutoUpdatedClientObjectClass.js";
4
+ import { AutoUpdated } from "./AutoUpdatedClientObjectClass.ts";
5
+ import "reflect-metadata";
5
6
 
6
7
  export type Ref<T> = string | (T extends Constructor<any> ? AutoUpdated<T> : (T & { _id: string }));
7
8
  export type LoggersTypeInternal = LoggersType & {
package/client.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as AutoUpdateClientManagerClass from "./AutoUpdateClientManagerClass.js";
2
- import * as AutoUpdateManagerClass from "./AutoUpdateManagerClass.js";
3
- import * as AutoUpdatedClientObjectClass from "./AutoUpdatedClientObjectClass.js";
4
- import * as CommonTypes from "./CommonTypes.js";
1
+ import * as AutoUpdateClientManagerClass from "./AutoUpdateClientManagerClass.ts";
2
+ import * as AutoUpdateManagerClass from "./AutoUpdateManagerClass.ts";
3
+ import * as AutoUpdatedClientObjectClass from "./AutoUpdatedClientObjectClass.ts";
4
+ import * as CommonTypes from "./CommonTypes.ts";
5
5
 
6
6
  module.exports = {
7
7
  AutoUpdateClientManagerClass,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/client-dem",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"