@dnax/core 0.1.4 → 0.1.6
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/driver/mongo/utils.ts +14 -14
- package/package.json +1 -1
- package/utils/index.ts +5 -1
package/driver/mongo/utils.ts
CHANGED
|
@@ -10,6 +10,20 @@ import { Cfg } from "../../config";
|
|
|
10
10
|
function buildPipeline(params: findParam, col?: Collection | undefined | null) {
|
|
11
11
|
let pipeline = [];
|
|
12
12
|
|
|
13
|
+
// sorted
|
|
14
|
+
if (!params?.$sort?.createdAt) {
|
|
15
|
+
pipeline.push({
|
|
16
|
+
$sort: {
|
|
17
|
+
...(params?.$sort || {}),
|
|
18
|
+
createdAt: -1,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
pipeline.push({
|
|
23
|
+
$sort: params?.$sort,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
// $match
|
|
14
28
|
if (params?.$match) {
|
|
15
29
|
pipeline.push({
|
|
@@ -110,20 +124,6 @@ function buildPipeline(params: findParam, col?: Collection | undefined | null) {
|
|
|
110
124
|
});
|
|
111
125
|
}
|
|
112
126
|
|
|
113
|
-
// sorted
|
|
114
|
-
if (!params?.$sort?.createdAt) {
|
|
115
|
-
pipeline.push({
|
|
116
|
-
$sort: {
|
|
117
|
-
...(params?.$sort || {}),
|
|
118
|
-
createdAt: -1,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
} else {
|
|
122
|
-
pipeline.push({
|
|
123
|
-
$sort: params?.$sort,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
127
|
// sample aleatoire
|
|
128
128
|
if (params?.$sample) {
|
|
129
129
|
pipeline.push({
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -76,7 +76,11 @@ function toJson(data: object): object | null | undefined | any {
|
|
|
76
76
|
|
|
77
77
|
function isDate(date: string): boolean {
|
|
78
78
|
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
79
|
-
|
|
79
|
+
const dateRegex2 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
|
|
80
|
+
const dateRegex3 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
|
|
81
|
+
let isDate_ =
|
|
82
|
+
!isNaN(Date.parse(date)) &&
|
|
83
|
+
(dateRegex.test(date) || dateRegex2.test(date) || dateRegex3.test(date));
|
|
80
84
|
if (isDate_) return true;
|
|
81
85
|
try {
|
|
82
86
|
isDate_ = moment(date, "YYYY-MM-DD", true).isValid();
|