@prestizni-software/server-dem 0.1.24 → 0.1.25

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/CHANGELOG.md CHANGED
@@ -2,36 +2,4 @@
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.1.24](https://github.com/Prestizni-Software/DEM/compare/v0.1.23...v0.1.24) (2025-11-04)
6
-
7
- ### [0.1.23](https://github.com/Prestizni-Software/DEM/compare/v0.1.22...v0.1.23) (2025-11-04)
8
-
9
- ### [0.1.22](https://github.com/Prestizni-Software/DEM/compare/v0.1.21...v0.1.22) (2025-11-04)
10
-
11
- ### [0.1.21](https://github.com/Prestizni-Software/DEM/compare/v0.1.20...v0.1.21) (2025-11-04)
12
-
13
- ### [0.1.20](https://github.com/Prestizni-Software/DEM/compare/v0.1.19...v0.1.20) (2025-11-04)
14
-
15
- ### [0.1.19](https://github.com/Prestizni-Software/DEM/compare/v0.1.18...v0.1.19) (2025-11-04)
16
-
17
- ### [0.1.18](https://github.com/Prestizni-Software/DEM/compare/v0.1.17...v0.1.18) (2025-11-04)
18
-
19
- ### [0.1.17](https://github.com/Prestizni-Software/DEM/compare/v0.1.16...v0.1.17) (2025-11-04)
20
-
21
- ### [0.1.16](https://github.com/Prestizni-Software/DEM/compare/v0.1.15...v0.1.16) (2025-11-04)
22
-
23
- ### [0.1.15](https://github.com/Prestizni-Software/DEM/compare/v0.1.14...v0.1.15) (2025-11-04)
24
-
25
- ### [0.1.14](https://github.com/Prestizni-Software/DEM/compare/v0.1.13...v0.1.14) (2025-11-04)
26
-
27
- ### [0.1.13](https://github.com/Prestizni-Software/DEM/compare/v0.1.12...v0.1.13) (2025-11-04)
28
-
29
- ### [0.1.12](https://github.com/Prestizni-Software/DEM/compare/v0.1.11...v0.1.12) (2025-11-04)
30
-
31
- ### [0.1.11](https://github.com/Prestizni-Software/DEM/compare/v0.1.10...v0.1.11) (2025-11-04)
32
-
33
- ### [0.1.10](https://github.com/Prestizni-Software/DEM/compare/v0.1.9...v0.1.10) (2025-11-04)
34
-
35
- ### [0.1.9](https://github.com/Prestizni-Software/DEM/compare/v0.1.8...v0.1.9) (2025-11-04)
36
-
37
- ### 0.1.8 (2025-11-04)
5
+ ### [0.1.25](https://github.com/Prestizni-Software/DEM/compare/v0.1.24...v0.1.25) (2025-11-04)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/server-dem",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@typegoose/typegoose": "^12.20.0",
21
+ "mongoose": "^8.19.2",
21
22
  "socket.io": "^4.8.1",
22
23
  "socket.io-client": "^4.8.1"
23
24
  },
@@ -1,77 +0,0 @@
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
-
9
- // ---------------------- Factory ----------------------
10
- export async function AUCManagerFactory<
11
- T extends Record<string, Constructor<any>>
12
- >(defs: T, loggers: LoggersType, socket: Socket): Promise<WrappedInstances<T>> {
13
- const classers = {} as WrappedInstances<T>;
14
-
15
- for (const key in defs) {
16
- const Model = defs[key];
17
- const c = new AutoUpdateClientManager(
18
- Model,
19
- loggers,
20
- socket,
21
- classers as any
22
- );
23
- classers[key] = c;
24
- }
25
-
26
- return classers;
27
- }
28
-
29
- export class AutoUpdateClientManager<
30
- T extends Constructor<any>
31
- > extends AutoUpdateManager<T> {
32
- constructor(
33
- classParam: T,
34
- loggers: LoggersType,
35
- socket: Socket,
36
- classers: Record<string, AutoUpdateManager<any>>
37
- ) {
38
- super(classParam, socket, loggers, classers);
39
- socket.emit("startup" + classParam.name, async (data: string[]) => {
40
- for (const id of data) {
41
- this.classes[id] = await this.handleGetMissingObject(id);
42
- this.classesAsArray.push(this.classes[id]);
43
- }
44
- });
45
- socket.on("new" + classParam.name, async (id: string) => {
46
- this.classes[id] = await this.handleGetMissingObject(id);
47
- this.classesAsArray.push(this.classes[id]);
48
- });
49
- socket.on("delete" + classParam.name, (id: string) => {
50
- this.deleteObject(id);
51
- });
52
- }
53
-
54
- protected async handleGetMissingObject(_id: string) {
55
- if (!this.classers) throw new Error(`No classers.`);
56
- return await createAutoUpdatedClass(
57
- this.classParam,
58
- this.socket,
59
- _id,
60
- this.loggers,
61
- this.classers
62
- );
63
- }
64
-
65
- public async createObject(data: IsData<InstanceType<T>>) {
66
- if (!this.classers) throw new Error(`No classers.`);
67
- const object = await createAutoUpdatedClass(
68
- this.classParam,
69
- this.socket,
70
- data,
71
- this.loggers,
72
- this.classers
73
- );
74
- this.classes[object._id as any] = object;
75
- return object;
76
- }
77
- }
package/DEM_requests.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Paths } from "./CommonTypes.js"
2
- import { Test } from "./server.js"
3
-
4
- type AutoStatusOptions<T> = {
5
- statusVariable: Paths<T>
6
- }
7
-
8
- const example_auto_status_options:AutoStatusOptions<typeof Test.prototype> = {
9
- statusVariable: "status",
10
-
11
- }
12
-
13
- /*
14
- *
15
- *
16
- */
package/client.ts DELETED
@@ -1,120 +0,0 @@
1
- import { io } from "socket.io-client";
2
- import readline from "readline";
3
- import { classProp, classRef, LoggersType } from "./CommonTypes.js";
4
- import { AUCManagerFactory } from "./AutoUpdateClientManagerClass.js";
5
-
6
- class Test2 {
7
- @classProp public _id!: string;
8
- @classProp public login!: string;
9
- @classProp public loggers!: LoggersType;
10
- public func = () => {
11
- console.log("func");
12
- };
13
- }
14
-
15
- class Test {
16
- @classProp public _id!: string;
17
- @classProp public login!: string[];
18
- @classProp public loggers!: LoggersType;
19
-
20
- // mark as compile-time Ref<Test2> (runtime is still string id)
21
- @classProp @classRef public test2!: Test2;
22
-
23
- // force-loaded ref
24
- @classProp @classRef public test3!: Test2;
25
- }
26
- const loggers: LoggersType = {
27
- info: console.log,
28
- debug: console.debug,
29
- error: console.error,
30
- warn: console.warn,
31
- };
32
-
33
- const socket = io("http://localhost:3000", {
34
- extraHeaders: {
35
- //HEADRY
36
- Authorization: "Bearer " + "token",
37
- },
38
- });
39
- socket.on("connect", async () => {
40
-
41
- const classers = await AUCManagerFactory({ Test, Test2 }, loggers, socket);
42
-
43
- // ---------------------- Setup CLI ----------------------
44
- const rl = readline.createInterface({
45
- input: process.stdin,
46
- output: process.stdout,
47
- });
48
-
49
- setTimeout(async () => {
50
- const ass = ((classers).Test.getObject("68c9f23872cff1778cb1abe2"));
51
- ass?.test2.loggers.info("test");
52
- ass?.test2.func();
53
- }, 100);
54
-
55
- // ---------------------- Interactive CLI ----------------------
56
- function prompt() {
57
- rl.question(
58
- "\nCommands:\n[list] List all collections\n[show <collection> <id> <field?>] Show object\n[set <collection> <id> <field> <value>] Update field\n[new <collection>] Request new object\n[exit] Exit\n> ",
59
- async (input) => {
60
- const args = input.trim().split(" ");
61
- const cmd = args[0];
62
-
63
- switch (cmd) {
64
- case "list":
65
- console.log("Collections:");
66
- for (const classer of Object.values(classers)) {
67
- console.log(`- ${classer.className}`);
68
- for (const id of classer.objectIDs) {
69
- console.log(` • ${id}`);
70
- }
71
- }
72
- break;
73
-
74
- case "show":
75
- if (args.length < 3)
76
- return console.log("❌ Usage: show <collection> <id> <field?>");
77
-
78
- const objShow = await (classers as any)[args[1]]?.getClass(args[2]);
79
- if (!objShow) return console.log("❌ Collection not found");
80
-
81
- if (args[3]) {
82
- const val = objShow.getValue(args[3]);
83
- console.log(val !== undefined ? val : "❌ Field not found");
84
- } else {
85
- console.log(objShow.extractData);
86
- }
87
- break;
88
-
89
- case "set":
90
- if (args.length < 5)
91
- return console.log(
92
- "❌ Usage: set <collection> <id> <field> <value>"
93
- );
94
-
95
- const objSet = await (classers as any)[args[1]]?.getClass(args[2]);
96
- if (!objSet) return console.log("❌ Object not found");
97
-
98
- const fieldPath = args[3];
99
- const value = args.slice(4).join(" "); // allow spaces in value
100
-
101
- if (fieldPath === "_id") return console.log("❌ Cannot change _id");
102
-
103
- objSet.setValue(fieldPath, value);
104
- console.log(`✅ Updated ${fieldPath} = ${value}`);
105
- break;
106
-
107
- case "exit":
108
- console.log("👋 Exiting...");
109
- process.exit(0);
110
-
111
- default:
112
- console.log("❌ Unknown command");
113
- }
114
-
115
- prompt();
116
- }
117
- );
118
- }
119
- prompt();
120
- });
package/server.ts DELETED
@@ -1,116 +0,0 @@
1
- import { createServer } from "node:http";
2
- import { Server } from "socket.io";
3
- import mongoose, { Types } from "mongoose";
4
- import { getModelForClass, prop, Ref } from "@typegoose/typegoose";
5
- import readline from "node:readline";
6
- import { LoggersType, classProp, classRef } from "./CommonTypes.js";
7
- import {
8
- AUSManagerFactory,
9
- createAutoStatusDefinitions,
10
- } from "./AutoUpdateServerManagerClass.js";
11
-
12
- // ---------------------- Data Models ----------------------
13
-
14
- enum Statuses {
15
- Status1 = "Status1",
16
- Status2 = "Banana",
17
- }
18
- class Test2 {
19
- @classProp public _id!: Types.ObjectId;
20
- @classProp public login!: string;
21
- @classProp public loggers2!: LoggersType;
22
- }
23
-
24
- export class Test {
25
- @classProp public _id!: Types.ObjectId;
26
- @classProp public login!: string[];
27
- @classProp public loggers2!: LoggersType;
28
- @classProp public status!: Statuses;
29
-
30
- @classProp @classRef @prop() public test2!: Ref<Test2>;
31
-
32
- @classProp @classRef @prop() public test3?: Ref<Test2>;
33
- }
34
-
35
- // ---------------------- Setup CLI ----------------------
36
- const rl = readline.createInterface({
37
- input: process.stdin,
38
- output: process.stdout,
39
- });
40
-
41
- // ---------------------- Loggers ----------------------
42
- const loggers: LoggersType = {
43
- info: console.log,
44
- debug: console.debug,
45
- error: console.error,
46
- warn: console.warn,
47
- };
48
-
49
- // ---------------------- Start Server ----------------------
50
- const start = async () => {
51
- console.log("📡 Connecting to MongoDB...");
52
- await mongoose.connect("mongodb://localhost:27017");
53
- console.log("✅ Connected to MongoDB");
54
-
55
- const TestModel = getModelForClass(Test);
56
- const Test2Model = getModelForClass(Test2);
57
-
58
- // ---------------------- Socket.IO ----------------------
59
- const httpServer = createServer();
60
- const io = new Server(httpServer, { cors: { origin: "*" } });
61
-
62
- httpServer.listen(3000, () => {
63
- console.log("📡 Socket.IO server running on port 3000");
64
- });
65
-
66
- // ---------------------- Wrap DB entries ----------------------
67
-
68
- const classers = await AUSManagerFactory(
69
- {
70
- Test: {
71
- model: TestModel,
72
- class: Test,
73
- options: {
74
- accessDefinitions: {
75
- status: {},
76
- "test3.loggers2.warn": {},
77
- },
78
- autoStatusDefinitions: createAutoStatusDefinitions({
79
- class: Test,
80
- statusProperty: "status",
81
- statusEnum: Statuses,
82
- definitions: {
83
- Status1: {},
84
- Status2:{}
85
- },
86
- }),
87
- },
88
- },
89
- Test2: {
90
- model: Test2Model,
91
- class: Test2,
92
- },
93
- },
94
- loggers,
95
- io
96
- );
97
-
98
- const testObject = classers.Test.getObject("68c9f23872cff1778cb1abe2");
99
- await testObject?.setValue("test2.loggers2", loggers);
100
- testObject?.test2.loggers2.info("test");
101
- await testObject?.setValue("test2.loggers2.info", console.error);
102
- testObject?.test2.loggers2.info("test");
103
-
104
- // ---------------------- Handle Socket Connections ----------------------
105
- io.on("connection", async (socket) => {
106
- console.log(`🔌 Client connected: ${socket.id}`);
107
- for (const classer of Object.values(classers)) {
108
- classer.registerSocket(socket);
109
- }
110
- // Client disconnect
111
- socket.on("disconnect", () => {
112
- console.log(`❌ Client disconnected: ${socket.id}`);
113
- });
114
- });
115
- };
116
- start();