@nymphjs/nymph 1.0.0-beta.125 → 1.0.0-beta.127

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.
@@ -20,7 +20,13 @@ import {
20
20
  InvalidParametersError,
21
21
  UnableToConnectError,
22
22
  } from '../errors/index.js';
23
- import { xor } from '../utils.js';
23
+ import {
24
+ classNamesToEntityConstructors,
25
+ entitiesToReferences,
26
+ entityConstructorsToClassNames,
27
+ referencesToEntities,
28
+ xor,
29
+ } from '../utils.js';
24
30
 
25
31
  // from: https://stackoverflow.com/a/6969486/664915
26
32
  function escapeRegExp(string: string): string {
@@ -1340,7 +1346,20 @@ export default abstract class NymphDriver {
1340
1346
  entity.cdate = cdate;
1341
1347
  entity.mdate = mdate;
1342
1348
  entity.tags = tags;
1343
- entity.$putData(data, sdata, 'server');
1349
+ entity.$putData(
1350
+ classNamesToEntityConstructors(
1351
+ this.nymph,
1352
+ referencesToEntities(
1353
+ data,
1354
+ this.nymph,
1355
+ !!options.skipAc,
1356
+ false,
1357
+ ),
1358
+ false,
1359
+ ),
1360
+ sdata,
1361
+ 'server',
1362
+ );
1344
1363
  return {
1345
1364
  result: Promise.resolve(null),
1346
1365
  process: () => [entity],
@@ -1458,11 +1477,29 @@ export default abstract class NymphDriver {
1458
1477
  cdate,
1459
1478
  mdate,
1460
1479
  tags,
1461
- ...data,
1480
+ ...classNamesToEntityConstructors(
1481
+ this.nymph,
1482
+ referencesToEntities(
1483
+ data,
1484
+ this.nymph,
1485
+ !!options.skipAc,
1486
+ false,
1487
+ ),
1488
+ false,
1489
+ ),
1462
1490
  ...Object.fromEntries(
1463
1491
  Object.entries(sdata).map(([name, value]) => [
1464
1492
  name,
1465
- JSON.parse(value),
1493
+ classNamesToEntityConstructors(
1494
+ this.nymph,
1495
+ referencesToEntities(
1496
+ JSON.parse(value),
1497
+ this.nymph,
1498
+ !!options.skipAc,
1499
+ false,
1500
+ ),
1501
+ false,
1502
+ ),
1466
1503
  ]),
1467
1504
  ),
1468
1505
  } as EntityObjectType<T>);
@@ -1481,7 +1518,20 @@ export default abstract class NymphDriver {
1481
1518
  if (this.putDataCounter == 100) {
1482
1519
  throw new Error('Infinite loop detected in Entity loading.');
1483
1520
  }
1484
- entity.$putData(data, sdata, 'server');
1521
+ entity.$putData(
1522
+ classNamesToEntityConstructors(
1523
+ this.nymph,
1524
+ referencesToEntities(
1525
+ data,
1526
+ this.nymph,
1527
+ !!options.skipAc,
1528
+ false,
1529
+ ),
1530
+ false,
1531
+ ),
1532
+ sdata,
1533
+ 'server',
1534
+ );
1485
1535
  this.putDataCounter--;
1486
1536
  entities.push(entity);
1487
1537
  }
@@ -1549,7 +1599,11 @@ export default abstract class NymphDriver {
1549
1599
  }
1550
1600
  }
1551
1601
  const tags = difference(entity.tags, ['']);
1552
- const data = entity.$getData();
1602
+ const data = entityConstructorsToClassNames(
1603
+ // Explicitly save references to entities that aren't saved yet to help
1604
+ // save circular references by saving with a guaranteed GUID.
1605
+ entitiesToReferences(entity.$getData(), false),
1606
+ );
1553
1607
  const sdata = entity.$getSData();
1554
1608
  const uniques = await entity.$getUniques();
1555
1609
  const EntityClass = entity.constructor as EntityConstructor;
@@ -15,6 +15,10 @@ import {
15
15
  TestModelData,
16
16
  TestEmptyModel as TestEmptyModelClass,
17
17
  } from '../testArtifacts.js';
18
+ import {
19
+ entitiesToReferences,
20
+ entityConstructorsToClassNames,
21
+ } from '../utils.js';
18
22
 
19
23
  const __dirname = dirname(fileURLToPath(import.meta.url));
20
24
 
@@ -2706,7 +2710,9 @@ export function ExportImportTest(
2706
2710
  expect(model).not.toBeNull();
2707
2711
 
2708
2712
  if (model != null) {
2709
- const data = model.$getData(true);
2713
+ const data = entityConstructorsToClassNames(
2714
+ entitiesToReferences(model.$getData(true), true),
2715
+ );
2710
2716
  // These should not actually be saved in the DB.
2711
2717
  data.number = 424242424242;
2712
2718
  // But this should become searchable.
package/src/testMocks.ts CHANGED
@@ -10,6 +10,12 @@ import type {
10
10
  import { Options, Selector } from './Nymph.types.js';
11
11
  import { ClassNotAvailableError, EntityConflictError } from './errors/index.js';
12
12
  import Entity from './Entity.js';
13
+ import {
14
+ classNamesToEntityConstructors,
15
+ entitiesToReferences,
16
+ entityConstructorsToClassNames,
17
+ referencesToEntities,
18
+ } from './utils.js';
13
19
 
14
20
  const entities: { [k: string]: EntityJson } = {};
15
21
 
@@ -62,7 +68,20 @@ export class MockNymphDriver {
62
68
  entity.cdate = entityJson.cdate;
63
69
  entity.mdate = entityJson.mdate;
64
70
  entity.tags = entityJson.tags;
65
- entity.$putData(entityJson.data, {}, 'server');
71
+ entity.$putData(
72
+ classNamesToEntityConstructors(
73
+ this.nymph as unknown as Nymph,
74
+ referencesToEntities(
75
+ entityJson.data,
76
+ this.nymph as unknown as Nymph,
77
+ !!options.skipAc,
78
+ false,
79
+ ),
80
+ false,
81
+ ),
82
+ {},
83
+ 'server',
84
+ );
66
85
 
67
86
  return entity as EntityInstanceType<T>;
68
87
  }
@@ -174,7 +193,13 @@ export class MockNymph {
174
193
  cdate: entity.cdate,
175
194
  mdate: entity.mdate,
176
195
  tags: [...entity.tags],
177
- data: JSON.parse(JSON.stringify(entity.$getData(true))),
196
+ data: JSON.parse(
197
+ JSON.stringify(
198
+ entityConstructorsToClassNames(
199
+ entitiesToReferences(entity.$getData(true), true),
200
+ ),
201
+ ),
202
+ ),
178
203
  };
179
204
 
180
205
  entities[entity.guid] = entityJson;