@prestizni-software/client-dem 0.2.20 → 0.2.21

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.
@@ -64,7 +64,6 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
64
64
  protected isLoadingReferences = false;
65
65
  public readonly classProp: Constructor<T>;
66
66
  private readonly EmitterID = new ObjectId().toHexString();
67
- protected unpopulatedData: RefToId<IsData<T>>;
68
67
  private readonly loadShit = async () => {
69
68
  if (this.isLoaded()) {
70
69
  try {
@@ -122,7 +121,6 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
122
121
  this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
123
122
  return;
124
123
  }
125
- this.unpopulatedData = res.data as any;
126
124
  checkForMissingRefs<T>(
127
125
  res.data as any,
128
126
  properties,
@@ -135,16 +133,14 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
135
133
  }
136
134
  );
137
135
  this.data = { _id: data } as IsData<T>;
138
- this.unpopulatedData = { _id: data } as any;
139
136
  } else {
140
137
  this.isLoading = true;
141
- this.unpopulatedData = data;
142
138
  checkForMissingRefs<T>(
143
- data as any,
144
- properties,
145
- classProperty as any,
146
- autoClassers
147
- );
139
+ data as any,
140
+ properties,
141
+ classProperty as any,
142
+ autoClassers
143
+ );
148
144
  this.data = data as any;
149
145
 
150
146
  if (this.data._id === "") this.handleNewObject(data as any);
@@ -167,13 +163,12 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
167
163
  this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
168
164
  return;
169
165
  }
170
- this.unpopulatedData = res.data as any;
171
166
  checkForMissingRefs<T>(
172
- res.data as any,
173
- this.properties,
174
- this.classProp as any,
175
- this.autoClassers
176
- );
167
+ res.data as any,
168
+ this.properties,
169
+ this.classProp as any,
170
+ this.autoClassers
171
+ );
177
172
  this.data = res.data as IsData<T>;
178
173
  this.isLoading = false;
179
174
  this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
@@ -183,13 +178,12 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
183
178
  public get extractedData(): {
184
179
  [K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
185
180
  } {
186
-
187
- const extracted = Object.fromEntries(
188
- Object.entries(this.unpopulatedData).filter(([k, v]) => typeof v !== "function")
189
- )
190
- return structuredClone(
191
- extracted
192
- ) as any as {
181
+ const extracted = Object.fromEntries(
182
+ Object.entries(
183
+ processIsRefProperties(this.data, this.classProp.prototype).newData
184
+ ).filter(([k, v]) => typeof v !== "function")
185
+ );
186
+ return structuredClone(extracted) as any as {
193
187
  [K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
194
188
  };
195
189
  }
@@ -248,7 +242,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
248
242
  }
249
243
 
250
244
  private generateSettersAndGetters() {
251
- this.properties.forEach((key) => {
245
+ for (const key of this.properties) {
252
246
  if (typeof key !== "string") return;
253
247
 
254
248
  const k = key as keyof IsData<T>;
@@ -259,8 +253,13 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
259
253
  );
260
254
 
261
255
  Object.defineProperty(this, key, {
262
- get: () =>
263
- isRef ? this.findReference(this.data[k] as string) : this.data[k],
256
+ get: () => {
257
+ if (isRef)
258
+ return typeof this.data[k] === "string"
259
+ ? this.findReference(this.data[k] as string)
260
+ : this.data[k];
261
+ else return this.data[k];
262
+ },
264
263
  set: () => {
265
264
  throw new Error(
266
265
  `Cannot set ${key} this way, use "setValue" function.`
@@ -269,7 +268,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
269
268
  enumerable: true,
270
269
  configurable: true,
271
270
  });
272
- });
271
+ }
273
272
  }
274
273
 
275
274
  protected findReference(id: string): AutoUpdated<any> | undefined {
@@ -429,8 +428,9 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
429
428
  export function processIsRefProperties(
430
429
  instance: any,
431
430
  target: any,
432
- prefix = "",
431
+ prefix: string | null = null,
433
432
  allProps: string[] = [],
433
+ newData = {} as any,
434
434
  loggers?: LoggersType
435
435
  ) {
436
436
  const props: string[] = Reflect.getMetadata("props", target) || [];
@@ -438,25 +438,31 @@ export function processIsRefProperties(
438
438
  for (const prop of props) {
439
439
  const path = prefix ? `${prefix}.${prop}` : prop;
440
440
  allProps.push(path);
441
+ newData[prop] = instance[prop];
441
442
  if (Reflect.getMetadata("isRef", target, prop)) {
442
443
  (loggers ?? console).debug("Changing isRef:", path);
443
-
444
- instance[prop] =
444
+ newData[prop] =
445
445
  typeof instance[prop] === "string"
446
446
  ? instance[prop]
447
- : instance[prop]._id;
447
+ : instance[prop]?._id;
448
448
  }
449
449
 
450
- // recurse into nested objects
451
450
  const type = Reflect.getMetadata("design:type", target, prop);
452
451
  if (type?.prototype) {
453
452
  const nestedProps = Reflect.getMetadata("props", type.prototype);
454
453
  if (nestedProps && instance[prop]) {
455
- processIsRefProperties(instance[prop], type.prototype, path, allProps);
454
+ newData[prop] = processIsRefProperties(
455
+ instance[prop],
456
+ type.prototype,
457
+ path,
458
+ allProps,
459
+ undefined,
460
+ loggers
461
+ ).newData;
456
462
  }
457
463
  }
458
464
  }
459
- return allProps;
465
+ return { allProps, newData };
460
466
  }
461
467
 
462
468
  export function getMetadataRecursive(
@@ -495,15 +501,16 @@ function findMissingObjectReference(
495
501
  prop: any,
496
502
  autoClassers: { [key: string]: AutoUpdateManager<any> }
497
503
  ) {
498
- for(const ac of Object.values(autoClassers)){
499
- for(const obj of ac.objectsAsArray){
504
+ for (const ac of Object.values(autoClassers)) {
505
+ for (const obj of ac.objectsAsArray) {
500
506
  const found = Object.values(obj.extractedData).find((value) =>
501
507
  Array.isArray(value) ? value.includes(data._id) : value === data._id
502
- )
503
- if(found){
508
+ );
509
+ if (found) {
504
510
  data[prop] = obj._id;
505
511
  return;
506
512
  }
507
513
  }
508
514
  }
515
+ console.log("a");
509
516
  }
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.21](https://github.com/Prestizni-Software/client-dem/compare/v0.2.20...v0.2.21) (2025-11-10)
6
+
5
7
  ### [0.2.20](https://github.com/Prestizni-Software/client-dem/compare/v0.2.19...v0.2.20) (2025-11-10)
6
8
 
7
9
  ### [0.2.19](https://github.com/Prestizni-Software/client-dem/compare/v0.2.18...v0.2.19) (2025-11-10)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/client-dem",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"