@prestizni-software/client-dem 0.2.14 → 0.2.16

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.
@@ -27,18 +27,18 @@ export async function createAutoUpdatedClass<C extends Constructor<any>>(
27
27
  ): Promise<AutoUpdated<C>> {
28
28
  if (typeof data !== "string")
29
29
  processIsRefProperties(data, classParam.prototype, undefined, [], loggers);
30
-
30
+ const props = Reflect.getMetadata("props", classParam.prototype);
31
+ if (typeof data !== "string")
32
+ checkForMissingRefs<C>(data, props, classParam, autoClassers);
31
33
  const instance = new (class extends AutoUpdatedClientObject<C> {})(
32
34
  socket,
33
35
  data,
34
36
  loggers,
35
- Reflect.getMetadata("props", classParam.prototype),
37
+ props,
36
38
  classParam.name,
37
39
  classParam,
38
40
  autoClassers,
39
41
  emitter
40
-
41
-
42
42
  );
43
43
 
44
44
  await instance.isLoadedAsync();
@@ -77,7 +77,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
77
77
 
78
78
  return;
79
79
  }
80
- this.emitter.addEventListener("loaded"+this.EmitterID, async () => {
80
+ this.emitter.addEventListener("loaded" + this.EmitterID, async () => {
81
81
  try {
82
82
  await this.loadForceReferences();
83
83
  } catch (error) {
@@ -120,12 +120,18 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
120
120
  if (!res.success) {
121
121
  this.isLoading = false;
122
122
  this.loggers.error("Could not load data from server:", res.message);
123
- this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
123
+ this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
124
124
  return;
125
125
  }
126
+ checkForMissingRefs<T>(
127
+ res.data as any,
128
+ properties,
129
+ classProperty as any,
130
+ autoClassers
131
+ );
126
132
  this.data = res.data as IsData<T>;
127
133
  this.isLoading = false;
128
- this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
134
+ this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
129
135
  }
130
136
  );
131
137
  this.data = { _id: data } as IsData<T>;
@@ -149,12 +155,12 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
149
155
  if (!res.success) {
150
156
  this.isLoading = false;
151
157
  this.loggers.error("Could not create data on server:", res.message);
152
- this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
158
+ this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
153
159
  return;
154
160
  }
155
161
  this.data = res.data as IsData<T>;
156
162
  this.isLoading = false;
157
- this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
163
+ this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
158
164
  });
159
165
  }
160
166
 
@@ -174,7 +180,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
174
180
  await this.loadShit();
175
181
  return this.isLoading
176
182
  ? new Promise((resolve) => {
177
- this.emitter.addEventListener("loaded"+this.EmitterID, () => {
183
+ this.emitter.addEventListener("loaded" + this.EmitterID, () => {
178
184
  resolve(this.isLoading === false);
179
185
  });
180
186
  })
@@ -224,7 +230,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
224
230
  if (typeof key !== "string") return;
225
231
 
226
232
  const k = key as keyof IsData<T>;
227
- const isRef = this.getMetadataRecursive(
233
+ const isRef = getMetadataRecursive(
228
234
  "isRef",
229
235
  this.classProp.prototype,
230
236
  key
@@ -333,15 +339,6 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
333
339
  return { _id: id, key, value } as any;
334
340
  }
335
341
 
336
- private getMetadataRecursive(metaKey: string, proto: any, prop: string) {
337
- while (proto) {
338
- const meta = Reflect.getMetadata(metaKey, proto, prop);
339
- if (meta !== undefined) return meta;
340
- proto = Object.getPrototypeOf(proto);
341
- }
342
- return undefined;
343
- }
344
-
345
342
  // return a properly typed AutoUpdatedClientClass (or null)
346
343
  // inside AutoUpdatedClientClass
347
344
  protected resolveReference(id: string): AutoUpdatedClientObject<any> | null {
@@ -424,7 +421,10 @@ export function processIsRefProperties(
424
421
  (loggers ?? console).debug("Changing isRef:", path);
425
422
 
426
423
  // Example: replace with a proxy or a marker object
427
- instance[prop] = typeof instance[prop] === "string" ? instance[prop] : instance[prop]._id;
424
+ instance[prop] =
425
+ typeof instance[prop] === "string"
426
+ ? instance[prop]
427
+ : instance[prop]._id;
428
428
  }
429
429
 
430
430
  // recurse into nested objects
@@ -438,3 +438,43 @@ export function processIsRefProperties(
438
438
  }
439
439
  return allProps;
440
440
  }
441
+
442
+ export function getMetadataRecursive(
443
+ metaKey: string,
444
+ proto: any,
445
+ prop: string
446
+ ) {
447
+ while (proto) {
448
+ const meta = Reflect.getMetadata(metaKey, proto, prop);
449
+ if (meta !== undefined) return meta;
450
+ proto = Object.getPrototypeOf(proto);
451
+ }
452
+ return undefined;
453
+ }
454
+
455
+ function checkForMissingRefs<C extends Constructor<any>>(
456
+ data: IsData<InstanceType<C>>,
457
+ props: any,
458
+ classParam: C,
459
+ autoClassers: { [key: string]: AutoUpdateManager<any> }
460
+ ) {
461
+ if (typeof data !== "string") {
462
+ const entryKeys = Object.keys(data);
463
+ for (const prop of props) {
464
+ if (
465
+ !entryKeys.includes(prop.toString()) &&
466
+ getMetadataRecursive("isRef", classParam.prototype, prop.toString())
467
+ ) {
468
+ (data as any)[prop] = Object.values(autoClassers).find((autoClasser) =>
469
+ autoClasser.objectsAsArray.find((object) =>
470
+ Object.values(object.extractedData).find((value) =>
471
+ Array.isArray(value)
472
+ ? value.includes(data._id)
473
+ : value === data._id
474
+ )
475
+ )
476
+ );
477
+ }
478
+ }
479
+ }
480
+ }
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.16](https://github.com/Prestizni-Software/client-dem/compare/v0.2.15...v0.2.16) (2025-11-10)
6
+
7
+ ### [0.2.15](https://github.com/Prestizni-Software/client-dem/compare/v0.2.14...v0.2.15) (2025-11-10)
8
+
5
9
  ### [0.2.14](https://github.com/Prestizni-Software/client-dem/compare/v0.2.13...v0.2.14) (2025-11-06)
6
10
 
7
11
  ### [0.2.13](https://github.com/Prestizni-Software/client-dem/compare/v0.2.12...v0.2.13) (2025-11-06)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/client-dem",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"