@prestizni-software/server-dem 0.2.3 → 0.2.4

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.
@@ -10,6 +10,7 @@ import {
10
10
  ServerUpdateRequest,
11
11
  } from "./CommonTypes.js";
12
12
  import { BeAnObject, ReturnModelType } from "@typegoose/typegoose/lib/types.js";
13
+ import { getModelForClass } from "@typegoose/typegoose";
13
14
  export type WrappedInstances<T extends Record<string, Constructor<any>>> = {
14
15
  [K in keyof T]: AutoUpdateServerManager<T[K]>;
15
16
  };
@@ -30,29 +31,35 @@ export function createAutoStatusDefinitions<
30
31
  C extends Constructor<any>,
31
32
  E extends { [k: string]: string | number }
32
33
  >(def: {
33
- class: C
34
+ class: C;
34
35
  statusProperty: Paths<C>;
35
36
  statusEnum: E;
36
37
  definitions: { [K in keyof E]: {} };
37
- }): AutoStatusDefinitions<C> & { statusEnum: E; definitions: { [K in keyof E]: {} } } {
38
+ }): AutoStatusDefinitions<C> & {
39
+ statusEnum: E;
40
+ definitions: { [K in keyof E]: {} };
41
+ } {
38
42
  return def;
39
43
  }
40
44
 
41
- export type AUSOptions<C extends Constructor<any>> = {
45
+ export type AUSOptions<T extends Record<string, Constructor<any>>> = {
46
+ [K in keyof T]: ServerManagerDefinition<T[K]>;
47
+ };
48
+
49
+ export type AUSOption<C extends Constructor<any>> = {
42
50
  accessDefinitions?: Partial<AccessDefinitions<C>>;
43
51
  autoStatusDefinitions?: Partial<AutoStatusDefinitions<C>>;
44
- }
52
+ };
45
53
 
46
54
  type ServerManagerDefinition<C extends Constructor<any>> = {
47
55
  class: C;
48
- model: ReturnModelType<C, BeAnObject>;
49
- options?: AUSOptions<C>;
56
+ options?: AUSOption<C>;
50
57
  };
51
58
 
52
59
  export async function AUSManagerFactory<
53
60
  T extends Record<string, Constructor<any>>
54
61
  >(
55
- defs: { [K in keyof T]: ServerManagerDefinition<T[K]> },
62
+ defs: AUSOptions<T>,
56
63
  loggers: LoggersType,
57
64
  socket: Server
58
65
  ): Promise<{ [K in keyof T]: AutoUpdateServerManager<T[K]> }> {
@@ -65,7 +72,7 @@ export async function AUSManagerFactory<
65
72
  def.class,
66
73
  loggers,
67
74
  socket,
68
- def.model,
75
+ getModelForClass(def.class),
69
76
  classers,
70
77
  def.options
71
78
  ) as any;
@@ -89,7 +96,7 @@ export class AutoUpdateServerManager<
89
96
  socket: Server,
90
97
  model: ReturnModelType<T, BeAnObject>,
91
98
  classers: Record<string, AutoUpdateManager<any>>,
92
- options?: AUSOptions<T>
99
+ options?: AUSOption<T>
93
100
  ) {
94
101
  super(classParam, socket, loggers, classers);
95
102
  this.model = model;
@@ -112,7 +119,7 @@ export class AutoUpdateServerManager<
112
119
  async (ack: (ids: string[]) => void) => {
113
120
  const ids: string[] = [];
114
121
  ack(this.objectIDs);
115
- }
122
+ }
116
123
  );
117
124
  socket.on("delete" + this.className, async (id: string) => {
118
125
  this.classes[id].destroy();
@@ -418,7 +418,7 @@ export function processIsRefProperties(
418
418
  (loggers ?? console).debug("Changing isRef:", path);
419
419
 
420
420
  // Example: replace with a proxy or a marker object
421
- instance[prop] = instance[prop]._id;
421
+ instance[prop] = typeof instance[prop] === "string" ? instance[prop] : instance[prop]._id;
422
422
  }
423
423
 
424
424
  // recurse into nested objects
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
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.4](https://github.com/Prestizni-Software/server-dem/compare/v0.2.3...v0.2.4) (2025-11-06)
6
+
5
7
  ### [0.2.3](https://github.com/Prestizni-Software/server-dem/compare/v0.2.2...v0.2.3) (2025-11-04)
6
8
 
7
9
  ### [0.2.2](https://github.com/Prestizni-Software/server-dem/compare/v0.2.1...v0.2.2) (2025-11-04)
package/CommonTypes.ts CHANGED
@@ -1,9 +1,9 @@
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 { Test } from "./server.js";
4
+ import { AutoUpdated } from "./AutoUpdatedClientObjectClass.js";
5
5
 
6
- export type Ref<T> = T & { _id: string };
6
+ export type Ref<T extends Constructor<any>> = T & { _id: string } | string | AutoUpdated<T>;
7
7
  export type LoggersTypeInternal = LoggersType & {
8
8
  warn: (...args: any[]) => void;
9
9
  };
@@ -153,7 +153,4 @@ export type PathValueOf<
153
153
  > = PathValue<DeRef<InstanceOf<T>>, Split<P>, Depth>;
154
154
 
155
155
  // ---------------------- Pretty ----------------------
156
- export type Pretty<T> = { [K in keyof T]: T[K] };
157
-
158
- let test1: Paths<Test> = "test2";
159
- let test2: PathValueOf<Test, "test2.loggers2">;
156
+ export type Pretty<T> = { [K in keyof T]: T[K] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/server-dem",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"