@r5v/mongoose-paginate 1.0.13 → 1.0.15
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 +210 -17
- package/dist/{types/aggregationPagingQuery.d.ts → aggregationPagingQuery.d.ts} +6 -7
- package/dist/aggregationPagingQuery.d.ts.map +1 -0
- package/dist/aggregationPagingQuery.js +19 -4
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -1
- package/dist/{types/pagingQuery.d.ts → pagingQuery.d.ts} +6 -7
- package/dist/pagingQuery.d.ts.map +1 -0
- package/dist/pagingQuery.js +8 -3
- package/dist/tests/aggregationPagingQuery.spec.d.ts +2 -0
- package/dist/tests/aggregationPagingQuery.spec.d.ts.map +1 -0
- package/dist/tests/aggregationPagingQuery.spec.js +419 -0
- package/dist/tests/buildPopulateFromString.spec.d.ts +2 -0
- package/dist/tests/buildPopulateFromString.spec.d.ts.map +1 -0
- package/dist/tests/buildPopulateFromString.spec.js +223 -0
- package/dist/tests/dotNotation.spec.d.ts.map +1 -0
- package/dist/tests/findProtectedPaths.spec.d.ts.map +1 -0
- package/dist/tests/findProtectedPaths.spec.js +128 -6
- package/dist/tests/getPathsWithRef.spec.d.ts.map +1 -0
- package/dist/tests/getPathsWithRef.spec.js +92 -18
- package/dist/tests/getPropertyFromDotNotation.spec.d.ts.map +1 -0
- package/dist/tests/insertPopulate.spec.d.ts.map +1 -0
- package/dist/tests/isJsonString.spec.d.ts +2 -0
- package/dist/tests/isJsonString.spec.d.ts.map +1 -0
- package/dist/tests/isJsonString.spec.js +116 -0
- package/dist/tests/isValidDateString.spec.d.ts +2 -0
- package/dist/tests/isValidDateString.spec.d.ts.map +1 -0
- package/dist/tests/isValidDateString.spec.js +116 -0
- package/dist/tests/pagingQuery.spec.d.ts.map +1 -0
- package/dist/tests/pagingQuery.spec.js +238 -13
- package/dist/tests/parseParams.spec.d.ts +2 -0
- package/dist/tests/parseParams.spec.d.ts.map +1 -0
- package/dist/tests/parseParams.spec.js +212 -0
- package/dist/tests/parseSortString.spec.d.ts.map +1 -0
- package/dist/tests/schemaTraversal.spec.d.ts +2 -0
- package/dist/tests/schemaTraversal.spec.d.ts.map +1 -0
- package/dist/tests/schemaTraversal.spec.js +139 -0
- package/dist/types/index.d.ts +72 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/buildPopulateFromString.d.ts +8 -0
- package/dist/utils/buildPopulateFromString.d.ts.map +1 -0
- package/dist/utils/buildPopulateFromString.js +54 -49
- package/dist/utils/dotNotation.d.ts +11 -0
- package/dist/utils/dotNotation.d.ts.map +1 -0
- package/dist/utils/dotNotation.js +2 -2
- package/dist/utils/findKeyWithValue.d.ts.map +1 -0
- package/dist/utils/findProtectedPaths.d.ts.map +1 -0
- package/dist/utils/findProtectedPaths.js +14 -56
- package/dist/utils/getPathsWithRef.d.ts +5 -0
- package/dist/utils/getPathsWithRef.d.ts.map +1 -0
- package/dist/utils/getPathsWithRef.js +59 -96
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +33 -0
- package/dist/utils/isJsonString.d.ts.map +1 -0
- package/dist/utils/isValidDateString.d.ts.map +1 -0
- package/dist/utils/parseParams.d.ts.map +1 -0
- package/dist/utils/parseParams.js +14 -12
- package/dist/utils/parsePopulateQuery.d.ts.map +1 -0
- package/dist/utils/parsePopulateQuery.js +1 -1
- package/dist/{types/utils → utils}/parseSortString.d.ts +1 -1
- package/dist/utils/parseSortString.d.ts.map +1 -0
- package/dist/utils/schemaTraversal.d.ts +9 -0
- package/dist/utils/schemaTraversal.d.ts.map +1 -0
- package/dist/utils/schemaTraversal.js +37 -0
- package/package.json +23 -2
- package/dist/types/aggregationPagingQuery.d.ts.map +0 -1
- package/dist/types/pagingQuery.d.ts.map +0 -1
- package/dist/types/tests/dotNotation.spec.d.ts.map +0 -1
- package/dist/types/tests/findProtectedPaths.spec.d.ts.map +0 -1
- package/dist/types/tests/getPathsWithRef.spec.d.ts.map +0 -1
- package/dist/types/tests/getPropertyFromDotNotation.spec.d.ts.map +0 -1
- package/dist/types/tests/insertPopulate.spec.d.ts.map +0 -1
- package/dist/types/tests/pagingQuery.spec.d.ts.map +0 -1
- package/dist/types/tests/parseSortString.spec.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -61
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/utils/buildPopulateFromString.d.ts +0 -8
- package/dist/types/utils/buildPopulateFromString.d.ts.map +0 -1
- package/dist/types/utils/dotNotation.d.ts +0 -11
- package/dist/types/utils/dotNotation.d.ts.map +0 -1
- package/dist/types/utils/findKeyWithValue.d.ts.map +0 -1
- package/dist/types/utils/findProtectedPaths.d.ts.map +0 -1
- package/dist/types/utils/getPathsWithRef.d.ts +0 -5
- package/dist/types/utils/getPathsWithRef.d.ts.map +0 -1
- package/dist/types/utils/isJsonString.d.ts.map +0 -1
- package/dist/types/utils/isValidDateString.d.ts.map +0 -1
- package/dist/types/utils/parseParams.d.ts.map +0 -1
- package/dist/types/utils/parsePopulateQuery.d.ts.map +0 -1
- package/dist/types/utils/parseSortString.d.ts.map +0 -1
- /package/dist/{types/tests → tests}/dotNotation.spec.d.ts +0 -0
- /package/dist/{types/tests → tests}/findProtectedPaths.spec.d.ts +0 -0
- /package/dist/{types/tests → tests}/getPathsWithRef.spec.d.ts +0 -0
- /package/dist/{types/tests → tests}/getPropertyFromDotNotation.spec.d.ts +0 -0
- /package/dist/{types/tests → tests}/insertPopulate.spec.d.ts +0 -0
- /package/dist/{types/tests → tests}/pagingQuery.spec.d.ts +0 -0
- /package/dist/{types/tests → tests}/parseSortString.spec.d.ts +0 -0
- /package/dist/{types/utils → utils}/findKeyWithValue.d.ts +0 -0
- /package/dist/{types/utils → utils}/findProtectedPaths.d.ts +0 -0
- /package/dist/{types/utils → utils}/isJsonString.d.ts +0 -0
- /package/dist/{types/utils → utils}/isValidDateString.d.ts +0 -0
- /package/dist/{types/utils → utils}/parseParams.d.ts +0 -0
- /package/dist/{types/utils → utils}/parsePopulateQuery.d.ts +0 -0
|
@@ -1,11 +1,133 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
2
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
45
|
+
const findProtectedPaths_1 = require("../utils/findProtectedPaths");
|
|
46
|
+
const mongoose_1 = __importStar(require("mongoose"));
|
|
5
47
|
describe('findProtectedPaths', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
48
|
+
afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
// Clean up mongoose connections
|
|
50
|
+
yield mongoose_1.default.disconnect();
|
|
51
|
+
}));
|
|
52
|
+
test('should return empty array for schema with no protected paths', () => {
|
|
53
|
+
const schema = new mongoose_1.Schema({
|
|
54
|
+
name: { type: String },
|
|
55
|
+
age: { type: Number }
|
|
56
|
+
});
|
|
57
|
+
const model = mongoose_1.default.model('NoProtectedModel', schema);
|
|
58
|
+
const results = (0, findProtectedPaths_1.findProtectedPaths)(model);
|
|
59
|
+
expect(results).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
test('should find paths with select: false', () => {
|
|
62
|
+
const schema = new mongoose_1.Schema({
|
|
63
|
+
name: { type: String },
|
|
64
|
+
password: { type: String, select: false },
|
|
65
|
+
email: { type: String }
|
|
66
|
+
});
|
|
67
|
+
const model = mongoose_1.default.model('ProtectedModel', schema);
|
|
68
|
+
const results = (0, findProtectedPaths_1.findProtectedPaths)(model);
|
|
69
|
+
expect(results).toContain('password');
|
|
70
|
+
});
|
|
71
|
+
test('should find multiple protected paths', () => {
|
|
72
|
+
const schema = new mongoose_1.Schema({
|
|
73
|
+
name: { type: String },
|
|
74
|
+
password: { type: String, select: false },
|
|
75
|
+
secretKey: { type: String, select: false },
|
|
76
|
+
email: { type: String }
|
|
77
|
+
});
|
|
78
|
+
const model = mongoose_1.default.model('MultiProtectedModel', schema);
|
|
79
|
+
const results = (0, findProtectedPaths_1.findProtectedPaths)(model);
|
|
80
|
+
expect(results).toContain('password');
|
|
81
|
+
expect(results).toContain('secretKey');
|
|
82
|
+
expect(results.length).toBe(2);
|
|
83
|
+
});
|
|
84
|
+
test('should find protected paths in nested objects', () => {
|
|
85
|
+
const schema = new mongoose_1.Schema({
|
|
86
|
+
name: { type: String },
|
|
87
|
+
profile: {
|
|
88
|
+
bio: { type: String },
|
|
89
|
+
privateData: { type: String, select: false }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const model = mongoose_1.default.model('NestedProtectedModel', schema);
|
|
93
|
+
const results = (0, findProtectedPaths_1.findProtectedPaths)(model);
|
|
94
|
+
expect(results.some(p => p.includes('privateData'))).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
test('should handle schema with mixed regular and protected fields', () => {
|
|
97
|
+
const schema = new mongoose_1.Schema({
|
|
98
|
+
username: { type: String, required: true },
|
|
99
|
+
email: { type: String, unique: true },
|
|
100
|
+
password: { type: String, select: false },
|
|
101
|
+
apiKey: { type: String, select: false },
|
|
102
|
+
createdAt: { type: Date, default: Date.now }
|
|
103
|
+
});
|
|
104
|
+
const model = mongoose_1.default.model('MixedFieldsModel', schema);
|
|
105
|
+
const results = (0, findProtectedPaths_1.findProtectedPaths)(model);
|
|
106
|
+
expect(results).toContain('password');
|
|
107
|
+
expect(results).toContain('apiKey');
|
|
108
|
+
expect(results).not.toContain('username');
|
|
109
|
+
expect(results).not.toContain('email');
|
|
110
|
+
expect(results).not.toContain('createdAt');
|
|
111
|
+
});
|
|
112
|
+
test('should handle deeply nested schema with protected paths', () => {
|
|
113
|
+
const nestedSchema = new mongoose_1.Schema({
|
|
114
|
+
secret: { type: String, select: false }
|
|
115
|
+
}, { _id: false });
|
|
116
|
+
const schema = new mongoose_1.Schema({
|
|
117
|
+
name: { type: String },
|
|
118
|
+
nested: nestedSchema
|
|
119
|
+
});
|
|
120
|
+
const model = mongoose_1.default.model('DeepNestedModel', schema);
|
|
121
|
+
const results = (0, findProtectedPaths_1.findProtectedPaths)(model);
|
|
122
|
+
expect(results.some(p => p.includes('secret'))).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
test('should return empty array when schema has simple array fields', () => {
|
|
125
|
+
const schema = new mongoose_1.Schema({
|
|
126
|
+
tags: [String],
|
|
127
|
+
scores: [Number]
|
|
128
|
+
});
|
|
129
|
+
const model = mongoose_1.default.model('ArrayFieldsModel', schema);
|
|
130
|
+
const results = (0, findProtectedPaths_1.findProtectedPaths)(model);
|
|
131
|
+
expect(Array.isArray(results)).toBe(true);
|
|
10
132
|
});
|
|
11
133
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPathsWithRef.spec.d.ts","sourceRoot":"","sources":["../../src/tests/getPathsWithRef.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,28 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getPathsWithRef_1 = require("../utils/getPathsWithRef");
|
|
4
|
-
const
|
|
4
|
+
const sampleSchemaData = [
|
|
5
|
+
{ "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
6
|
{ "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
7
|
{ "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
|
-
{ "
|
|
8
|
-
{ "path": "
|
|
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 },
|
|
8
|
+
{ "schemaOptions": { "strict": 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 },
|
|
9
|
+
{ "path": "author", "instance": "ObjectId", "validators": [], "getters": [], "setters": [], "_presplitPath": ["author"], "options": { "ref": "Author" }, "_index": null },
|
|
18
10
|
{ "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 }
|
|
11
|
+
{ "path": "_id", "instance": "ObjectId", "validators": [], "getters": [], "setters": [null], "_presplitPath": ["_id"], "options": { "auto": true, "type": "ObjectId" }, "_index": null }
|
|
23
12
|
];
|
|
24
13
|
describe('getPathsWithRef', () => {
|
|
25
|
-
|
|
26
|
-
const results = (0, getPathsWithRef_1.getPathsWithRef)(
|
|
14
|
+
test('should return correct paths with ref from array data', () => {
|
|
15
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(sampleSchemaData);
|
|
16
|
+
expect(Array.isArray(results)).toBe(true);
|
|
17
|
+
expect(results.length).toBeGreaterThan(0);
|
|
18
|
+
const paths = results.map(r => r.path);
|
|
19
|
+
expect(paths).toContain('books');
|
|
20
|
+
expect(paths).toContain('author');
|
|
21
|
+
});
|
|
22
|
+
test('should return path and options for each ref', () => {
|
|
23
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(sampleSchemaData);
|
|
24
|
+
results.forEach(result => {
|
|
25
|
+
expect(result).toHaveProperty('path');
|
|
26
|
+
expect(result).toHaveProperty('options');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
test('should correctly identify ref in options', () => {
|
|
30
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(sampleSchemaData);
|
|
31
|
+
const authorRef = results.find(r => r.path === 'author');
|
|
32
|
+
expect(authorRef).toBeDefined();
|
|
33
|
+
expect(authorRef === null || authorRef === void 0 ? void 0 : authorRef.options.ref).toBe('Author');
|
|
34
|
+
});
|
|
35
|
+
test('should correctly identify ref in array type', () => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(sampleSchemaData);
|
|
38
|
+
const booksRef = results.find(r => r.path === 'books');
|
|
39
|
+
expect(booksRef).toBeDefined();
|
|
40
|
+
// For array types, the ref is in options.type[0].ref or caster.options.ref
|
|
41
|
+
expect(((_b = (_a = booksRef === null || booksRef === void 0 ? void 0 : booksRef.options.type) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.ref) || (booksRef === null || booksRef === void 0 ? void 0 : booksRef.options.ref)).toBe('Book');
|
|
42
|
+
});
|
|
43
|
+
test('should not include paths without ref', () => {
|
|
44
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(sampleSchemaData);
|
|
45
|
+
const paths = results.map(r => r.path);
|
|
46
|
+
expect(paths).not.toContain('firstName');
|
|
47
|
+
expect(paths).not.toContain('lastName');
|
|
48
|
+
expect(paths).not.toContain('email');
|
|
49
|
+
expect(paths).not.toContain('isActive');
|
|
50
|
+
expect(paths).not.toContain('_id');
|
|
51
|
+
});
|
|
52
|
+
test('should handle empty array', () => {
|
|
53
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)([]);
|
|
54
|
+
expect(Array.isArray(results)).toBe(true);
|
|
55
|
+
expect(results.length).toBe(0);
|
|
56
|
+
});
|
|
57
|
+
test('should handle array with no refs', () => {
|
|
58
|
+
const dataWithoutRefs = [
|
|
59
|
+
{ "path": "name", "instance": "String", "options": { "required": true } },
|
|
60
|
+
{ "path": "age", "instance": "Number", "options": {} }
|
|
61
|
+
];
|
|
62
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(dataWithoutRefs);
|
|
63
|
+
expect(results.length).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
test('should handle string input', () => {
|
|
66
|
+
const stringData = JSON.stringify({ "path": "user", "instance": "ObjectId", "options": { "ref": "User" } });
|
|
67
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(stringData);
|
|
68
|
+
expect(Array.isArray(results)).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
test('should not have duplicate paths', () => {
|
|
71
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(sampleSchemaData);
|
|
72
|
+
const paths = results.map(r => r.path);
|
|
73
|
+
const uniquePaths = [...new Set(paths)];
|
|
74
|
+
expect(paths.length).toBe(uniquePaths.length);
|
|
75
|
+
});
|
|
76
|
+
test('should handle nested refs in options.type array', () => {
|
|
77
|
+
const nestedRefData = [
|
|
78
|
+
{
|
|
79
|
+
"path": "categories",
|
|
80
|
+
"instance": "Array",
|
|
81
|
+
"options": {
|
|
82
|
+
"type": [{ "ref": "Category" }]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(nestedRefData);
|
|
87
|
+
expect(results.some(r => r.path === 'categories')).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
test('should handle ref in options.type object', () => {
|
|
90
|
+
const typeObjectRefData = [
|
|
91
|
+
{
|
|
92
|
+
"path": "parent",
|
|
93
|
+
"instance": "ObjectId",
|
|
94
|
+
"options": {
|
|
95
|
+
"type": { "ref": "Parent" }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
const results = (0, getPathsWithRef_1.getPathsWithRef)(typeObjectRefData);
|
|
100
|
+
expect(results.some(r => r.path === 'parent')).toBe(true);
|
|
27
101
|
});
|
|
28
102
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPropertyFromDotNotation.spec.d.ts","sourceRoot":"","sources":["../../src/tests/getPropertyFromDotNotation.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insertPopulate.spec.d.ts","sourceRoot":"","sources":["../../src/tests/insertPopulate.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isJsonString.spec.d.ts","sourceRoot":"","sources":["../../src/tests/isJsonString.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const isJsonString_1 = require("../utils/isJsonString");
|
|
4
|
+
describe('isJsonString', () => {
|
|
5
|
+
describe('valid JSON strings', () => {
|
|
6
|
+
test('should return true for empty object', () => {
|
|
7
|
+
expect((0, isJsonString_1.isJsonString)('{}')).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
test('should return true for empty array', () => {
|
|
10
|
+
expect((0, isJsonString_1.isJsonString)('[]')).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
test('should return true for simple object', () => {
|
|
13
|
+
expect((0, isJsonString_1.isJsonString)('{"name":"John"}')).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
test('should return true for simple array', () => {
|
|
16
|
+
expect((0, isJsonString_1.isJsonString)('[1,2,3]')).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
test('should return true for nested object', () => {
|
|
19
|
+
expect((0, isJsonString_1.isJsonString)('{"user":{"name":"John","age":30}}')).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
test('should return true for array of objects', () => {
|
|
22
|
+
expect((0, isJsonString_1.isJsonString)('[{"id":1},{"id":2}]')).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
test('should return true for string value', () => {
|
|
25
|
+
expect((0, isJsonString_1.isJsonString)('"hello"')).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
test('should return true for number value', () => {
|
|
28
|
+
expect((0, isJsonString_1.isJsonString)('123')).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
test('should return true for boolean true', () => {
|
|
31
|
+
expect((0, isJsonString_1.isJsonString)('true')).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
test('should return true for boolean false', () => {
|
|
34
|
+
expect((0, isJsonString_1.isJsonString)('false')).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
test('should return true for null', () => {
|
|
37
|
+
expect((0, isJsonString_1.isJsonString)('null')).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
test('should return true for complex nested structure', () => {
|
|
40
|
+
const complex = JSON.stringify({
|
|
41
|
+
users: [
|
|
42
|
+
{ id: 1, profile: { name: 'John', tags: ['admin', 'user'] } },
|
|
43
|
+
{ id: 2, profile: { name: 'Jane', tags: ['user'] } }
|
|
44
|
+
],
|
|
45
|
+
meta: { total: 2, page: 1 }
|
|
46
|
+
});
|
|
47
|
+
expect((0, isJsonString_1.isJsonString)(complex)).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
test('should return true for JSON with special characters', () => {
|
|
50
|
+
expect((0, isJsonString_1.isJsonString)('{"message":"Hello\\nWorld"}')).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
test('should return true for JSON with unicode', () => {
|
|
53
|
+
expect((0, isJsonString_1.isJsonString)('{"emoji":"\\u2764"}')).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('invalid JSON strings', () => {
|
|
57
|
+
test('should return false for plain text', () => {
|
|
58
|
+
expect((0, isJsonString_1.isJsonString)('hello world')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
test('should return false for single quotes', () => {
|
|
61
|
+
expect((0, isJsonString_1.isJsonString)("{'name':'John'}")).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
test('should return false for missing quotes on keys', () => {
|
|
64
|
+
expect((0, isJsonString_1.isJsonString)('{name:"John"}')).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
test('should return false for trailing comma', () => {
|
|
67
|
+
expect((0, isJsonString_1.isJsonString)('{"name":"John",}')).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
test('should return false for unclosed object', () => {
|
|
70
|
+
expect((0, isJsonString_1.isJsonString)('{"name":"John"')).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
test('should return false for unclosed array', () => {
|
|
73
|
+
expect((0, isJsonString_1.isJsonString)('[1,2,3')).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
test('should return false for undefined', () => {
|
|
76
|
+
expect((0, isJsonString_1.isJsonString)('undefined')).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
test('should return false for NaN', () => {
|
|
79
|
+
expect((0, isJsonString_1.isJsonString)('NaN')).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
test('should return false for Infinity', () => {
|
|
82
|
+
expect((0, isJsonString_1.isJsonString)('Infinity')).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
test('should return false for JavaScript object literal', () => {
|
|
85
|
+
expect((0, isJsonString_1.isJsonString)('{name: "John"}')).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
test('should return false for empty string', () => {
|
|
88
|
+
expect((0, isJsonString_1.isJsonString)('')).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
test('should return false for whitespace only', () => {
|
|
91
|
+
expect((0, isJsonString_1.isJsonString)(' ')).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
test('should return false for function', () => {
|
|
94
|
+
expect((0, isJsonString_1.isJsonString)('function() {}')).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
test('should return false for date string', () => {
|
|
97
|
+
expect((0, isJsonString_1.isJsonString)('2023-01-01')).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe('edge cases', () => {
|
|
101
|
+
test('should return true for deeply nested structure', () => {
|
|
102
|
+
const deep = '{"a":{"b":{"c":{"d":{"e":"value"}}}}}';
|
|
103
|
+
expect((0, isJsonString_1.isJsonString)(deep)).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
test('should return true for large array', () => {
|
|
106
|
+
const arr = JSON.stringify(Array.from({ length: 1000 }, (_, i) => i));
|
|
107
|
+
expect((0, isJsonString_1.isJsonString)(arr)).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
test('should return true for JSON with whitespace', () => {
|
|
110
|
+
expect((0, isJsonString_1.isJsonString)('{ "name" : "John" }')).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
test('should return true for JSON with newlines', () => {
|
|
113
|
+
expect((0, isJsonString_1.isJsonString)('{\n "name": "John"\n}')).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidDateString.spec.d.ts","sourceRoot":"","sources":["../../src/tests/isValidDateString.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const isValidDateString_1 = require("../utils/isValidDateString");
|
|
4
|
+
describe('isValidDateString', () => {
|
|
5
|
+
describe('valid ISO 8601 date strings', () => {
|
|
6
|
+
test('should return true for date only (YYYY-MM-DD)', () => {
|
|
7
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15')).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
test('should return true for date with UTC time', () => {
|
|
10
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00Z')).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
test('should return true for date with milliseconds and UTC', () => {
|
|
13
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00.000Z')).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
test('should return true for date with positive timezone offset', () => {
|
|
16
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00+05:30')).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
test('should return true for date with negative timezone offset', () => {
|
|
19
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00-08:00')).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
test('should return true for date with milliseconds and positive offset', () => {
|
|
22
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00.123+05:30')).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
test('should return true for date with milliseconds and negative offset', () => {
|
|
25
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00.999-08:00')).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
test('should return true for midnight UTC', () => {
|
|
28
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T00:00:00Z')).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
test('should return true for end of day UTC', () => {
|
|
31
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T23:59:59Z')).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
test('should return true for leap year date', () => {
|
|
34
|
+
expect((0, isValidDateString_1.isValidDateString)('2024-02-29')).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('invalid date strings', () => {
|
|
38
|
+
test('should return false for empty string', () => {
|
|
39
|
+
expect((0, isValidDateString_1.isValidDateString)('')).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
test('should return false for plain text', () => {
|
|
42
|
+
expect((0, isValidDateString_1.isValidDateString)('hello')).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
test('should return false for number string', () => {
|
|
45
|
+
expect((0, isValidDateString_1.isValidDateString)('12345')).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
test('should return false for MM/DD/YYYY format', () => {
|
|
48
|
+
expect((0, isValidDateString_1.isValidDateString)('01/15/2023')).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
test('should return false for DD/MM/YYYY format', () => {
|
|
51
|
+
expect((0, isValidDateString_1.isValidDateString)('15/01/2023')).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
test('should return false for date with spaces', () => {
|
|
54
|
+
expect((0, isValidDateString_1.isValidDateString)('2023 01 15')).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
test('should return false for date without leading zeros', () => {
|
|
57
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-1-15')).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
test('should return false for time only', () => {
|
|
60
|
+
expect((0, isValidDateString_1.isValidDateString)('10:30:00')).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
test('should return false for Unix timestamp', () => {
|
|
63
|
+
expect((0, isValidDateString_1.isValidDateString)('1673784600')).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
test('should return false for date with invalid month', () => {
|
|
66
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-13-15')).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
test('should return false for date with invalid day', () => {
|
|
69
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-32')).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
test('should handle Feb 29 on non-leap year', () => {
|
|
72
|
+
// Note: The function checks format and Date.parse, not calendar validity
|
|
73
|
+
// Date.parse('2023-02-29') returns a valid date (March 1, 2023)
|
|
74
|
+
// This is expected behavior as the function validates ISO format, not calendar semantics
|
|
75
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-02-29')).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
test('should return false for incomplete date', () => {
|
|
78
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01')).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
test('should return false for date with invalid time separator', () => {
|
|
81
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15 10:30:00')).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
test('should return false for timezone without colon', () => {
|
|
84
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00+0530')).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
test('should return false for date string with text', () => {
|
|
87
|
+
expect((0, isValidDateString_1.isValidDateString)('January 15, 2023')).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
test('should return false for ISO week date', () => {
|
|
90
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-W03-7')).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
test('should return false for ordinal date', () => {
|
|
93
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-015')).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('edge cases', () => {
|
|
97
|
+
test('should return true for year boundary', () => {
|
|
98
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-12-31')).toBe(true);
|
|
99
|
+
expect((0, isValidDateString_1.isValidDateString)('2024-01-01')).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
test('should return true for various millisecond lengths', () => {
|
|
102
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00.1Z')).toBe(true);
|
|
103
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00.12Z')).toBe(true);
|
|
104
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00.123Z')).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
test('should return true for UTC midnight', () => {
|
|
107
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T00:00:00.000Z')).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
test('should return false for date with extra characters', () => {
|
|
110
|
+
expect((0, isValidDateString_1.isValidDateString)('2023-01-15T10:30:00Zextra')).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
test('should return false for date with prefix', () => {
|
|
113
|
+
expect((0, isValidDateString_1.isValidDateString)('date:2023-01-15')).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagingQuery.spec.d.ts","sourceRoot":"","sources":["../../src/tests/pagingQuery.spec.ts"],"names":[],"mappings":""}
|