@r5v/mongoose-paginate 1.0.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.
Files changed (59) hide show
  1. package/README.md +126 -0
  2. package/dist/aggregationPagingQuery.d.ts +25 -0
  3. package/dist/aggregationPagingQuery.d.ts.map +1 -0
  4. package/dist/aggregationPagingQuery.js +194 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +7 -0
  8. package/dist/pagingQuery.d.ts +16 -0
  9. package/dist/pagingQuery.d.ts.map +1 -0
  10. package/dist/pagingQuery.js +104 -0
  11. package/dist/tests/dotNotation.spec.d.ts +2 -0
  12. package/dist/tests/dotNotation.spec.d.ts.map +1 -0
  13. package/dist/tests/dotNotation.spec.js +249 -0
  14. package/dist/tests/findProtectedPaths.spec.d.ts +2 -0
  15. package/dist/tests/findProtectedPaths.spec.d.ts.map +1 -0
  16. package/dist/tests/findProtectedPaths.spec.js +11 -0
  17. package/dist/tests/getPathsWithRef.spec.d.ts +2 -0
  18. package/dist/tests/getPathsWithRef.spec.d.ts.map +1 -0
  19. package/dist/tests/getPathsWithRef.spec.js +28 -0
  20. package/dist/tests/getPropertyFromDotNotation.spec.d.ts +2 -0
  21. package/dist/tests/getPropertyFromDotNotation.spec.d.ts.map +1 -0
  22. package/dist/tests/getPropertyFromDotNotation.spec.js +213 -0
  23. package/dist/tests/insertPopulate.spec.d.ts +2 -0
  24. package/dist/tests/insertPopulate.spec.d.ts.map +1 -0
  25. package/dist/tests/insertPopulate.spec.js +64 -0
  26. package/dist/tests/pagingQuery.spec.d.ts +2 -0
  27. package/dist/tests/pagingQuery.spec.d.ts.map +1 -0
  28. package/dist/tests/pagingQuery.spec.js +21 -0
  29. package/dist/tests/parseSortString.spec.d.ts +2 -0
  30. package/dist/tests/parseSortString.spec.d.ts.map +1 -0
  31. package/dist/tests/parseSortString.spec.js +59 -0
  32. package/dist/utils/dotNotation.d.ts +10 -0
  33. package/dist/utils/dotNotation.d.ts.map +1 -0
  34. package/dist/utils/dotNotation.js +129 -0
  35. package/dist/utils/findKeyWithValue.d.ts +2 -0
  36. package/dist/utils/findKeyWithValue.d.ts.map +1 -0
  37. package/dist/utils/findKeyWithValue.js +19 -0
  38. package/dist/utils/findProtectedPaths.d.ts +3 -0
  39. package/dist/utils/findProtectedPaths.d.ts.map +1 -0
  40. package/dist/utils/findProtectedPaths.js +66 -0
  41. package/dist/utils/getPathsWithRef.d.ts +5 -0
  42. package/dist/utils/getPathsWithRef.d.ts.map +1 -0
  43. package/dist/utils/getPathsWithRef.js +111 -0
  44. package/dist/utils/isJsonString.d.ts +2 -0
  45. package/dist/utils/isJsonString.d.ts.map +1 -0
  46. package/dist/utils/isJsonString.js +13 -0
  47. package/dist/utils/isValidDateString.d.ts +2 -0
  48. package/dist/utils/isValidDateString.d.ts.map +1 -0
  49. package/dist/utils/isValidDateString.js +8 -0
  50. package/dist/utils/parseParams.d.ts +4 -0
  51. package/dist/utils/parseParams.d.ts.map +1 -0
  52. package/dist/utils/parseParams.js +49 -0
  53. package/dist/utils/parsePopulateQuery.d.ts +5 -0
  54. package/dist/utils/parsePopulateQuery.d.ts.map +1 -0
  55. package/dist/utils/parsePopulateQuery.js +29 -0
  56. package/dist/utils/parseSortString.d.ts +6 -0
  57. package/dist/utils/parseSortString.d.ts.map +1 -0
  58. package/dist/utils/parseSortString.js +39 -0
  59. package/package.json +60 -0
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dotNotation_1 = require("../utils/dotNotation");
4
+ describe('dotNotationToObject', () => {
5
+ test('should create simple nested object', () => {
6
+ const result = (0, dotNotation_1.dotNotationToObject)('user.name', 'John Doe');
7
+ expect(result).toEqual({
8
+ user: {
9
+ name: 'John Doe'
10
+ }
11
+ });
12
+ });
13
+ test('should create deeply nested object', () => {
14
+ const result = (0, dotNotation_1.dotNotationToObject)('user.profile.personal.name', 'Jane Smith');
15
+ expect(result).toEqual({
16
+ user: {
17
+ profile: {
18
+ personal: {
19
+ name: 'Jane Smith'
20
+ }
21
+ }
22
+ }
23
+ });
24
+ });
25
+ test('should handle single key (no dots)', () => {
26
+ const result = (0, dotNotation_1.dotNotationToObject)('name', 'Alice');
27
+ expect(result).toEqual({
28
+ name: 'Alice'
29
+ });
30
+ });
31
+ test('should handle null value', () => {
32
+ const result = (0, dotNotation_1.dotNotationToObject)('user.name', null);
33
+ expect(result).toEqual({
34
+ user: {
35
+ name: null
36
+ }
37
+ });
38
+ });
39
+ test('should handle undefined value', () => {
40
+ let a;
41
+ const result = (0, dotNotation_1.dotNotationToObject)('user.name', a);
42
+ expect(result).toEqual({
43
+ user: {
44
+ name: null
45
+ }
46
+ });
47
+ });
48
+ test('should handle different value types', () => {
49
+ expect((0, dotNotation_1.dotNotationToObject)('user.age', 25)).toEqual({
50
+ user: { age: 25 }
51
+ });
52
+ expect((0, dotNotation_1.dotNotationToObject)('user.active', true)).toEqual({
53
+ user: { active: true }
54
+ });
55
+ expect((0, dotNotation_1.dotNotationToObject)('user.tags', ['admin', 'user'])).toEqual({
56
+ user: { tags: ['admin', 'user'] }
57
+ });
58
+ expect((0, dotNotation_1.dotNotationToObject)('user.meta', { created: '2023-01-01' })).toEqual({
59
+ user: { meta: { created: '2023-01-01' } }
60
+ });
61
+ });
62
+ test('should handle empty string key', () => {
63
+ const result = (0, dotNotation_1.dotNotationToObject)('user..name', 'Test');
64
+ expect(result).toEqual({
65
+ user: {
66
+ '': {
67
+ name: 'Test'
68
+ }
69
+ }
70
+ });
71
+ });
72
+ test('should use null as default value when no value provided', () => {
73
+ const result = (0, dotNotation_1.dotNotationToObject)('user.name');
74
+ expect(result).toEqual({
75
+ user: {
76
+ name: null
77
+ }
78
+ });
79
+ });
80
+ });
81
+ describe('createObjectFromDotNotation', () => {
82
+ test('should create object from single dot notation entry', () => {
83
+ const input = {
84
+ 'user.name': 'John Doe'
85
+ };
86
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
87
+ expect(result).toEqual({
88
+ user: {
89
+ name: 'John Doe'
90
+ }
91
+ });
92
+ });
93
+ test('should merge multiple dot notation entries', () => {
94
+ const input = {
95
+ 'user.profile.name': 'John Doe',
96
+ 'user.profile.age': 30,
97
+ 'user.settings.theme': 'dark'
98
+ };
99
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
100
+ expect(result).toEqual({
101
+ user: {
102
+ profile: {
103
+ name: 'John Doe',
104
+ age: 30
105
+ },
106
+ settings: {
107
+ theme: 'dark'
108
+ }
109
+ }
110
+ });
111
+ });
112
+ test('should handle complex nested structure', () => {
113
+ const input = {
114
+ 'app.name': 'MyApp',
115
+ 'app.version': '1.0.0',
116
+ 'app.config.database.host': 'localhost',
117
+ 'app.config.database.port': 5432,
118
+ 'app.config.redis.host': 'redis-server',
119
+ 'app.features.auth.enabled': true,
120
+ 'app.features.auth.providers': ['google', 'github'],
121
+ 'app.features.notifications.email': true,
122
+ 'app.features.notifications.push': false
123
+ };
124
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
125
+ expect(result).toEqual({
126
+ app: {
127
+ name: 'MyApp',
128
+ version: '1.0.0',
129
+ config: {
130
+ database: {
131
+ host: 'localhost',
132
+ port: 5432
133
+ },
134
+ redis: {
135
+ host: 'redis-server'
136
+ }
137
+ },
138
+ features: {
139
+ auth: {
140
+ enabled: true,
141
+ providers: ['google', 'github']
142
+ },
143
+ notifications: {
144
+ email: true,
145
+ push: false
146
+ }
147
+ }
148
+ }
149
+ });
150
+ });
151
+ test('should handle conflicting paths by overwriting', () => {
152
+ const input = {
153
+ 'user.name': 'John',
154
+ 'user.name.first': 'John',
155
+ 'user.name.last': 'Doe'
156
+ };
157
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
158
+ // The object should be overwritten when there's a conflict
159
+ expect(result).toEqual({
160
+ user: {
161
+ name: {
162
+ first: 'John',
163
+ last: 'Doe'
164
+ }
165
+ }
166
+ });
167
+ });
168
+ test('should handle empty object', () => {
169
+ const result = (0, dotNotation_1.createObjectFromDotNotation)({});
170
+ expect(result).toEqual({});
171
+ });
172
+ test('should handle single key without dots', () => {
173
+ const input = {
174
+ 'name': 'John Doe',
175
+ 'age': 30
176
+ };
177
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
178
+ expect(result).toEqual({
179
+ name: 'John Doe',
180
+ age: 30
181
+ });
182
+ });
183
+ test('should handle various value types', () => {
184
+ const input = {
185
+ 'string': 'text',
186
+ 'number': 42,
187
+ 'boolean': true,
188
+ 'null': null,
189
+ 'undefined': undefined,
190
+ 'array': [1, 2, 3],
191
+ 'object': { nested: 'value' }
192
+ };
193
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
194
+ expect(result).toEqual({
195
+ string: 'text',
196
+ number: 42,
197
+ boolean: true,
198
+ null: null,
199
+ undefined: undefined,
200
+ array: [1, 2, 3],
201
+ object: { nested: 'value' }
202
+ });
203
+ });
204
+ test('should handle empty string keys', () => {
205
+ const input = {
206
+ 'user..name': 'Test',
207
+ 'user...deep': 'Value'
208
+ };
209
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
210
+ expect(result).toEqual({
211
+ user: {
212
+ '': {
213
+ name: 'Test',
214
+ '': {
215
+ deep: 'Value'
216
+ }
217
+ }
218
+ }
219
+ });
220
+ });
221
+ });
222
+ describe('Edge cases and error handling', () => {
223
+ test('dotNotationToObject should handle empty string', () => {
224
+ const result = (0, dotNotation_1.dotNotationToObject)('', 'value');
225
+ expect(result).toEqual({
226
+ '': 'value'
227
+ });
228
+ });
229
+ test('createObjectFromDotNotation should handle keys with empty string', () => {
230
+ const input = {
231
+ '': 'root value'
232
+ };
233
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
234
+ expect(result).toEqual({
235
+ '': 'root value'
236
+ });
237
+ });
238
+ test('should preserve object references', () => {
239
+ const sharedObject = { shared: 'data' };
240
+ const input = {
241
+ 'user.meta': sharedObject,
242
+ 'app.config': sharedObject
243
+ };
244
+ const result = (0, dotNotation_1.createObjectFromDotNotation)(input);
245
+ expect(result.user.meta).toBe(sharedObject);
246
+ expect(result.app.config).toBe(sharedObject);
247
+ expect(result.user.meta).toBe(result.app.config);
248
+ });
249
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=findProtectedPaths.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findProtectedPaths.spec.d.ts","sourceRoot":"","sources":["../../src/tests/findProtectedPaths.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mockingoose = require("mockingoose");
4
+ // Build Test Schemas
5
+ describe('findProtectedPaths', () => {
6
+ it('returns expected array', () => {
7
+ /* mockingoose();
8
+ const results = findProtectedPaths()
9
+ console.log(results)*/
10
+ });
11
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getPathsWithRef.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPathsWithRef.spec.d.ts","sourceRoot":"","sources":["../../src/tests/getPathsWithRef.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getPathsWithRef_1 = require("../utils/getPathsWithRef");
4
+ const data = [{ "enumValues": [], "regExp": null, "path": "firstName", "instance": "String", "validators": [{ "message": "Path `{PATH}` is required.", "type": "required" }], "getters": [], "setters": [null], "_presplitPath": ["firstName"], "options": { "required": true, "trim": true }, "_index": null, "isRequired": true, "originalRequiredValue": true },
5
+ { "enumValues": [], "regExp": null, "path": "lastName", "instance": "String", "validators": [{ "message": "Path `{PATH}` is required.", "type": "required" }], "getters": [], "setters": [null], "_presplitPath": ["lastName"], "options": { "required": true, "trim": true }, "_index": null, "isRequired": true, "originalRequiredValue": true },
6
+ { "enumValues": [], "regExp": null, "path": "email", "instance": "String", "validators": [], "getters": [], "setters": [null, null], "_presplitPath": ["email"], "options": { "unique": true, "lowercase": true, "trim": true }, "_index": { "unique": true, "background": true } },
7
+ { "enumValues": [], "regExp": null, "path": "c.child.str", "instance": "String", "validators": [], "getters": [], "setters": [], "_presplitPath": ["c", "child", "str"], "options": { "selected": false }, "_index": null },
8
+ { "path": "c.child.grandchild", "options": { "type": { "obj": { "test": { "select": false } }, "paths": { "test": { "enumValues": [], "regExp": null, "path": "test", "instance": "String", "validators": [], "getters": [], "setters": [], "_presplitPath": ["test"], "options": { "select": false }, "_index": null, "selected": false }, "_id": { "path": "_id", "instance": "ObjectId", "validators": [], "getters": [], "setters": [null], "_presplitPath": ["_id"], "options": { "auto": true, "type": "ObjectId" }, "_index": null } }, "aliases": {}, "subpaths": {}, "virtuals": { "id": { "path": "id", "getters": [null], "setters": [], "options": {} } }, "singleNestedPaths": {}, "nested": {}, "inherits": {}, "callQueue": [], "_indexes": [], "_searchIndexes": [], "methods": {}, "methodOptions": {}, "statics": {}, "tree": { "test": { "select": false }, "_id": { "auto": true, "type": "ObjectId" }, "id": { "path": "id", "getters": [null], "setters": [], "options": {} } }, "query": {}, "childSchemas": [], "plugins": [{ "opts": { "deduplicate": true } }, { "opts": { "deduplicate": true } }, { "opts": { "deduplicate": true } }, { "opts": { "deduplicate": true } }, { "opts": { "deduplicate": true } }], "$id": 1, "mapPaths": [], "encryptedFields": {}, "s": { "hooks": { "_pres": {}, "_posts": {} } }, "_userProvidedOptions": {}, "options": { "strict": true, "strictQuery": false, "bufferCommands": true, "capped": false, "versionKey": "__v", "optimisticConcurrency": false, "minimize": true, "autoIndex": null, "discriminatorKey": "__t", "shardKey": null, "read": null, "validateBeforeSave": true, "validateModifiedOnly": false, "_id": true, "id": true, "typeKey": "type" }, "$globalPluginsApplied": true } } },
9
+ { "enumValues": [], "regExp": null, "path": "biography", "instance": "String", "validators": [{ "message": "Path `{PATH}` (`{VALUE}`) is longer than the maximum allowed length (2000).", "type": "maxlength", "maxlength": 2000 }], "getters": [], "setters": [], "_presplitPath": ["biography"], "options": { "select": false, "maxlength": 2000 }, "_index": null, "selected": false },
10
+ { "path": "birthDate", "instance": "Date", "validators": [], "getters": [], "setters": [], "_presplitPath": ["birthDate"], "options": {}, "_index": null },
11
+ { "enumValues": [], "regExp": null, "path": "nationality", "instance": "String", "validators": [], "getters": [], "setters": [null], "_presplitPath": ["nationality"], "options": { "trim": true }, "_index": null },
12
+ { "enumValues": [], "regExp": null, "path": "website", "instance": "String", "validators": [], "getters": [], "setters": [null], "_presplitPath": ["website"], "options": { "trim": true }, "_index": null },
13
+ { "enumValues": [], "regExp": null, "path": "socialMedia.twitter", "instance": "String", "validators": [], "getters": [], "setters": [], "_presplitPath": ["socialMedia", "twitter"], "options": {}, "_index": null },
14
+ { "enumValues": [], "regExp": null, "path": "socialMedia.instagram", "instance": "String", "validators": [], "getters": [], "setters": [], "_presplitPath": ["socialMedia", "instagram"], "options": {}, "_index": null },
15
+ { "enumValues": [], "regExp": null, "path": "socialMedia.facebook", "instance": "String", "validators": [], "getters": [], "setters": [], "_presplitPath": ["socialMedia", "facebook"], "options": {}, "_index": null },
16
+ { "schemaOptions": { "strict": true, "strictQuery": false, "bufferCommands": true, "capped": false, "versionKey": "__v", "optimisticConcurrency": false, "minimize": true, "autoIndex": null, "discriminatorKey": "__t", "shardKey": null, "read": null, "validateBeforeSave": true, "validateModifiedOnly": false, "_id": true, "id": true, "typeKey": "type", "timestamps": true, "toJSON": { "virtuals": true }, "toObject": { "virtuals": true }, "pluralization": true }, "caster": { "path": "books", "instance": "ObjectId", "validators": [], "getters": [], "setters": [], "_presplitPath": ["books"], "options": { "ref": "Book" }, "_index": null, "_arrayPath": "books.$", "_arrayParentPath": "books" }, "$embeddedSchemaType": { "path": "books", "instance": "ObjectId", "validators": [], "getters": [], "setters": [], "_presplitPath": ["books"], "options": { "ref": "Book" }, "_index": null, "_arrayPath": "books.$", "_arrayParentPath": "books" }, "$isMongooseArray": true, "path": "books", "instance": "Array", "validators": [], "getters": [], "setters": [], "_presplitPath": ["books"], "options": { "type": [{ "ref": "Book" }] }, "_index": null },
17
+ { "path": "book", "instance": "ObjectId", "validators": [], "getters": [], "setters": [], "_presplitPath": ["book"], "options": { "ref": "Book" }, "_index": null },
18
+ { "path": "isActive", "instance": "Boolean", "validators": [], "getters": [], "setters": [], "_presplitPath": ["isActive"], "options": { "default": true }, "_index": null, "defaultValue": true },
19
+ { "path": "_id", "instance": "ObjectId", "validators": [], "getters": [], "setters": [null], "_presplitPath": ["_id"], "options": { "auto": true, "type": "ObjectId" }, "_index": null },
20
+ { "path": "createdAt", "instance": "Date", "validators": [], "getters": [], "setters": [null, null], "_presplitPath": ["createdAt"], "options": { "immutable": true }, "_index": null, "$immutable": true },
21
+ { "path": "updatedAt", "instance": "Date", "validators": [], "getters": [], "setters": [], "_presplitPath": ["updatedAt"], "options": {}, "_index": null },
22
+ { "path": "__v", "instance": "Number", "validators": [], "getters": [], "setters": [], "_presplitPath": ["__v"], "options": {}, "_index": null }
23
+ ];
24
+ describe('getPathsWithRef', () => {
25
+ it('returns correct values', () => {
26
+ const results = (0, getPathsWithRef_1.getPathsWithRef)(data);
27
+ });
28
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getPropertyFromDotNotation.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPropertyFromDotNotation.spec.d.ts","sourceRoot":"","sources":["../../src/tests/getPropertyFromDotNotation.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Import the function (assuming it's exported from a module)
4
+ const dotNotation_1 = require("../utils/dotNotation");
5
+ describe('getPropertyFromDotNotation', () => {
6
+ const testObject = {
7
+ user: {
8
+ profile: {
9
+ name: 'John Doe',
10
+ age: 30,
11
+ address: {
12
+ street: '123 Main St',
13
+ city: 'New York',
14
+ zipCode: '10001'
15
+ }
16
+ },
17
+ settings: {
18
+ theme: 'dark',
19
+ notifications: {
20
+ email: true,
21
+ push: false,
22
+ sms: null
23
+ }
24
+ },
25
+ tags: ['admin', 'user'],
26
+ active: true,
27
+ score: 0,
28
+ metadata: {
29
+ created: '2023-01-01',
30
+ updated: null
31
+ }
32
+ },
33
+ app: {
34
+ version: '1.0.0',
35
+ features: {
36
+ auth: true
37
+ }
38
+ }
39
+ };
40
+ test('should retrieve simple nested property', () => {
41
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.profile.name');
42
+ expect(result).toBe('John Doe');
43
+ });
44
+ test('should retrieve deeply nested property', () => {
45
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.profile.address.street');
46
+ expect(result).toBe('123 Main St');
47
+ });
48
+ test('should retrieve top-level property', () => {
49
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'app');
50
+ expect(result).toEqual({
51
+ version: '1.0.0',
52
+ features: {
53
+ auth: true
54
+ }
55
+ });
56
+ });
57
+ test('should retrieve array property', () => {
58
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.tags');
59
+ expect(result).toEqual(['admin', 'user']);
60
+ });
61
+ test('should retrieve boolean property', () => {
62
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.active');
63
+ expect(result).toBe(true);
64
+ const result2 = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.settings.notifications.push');
65
+ expect(result2).toBe(false);
66
+ });
67
+ test('should retrieve number property including zero', () => {
68
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.profile.age');
69
+ expect(result).toBe(30);
70
+ const result2 = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.score');
71
+ expect(result2).toBe(0);
72
+ });
73
+ test('should retrieve null values', () => {
74
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.settings.notifications.sms');
75
+ expect(result).toBeNull();
76
+ const result2 = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.metadata.updated');
77
+ expect(result2).toBeNull();
78
+ });
79
+ test('should return undefined for non-existent property', () => {
80
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.nonExistent');
81
+ expect(result).toBeUndefined();
82
+ });
83
+ test('should return undefined for deeply nested non-existent property', () => {
84
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, 'user.profile.nonExistent.deeply.nested');
85
+ expect(result).toBeUndefined();
86
+ });
87
+ test('should handle empty path', () => {
88
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(testObject, '');
89
+ expect(result).toBeUndefined();
90
+ });
91
+ test('should handle single property name (no dots)', () => {
92
+ const simpleObject = { name: 'test' };
93
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(simpleObject, 'name');
94
+ expect(result).toBe('test');
95
+ });
96
+ test('should handle null object', () => {
97
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(null, 'user.name');
98
+ expect(result).toBeNull();
99
+ });
100
+ test('should handle undefined object', () => {
101
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(undefined, 'user.name');
102
+ expect(result).toBeUndefined();
103
+ });
104
+ test('should handle empty object', () => {
105
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)({}, 'user.name');
106
+ expect(result).toBeUndefined();
107
+ });
108
+ test('should handle path with empty string segments', () => {
109
+ const objWithEmptyKey = {
110
+ user: {
111
+ '': {
112
+ name: 'test'
113
+ }
114
+ }
115
+ };
116
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(objWithEmptyKey, 'user..name');
117
+ expect(result).toBe('test');
118
+ });
119
+ test('should handle numeric string keys', () => {
120
+ const objWithNumericKeys = {
121
+ items: {
122
+ '0': 'first',
123
+ '1': 'second'
124
+ }
125
+ };
126
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(objWithNumericKeys, 'items.0');
127
+ expect(result).toBe('first');
128
+ });
129
+ test('should handle array access with numeric keys', () => {
130
+ const objWithArray = {
131
+ list: ['item1', 'item2', 'item3']
132
+ };
133
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(objWithArray, 'list.1');
134
+ expect(result).toBe('item2');
135
+ });
136
+ test('should handle special characters in keys', () => {
137
+ const objWithSpecialKeys = {
138
+ 'user-name': 'test',
139
+ 'user_id': 123,
140
+ 'user@domain': 'email'
141
+ };
142
+ expect((0, dotNotation_1.getPropertyFromDotNotation)(objWithSpecialKeys, 'user-name')).toBe('test');
143
+ expect((0, dotNotation_1.getPropertyFromDotNotation)(objWithSpecialKeys, 'user_id')).toBe(123);
144
+ expect((0, dotNotation_1.getPropertyFromDotNotation)(objWithSpecialKeys, 'user@domain')).toBe('email');
145
+ });
146
+ test('should handle complex nested structures', () => {
147
+ const complexObject = {
148
+ data: {
149
+ results: [
150
+ { id: 1, name: 'First' },
151
+ { id: 2, name: 'Second' }
152
+ ],
153
+ pagination: {
154
+ total: 2,
155
+ page: 1
156
+ }
157
+ }
158
+ };
159
+ expect((0, dotNotation_1.getPropertyFromDotNotation)(complexObject, 'data.results.0.name')).toBe('First');
160
+ expect((0, dotNotation_1.getPropertyFromDotNotation)(complexObject, 'data.pagination.total')).toBe(2);
161
+ });
162
+ test('should handle function properties', () => {
163
+ const objWithFunction = {
164
+ utils: {
165
+ getValue: () => 'function result'
166
+ }
167
+ };
168
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(objWithFunction, 'utils.getValue');
169
+ expect(typeof result).toBe('function');
170
+ expect(result()).toBe('function result');
171
+ });
172
+ test('should handle Symbol keys', () => {
173
+ const symbolKey = Symbol('test');
174
+ const objWithSymbol = {
175
+ data: {
176
+ [symbolKey]: 'symbol value'
177
+ }
178
+ };
179
+ // This should return undefined since symbols can't be accessed via string paths
180
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(objWithSymbol, 'data.Symbol(test)');
181
+ expect(result).toBeUndefined();
182
+ });
183
+ test('should handle prototype chain properties', () => {
184
+ function TestClass() {
185
+ this.instanceProp = 'instance';
186
+ }
187
+ TestClass.prototype.prototypeProp = 'prototype';
188
+ const instance = new TestClass();
189
+ expect((0, dotNotation_1.getPropertyFromDotNotation)(instance, 'instanceProp')).toBe('instance');
190
+ expect((0, dotNotation_1.getPropertyFromDotNotation)(instance, 'prototypeProp')).toBe('prototype');
191
+ });
192
+ test('should handle Date objects', () => {
193
+ const objWithDate = {
194
+ event: {
195
+ date: new Date('2023-01-01T10:00:00Z')
196
+ }
197
+ };
198
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(objWithDate, 'event.date');
199
+ expect(result).toBeInstanceOf(Date);
200
+ expect(result.getFullYear()).toBe(2023);
201
+ });
202
+ test('should handle performance with deeply nested objects', () => {
203
+ // Create a deeply nested object
204
+ let deepObject = { value: 'deep' };
205
+ let path = 'value';
206
+ for (let i = 0; i < 100; i++) {
207
+ deepObject = { level: deepObject };
208
+ path = 'level.' + path;
209
+ }
210
+ const result = (0, dotNotation_1.getPropertyFromDotNotation)(deepObject, path);
211
+ expect(result).toBe('deep');
212
+ });
213
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=insertPopulate.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insertPopulate.spec.d.ts","sourceRoot":"","sources":["../../src/tests/insertPopulate.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_assert_1 = __importDefault(require("node:assert"));
7
+ const parsePopulateQuery_1 = require("../utils/parsePopulateQuery");
8
+ describe('parsePopulateQuery', () => {
9
+ it('should return a populated path object', () => {
10
+ const { pop, select } = { pop: ['books'], select: [] };
11
+ const [r1] = (0, parsePopulateQuery_1.parsePopulateArray)(pop, select);
12
+ (0, node_assert_1.default)(r1.hasOwnProperty('path'), 'object does not contain path key');
13
+ (0, node_assert_1.default)(!r1.hasOwnProperty('select'), 'object contains a select key');
14
+ (0, node_assert_1.default)(r1.path === 'books', 'object contains expected value in path object');
15
+ });
16
+ it('should return a populated path and selectobject', () => {
17
+ const { pop, select } = { pop: ['books'], select: ['books.items'] };
18
+ const [r1] = (0, parsePopulateQuery_1.parsePopulateArray)(pop, select);
19
+ (0, node_assert_1.default)(r1.hasOwnProperty('path'), 'object does not contain path key');
20
+ (0, node_assert_1.default)(r1.hasOwnProperty('select'), 'object contains a select key');
21
+ (0, node_assert_1.default)(r1.path === 'books', 'object contains expected value in path object');
22
+ (0, node_assert_1.default)(r1.select.hasOwnProperty('items'), 'object contains expected value in select object');
23
+ (0, node_assert_1.default)(r1.select.items === 1, 'object contains expected value in select object');
24
+ });
25
+ it('should return a falsy 0 in the item select', () => {
26
+ const { pop, select } = { pop: ['books'], select: ['books.-items'] };
27
+ const [r1] = (0, parsePopulateQuery_1.parsePopulateArray)(pop, select);
28
+ (0, node_assert_1.default)(r1.hasOwnProperty('path'), 'object does not contain path key');
29
+ (0, node_assert_1.default)(r1.hasOwnProperty('select'), 'object contains a select key');
30
+ (0, node_assert_1.default)(r1.path === 'books', 'object contains expected value in path object');
31
+ (0, node_assert_1.default)(r1.select.hasOwnProperty('items'), 'object contains expected value in select object');
32
+ (0, node_assert_1.default)(r1.select.items === 0, 'object contains expected value in select object');
33
+ });
34
+ it('should return array with more than one item', () => {
35
+ const { pop, select } = { pop: ['books', 'author'], select: [] };
36
+ const popArr = (0, parsePopulateQuery_1.parsePopulateArray)(pop, select);
37
+ const [r1, r2] = popArr;
38
+ node_assert_1.default.equal(popArr.length, 2, 'array has the proper length');
39
+ (0, node_assert_1.default)(r1.hasOwnProperty('path'), 'object does not contain path key');
40
+ (0, node_assert_1.default)(!r1.hasOwnProperty('select'), 'object contains a select key');
41
+ (0, node_assert_1.default)(r1.path === 'books', 'object contains expected value in path object');
42
+ (0, node_assert_1.default)(r2.hasOwnProperty('path'), 'object does not contain path key');
43
+ (0, node_assert_1.default)(!r2.hasOwnProperty('select'), 'object contains a select key');
44
+ (0, node_assert_1.default)(r2.path === 'author', 'object contains expected value in path object');
45
+ });
46
+ it('should return array with more than one item and select', () => {
47
+ const { pop, select } = { pop: ['books', 'author'], select: ['books.items', 'author.-items.passage', 'author.test.passage'] };
48
+ const popArr = (0, parsePopulateQuery_1.parsePopulateArray)(pop, select);
49
+ const [r1, r2] = popArr;
50
+ node_assert_1.default.equal(popArr.length, 2, 'array has the proper length');
51
+ (0, node_assert_1.default)(r1.hasOwnProperty('path'), 'object does not contain path key');
52
+ (0, node_assert_1.default)(r1.hasOwnProperty('select'), 'object contains a select key');
53
+ (0, node_assert_1.default)(r1.select.hasOwnProperty('items'), 'object contains a select key');
54
+ (0, node_assert_1.default)(r1.path === 'books', 'object contains expected value in path object');
55
+ (0, node_assert_1.default)(r1.select.items === 1, 'object contains expected value in path object');
56
+ (0, node_assert_1.default)(r2.hasOwnProperty('path'), 'object does not contain path key');
57
+ (0, node_assert_1.default)(r2.hasOwnProperty('select'), 'object contains a select key');
58
+ (0, node_assert_1.default)(r2.select.hasOwnProperty('items.passage'), 'object contains a select key');
59
+ (0, node_assert_1.default)(r2.select.hasOwnProperty('test.passage'), 'object contains a select key');
60
+ node_assert_1.default.equal(r2.select['items.passage'], 0, 'objects select key is the correct value');
61
+ node_assert_1.default.equal(r2.select['test.passage'], 1, 'objects select key is the correct value');
62
+ (0, node_assert_1.default)(r2.path === 'author', 'object contains expected value in path object');
63
+ });
64
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pagingQuery.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagingQuery.spec.d.ts","sourceRoot":"","sources":["../../src/tests/pagingQuery.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mockingoose = require('mockingoose');
4
+ const node_mocks_http_1 = require("node-mocks-http");
5
+ const req = (0, node_mocks_http_1.createRequest)({ query: {
6
+ $filter: '{"a":123}',
7
+ $sort: 'name 1', '$populate': 'books'
8
+ } });
9
+ describe('PagingQuery', () => {
10
+ beforeEach(() => {
11
+ // Reset mockingoose before each test to ensure isolation
12
+ // mockingoose.resetAll();
13
+ });
14
+ test('should have standard params on new', () => {
15
+ /*
16
+ mockingoose(Author)
17
+ const obj = new PagingQuery(req, Author, {sanitizeFilter: true})
18
+
19
+ assert.equal(obj.params.$limit,25)*/
20
+ });
21
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=parseSortString.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSortString.spec.d.ts","sourceRoot":"","sources":["../../src/tests/parseSortString.spec.ts"],"names":[],"mappings":""}