@nymphjs/nymph 1.0.0-beta.12 → 1.0.0-beta.121

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +588 -0
  2. package/README.md +23 -21
  3. package/dist/Entity.d.ts +295 -12
  4. package/dist/Entity.js +560 -148
  5. package/dist/Entity.js.map +1 -1
  6. package/dist/Entity.test.js +52 -13
  7. package/dist/Entity.test.js.map +1 -1
  8. package/dist/Entity.types.d.ts +256 -23
  9. package/dist/Entity.types.js +1 -2
  10. package/dist/Nymph.d.ts +590 -13
  11. package/dist/Nymph.js +846 -180
  12. package/dist/Nymph.js.map +1 -1
  13. package/dist/Nymph.types.d.ts +131 -8
  14. package/dist/Nymph.types.js +47 -5
  15. package/dist/Nymph.types.js.map +1 -1
  16. package/dist/conf/defaults.d.ts +1 -1
  17. package/dist/conf/defaults.js +26 -3
  18. package/dist/conf/defaults.js.map +1 -1
  19. package/dist/conf/index.d.ts +50 -2
  20. package/dist/conf/index.js +2 -8
  21. package/dist/conf/index.js.map +1 -1
  22. package/dist/driver/NymphDriver.d.ts +205 -40
  23. package/dist/driver/NymphDriver.js +712 -238
  24. package/dist/driver/NymphDriver.js.map +1 -1
  25. package/dist/driver/index.d.ts +1 -2
  26. package/dist/driver/index.js +2 -23
  27. package/dist/driver/index.js.map +1 -1
  28. package/dist/driver/testArtifacts.d.ts +4 -4
  29. package/dist/driver/testArtifacts.js +1920 -1086
  30. package/dist/driver/testArtifacts.js.map +1 -1
  31. package/dist/errors/ClassNotAvailableError.js +1 -5
  32. package/dist/errors/ClassNotAvailableError.js.map +1 -1
  33. package/dist/errors/EntityConflictError.js +1 -5
  34. package/dist/errors/EntityConflictError.js.map +1 -1
  35. package/dist/errors/EntityInvalidDataError.d.ts +6 -0
  36. package/dist/errors/EntityInvalidDataError.js +8 -6
  37. package/dist/errors/EntityInvalidDataError.js.map +1 -1
  38. package/dist/errors/EntityIsSleepingReferenceError.js +1 -5
  39. package/dist/errors/EntityIsSleepingReferenceError.js.map +1 -1
  40. package/dist/errors/EntityUniqueConstraintError.d.ts +3 -0
  41. package/dist/errors/EntityUniqueConstraintError.js +7 -0
  42. package/dist/errors/EntityUniqueConstraintError.js.map +1 -0
  43. package/dist/errors/HttpError.d.ts +5 -0
  44. package/dist/errors/HttpError.js +11 -0
  45. package/dist/errors/HttpError.js.map +1 -0
  46. package/dist/errors/InvalidParametersError.js +1 -5
  47. package/dist/errors/InvalidParametersError.js.map +1 -1
  48. package/dist/errors/InvalidStateError.d.ts +3 -0
  49. package/dist/errors/InvalidStateError.js +7 -0
  50. package/dist/errors/InvalidStateError.js.map +1 -0
  51. package/dist/errors/NotConfiguredError.js +1 -5
  52. package/dist/errors/NotConfiguredError.js.map +1 -1
  53. package/dist/errors/QueryFailedError.d.ts +2 -1
  54. package/dist/errors/QueryFailedError.js +5 -6
  55. package/dist/errors/QueryFailedError.js.map +1 -1
  56. package/dist/errors/UnableToConnectError.js +1 -5
  57. package/dist/errors/UnableToConnectError.js.map +1 -1
  58. package/dist/errors/index.d.ts +11 -8
  59. package/dist/errors/index.js +11 -24
  60. package/dist/errors/index.js.map +1 -1
  61. package/dist/index.d.ts +11 -11
  62. package/dist/index.js +14 -34
  63. package/dist/index.js.map +1 -1
  64. package/dist/nymphJoiProps.d.ts +1 -1
  65. package/dist/nymphJoiProps.js +10 -15
  66. package/dist/nymphJoiProps.js.map +1 -1
  67. package/dist/testArtifacts.d.ts +19 -6
  68. package/dist/testArtifacts.js +32 -37
  69. package/dist/testArtifacts.js.map +1 -1
  70. package/dist/testMocks.d.ts +27 -12
  71. package/dist/testMocks.js +40 -29
  72. package/dist/testMocks.js.map +1 -1
  73. package/dist/utils.d.ts +4 -4
  74. package/dist/utils.js +40 -29
  75. package/dist/utils.js.map +1 -1
  76. package/jest.config.js +31 -5
  77. package/package.json +33 -23
  78. package/src/Entity.test.ts +50 -7
  79. package/src/Entity.ts +489 -150
  80. package/src/Entity.types.ts +72 -74
  81. package/src/Nymph.ts +991 -324
  82. package/src/Nymph.types.ts +201 -27
  83. package/src/conf/defaults.ts +34 -1
  84. package/src/conf/index.ts +50 -2
  85. package/src/driver/NymphDriver.ts +898 -413
  86. package/src/driver/index.ts +1 -3
  87. package/src/driver/testArtifacts.ts +2557 -1629
  88. package/src/errors/EntityUniqueConstraintError.ts +6 -0
  89. package/src/errors/HttpError.ts +12 -0
  90. package/src/errors/InvalidStateError.ts +6 -0
  91. package/src/errors/QueryFailedError.ts +3 -1
  92. package/src/errors/index.ts +14 -8
  93. package/src/index.ts +11 -11
  94. package/src/nymphJoiProps.ts +2 -2
  95. package/src/testArtifacts.ts +20 -20
  96. package/src/testMocks.ts +76 -35
  97. package/src/utils.ts +39 -18
  98. package/tsconfig.json +6 -3
  99. package/typedoc.json +4 -0
  100. package/dist/conf/d.d.ts +0 -6
  101. package/dist/conf/d.js +0 -3
  102. package/dist/conf/d.js.map +0 -1
  103. package/src/conf/d.ts +0 -24
@@ -0,0 +1,6 @@
1
+ export class EntityUniqueConstraintError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'EntityUniqueConstraintError';
5
+ }
6
+ }
@@ -0,0 +1,12 @@
1
+ export class HttpError extends Error {
2
+ status?: number;
3
+ statusText?: string;
4
+
5
+ constructor(message: string, status?: number, statusText?: string) {
6
+ super(message);
7
+
8
+ this.name = 'HttpError';
9
+ this.status = status;
10
+ this.statusText = statusText;
11
+ }
12
+ }
@@ -0,0 +1,6 @@
1
+ export class InvalidStateError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'InvalidStateError';
5
+ }
6
+ }
@@ -1,10 +1,12 @@
1
1
  export class QueryFailedError extends Error {
2
2
  private query?: string;
3
+ public errorCode?: number;
3
4
 
4
- constructor(message: string, query?: string) {
5
+ constructor(message: string, query?: string, errorCode?: number) {
5
6
  super(message);
6
7
  this.name = 'QueryFailedError';
7
8
  this.query = query;
9
+ this.errorCode = errorCode;
8
10
  }
9
11
 
10
12
  public getQuery() {
@@ -1,15 +1,21 @@
1
- export * from './ClassNotAvailableError';
1
+ export * from './ClassNotAvailableError.js';
2
2
 
3
- export * from './EntityConflictError';
3
+ export * from './EntityConflictError.js';
4
4
 
5
- export * from './EntityInvalidDataError';
5
+ export * from './EntityInvalidDataError.js';
6
6
 
7
- export * from './EntityIsSleepingReferenceError';
7
+ export * from './EntityIsSleepingReferenceError.js';
8
8
 
9
- export * from './InvalidParametersError';
9
+ export * from './EntityUniqueConstraintError.js';
10
10
 
11
- export * from './NotConfiguredError';
11
+ export * from './HttpError.js';
12
12
 
13
- export * from './QueryFailedError';
13
+ export * from './InvalidParametersError.js';
14
14
 
15
- export * from './UnableToConnectError';
15
+ export * from './InvalidStateError.js';
16
+
17
+ export * from './NotConfiguredError.js';
18
+
19
+ export * from './QueryFailedError.js';
20
+
21
+ export * from './UnableToConnectError.js';
package/src/index.ts CHANGED
@@ -1,20 +1,20 @@
1
- export * from './conf';
2
- export * from './driver';
3
- export * from './errors';
1
+ export * from './conf/index.js';
2
+ export * from './driver/index.js';
3
+ export * from './errors/index.js';
4
4
 
5
- export * from './Entity.types';
5
+ export * from './Entity.types.js';
6
6
 
7
- export * from './Entity';
8
- import Entity from './Entity';
7
+ export * from './Entity.js';
8
+ import Entity from './Entity.js';
9
9
  export { Entity };
10
10
 
11
- export * from './Nymph.types';
11
+ export * from './Nymph.types.js';
12
12
 
13
- export * from './Nymph';
14
- import Nymph from './Nymph';
13
+ export * from './Nymph.js';
14
+ import Nymph from './Nymph.js';
15
15
  export { Nymph };
16
16
 
17
- import nymphJoiProps from './nymphJoiProps';
17
+ import nymphJoiProps from './nymphJoiProps.js';
18
18
  export { nymphJoiProps };
19
19
 
20
- export * from './utils';
20
+ export * from './utils.js';
@@ -4,7 +4,7 @@ export default {
4
4
  guid: Joi.alternatives()
5
5
  .try(
6
6
  Joi.any().only().allow(null),
7
- Joi.string().trim(false).length(24).hex()
7
+ Joi.string().trim(false).length(24).hex(),
8
8
  )
9
9
  .required(),
10
10
  cdate: Joi.alternatives()
@@ -18,7 +18,7 @@ export default {
18
18
  Joi.string().pattern(/[[\x01-\x1F\x7F]]/, {
19
19
  name: 'control characters',
20
20
  invert: true,
21
- })
21
+ }),
22
22
  )
23
23
  .required(),
24
24
  };
@@ -1,4 +1,4 @@
1
- import Entity from './Entity';
1
+ import Entity from './Entity.js';
2
2
 
3
3
  export type TestModelData = {
4
4
  name?: string;
@@ -7,6 +7,7 @@ export type TestModelData = {
7
7
  test?: string;
8
8
  array?: any[];
9
9
  match?: string;
10
+ search?: string;
10
11
  number?: number;
11
12
  numberString?: string;
12
13
  timestamp?: Number;
@@ -17,8 +18,10 @@ export type TestModelData = {
17
18
  [k: string]: TestModel & TestModelData;
18
19
  };
19
20
  parent?: TestModel & TestModelData;
20
- // For Import/Export Tests.
21
+ // For import/export tests.
21
22
  index?: string;
23
+ // For uniqueness tests.
24
+ uniques?: string[];
22
25
  };
23
26
 
24
27
  /**
@@ -34,21 +37,16 @@ export class TestModel extends Entity<TestModelData> {
34
37
  protected $protectedTags = ['test', 'notag'];
35
38
  protected $allowlistTags? = ['newtag'];
36
39
 
37
- static async factory(guid?: string): Promise<TestModel & TestModelData> {
38
- return (await super.factory(guid)) as TestModel & TestModelData;
39
- }
40
+ constructor() {
41
+ super();
40
42
 
41
- static factorySync(guid?: string): TestModel & TestModelData {
42
- return super.factorySync(guid) as TestModel & TestModelData;
43
+ this.$addTag('test');
44
+ this.$data.boolean = true;
45
+ this.$data.uniques = [];
43
46
  }
44
47
 
45
- constructor(guid?: string) {
46
- super(guid);
47
-
48
- if (this.guid == null) {
49
- this.$addTag('test');
50
- this.$data.boolean = true;
51
- }
48
+ public async $getUniques() {
49
+ return this.$data.uniques ?? [];
52
50
  }
53
51
 
54
52
  public $useProtectedData() {
@@ -77,12 +75,14 @@ export class TestModel extends Entity<TestModelData> {
77
75
  export class TestBModel extends TestModel {
78
76
  static ETYPE = 'test_b_model';
79
77
  static class = 'TestBModel';
78
+ }
80
79
 
81
- static async factory(guid?: string): Promise<TestBModel & TestModelData> {
82
- return (await super.factory(guid)) as TestBModel & TestModelData;
83
- }
80
+ export type TestEmptyModelData = {};
84
81
 
85
- static factorySync(guid?: string): TestBModel & TestModelData {
86
- return super.factorySync(guid) as TestBModel & TestModelData;
87
- }
82
+ /**
83
+ * This class is a test class that extends the Entity class.
84
+ */
85
+ export class TestEmptyModel extends Entity<TestEmptyModelData> {
86
+ static ETYPE = 'test_empty_model';
87
+ static class = 'TestEmptyModel';
88
88
  }
package/src/testMocks.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  import { guid } from '@nymphjs/guid';
2
2
 
3
- import type Nymph from './Nymph';
4
- import { EntityConstructor, EntityInterface, EntityJson } from './Entity.types';
5
- import { Options, Selector } from './Nymph.types';
6
- import { ClassNotAvailableError } from './errors';
7
- import Entity from './Entity';
3
+ import type Nymph from './Nymph.js';
4
+ import type { EntityInstanceType, EntityObjectType } from './Entity.js';
5
+ import type {
6
+ EntityConstructor,
7
+ EntityInterface,
8
+ EntityJson,
9
+ } from './Entity.types.js';
10
+ import { Options, Selector } from './Nymph.types.js';
11
+ import { ClassNotAvailableError } from './errors/index.js';
12
+ import Entity from './Entity.js';
8
13
 
9
14
  const entities: { [k: string]: EntityJson } = {};
10
15
 
@@ -15,43 +20,51 @@ export class MockNymphDriver {
15
20
  this.nymph = nymph;
16
21
  }
17
22
 
18
- public getEntitySync<T extends EntityConstructor = EntityConstructor>(
23
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
19
24
  options: Options<T> & { return: 'guid' },
20
25
  ...selectors: Selector[]
21
- ): string | null;
22
- public getEntitySync<T extends EntityConstructor = EntityConstructor>(
26
+ ): Promise<string | null>;
27
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
28
+ options: Options<T> & { return: 'object' },
29
+ ...selectors: Selector[]
30
+ ): Promise<EntityObjectType<T> | null>;
31
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
23
32
  options: Options<T>,
24
33
  ...selectors: Selector[]
25
- ): ReturnType<T['factorySync']> | null;
26
- public getEntitySync<T extends EntityConstructor = EntityConstructor>(
34
+ ): Promise<EntityInstanceType<T> | null>;
35
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
27
36
  options: Options<T> & { return: 'guid' },
28
- guid: string
29
- ): string | null;
30
- public getEntitySync<T extends EntityConstructor = EntityConstructor>(
37
+ guid: string,
38
+ ): Promise<string | null>;
39
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
40
+ options: Options<T> & { return: 'object' },
41
+ guid: string,
42
+ ): Promise<EntityObjectType<T> | null>;
43
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
31
44
  options: Options<T>,
32
- guid: string
33
- ): ReturnType<T['factorySync']> | null;
34
- public getEntitySync<T extends EntityConstructor = EntityConstructor>(
45
+ guid: string,
46
+ ): Promise<EntityInstanceType<T> | null>;
47
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
35
48
  options: Options<T> = {},
36
49
  ...selectors: Selector[] | string[]
37
- ): ReturnType<T['factorySync']> | string | null {
50
+ ): Promise<EntityInstanceType<T> | EntityObjectType<T> | string | null> {
38
51
  const guid =
39
52
  typeof selectors[0] === 'string' ? selectors[0] : selectors[0].guid;
40
53
  if (!options || !guid || typeof guid !== 'string' || !(guid in entities)) {
41
54
  return null;
42
55
  }
43
56
 
44
- const entity: EntityInterface = (
45
- (options.class as T) ?? this.nymph.getEntityClass('Entity')
57
+ const entity = (
58
+ (options.class ?? this.nymph.getEntityClass('Entity')) as T
46
59
  ).factorySync();
47
60
  const entityJson = entities[guid];
48
61
  entity.guid = guid;
49
62
  entity.cdate = entityJson.cdate;
50
63
  entity.mdate = entityJson.mdate;
51
64
  entity.tags = entityJson.tags;
52
- entity.$putData(entityJson.data, {});
65
+ entity.$putData(entityJson.data, {}, 'server');
53
66
 
54
- return entity as ReturnType<T['factorySync']>;
67
+ return entity as EntityInstanceType<T>;
55
68
  }
56
69
  }
57
70
 
@@ -68,48 +81,76 @@ export class MockNymph {
68
81
  this.Entity = this.addEntityClass(Entity);
69
82
  }
70
83
 
71
- public addEntityClass<T extends EntityConstructor>(entityClass: T): T {
84
+ public addEntityClass<T extends EntityConstructor>(EntityClass: T): T {
72
85
  const nymph = this;
73
- class NymphEntity extends entityClass {
86
+ this.entityClasses[EntityClass.class] = class extends EntityClass {
74
87
  static nymph: Nymph = nymph as unknown as Nymph;
75
88
 
76
89
  constructor(...args: any[]) {
77
90
  super(...args);
78
91
  }
92
+ };
93
+ return this.entityClasses[EntityClass.class] as T;
94
+ }
95
+
96
+ public getEntityClass(className: string): EntityConstructor;
97
+ public getEntityClass<T extends EntityConstructor>(className: T): T;
98
+ public getEntityClass<T extends EntityConstructor = EntityConstructor>(
99
+ className: T | string,
100
+ ): T | EntityConstructor {
101
+ let key: string | null = null;
102
+ if (typeof className === 'string') {
103
+ key = className;
104
+ } else {
105
+ key = className.class;
106
+ }
107
+ if (key in this.entityClasses) {
108
+ return this.entityClasses[key];
79
109
  }
80
- this.entityClasses[entityClass.class] = NymphEntity;
81
- return NymphEntity;
110
+ throw new ClassNotAvailableError(`Tried to use missing class "${key}".`);
82
111
  }
83
112
 
84
- public getEntityClass(className: string): EntityConstructor {
85
- if (className in this.entityClasses) {
86
- return this.entityClasses[className];
113
+ public getEntityClassByEtype(etype: string): EntityConstructor {
114
+ for (const EntityClass of Object.values(this.entityClasses)) {
115
+ if (EntityClass.ETYPE === etype) {
116
+ return EntityClass;
117
+ }
87
118
  }
88
- throw new ClassNotAvailableError('Tried to use class: ' + className);
119
+ throw new ClassNotAvailableError(
120
+ `Tried to use missing class by etype "${etype}".`,
121
+ );
89
122
  }
90
123
 
91
124
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
92
125
  options: Options<T> & { return: 'guid' },
93
126
  ...selectors: Selector[]
94
127
  ): Promise<string | null>;
128
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
129
+ options: Options<T> & { return: 'object' },
130
+ ...selectors: Selector[]
131
+ ): Promise<EntityObjectType<T> | null>;
95
132
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
96
133
  options: Options<T>,
97
134
  ...selectors: Selector[]
98
- ): Promise<ReturnType<T['factorySync']> | null>;
135
+ ): Promise<EntityInstanceType<T> | null>;
99
136
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
100
137
  options: Options<T> & { return: 'guid' },
101
- guid: string
138
+ guid: string,
102
139
  ): Promise<string | null>;
140
+ public async getEntity<T extends EntityConstructor = EntityConstructor>(
141
+ options: Options<T> & { return: 'object' },
142
+ guid: string,
143
+ ): Promise<EntityObjectType<T> | null>;
103
144
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
104
145
  options: Options<T>,
105
- guid: string
106
- ): Promise<ReturnType<T['factorySync']> | null>;
146
+ guid: string,
147
+ ): Promise<EntityInstanceType<T> | null>;
107
148
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
108
149
  options: Options<T> = {},
109
150
  ...selectors: Selector[] | string[]
110
- ): Promise<ReturnType<T['factorySync']> | string | null> {
151
+ ): Promise<EntityInstanceType<T> | EntityObjectType<T> | string | null> {
111
152
  // @ts-ignore: The selector type is correct here.
112
- return this.driver.getEntitySync(options, ...selectors);
153
+ return await this.driver.getEntity(options, ...selectors);
113
154
  }
114
155
 
115
156
  public async saveEntity(entity: EntityInterface): Promise<boolean> {
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
- import Entity from './Entity';
2
- import { EntityReference } from './Entity.types';
3
- import Nymph from './Nymph';
4
- import { Options, Selector } from './Nymph.types';
1
+ import Entity from './Entity.js';
2
+ import { EntityReference } from './Entity.types.js';
3
+ import Nymph from './Nymph.js';
4
+ import { Options, Selector } from './Nymph.types.js';
5
5
 
6
6
  export function xor(a: any, b: any): boolean {
7
7
  return !!(a && !b) || (!a && b);
@@ -17,7 +17,8 @@ export function uniqueStrings(array: string[]) {
17
17
 
18
18
  export function classNamesToEntityConstructors(
19
19
  nymph: Nymph,
20
- selectors: Selector[]
20
+ selectors: Selector[],
21
+ enforceRestEnabledFlag = false,
21
22
  ): Selector[] {
22
23
  const newSelectors: Selector[] = [];
23
24
 
@@ -45,22 +46,35 @@ export function classNamesToEntityConstructors(
45
46
  for (let i = 0; i < tmpArr.length; i++) {
46
47
  const name = tmpArr[i][0];
47
48
  const [qrefOptions, ...selectors] = tmpArr[i][1];
48
- const QrefEntityClass =
49
- typeof qrefOptions.class === 'string'
50
- ? nymph.getEntityClass(qrefOptions.class)
51
- : qrefOptions.class ?? nymph.getEntityClass('Entity');
49
+ const QrefEntityClass = qrefOptions.class
50
+ ? nymph.getEntityClass(qrefOptions.class)
51
+ : nymph.getEntityClass('Entity');
52
+ if (enforceRestEnabledFlag && !QrefEntityClass.restEnabled) {
53
+ throw new Error('Not accessible.');
54
+ }
52
55
  const options = { ...qrefOptions, class: QrefEntityClass };
53
56
  if (!newSelector[key]) {
54
57
  newSelector[key] = [];
55
58
  }
56
59
  (newSelector[key] as [string, [Options, ...Selector[]]][]).push([
57
60
  name,
58
- [options, ...classNamesToEntityConstructors(nymph, selectors)],
61
+ [
62
+ options,
63
+ ...classNamesToEntityConstructors(
64
+ nymph,
65
+ selectors,
66
+ enforceRestEnabledFlag,
67
+ ),
68
+ ],
59
69
  ]);
60
70
  }
61
71
  } else if (key === 'selector' || key === '!selector') {
62
72
  const tmpArr = (Array.isArray(value) ? value : [value]) as Selector[];
63
- newSelector[key] = classNamesToEntityConstructors(nymph, tmpArr);
73
+ newSelector[key] = classNamesToEntityConstructors(
74
+ nymph,
75
+ tmpArr,
76
+ enforceRestEnabledFlag,
77
+ );
64
78
  } else {
65
79
  // @ts-ignore: ts doesn't know what value is here.
66
80
  newSelector[key] = value;
@@ -73,17 +87,22 @@ export function classNamesToEntityConstructors(
73
87
  return newSelectors;
74
88
  }
75
89
 
76
- export function entitiesToReferences(item: any): any {
77
- if (item instanceof Entity && typeof item.$toReference === 'function') {
90
+ export function entitiesToReferences(item: any, existingOnly?: boolean): any {
91
+ if (item == null || Buffer.isBuffer(item) || ArrayBuffer.isView(item)) {
92
+ return item;
93
+ } else if (
94
+ item instanceof Entity &&
95
+ typeof item.$toReference === 'function'
96
+ ) {
78
97
  // Convert entities to references.
79
- return item.$toReference();
98
+ return item.$toReference(existingOnly);
80
99
  } else if (Array.isArray(item)) {
81
100
  // Recurse into lower arrays.
82
- return item.map((entry) => entitiesToReferences(entry));
101
+ return item.map((entry) => entitiesToReferences(entry, existingOnly));
83
102
  } else if (item instanceof Object) {
84
103
  let newObj = Object.create(item);
85
104
  for (let [key, value] of Object.entries(item)) {
86
- newObj[key] = entitiesToReferences(value);
105
+ newObj[key] = entitiesToReferences(value, existingOnly);
87
106
  }
88
107
  return newObj;
89
108
  }
@@ -94,9 +113,11 @@ export function entitiesToReferences(item: any): any {
94
113
  export function referencesToEntities(
95
114
  item: any,
96
115
  nymph: Nymph,
97
- useSkipAc = false
116
+ useSkipAc = false,
98
117
  ): any {
99
- if (Array.isArray(item)) {
118
+ if (item == null || Buffer.isBuffer(item) || ArrayBuffer.isView(item)) {
119
+ return item;
120
+ } else if (Array.isArray(item)) {
100
121
  // Check if it's a reference.
101
122
  if (item[0] === 'nymph_entity_reference') {
102
123
  try {
package/tsconfig.json CHANGED
@@ -2,10 +2,13 @@
2
2
  "extends": "@tsconfig/recommended/tsconfig.json",
3
3
 
4
4
  "compilerOptions": {
5
- "lib": ["ES2021"],
6
- "target": "ES2021",
5
+ "types": ["node", "jest"],
6
+ "module": "nodenext",
7
+ "moduleResolution": "nodenext",
8
+ "lib": ["es2023"],
9
+ "target": "es2023",
7
10
  "noImplicitAny": true,
8
- "removeComments": true,
11
+ "removeComments": false,
9
12
  "sourceMap": true,
10
13
  "outDir": "dist",
11
14
  "resolveJsonModule": true,
package/typedoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": ["../../typedoc.base.json"],
3
+ "entryPoints": ["src/index.ts"]
4
+ }
package/dist/conf/d.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export interface Config {
2
- cache: boolean;
3
- cacheThreshold: number;
4
- cacheLimit: number;
5
- emptyListError: boolean;
6
- }
package/dist/conf/d.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"d.js","sourceRoot":"","sources":["../../src/conf/d.ts"],"names":[],"mappings":""}
package/src/conf/d.ts DELETED
@@ -1,24 +0,0 @@
1
- /**
2
- * Nymph Config
3
- */
4
- export interface Config {
5
- /**
6
- * Cache recently retrieved entities to speed up database queries. Uses more
7
- * memory.
8
- */
9
- cache: boolean;
10
- /**
11
- * Cache entities after they're accessed this many times.
12
- */
13
- cacheThreshold: number;
14
- /**
15
- * The number of recently retrieved entities to cache. If you're running out
16
- * of memory, try lowering this value. 0 means unlimited.
17
- */
18
- cacheLimit: number;
19
- /**
20
- * When querying for multiple entities with NymphREST, if the list is empty,
21
- * return a 404 error.
22
- */
23
- emptyListError: boolean;
24
- }