@e22m4u/js-repository 0.1.8 → 0.1.10

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 (128) hide show
  1. package/README.md +22 -1
  2. package/docs/assets/navigation.js +1 -1
  3. package/docs/assets/search.js +1 -1
  4. package/docs/classes/Adapter.html +1 -1
  5. package/docs/classes/AdapterLoader.html +1 -1
  6. package/docs/classes/AdapterRegistry.html +1 -1
  7. package/docs/classes/BelongsToResolver.html +1 -1
  8. package/docs/classes/DatasourceDefinitionValidator.html +1 -1
  9. package/docs/classes/DefinitionRegistry.html +1 -1
  10. package/docs/classes/EmptyValuesDefiner.html +18 -0
  11. package/docs/classes/FieldsClauseTool.html +1 -1
  12. package/docs/classes/HasManyResolver.html +1 -1
  13. package/docs/classes/HasOneResolver.html +1 -1
  14. package/docs/classes/IncludeClauseTool.html +1 -1
  15. package/docs/classes/InvalidArgumentError.html +1 -1
  16. package/docs/classes/InvalidOperatorValueError.html +1 -1
  17. package/docs/classes/ModelDataSanitizer.html +1 -1
  18. package/docs/classes/ModelDataTransformer.html +1 -1
  19. package/docs/classes/ModelDataValidator.html +1 -1
  20. package/docs/classes/ModelDefinitionUtils.html +1 -1
  21. package/docs/classes/ModelDefinitionValidator.html +1 -1
  22. package/docs/classes/NotImplementedError.html +1 -1
  23. package/docs/classes/OperatorClauseTool.html +1 -1
  24. package/docs/classes/OrderClauseTool.html +1 -1
  25. package/docs/classes/PrimaryKeysDefinitionValidator.html +1 -1
  26. package/docs/classes/PropertiesDefinitionValidator.html +1 -1
  27. package/docs/classes/PropertyTransformerRegistry.html +1 -1
  28. package/docs/classes/PropertyUniquenessValidator.html +16 -0
  29. package/docs/classes/PropertyValidatorRegistry.html +1 -1
  30. package/docs/classes/ReferencesManyResolver.html +1 -1
  31. package/docs/classes/RelationsDefinitionValidator.html +1 -1
  32. package/docs/classes/Repository.html +1 -1
  33. package/docs/classes/RepositoryRegistry.html +1 -1
  34. package/docs/classes/Schema.html +1 -1
  35. package/docs/classes/SliceClauseTool.html +1 -1
  36. package/docs/classes/WhereClauseTool.html +1 -1
  37. package/docs/enums/DataType.html +1 -1
  38. package/docs/enums/DecoratorTargetType.html +1 -1
  39. package/docs/enums/RelationType.html +1 -1
  40. package/docs/functions/capitalize.html +1 -1
  41. package/docs/functions/cloneDeep.html +1 -1
  42. package/docs/functions/excludeObjectKeys.html +1 -1
  43. package/docs/functions/getCtorName.html +1 -1
  44. package/docs/functions/getDecoratorTargetType.html +1 -1
  45. package/docs/functions/getValueByPath.html +1 -1
  46. package/docs/functions/isCtor.html +1 -1
  47. package/docs/functions/isDeepEqual.html +2 -0
  48. package/docs/functions/isPureObject.html +1 -1
  49. package/docs/functions/selectObjectKeys.html +1 -1
  50. package/docs/functions/singularize.html +1 -1
  51. package/docs/functions/stringToRegexp.html +1 -1
  52. package/docs/index.html +18 -3
  53. package/docs/interfaces/AndClause.html +1 -1
  54. package/docs/interfaces/Constructor.html +1 -1
  55. package/docs/interfaces/OrClause.html +1 -1
  56. package/docs/modules.html +6 -1
  57. package/docs/types/AnyObject.html +1 -1
  58. package/docs/types/BelongsToDefinition.html +1 -1
  59. package/docs/types/CountMethod.html +2 -0
  60. package/docs/types/DEFAULT_PRIMARY_KEY_PROPERTY_NAME.html +1 -1
  61. package/docs/types/DatasourceDefinition.html +1 -1
  62. package/docs/types/FieldsClause.html +1 -1
  63. package/docs/types/FilterClause.html +1 -1
  64. package/docs/types/Flatten.html +1 -1
  65. package/docs/types/FullPropertyDefinition.html +2 -2
  66. package/docs/types/HasManyDefinition.html +1 -1
  67. package/docs/types/HasOneDefinition.html +1 -1
  68. package/docs/types/Identity.html +1 -1
  69. package/docs/types/IncludeClause.html +1 -1
  70. package/docs/types/ItemFilterClause.html +1 -1
  71. package/docs/types/ModelData.html +1 -1
  72. package/docs/types/ModelDefinition.html +1 -1
  73. package/docs/types/ModelId.html +1 -1
  74. package/docs/types/NestedIncludeClause.html +1 -1
  75. package/docs/types/NormalizedFieldsClause.html +1 -1
  76. package/docs/types/NormalizedIncludeClause.html +1 -1
  77. package/docs/types/OperatorClause.html +1 -1
  78. package/docs/types/OptionalUnlessRequiredId.html +1 -1
  79. package/docs/types/OrderClause.html +1 -1
  80. package/docs/types/PartialBy.html +1 -1
  81. package/docs/types/PartialWithoutId.html +1 -1
  82. package/docs/types/PolyBelongsToDefinition.html +1 -1
  83. package/docs/types/PolyHasManyDefinitionWithTargetKeys.html +1 -1
  84. package/docs/types/PolyHasManyDefinitionWithTargetRelationName.html +1 -1
  85. package/docs/types/PolyHasOneDefinitionWithTargetKeys.html +1 -1
  86. package/docs/types/PolyHasOneDefinitionWithTargetRelationName.html +1 -1
  87. package/docs/types/PropertiesClause.html +1 -1
  88. package/docs/types/PropertyDefinition.html +1 -1
  89. package/docs/types/PropertyDefinitionMap.html +1 -1
  90. package/docs/types/PropertyTransformOptions.html +1 -1
  91. package/docs/types/PropertyTransformer.html +1 -1
  92. package/docs/types/PropertyTransformerContext.html +1 -1
  93. package/docs/types/PropertyUniqueness.html +2 -0
  94. package/docs/types/PropertyValidateOptions.html +1 -1
  95. package/docs/types/PropertyValidator.html +1 -1
  96. package/docs/types/PropertyValidatorContext.html +1 -1
  97. package/docs/types/ReferencesManyDefinition.html +1 -1
  98. package/docs/types/RelationDefinition.html +1 -1
  99. package/docs/types/RelationDefinitionMap.html +1 -1
  100. package/docs/types/WhereClause.html +1 -1
  101. package/docs/types/WithoutId.html +1 -1
  102. package/package.json +4 -4
  103. package/src/adapter/adapter.js +2 -0
  104. package/src/adapter/adapter.spec.js +8 -2
  105. package/src/adapter/decorator/index.d.ts +1 -0
  106. package/src/adapter/decorator/index.js +1 -0
  107. package/src/adapter/decorator/property-uniqueness-decorator.d.ts +14 -0
  108. package/src/adapter/decorator/property-uniqueness-decorator.js +76 -0
  109. package/src/adapter/decorator/property-uniqueness-decorator.spec.js +135 -0
  110. package/src/definition/definition-registry.spec.js +1 -0
  111. package/src/definition/model/properties/empty-values-definer.d.ts +23 -0
  112. package/src/definition/model/properties/empty-values-definer.js +66 -0
  113. package/src/definition/model/properties/empty-values-definer.spec.js +96 -0
  114. package/src/definition/model/properties/index.d.ts +3 -0
  115. package/src/definition/model/properties/index.js +3 -0
  116. package/src/definition/model/properties/properties-definition-validator.js +21 -0
  117. package/src/definition/model/properties/properties-definition-validator.spec.js +50 -5
  118. package/src/definition/model/properties/property-definition.d.ts +3 -0
  119. package/src/definition/model/properties/property-uniqueness-validator.d.ts +31 -0
  120. package/src/definition/model/properties/property-uniqueness-validator.js +141 -0
  121. package/src/definition/model/properties/property-uniqueness-validator.spec.js +987 -0
  122. package/src/definition/model/properties/property-uniqueness.d.ts +8 -0
  123. package/src/definition/model/properties/property-uniqueness.js +8 -0
  124. package/src/utils/index.d.ts +1 -0
  125. package/src/utils/index.js +1 -0
  126. package/src/utils/is-deep-equal.d.ts +10 -0
  127. package/src/utils/is-deep-equal.js +71 -0
  128. package/src/utils/is-deep-equal.spec.js +238 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Property uniqueness.
3
+ */
4
+ export declare type PropertyUniqueness = {
5
+ UNIQUE: true;
6
+ SPARSE: 'sparse';
7
+ NON_UNIQUE: false;
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Property uniqueness.
3
+ */
4
+ export const PropertyUniqueness = {
5
+ UNIQUE: true,
6
+ SPARSE: 'sparse',
7
+ NON_UNIQUE: false,
8
+ };
@@ -2,6 +2,7 @@ export * from './is-ctor.js';
2
2
  export * from './capitalize.js';
3
3
  export * from './clone-deep.js';
4
4
  export * from './singularize.js';
5
+ export * from './is-deep-equal.js';
5
6
  export * from './get-ctor-name.js';
6
7
  export * from './is-pure-object.js';
7
8
  export * from './string-to-regexp.js';
@@ -2,6 +2,7 @@ export * from './is-ctor.js';
2
2
  export * from './capitalize.js';
3
3
  export * from './clone-deep.js';
4
4
  export * from './singularize.js';
5
+ export * from './is-deep-equal.js';
5
6
  export * from './get-ctor-name.js';
6
7
  export * from './is-pure-object.js';
7
8
  export * from './string-to-regexp.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Is deep equal.
3
+ *
4
+ * @param firstValue
5
+ * @param secondValue
6
+ */
7
+ export declare function isDeepEqual(
8
+ firstValue: unknown,
9
+ secondValue: unknown,
10
+ ): boolean;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Is deep equal.
3
+ * https://github.com/pinglu85/BFEdevSolutions/blob/main/Coding-Problems/69.implement-deep-equal-isEqual.md
4
+ *
5
+ * @param {*} firstValue
6
+ * @param {*} secondValue
7
+ * @returns {boolean}
8
+ */
9
+ export function isDeepEqual(firstValue, secondValue) {
10
+ const cached = new WeakMap();
11
+ const compare = (a, b) => {
12
+ // Check if one of the two inputs is primitive by using typeof
13
+ // operator; since the typeof primitive null is object, check
14
+ // if one of the inputs is equal to null. If one of the two
15
+ // inputs is primitive, then I can compare them by reference.
16
+ if (a === null || b === null) return a === b;
17
+ if (typeof a !== 'object' || typeof b !== 'object') return a === b;
18
+ // Check if the data type of the two inputs are the same,
19
+ // both are arrays or objects. If they are not, return false.
20
+ const dataTypeA = Array.isArray(a) ? 'array' : 'object';
21
+ const dataTypeB = Array.isArray(b) ? 'array' : 'object';
22
+ if (dataTypeA !== dataTypeB) return false;
23
+ // Use Object.keys and Object.getOwnPropertySymbols to get
24
+ // all of enumerable and not-inherited properties of the two
25
+ // inputs. Compare their size respectively, if one of them
26
+ // is not equal, return false.
27
+ const keysA = Object.keys(a);
28
+ const keysB = Object.keys(b);
29
+ if (keysA.length !== keysB.length) return false;
30
+ const symbolsA = Object.getOwnPropertySymbols(a);
31
+ const symbolsB = Object.getOwnPropertySymbols(b);
32
+ if (symbolsA.length !== symbolsB.length) return false;
33
+ // To handle the circular reference, initialize a WeakMap
34
+ // that is going to keep track of the objects or arrays
35
+ // that have been seen, in which each key is an object
36
+ // or an array and each value is a set of objects or arrays,
37
+ // that have been compared to that object or array.
38
+ let setForA = cached.get(a);
39
+ if (setForA == null) {
40
+ setForA = new Set();
41
+ cached.set(a, setForA);
42
+ } else if (setForA.has(b)) {
43
+ return true;
44
+ }
45
+ setForA.add(b);
46
+ let setForB = cached.get(b);
47
+ if (setForB == null) {
48
+ setForB = new Set();
49
+ cached.set(b, setForB);
50
+ } else if (setForB.has(a)) {
51
+ return true;
52
+ }
53
+ setForB.add(a);
54
+ // Compare the property names and the values. Loop through
55
+ // all the properties of the first input data, check if
56
+ // the property name also exist in the second input data,
57
+ // if not, return false; otherwise recursively compare
58
+ // the property value.
59
+ const propertyNamesA = [...keysA, ...symbolsA];
60
+ for (const propertyNameA of propertyNamesA) {
61
+ if (!b.hasOwnProperty(propertyNameA)) return false;
62
+ const propertyValueA = a[propertyNameA];
63
+ const propertyValueB = b[propertyNameA];
64
+ if (!compare(propertyValueA, propertyValueB)) return false;
65
+ }
66
+ // If we get out of the loop without
67
+ // returning false, return true.
68
+ return true;
69
+ };
70
+ return compare(firstValue, secondValue);
71
+ }
@@ -0,0 +1,238 @@
1
+ import {expect} from 'chai';
2
+ import {isDeepEqual} from './is-deep-equal.js';
3
+
4
+ const check = (a, b, expected) => {
5
+ expect(isDeepEqual(a, b)).to.be.eq(expected);
6
+ expect(isDeepEqual(b, a)).to.be.eq(expected);
7
+ };
8
+
9
+ describe('isDeepEqual', function () {
10
+ describe('string', function () {
11
+ it('a non-empty string', function () {
12
+ check('str', 'str', true);
13
+ check('str', '', false);
14
+ check('str', 10, false);
15
+ check('str', 0, false);
16
+ check('str', -10, false);
17
+ check('str', true, false);
18
+ check('str', false, false);
19
+ check('str', undefined, false);
20
+ check('str', null, false);
21
+ check('str', {foo: 'bar'}, false);
22
+ check('str', {}, false);
23
+ check('str', [1, 2, 3], false);
24
+ check('str', [], false);
25
+ });
26
+
27
+ it('an empty string', function () {
28
+ check('', 'str', false);
29
+ check('', '', true);
30
+ check('', 10, false);
31
+ check('', 0, false);
32
+ check('', -10, false);
33
+ check('', true, false);
34
+ check('', false, false);
35
+ check('', undefined, false);
36
+ check('', null, false);
37
+ check('', {foo: 'bar'}, false);
38
+ check('', {}, false);
39
+ check('', [1, 2, 3], false);
40
+ check('', [], false);
41
+ });
42
+ });
43
+
44
+ describe('number', function () {
45
+ it('a positive number', function () {
46
+ check(10, 'str', false);
47
+ check(10, '', false);
48
+ check(10, 10, true);
49
+ check(10, 0, false);
50
+ check(10, -10, false);
51
+ check(10, true, false);
52
+ check(10, false, false);
53
+ check(10, undefined, false);
54
+ check(10, null, false);
55
+ check(10, {foo: 'bar'}, false);
56
+ check(10, {}, false);
57
+ check(10, [1, 2, 3], false);
58
+ check(10, [], false);
59
+ });
60
+
61
+ it('zero', function () {
62
+ check(0, 'str', false);
63
+ check(0, '', false);
64
+ check(0, 10, false);
65
+ check(0, 0, true);
66
+ check(0, -10, false);
67
+ check(0, true, false);
68
+ check(0, false, false);
69
+ check(0, undefined, false);
70
+ check(0, null, false);
71
+ check(0, {foo: 'bar'}, false);
72
+ check(0, {}, false);
73
+ check(0, [1, 2, 3], false);
74
+ check(0, [], false);
75
+ });
76
+
77
+ it('a negative number', function () {
78
+ check(-10, 'str', false);
79
+ check(-10, '', false);
80
+ check(-10, 10, false);
81
+ check(-10, 0, false);
82
+ check(-10, -10, true);
83
+ check(-10, true, false);
84
+ check(-10, false, false);
85
+ check(-10, undefined, false);
86
+ check(-10, null, false);
87
+ check(-10, {foo: 'bar'}, false);
88
+ check(-10, {}, false);
89
+ check(-10, [1, 2, 3], false);
90
+ check(-10, [], false);
91
+ });
92
+ });
93
+
94
+ describe('boolean', function () {
95
+ it('true', function () {
96
+ check(true, 'str', false);
97
+ check(true, '', false);
98
+ check(true, 10, false);
99
+ check(true, 0, false);
100
+ check(true, -10, false);
101
+ check(true, true, true);
102
+ check(true, false, false);
103
+ check(true, undefined, false);
104
+ check(true, null, false);
105
+ check(true, {foo: 'bar'}, false);
106
+ check(true, {}, false);
107
+ check(true, [1, 2, 3], false);
108
+ check(true, [], false);
109
+ });
110
+
111
+ it('false', function () {
112
+ check(false, 'str', false);
113
+ check(false, '', false);
114
+ check(false, 10, false);
115
+ check(false, 0, false);
116
+ check(false, -10, false);
117
+ check(false, true, false);
118
+ check(false, false, true);
119
+ check(false, undefined, false);
120
+ check(false, null, false);
121
+ check(false, {foo: 'bar'}, false);
122
+ check(false, {}, false);
123
+ check(false, [1, 2, 3], false);
124
+ check(false, [], false);
125
+ });
126
+ });
127
+
128
+ describe('array', function () {
129
+ it('an array of numbers', function () {
130
+ check([1, 2, 3], 'str', false);
131
+ check([1, 2, 3], '', false);
132
+ check([1, 2, 3], 10, false);
133
+ check([1, 2, 3], 0, false);
134
+ check([1, 2, 3], -10, false);
135
+ check([1, 2, 3], true, false);
136
+ check([1, 2, 3], false, false);
137
+ check([1, 2, 3], undefined, false);
138
+ check([1, 2, 3], null, false);
139
+ check([1, 2, 3], {foo: 'bar'}, false);
140
+ check([1, 2, 3], {}, false);
141
+ check([1, 2, 3], [1, 2, 3], true);
142
+ check([1, 2, 3], [], false);
143
+ });
144
+
145
+ it('an empty array', function () {
146
+ check([], 'str', false);
147
+ check([], '', false);
148
+ check([], 10, false);
149
+ check([], 0, false);
150
+ check([], -10, false);
151
+ check([], true, false);
152
+ check([], false, false);
153
+ check([], undefined, false);
154
+ check([], null, false);
155
+ check([], {foo: 'bar'}, false);
156
+ check([], {}, false);
157
+ check([], [1, 2, 3], false);
158
+ check([], [], true);
159
+ });
160
+ });
161
+
162
+ describe('object', function () {
163
+ it('string key and string value', function () {
164
+ check({foo: 'bar'}, 'str', false);
165
+ check({foo: 'bar'}, '', false);
166
+ check({foo: 'bar'}, 10, false);
167
+ check({foo: 'bar'}, 0, false);
168
+ check({foo: 'bar'}, -10, false);
169
+ check({foo: 'bar'}, true, false);
170
+ check({foo: 'bar'}, false, false);
171
+ check({foo: 'bar'}, undefined, false);
172
+ check({foo: 'bar'}, null, false);
173
+ check({foo: 'bar'}, {foo: 'bar'}, true);
174
+ check({foo: 'bar'}, {}, false);
175
+ check({foo: 'bar'}, [1, 2, 3], false);
176
+ check({foo: 'bar'}, [], false);
177
+ });
178
+
179
+ it('an empty object', function () {
180
+ check({}, 'str', false);
181
+ check({}, '', false);
182
+ check({}, 10, false);
183
+ check({}, 0, false);
184
+ check({}, -10, false);
185
+ check({}, true, false);
186
+ check({}, false, false);
187
+ check({}, undefined, false);
188
+ check({}, null, false);
189
+ check({}, {foo: 'bar'}, false);
190
+ check({}, {}, true);
191
+ check({}, [1, 2, 3], false);
192
+ check({}, [], false);
193
+ });
194
+
195
+ it('null', function () {
196
+ check(null, 'str', false);
197
+ check(null, '', false);
198
+ check(null, 10, false);
199
+ check(null, 0, false);
200
+ check(null, -10, false);
201
+ check(null, true, false);
202
+ check(null, false, false);
203
+ check(null, undefined, false);
204
+ check(null, null, true);
205
+ check(null, {foo: 'bar'}, false);
206
+ check(null, {}, false);
207
+ check(null, [1, 2, 3], false);
208
+ check(null, [], false);
209
+ });
210
+
211
+ it('circular reference to itself', function () {
212
+ const a = {foo: 'bar'};
213
+ const b = {baz: 'qux'};
214
+ const c = {foo: 'bar'};
215
+ a.itself = a;
216
+ b.itself = b;
217
+ c.itself = c;
218
+ check(a, b, false);
219
+ check(a, c, true);
220
+ });
221
+ });
222
+
223
+ it('undefined', function () {
224
+ check(undefined, 'str', false);
225
+ check(undefined, '', false);
226
+ check(undefined, 10, false);
227
+ check(undefined, 0, false);
228
+ check(undefined, -10, false);
229
+ check(undefined, true, false);
230
+ check(undefined, false, false);
231
+ check(undefined, undefined, true);
232
+ check(undefined, null, false);
233
+ check(undefined, {foo: 'bar'}, false);
234
+ check(undefined, {}, false);
235
+ check(undefined, [1, 2, 3], false);
236
+ check(undefined, [], false);
237
+ });
238
+ });