@prestizni-software/client-dem 0.2.18 → 0.2.20

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.
@@ -8,6 +8,7 @@ import {
8
8
  LoggersTypeInternal,
9
9
  Paths,
10
10
  PathValueOf,
11
+ RefToId,
11
12
  ServerResponse,
12
13
  ServerUpdateRequest,
13
14
  SocketType,
@@ -20,7 +21,7 @@ export type AutoUpdated<T extends Constructor<any>> =
20
21
  export async function createAutoUpdatedClass<C extends Constructor<any>>(
21
22
  classParam: C,
22
23
  socket: SocketType,
23
- data: IsData<InstanceType<C>> | string,
24
+ data: RefToId<IsData<InstanceType<C>>> | string,
24
25
  loggers: LoggersType,
25
26
  autoClassers: { [key: string]: AutoUpdateManager<any> },
26
27
  emitter: EventTarget
@@ -28,8 +29,6 @@ export async function createAutoUpdatedClass<C extends Constructor<any>>(
28
29
  if (typeof data !== "string")
29
30
  processIsRefProperties(data, classParam.prototype, undefined, [], loggers);
30
31
  const props = Reflect.getMetadata("props", classParam.prototype);
31
- if (typeof data !== "string")
32
- checkForMissingRefs<C>(data, props, classParam, autoClassers);
33
32
  const instance = new (class extends AutoUpdatedClientObject<C> {})(
34
33
  socket,
35
34
  data,
@@ -65,7 +64,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
65
64
  protected isLoadingReferences = false;
66
65
  public readonly classProp: Constructor<T>;
67
66
  private readonly EmitterID = new ObjectId().toHexString();
68
-
67
+ protected unpopulatedData: RefToId<IsData<T>>;
69
68
  private readonly loadShit = async () => {
70
69
  if (this.isLoaded()) {
71
70
  try {
@@ -88,7 +87,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
88
87
  };
89
88
  constructor(
90
89
  socket: SocketType,
91
- data: string | IsData<T>,
90
+ data: string | RefToId<IsData<T>>,
92
91
  loggers: LoggersType,
93
92
  properties: (keyof T)[],
94
93
  className: string,
@@ -123,6 +122,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
123
122
  this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
124
123
  return;
125
124
  }
125
+ this.unpopulatedData = res.data as any;
126
126
  checkForMissingRefs<T>(
127
127
  res.data as any,
128
128
  properties,
@@ -135,10 +135,19 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
135
135
  }
136
136
  );
137
137
  this.data = { _id: data } as IsData<T>;
138
+ this.unpopulatedData = { _id: data } as any;
138
139
  } else {
139
140
  this.isLoading = true;
140
- this.data = data;
141
- if (this.data._id === "") this.handleNewObject(data);
141
+ this.unpopulatedData = data;
142
+ checkForMissingRefs<T>(
143
+ data as any,
144
+ properties,
145
+ classProperty as any,
146
+ autoClassers
147
+ );
148
+ this.data = data as any;
149
+
150
+ if (this.data._id === "") this.handleNewObject(data as any);
142
151
  else this.isLoading = false;
143
152
  }
144
153
  if (!this.isServer) this.openSockets();
@@ -158,6 +167,13 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
158
167
  this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
159
168
  return;
160
169
  }
170
+ this.unpopulatedData = res.data as any;
171
+ checkForMissingRefs<T>(
172
+ res.data as any,
173
+ this.properties,
174
+ this.classProp as any,
175
+ this.autoClassers
176
+ );
161
177
  this.data = res.data as IsData<T>;
162
178
  this.isLoading = false;
163
179
  this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
@@ -167,10 +183,12 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
167
183
  public get extractedData(): {
168
184
  [K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
169
185
  } {
170
- return structuredClone(
171
- Object.fromEntries(
172
- Object.entries(this.data).filter(([k, v]) => typeof v !== "function")
186
+
187
+ const extracted = Object.fromEntries(
188
+ Object.entries(this.unpopulatedData).filter(([k, v]) => typeof v !== "function")
173
189
  )
190
+ return structuredClone(
191
+ extracted
174
192
  ) as any as {
175
193
  [K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
176
194
  };
@@ -421,10 +439,8 @@ export function processIsRefProperties(
421
439
  const path = prefix ? `${prefix}.${prop}` : prop;
422
440
  allProps.push(path);
423
441
  if (Reflect.getMetadata("isRef", target, prop)) {
424
- // 👇 here’s where you mutate
425
442
  (loggers ?? console).debug("Changing isRef:", path);
426
443
 
427
- // Example: replace with a proxy or a marker object
428
444
  instance[prop] =
429
445
  typeof instance[prop] === "string"
430
446
  ? instance[prop]
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.20](https://github.com/Prestizni-Software/client-dem/compare/v0.2.19...v0.2.20) (2025-11-10)
6
+
7
+ ### [0.2.19](https://github.com/Prestizni-Software/client-dem/compare/v0.2.18...v0.2.19) (2025-11-10)
8
+
5
9
  ### [0.2.18](https://github.com/Prestizni-Software/client-dem/compare/v0.2.17...v0.2.18) (2025-11-10)
6
10
 
7
11
  ### [0.2.17](https://github.com/Prestizni-Software/client-dem/compare/v0.2.16...v0.2.17) (2025-11-10)
package/CommonTypes.ts CHANGED
@@ -74,6 +74,10 @@ export type DeRef<T> = {
74
74
  : NonOptional<T[K]>;
75
75
  };
76
76
 
77
+ export type RefToId<T> = {
78
+ [K in keyof T]: T[K] extends Ref<infer U> ? string : T[K];
79
+ };
80
+
77
81
  // ---------------------- Instance helper ----------------------
78
82
  export type InstanceOf<T> = T extends Constructor<infer I> ? I : T;
79
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/client-dem",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"