querier-ts 2.1.0 → 2.2.0
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/README.md +17 -2
- package/lib/core/errors/invalid-argument-error.d.ts +1 -12
- package/lib/core/errors/invalid-argument-error.d.ts.map +1 -1
- package/lib/core/errors/invalid-argument-error.js +2 -8
- package/lib/core/errors/invalid-argument-error.js.map +1 -1
- package/lib/core/types/nullable-condition.d.ts +2 -0
- package/lib/core/types/nullable-condition.d.ts.map +1 -0
- package/lib/core/types/nullable-condition.js +2 -0
- package/lib/core/types/nullable-condition.js.map +1 -0
- package/lib/core/types/query-conditions-group-nullable.d.ts +2 -1
- package/lib/core/types/query-conditions-group-nullable.d.ts.map +1 -1
- package/lib/core/types/validation-options.d.ts +4 -0
- package/lib/core/types/validation-options.d.ts.map +1 -0
- package/lib/core/types/validation-options.js +2 -0
- package/lib/core/types/validation-options.js.map +1 -0
- package/lib/core/validation/decorators/number-validaton.d.ts.map +1 -1
- package/lib/core/validation/decorators/number-validaton.js +6 -18
- package/lib/core/validation/decorators/number-validaton.js.map +1 -1
- package/lib/core/validation/query-row-validator.d.ts +6 -40
- package/lib/core/validation/query-row-validator.d.ts.map +1 -1
- package/lib/core/validation/query-row-validator.js +22 -44
- package/lib/core/validation/query-row-validator.js.map +1 -1
- package/lib/query.d.ts +29 -20
- package/lib/query.d.ts.map +1 -1
- package/lib/query.js +60 -68
- package/lib/query.js.map +1 -1
- package/lib/utils/functions/type-guards/is-function.d.ts +2 -1
- package/lib/utils/functions/type-guards/is-function.d.ts.map +1 -1
- package/lib/utils/functions/type-guards/is-function.js +2 -0
- package/lib/utils/functions/type-guards/is-function.js.map +1 -1
- package/package.json +15 -13
- package/lib/__tests__/query.spec.d.ts +0 -1
- package/lib/__tests__/query.spec.js +0 -165
- package/lib/core/errors/__tests__/invalid-argument-error.spec.d.ts +0 -1
- package/lib/core/errors/__tests__/invalid-argument-error.spec.js +0 -54
- package/lib/core/validation/__tests__/query-row-validator.spec.d.ts +0 -1
- package/lib/core/validation/__tests__/query-row-validator.spec.js +0 -195
- package/lib/core/validation/decorators/__tests__/number-validation.spec.d.ts +0 -1
- package/lib/core/validation/decorators/__tests__/number-validation.spec.js +0 -114
- package/lib/utils/functions/generic/__tests__/compare-arrays.spec.d.ts +0 -1
- package/lib/utils/functions/generic/__tests__/compare-arrays.spec.js +0 -21
- package/lib/utils/functions/generic/__tests__/deep-equal.spec.d.ts +0 -1
- package/lib/utils/functions/generic/__tests__/deep-equal.spec.js +0 -82
- package/lib/utils/functions/generic/__tests__/get-entries.spec.d.ts +0 -1
- package/lib/utils/functions/generic/__tests__/get-entries.spec.js +0 -55
- package/lib/utils/functions/sort/__tests__/sort-by-properties.spec.d.ts +0 -1
- package/lib/utils/functions/sort/__tests__/sort-by-properties.spec.js +0 -69
- package/lib/utils/functions/sort/__tests__/sort-by-property.spec.d.ts +0 -1
- package/lib/utils/functions/sort/__tests__/sort-by-property.spec.js +0 -63
- package/lib/utils/functions/type-guards/__tests__/is-function.spec.d.ts +0 -1
- package/lib/utils/functions/type-guards/__tests__/is-function.spec.js +0 -38
- package/lib/utils/functions/type-guards/__tests__/is-number.spec.d.ts +0 -1
- package/lib/utils/functions/type-guards/__tests__/is-number.spec.js +0 -35
- package/lib/utils/functions/type-guards/__tests__/is-object.spec.d.ts +0 -1
- package/lib/utils/functions/type-guards/__tests__/is-object.spec.js +0 -38
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const query_row_validator_1 = require("../query-row-validator");
|
|
4
|
-
describe('QueryRowValidator', () => {
|
|
5
|
-
describe('primitive comparisons', () => {
|
|
6
|
-
it('should validate equality for primitive values', () => {
|
|
7
|
-
const row = { id: 1, name: 'Alice' };
|
|
8
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
9
|
-
conditionsObject: {
|
|
10
|
-
id: 1,
|
|
11
|
-
name: 'Alice',
|
|
12
|
-
},
|
|
13
|
-
ignoreNullValues: false,
|
|
14
|
-
});
|
|
15
|
-
expect(result).toBe(true);
|
|
16
|
-
});
|
|
17
|
-
it('should return false when primitive values differ', () => {
|
|
18
|
-
const row = { id: 1 };
|
|
19
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
20
|
-
conditionsObject: {
|
|
21
|
-
id: 2,
|
|
22
|
-
},
|
|
23
|
-
ignoreNullValues: false,
|
|
24
|
-
});
|
|
25
|
-
expect(result).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe('function conditions', () => {
|
|
29
|
-
it('should validate using a function condition', () => {
|
|
30
|
-
const row = { age: 30 };
|
|
31
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
32
|
-
conditionsObject: {
|
|
33
|
-
age: (value) => value > 18,
|
|
34
|
-
},
|
|
35
|
-
ignoreNullValues: false,
|
|
36
|
-
});
|
|
37
|
-
expect(result).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
it('should return false when function condition fails', () => {
|
|
40
|
-
const row = { age: 15 };
|
|
41
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
42
|
-
conditionsObject: {
|
|
43
|
-
age: (value) => value > 18,
|
|
44
|
-
},
|
|
45
|
-
ignoreNullValues: false,
|
|
46
|
-
});
|
|
47
|
-
expect(result).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('array conditions', () => {
|
|
51
|
-
it('should validate arrays using strict comparison', () => {
|
|
52
|
-
const row = { tags: ['a', 'b'] };
|
|
53
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
54
|
-
conditionsObject: {
|
|
55
|
-
tags: ['a', 'b'],
|
|
56
|
-
},
|
|
57
|
-
ignoreNullValues: false,
|
|
58
|
-
});
|
|
59
|
-
expect(result).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
it('should return false for arrays with different values', () => {
|
|
62
|
-
const row = { tags: ['a', 'b'] };
|
|
63
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
64
|
-
conditionsObject: {
|
|
65
|
-
tags: ['a', 'c'],
|
|
66
|
-
},
|
|
67
|
-
ignoreNullValues: false,
|
|
68
|
-
});
|
|
69
|
-
expect(result).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
it('should return false if condition is array but value is not', () => {
|
|
72
|
-
const row = { tags: 'a,b' };
|
|
73
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
74
|
-
conditionsObject: {
|
|
75
|
-
tags: ['a', 'b'],
|
|
76
|
-
},
|
|
77
|
-
ignoreNullValues: false,
|
|
78
|
-
});
|
|
79
|
-
expect(result).toBe(false);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe('object conditions (nested validation)', () => {
|
|
83
|
-
it('should validate nested objects recursively', () => {
|
|
84
|
-
const row = {
|
|
85
|
-
user: {
|
|
86
|
-
name: 'John',
|
|
87
|
-
age: 25,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
91
|
-
conditionsObject: {
|
|
92
|
-
user: {
|
|
93
|
-
name: 'John',
|
|
94
|
-
age: (value) => value >= 18,
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
ignoreNullValues: false,
|
|
98
|
-
});
|
|
99
|
-
expect(result).toBe(true);
|
|
100
|
-
});
|
|
101
|
-
it('should return false when nested validation fails', () => {
|
|
102
|
-
const row = {
|
|
103
|
-
user: {
|
|
104
|
-
name: 'John',
|
|
105
|
-
age: 15,
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
109
|
-
conditionsObject: {
|
|
110
|
-
user: {
|
|
111
|
-
age: (value) => value >= 18,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
ignoreNullValues: false,
|
|
115
|
-
});
|
|
116
|
-
expect(result).toBe(false);
|
|
117
|
-
});
|
|
118
|
-
it('should return false if condition is object but value is not', () => {
|
|
119
|
-
const row = {
|
|
120
|
-
user: 'John',
|
|
121
|
-
};
|
|
122
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
123
|
-
conditionsObject: {
|
|
124
|
-
user: { name: 'John' },
|
|
125
|
-
},
|
|
126
|
-
ignoreNullValues: false,
|
|
127
|
-
});
|
|
128
|
-
expect(result).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe('ignoreNullValues behavior', () => {
|
|
132
|
-
it('should ignore null conditions when ignoreNullValues is true', () => {
|
|
133
|
-
const row = { name: 'Alice' };
|
|
134
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
135
|
-
conditionsObject: {
|
|
136
|
-
name: null,
|
|
137
|
-
},
|
|
138
|
-
ignoreNullValues: true,
|
|
139
|
-
});
|
|
140
|
-
expect(result).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
it('should ignore undefined conditions when ignoreNullValues is true', () => {
|
|
143
|
-
const row = { name: 'Alice' };
|
|
144
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
145
|
-
conditionsObject: {
|
|
146
|
-
name: undefined,
|
|
147
|
-
},
|
|
148
|
-
ignoreNullValues: true,
|
|
149
|
-
});
|
|
150
|
-
expect(result).toBe(true);
|
|
151
|
-
});
|
|
152
|
-
it('should NOT ignore null when ignoreNullValues is false', () => {
|
|
153
|
-
const row = { name: 'Alice' };
|
|
154
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
155
|
-
conditionsObject: {
|
|
156
|
-
name: null,
|
|
157
|
-
},
|
|
158
|
-
ignoreNullValues: false,
|
|
159
|
-
});
|
|
160
|
-
expect(result).toBe(false);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
describe('multiple conditions', () => {
|
|
164
|
-
it('should return true only if all conditions pass', () => {
|
|
165
|
-
const row = {
|
|
166
|
-
id: 1,
|
|
167
|
-
active: true,
|
|
168
|
-
roles: ['admin'],
|
|
169
|
-
};
|
|
170
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
171
|
-
conditionsObject: {
|
|
172
|
-
id: 1,
|
|
173
|
-
active: true,
|
|
174
|
-
roles: ['admin'],
|
|
175
|
-
},
|
|
176
|
-
ignoreNullValues: false,
|
|
177
|
-
});
|
|
178
|
-
expect(result).toBe(true);
|
|
179
|
-
});
|
|
180
|
-
it('should return false if at least one condition fails', () => {
|
|
181
|
-
const row = {
|
|
182
|
-
id: 1,
|
|
183
|
-
active: false,
|
|
184
|
-
};
|
|
185
|
-
const result = query_row_validator_1.QueryRowValidator.validate(row, {
|
|
186
|
-
conditionsObject: {
|
|
187
|
-
id: 1,
|
|
188
|
-
active: true,
|
|
189
|
-
},
|
|
190
|
-
ignoreNullValues: false,
|
|
191
|
-
});
|
|
192
|
-
expect(result).toBe(false);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
require("reflect-metadata");
|
|
13
|
-
const errors_1 = require("../../../errors");
|
|
14
|
-
const number_validaton_1 = require("../number-validaton");
|
|
15
|
-
class TestService {
|
|
16
|
-
sum(a, b, c) {
|
|
17
|
-
return a + b + c;
|
|
18
|
-
}
|
|
19
|
-
onlyInteger(value) {
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
ranged(value) {
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
__decorate([
|
|
27
|
-
number_validaton_1.validateNumbers,
|
|
28
|
-
__param(0, (0, number_validaton_1.min)(0)),
|
|
29
|
-
__param(1, (0, number_validaton_1.max)(10)),
|
|
30
|
-
__param(2, number_validaton_1.integer)
|
|
31
|
-
], TestService.prototype, "sum", null);
|
|
32
|
-
__decorate([
|
|
33
|
-
number_validaton_1.validateNumbers,
|
|
34
|
-
__param(0, number_validaton_1.integer)
|
|
35
|
-
], TestService.prototype, "onlyInteger", null);
|
|
36
|
-
__decorate([
|
|
37
|
-
number_validaton_1.validateNumbers,
|
|
38
|
-
__param(0, (0, number_validaton_1.min)(5)),
|
|
39
|
-
__param(0, (0, number_validaton_1.max)(10))
|
|
40
|
-
], TestService.prototype, "ranged", null);
|
|
41
|
-
describe('number decorators', () => {
|
|
42
|
-
let service;
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
service = new TestService();
|
|
45
|
-
});
|
|
46
|
-
describe('valid scenarios', () => {
|
|
47
|
-
it('should allow valid arguments', () => {
|
|
48
|
-
expect(service.sum(1, 5, 3)).toBe(9);
|
|
49
|
-
});
|
|
50
|
-
it('should allow integer values', () => {
|
|
51
|
-
expect(service.onlyInteger(10)).toBe(10);
|
|
52
|
-
});
|
|
53
|
-
it('should allow values within min/max range', () => {
|
|
54
|
-
expect(service.ranged(5)).toBe(5);
|
|
55
|
-
expect(service.ranged(10)).toBe(10);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
describe('min decorator', () => {
|
|
59
|
-
it('should throw if value is less than min', () => {
|
|
60
|
-
expect(() => service.sum(-1, 5, 3)).toThrow(errors_1.InvalidArgumentError);
|
|
61
|
-
});
|
|
62
|
-
it('should throw with correct error message', () => {
|
|
63
|
-
try {
|
|
64
|
-
service.sum(-1, 5, 3);
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
expect(e).toBeInstanceOf(errors_1.InvalidArgumentError);
|
|
68
|
-
expect(e.message).toContain('equal or greater than 0');
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe('max decorator', () => {
|
|
73
|
-
it('should throw if value is greater than max', () => {
|
|
74
|
-
expect(() => service.sum(1, 20, 3)).toThrow(errors_1.InvalidArgumentError);
|
|
75
|
-
});
|
|
76
|
-
it('should throw with correct error message', () => {
|
|
77
|
-
try {
|
|
78
|
-
service.sum(1, 20, 3);
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
expect(e).toBeInstanceOf(errors_1.InvalidArgumentError);
|
|
82
|
-
expect(e.message).toContain('equal or less than 10');
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
describe('integer decorator', () => {
|
|
87
|
-
it('should throw if value is not an integer', () => {
|
|
88
|
-
expect(() => service.onlyInteger(1.5)).toThrow(errors_1.InvalidArgumentError);
|
|
89
|
-
});
|
|
90
|
-
it('should accept safe integers', () => {
|
|
91
|
-
expect(service.onlyInteger(Number.MAX_SAFE_INTEGER)).toBe(Number.MAX_SAFE_INTEGER);
|
|
92
|
-
});
|
|
93
|
-
it('should throw if value is NaN', () => {
|
|
94
|
-
expect(() => service.onlyInteger(NaN)).toThrow(errors_1.InvalidArgumentError);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe('combined decorators', () => {
|
|
98
|
-
it('should validate min and max together', () => {
|
|
99
|
-
expect(() => service.ranged(4)).toThrow(errors_1.InvalidArgumentError);
|
|
100
|
-
expect(() => service.ranged(11)).toThrow(errors_1.InvalidArgumentError);
|
|
101
|
-
});
|
|
102
|
-
it('should pass when all constraints are satisfied', () => {
|
|
103
|
-
expect(service.ranged(7)).toBe(7);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe('type validation', () => {
|
|
107
|
-
it('should throw if value is not a number for min', () => {
|
|
108
|
-
expect(() => service.sum('1', 5, 3)).toThrow(errors_1.InvalidArgumentError);
|
|
109
|
-
});
|
|
110
|
-
it('should throw if value is not a number for max', () => {
|
|
111
|
-
expect(() => service.sum(1, '5', 3)).toThrow(errors_1.InvalidArgumentError);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const compare_arrays_1 = require("../compare-arrays");
|
|
4
|
-
describe('compareArrays', () => {
|
|
5
|
-
it('returns true for ly equal arrays', () => {
|
|
6
|
-
const a = [{ x: 1 }, { y: 2 }];
|
|
7
|
-
const b = [{ x: 1 }, { y: 2 }];
|
|
8
|
-
expect((0, compare_arrays_1.compareArrays)(a, b)).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
it('returns false for ly different arrays', () => {
|
|
11
|
-
expect((0, compare_arrays_1.compareArrays)([{ x: 1 }], [{ x: 2 }])).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
it('returns false when order differs', () => {
|
|
14
|
-
expect((0, compare_arrays_1.compareArrays)([{ a: 1 }, { b: 2 }], [{ b: 2 }, { a: 1 }])).toBe(false);
|
|
15
|
-
});
|
|
16
|
-
it('works with nested objects', () => {
|
|
17
|
-
const a = [{ x: { y: 1 } }];
|
|
18
|
-
const b = [{ x: { y: 1 } }];
|
|
19
|
-
expect((0, compare_arrays_1.compareArrays)(a, b)).toBe(true);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const deep_equal_1 = require("../deep-equal");
|
|
4
|
-
describe('deepEqual', () => {
|
|
5
|
-
describe('primitive values', () => {
|
|
6
|
-
it('returns true for strictly equal primitives', () => {
|
|
7
|
-
expect((0, deep_equal_1.deepEqual)(1, 1)).toBe(true);
|
|
8
|
-
expect((0, deep_equal_1.deepEqual)('a', 'a')).toBe(true);
|
|
9
|
-
expect((0, deep_equal_1.deepEqual)(true, true)).toBe(true);
|
|
10
|
-
expect((0, deep_equal_1.deepEqual)(null, null)).toBe(true);
|
|
11
|
-
expect((0, deep_equal_1.deepEqual)(undefined, undefined)).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
it('returns false for different primitive values', () => {
|
|
14
|
-
expect((0, deep_equal_1.deepEqual)(1, 2)).toBe(false);
|
|
15
|
-
expect((0, deep_equal_1.deepEqual)('a', 'b')).toBe(false);
|
|
16
|
-
expect((0, deep_equal_1.deepEqual)(true, false)).toBe(false);
|
|
17
|
-
expect((0, deep_equal_1.deepEqual)(null, undefined)).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
describe('objects', () => {
|
|
21
|
-
it('returns true for deeply equal plain objects', () => {
|
|
22
|
-
const a = { x: 1, y: 2 };
|
|
23
|
-
const b = { x: 1, y: 2 };
|
|
24
|
-
expect((0, deep_equal_1.deepEqual)(a, b)).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
it('returns false for objects with different keys', () => {
|
|
27
|
-
expect((0, deep_equal_1.deepEqual)({ x: 1 }, { y: 1 })).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
it('returns false for objects with same keys but different values', () => {
|
|
30
|
-
expect((0, deep_equal_1.deepEqual)({ x: 1 }, { x: 2 })).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
it('returns false when one object has extra keys', () => {
|
|
33
|
-
expect((0, deep_equal_1.deepEqual)({ x: 1 }, { x: 1, y: 2 })).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe('nested structures', () => {
|
|
37
|
-
it('returns true for deeply nested objects', () => {
|
|
38
|
-
const a = { x: { y: { z: 1 } } };
|
|
39
|
-
const b = { x: { y: { z: 1 } } };
|
|
40
|
-
expect((0, deep_equal_1.deepEqual)(a, b)).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
it('returns false for deeply nested differences', () => {
|
|
43
|
-
const a = { x: { y: { z: 1 } } };
|
|
44
|
-
const b = { x: { y: { z: 2 } } };
|
|
45
|
-
expect((0, deep_equal_1.deepEqual)(a, b)).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe('arrays', () => {
|
|
49
|
-
it('returns true for deeply equal arrays', () => {
|
|
50
|
-
expect((0, deep_equal_1.deepEqual)([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
it('returns false for arrays with different order', () => {
|
|
53
|
-
expect((0, deep_equal_1.deepEqual)([1, 2, 3], [3, 2, 1])).toBe(false);
|
|
54
|
-
});
|
|
55
|
-
it('returns true for arrays with nested objects', () => {
|
|
56
|
-
const a = [{ x: 1 }, { y: 2 }];
|
|
57
|
-
const b = [{ x: 1 }, { y: 2 }];
|
|
58
|
-
expect((0, deep_equal_1.deepEqual)(a, b)).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
it('returns false for arrays with different lengths', () => {
|
|
61
|
-
expect((0, deep_equal_1.deepEqual)([1, 2], [1, 2, 3])).toBe(false);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
describe('mixed and edge cases', () => {
|
|
65
|
-
it('returns false when comparing array and object', () => {
|
|
66
|
-
expect((0, deep_equal_1.deepEqual)([], {})).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
it('returns false when one value is object and the other is primitive', () => {
|
|
69
|
-
expect((0, deep_equal_1.deepEqual)({ x: 1 }, 1)).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
it('returns true for same object reference', () => {
|
|
72
|
-
const obj = { x: 1 };
|
|
73
|
-
expect((0, deep_equal_1.deepEqual)(obj, obj)).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
it('returns false for Date objects with same value (by design)', () => {
|
|
76
|
-
const a = new Date(2020, 1, 1);
|
|
77
|
-
const b = new Date(2020, 1, 1);
|
|
78
|
-
// Date has no enumerable keys, so this documents the limitation
|
|
79
|
-
expect((0, deep_equal_1.deepEqual)(a, b)).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const get_entries_1 = require("../get-entries");
|
|
4
|
-
describe('getEntries', () => {
|
|
5
|
-
it('should return entries for a simple object', () => {
|
|
6
|
-
const obj = {
|
|
7
|
-
a: 1,
|
|
8
|
-
b: 2,
|
|
9
|
-
};
|
|
10
|
-
const entries = (0, get_entries_1.getEntries)(obj);
|
|
11
|
-
expect(entries).toEqual([
|
|
12
|
-
['a', 1],
|
|
13
|
-
['b', 2],
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
16
|
-
it('should return an empty array for an empty object', () => {
|
|
17
|
-
const obj = {};
|
|
18
|
-
const entries = (0, get_entries_1.getEntries)(obj);
|
|
19
|
-
expect(entries).toEqual([]);
|
|
20
|
-
});
|
|
21
|
-
it('should work with different value types', () => {
|
|
22
|
-
const obj = {
|
|
23
|
-
name: 'Alice',
|
|
24
|
-
age: 30,
|
|
25
|
-
active: true,
|
|
26
|
-
};
|
|
27
|
-
const entries = (0, get_entries_1.getEntries)(obj);
|
|
28
|
-
expect(entries).toEqual([
|
|
29
|
-
['name', 'Alice'],
|
|
30
|
-
['age', 30],
|
|
31
|
-
['active', true],
|
|
32
|
-
]);
|
|
33
|
-
});
|
|
34
|
-
it('should preserve key-value association', () => {
|
|
35
|
-
const obj = {
|
|
36
|
-
x: 10,
|
|
37
|
-
y: 20,
|
|
38
|
-
};
|
|
39
|
-
const entries = (0, get_entries_1.getEntries)(obj);
|
|
40
|
-
for (const [key, value] of entries) {
|
|
41
|
-
expect(obj[key]).toBe(value);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
it('should provide correct typing for keys and values (type-level test)', () => {
|
|
45
|
-
const obj = {
|
|
46
|
-
id: 1,
|
|
47
|
-
title: 'Post',
|
|
48
|
-
};
|
|
49
|
-
const entries = (0, get_entries_1.getEntries)(obj);
|
|
50
|
-
const key = 'id';
|
|
51
|
-
const value = obj[key];
|
|
52
|
-
expect(key).toBe('id');
|
|
53
|
-
expect(value).toBe(1);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const sort_by_properties_1 = require("../sort-by-properties");
|
|
4
|
-
describe('sortByProperties', () => {
|
|
5
|
-
it('sorts by a single property', () => {
|
|
6
|
-
const data = [
|
|
7
|
-
{ id: 2, name: 'B' },
|
|
8
|
-
{ id: 1, name: 'A' },
|
|
9
|
-
];
|
|
10
|
-
data.sort((0, sort_by_properties_1.sortByProperties)('id'));
|
|
11
|
-
expect(data).toEqual([
|
|
12
|
-
{ id: 1, name: 'A' },
|
|
13
|
-
{ id: 2, name: 'B' },
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
16
|
-
it('sorts by multiple properties in order', () => {
|
|
17
|
-
const data = [
|
|
18
|
-
{ id: 1, name: 'Bob', age: 30 },
|
|
19
|
-
{ id: 2, name: 'Alice', age: 30 },
|
|
20
|
-
{ id: 3, name: 'Alice', age: 25 },
|
|
21
|
-
];
|
|
22
|
-
data.sort((0, sort_by_properties_1.sortByProperties)('name', 'age'));
|
|
23
|
-
expect(data).toEqual([
|
|
24
|
-
{ id: 3, name: 'Alice', age: 25 },
|
|
25
|
-
{ id: 2, name: 'Alice', age: 30 },
|
|
26
|
-
{ id: 1, name: 'Bob', age: 30 },
|
|
27
|
-
]);
|
|
28
|
-
});
|
|
29
|
-
it('supports descending order with "-" prefix', () => {
|
|
30
|
-
const data = [
|
|
31
|
-
{ id: 1, name: 'Bob', age: 30 },
|
|
32
|
-
{ id: 2, name: 'Alice', age: 30 },
|
|
33
|
-
{ id: 3, name: 'Alice', age: 25 },
|
|
34
|
-
];
|
|
35
|
-
data.sort((0, sort_by_properties_1.sortByProperties)('name', '-age'));
|
|
36
|
-
expect(data).toEqual([
|
|
37
|
-
{ id: 2, name: 'Alice', age: 30 },
|
|
38
|
-
{ id: 3, name: 'Alice', age: 25 },
|
|
39
|
-
{ id: 1, name: 'Bob', age: 30 },
|
|
40
|
-
]);
|
|
41
|
-
});
|
|
42
|
-
it('places undefined values last when used as secondary key', () => {
|
|
43
|
-
const data = [
|
|
44
|
-
{ id: 1, name: 'Alice' },
|
|
45
|
-
{ id: 2, name: 'Alice', age: 20 },
|
|
46
|
-
{ id: 3, name: 'Alice', age: 10 },
|
|
47
|
-
];
|
|
48
|
-
data.sort((0, sort_by_properties_1.sortByProperties)('name', 'age'));
|
|
49
|
-
expect(data).toEqual([
|
|
50
|
-
{ id: 3, name: 'Alice', age: 10 },
|
|
51
|
-
{ id: 2, name: 'Alice', age: 20 },
|
|
52
|
-
{ id: 1, name: 'Alice' },
|
|
53
|
-
]);
|
|
54
|
-
});
|
|
55
|
-
it('returns 0 when all compared properties are equal', () => {
|
|
56
|
-
const comparator = (0, sort_by_properties_1.sortByProperties)('name', 'age');
|
|
57
|
-
expect(comparator({ id: 1, name: 'Alice', age: 20 }, { id: 2, name: 'Alice', age: 20 })).toBe(0);
|
|
58
|
-
});
|
|
59
|
-
it('returns 0 when no properties are provided', () => {
|
|
60
|
-
const comparator = (0, sort_by_properties_1.sortByProperties)();
|
|
61
|
-
expect(comparator({ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' })).toBe(0);
|
|
62
|
-
});
|
|
63
|
-
it('enforces type safety at compile time', () => {
|
|
64
|
-
// @ts-expect-error
|
|
65
|
-
(0, sort_by_properties_1.sortByProperties)('invalid');
|
|
66
|
-
// @ts-expect-error
|
|
67
|
-
(0, sort_by_properties_1.sortByProperties)('-invalid');
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const sort_by_property_1 = require("../sort-by-property");
|
|
4
|
-
describe('sortByProperty (improved)', () => {
|
|
5
|
-
describe('ascending order', () => {
|
|
6
|
-
it('sorts by numeric property', () => {
|
|
7
|
-
const data = [{ id: 3 }, { id: 1 }, { id: 2 }];
|
|
8
|
-
data.sort((0, sort_by_property_1.sortByProperty)('id'));
|
|
9
|
-
expect(data).toEqual([{ id: 1 }, { id: 2 }, { id: 3 }]);
|
|
10
|
-
});
|
|
11
|
-
it('sorts by string property', () => {
|
|
12
|
-
const data = [{ name: 'Charlie' }, { name: 'Alice' }, { name: 'Bob' }];
|
|
13
|
-
data.sort((0, sort_by_property_1.sortByProperty)('name'));
|
|
14
|
-
expect(data).toEqual([
|
|
15
|
-
{ name: 'Alice' },
|
|
16
|
-
{ name: 'Bob' },
|
|
17
|
-
{ name: 'Charlie' },
|
|
18
|
-
]);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
describe('descending order', () => {
|
|
22
|
-
it('sorts by numeric property descending', () => {
|
|
23
|
-
const data = [{ score: 10 }, { score: 30 }, { score: 20 }];
|
|
24
|
-
data.sort((0, sort_by_property_1.sortByProperty)('-score'));
|
|
25
|
-
expect(data).toEqual([{ score: 30 }, { score: 20 }, { score: 10 }]);
|
|
26
|
-
});
|
|
27
|
-
it('sorts by string property descending', () => {
|
|
28
|
-
const data = [{ name: 'Alice' }, { name: 'Charlie' }, { name: 'Bob' }];
|
|
29
|
-
data.sort((0, sort_by_property_1.sortByProperty)('-name'));
|
|
30
|
-
expect(data).toEqual([
|
|
31
|
-
{ name: 'Charlie' },
|
|
32
|
-
{ name: 'Bob' },
|
|
33
|
-
{ name: 'Alice' },
|
|
34
|
-
]);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe('null and undefined handling', () => {
|
|
38
|
-
it('places undefined values last', () => {
|
|
39
|
-
const data = [{ value: 2 }, { value: undefined }, { value: 1 }];
|
|
40
|
-
data.sort((0, sort_by_property_1.sortByProperty)('value'));
|
|
41
|
-
expect(data).toEqual([{ value: 1 }, { value: 2 }, { value: undefined }]);
|
|
42
|
-
});
|
|
43
|
-
it('places null values last', () => {
|
|
44
|
-
const data = [{ value: 2 }, { value: null }, { value: 1 }];
|
|
45
|
-
data.sort((0, sort_by_property_1.sortByProperty)('value'));
|
|
46
|
-
expect(data).toEqual([{ value: 1 }, { value: 2 }, { value: null }]);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
describe('equal values', () => {
|
|
50
|
-
it('returns 0 for equal property values', () => {
|
|
51
|
-
const comparator = (0, sort_by_property_1.sortByProperty)('id');
|
|
52
|
-
expect(comparator({ id: 1 }, { id: 1 })).toBe(0);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe('type safety (compile-time)', () => {
|
|
56
|
-
it('does not allow invalid properties', () => {
|
|
57
|
-
// @ts-expect-error
|
|
58
|
-
(0, sort_by_property_1.sortByProperty)('invalid');
|
|
59
|
-
// @ts-expect-error
|
|
60
|
-
(0, sort_by_property_1.sortByProperty)('-invalid');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const is_function_1 = require("../is-function");
|
|
4
|
-
describe('isFunction', () => {
|
|
5
|
-
it('should return true for regular functions', () => {
|
|
6
|
-
const fn = () => { };
|
|
7
|
-
expect((0, is_function_1.isFunction)(fn)).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
it('should return true for async functions', () => {
|
|
10
|
-
const fn = async () => { };
|
|
11
|
-
expect((0, is_function_1.isFunction)(fn)).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
it('should return true for class constructors', () => {
|
|
14
|
-
class Test {
|
|
15
|
-
}
|
|
16
|
-
expect((0, is_function_1.isFunction)(Test)).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
it('should return false for non-function values', () => {
|
|
19
|
-
expect((0, is_function_1.isFunction)(123)).toBe(false);
|
|
20
|
-
expect((0, is_function_1.isFunction)('string')).toBe(false);
|
|
21
|
-
expect((0, is_function_1.isFunction)(null)).toBe(false);
|
|
22
|
-
expect((0, is_function_1.isFunction)(undefined)).toBe(false);
|
|
23
|
-
expect((0, is_function_1.isFunction)({})).toBe(false);
|
|
24
|
-
expect((0, is_function_1.isFunction)([])).toBe(false);
|
|
25
|
-
expect((0, is_function_1.isFunction)(true)).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
it('should narrow the type when returning true (type guard)', () => {
|
|
28
|
-
const value = () => 'hello';
|
|
29
|
-
if ((0, is_function_1.isFunction)(value)) {
|
|
30
|
-
// If this compiles, the type guard works
|
|
31
|
-
const result = value();
|
|
32
|
-
expect(result).toBe('hello');
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
fail('Expected value to be a function');
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|