@prestizni-software/client-dem 0.2.15 → 0.2.17
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/AutoUpdatedClientObjectClass.ts +41 -26
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
|
@@ -39,8 +39,6 @@ export async function createAutoUpdatedClass<C extends Constructor<any>>(
|
|
|
39
39
|
classParam,
|
|
40
40
|
autoClassers,
|
|
41
41
|
emitter
|
|
42
|
-
|
|
43
|
-
|
|
44
42
|
);
|
|
45
43
|
|
|
46
44
|
await instance.isLoadedAsync();
|
|
@@ -79,7 +77,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
79
77
|
|
|
80
78
|
return;
|
|
81
79
|
}
|
|
82
|
-
this.emitter.addEventListener("loaded"+this.EmitterID, async () => {
|
|
80
|
+
this.emitter.addEventListener("loaded" + this.EmitterID, async () => {
|
|
83
81
|
try {
|
|
84
82
|
await this.loadForceReferences();
|
|
85
83
|
} catch (error) {
|
|
@@ -122,13 +120,18 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
122
120
|
if (!res.success) {
|
|
123
121
|
this.isLoading = false;
|
|
124
122
|
this.loggers.error("Could not load data from server:", res.message);
|
|
125
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
123
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
126
124
|
return;
|
|
127
125
|
}
|
|
128
|
-
checkForMissingRefs<T>(
|
|
126
|
+
checkForMissingRefs<T>(
|
|
127
|
+
res.data as any,
|
|
128
|
+
properties,
|
|
129
|
+
classProperty as any,
|
|
130
|
+
autoClassers
|
|
131
|
+
);
|
|
129
132
|
this.data = res.data as IsData<T>;
|
|
130
133
|
this.isLoading = false;
|
|
131
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
134
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
132
135
|
}
|
|
133
136
|
);
|
|
134
137
|
this.data = { _id: data } as IsData<T>;
|
|
@@ -152,19 +155,23 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
152
155
|
if (!res.success) {
|
|
153
156
|
this.isLoading = false;
|
|
154
157
|
this.loggers.error("Could not create data on server:", res.message);
|
|
155
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
158
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
156
159
|
return;
|
|
157
160
|
}
|
|
158
161
|
this.data = res.data as IsData<T>;
|
|
159
162
|
this.isLoading = false;
|
|
160
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
163
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
161
164
|
});
|
|
162
165
|
}
|
|
163
166
|
|
|
164
167
|
public get extractedData(): {
|
|
165
168
|
[K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
|
|
166
169
|
} {
|
|
167
|
-
return structuredClone(
|
|
170
|
+
return structuredClone(
|
|
171
|
+
Object.fromEntries(
|
|
172
|
+
Object.entries(this.data).filter(([k, v]) => typeof v !== "function")
|
|
173
|
+
)
|
|
174
|
+
) as any as {
|
|
168
175
|
[K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
|
|
169
176
|
};
|
|
170
177
|
}
|
|
@@ -177,7 +184,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
177
184
|
await this.loadShit();
|
|
178
185
|
return this.isLoading
|
|
179
186
|
? new Promise((resolve) => {
|
|
180
|
-
this.emitter.addEventListener("loaded"+this.EmitterID, () => {
|
|
187
|
+
this.emitter.addEventListener("loaded" + this.EmitterID, () => {
|
|
181
188
|
resolve(this.isLoading === false);
|
|
182
189
|
});
|
|
183
190
|
})
|
|
@@ -227,7 +234,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
227
234
|
if (typeof key !== "string") return;
|
|
228
235
|
|
|
229
236
|
const k = key as keyof IsData<T>;
|
|
230
|
-
const isRef =
|
|
237
|
+
const isRef = getMetadataRecursive(
|
|
231
238
|
"isRef",
|
|
232
239
|
this.classProp.prototype,
|
|
233
240
|
key
|
|
@@ -336,15 +343,6 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
336
343
|
return { _id: id, key, value } as any;
|
|
337
344
|
}
|
|
338
345
|
|
|
339
|
-
private getMetadataRecursive(metaKey: string, proto: any, prop: string) {
|
|
340
|
-
while (proto) {
|
|
341
|
-
const meta = Reflect.getMetadata(metaKey, proto, prop);
|
|
342
|
-
if (meta !== undefined) return meta;
|
|
343
|
-
proto = Object.getPrototypeOf(proto);
|
|
344
|
-
}
|
|
345
|
-
return undefined;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
346
|
// return a properly typed AutoUpdatedClientClass (or null)
|
|
349
347
|
// inside AutoUpdatedClientClass
|
|
350
348
|
protected resolveReference(id: string): AutoUpdatedClientObject<any> | null {
|
|
@@ -427,7 +425,10 @@ export function processIsRefProperties(
|
|
|
427
425
|
(loggers ?? console).debug("Changing isRef:", path);
|
|
428
426
|
|
|
429
427
|
// Example: replace with a proxy or a marker object
|
|
430
|
-
instance[prop] =
|
|
428
|
+
instance[prop] =
|
|
429
|
+
typeof instance[prop] === "string"
|
|
430
|
+
? instance[prop]
|
|
431
|
+
: instance[prop]._id;
|
|
431
432
|
}
|
|
432
433
|
|
|
433
434
|
// recurse into nested objects
|
|
@@ -455,15 +456,29 @@ export function getMetadataRecursive(
|
|
|
455
456
|
return undefined;
|
|
456
457
|
}
|
|
457
458
|
|
|
458
|
-
function checkForMissingRefs<C extends Constructor<any>>(
|
|
459
|
+
function checkForMissingRefs<C extends Constructor<any>>(
|
|
460
|
+
data: IsData<InstanceType<C>>,
|
|
461
|
+
props: any,
|
|
462
|
+
classParam: C,
|
|
463
|
+
autoClassers: { [key: string]: AutoUpdateManager<any> }
|
|
464
|
+
) {
|
|
459
465
|
if (typeof data !== "string") {
|
|
460
466
|
const entryKeys = Object.keys(data);
|
|
461
467
|
for (const prop of props) {
|
|
462
|
-
if (
|
|
463
|
-
|
|
464
|
-
(
|
|
468
|
+
if (
|
|
469
|
+
!entryKeys.includes(prop.toString()) &&
|
|
470
|
+
getMetadataRecursive("isRef", classParam.prototype, prop.toString())
|
|
471
|
+
) {
|
|
472
|
+
(data as any)[prop] = Object.values(autoClassers).find((autoClasser) =>
|
|
473
|
+
autoClasser.objectsAsArray.find((object) =>
|
|
474
|
+
Object.values(object.extractedData).find((value) =>
|
|
475
|
+
Array.isArray(value)
|
|
476
|
+
? value.includes(data._id)
|
|
477
|
+
: value === data._id
|
|
478
|
+
)
|
|
479
|
+
)
|
|
465
480
|
);
|
|
466
481
|
}
|
|
467
482
|
}
|
|
468
483
|
}
|
|
469
|
-
}
|
|
484
|
+
}
|
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.17](https://github.com/Prestizni-Software/client-dem/compare/v0.2.16...v0.2.17) (2025-11-10)
|
|
6
|
+
|
|
7
|
+
### [0.2.16](https://github.com/Prestizni-Software/client-dem/compare/v0.2.15...v0.2.16) (2025-11-10)
|
|
8
|
+
|
|
5
9
|
### [0.2.15](https://github.com/Prestizni-Software/client-dem/compare/v0.2.14...v0.2.15) (2025-11-10)
|
|
6
10
|
|
|
7
11
|
### [0.2.14](https://github.com/Prestizni-Software/client-dem/compare/v0.2.13...v0.2.14) (2025-11-06)
|