@dnax/core 0.69.13 → 0.69.14

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.
@@ -18,7 +18,12 @@ export type findParam = {
18
18
  $skip?: number;
19
19
  $limit?: number;
20
20
  $include?: Array<string | Lookup>;
21
- $project?: object;
21
+ $project?: {
22
+ [key: string]: 1 | 0;
23
+ };
24
+ $projectInclude?: {
25
+ [key: string]: 1 | 0;
26
+ };
22
27
  $matchInclude?: {
23
28
  _id?: string;
24
29
  [key: string]: any;
@@ -804,7 +804,7 @@ class useRest {
804
804
  io: Cfg.io,
805
805
  driver: "mongodb",
806
806
  action: "find",
807
- meta: meta,
807
+ meta: {},
808
808
  count: result?.docs?.length || 0,
809
809
  params: toJson(params),
810
810
  session: sessionStorage(),
@@ -837,7 +837,7 @@ class useRest {
837
837
  return new Promise(async (resolve, reject) => {
838
838
  try {
839
839
  let meta = {
840
- ms: 0, // time duration
840
+ ts: 0, // time duration
841
841
  };
842
842
  let start = Date.now();
843
843
 
@@ -900,7 +900,7 @@ class useRest {
900
900
  }),
901
901
  })) as any;
902
902
  // Temp dexecution en ms
903
- meta.ms = Date.now() - start;
903
+ meta.ts = Date.now() - start;
904
904
  return resolve({
905
905
  meta: meta,
906
906
  data: result,
@@ -916,7 +916,7 @@ class useRest {
916
916
  .toArray()) || [];
917
917
 
918
918
  result.docs = toJson(result.docs);
919
- meta.ms = Date.now() - start;
919
+ meta.ts = Date.now() - start;
920
920
  if (col?.hooks?.afterFindWithMeta && useHook) {
921
921
  await col.hooks.afterFindWithMeta({
922
922
  sharedData: sharedData,
@@ -1201,7 +1201,6 @@ class useRest {
1201
1201
  params: params,
1202
1202
  session: sessionStorage(),
1203
1203
  result: docs,
1204
- meta: meta,
1205
1204
  rest: new useRest({
1206
1205
  useHook: false,
1207
1206
  tenant_id: this.#tenant_id,
@@ -1209,15 +1208,6 @@ class useRest {
1209
1208
  });
1210
1209
  }
1211
1210
 
1212
- if (options?.withMeta) {
1213
- meta.count = docs?.length || 0;
1214
- meta.total = docs?.length || 0;
1215
- resolve({
1216
- data: docs?.length ? toJson(docs[0]) : null,
1217
- meta: meta,
1218
- });
1219
- }
1220
-
1221
1211
  return resolve(docs?.length ? toJson(docs[0]) : null);
1222
1212
  } catch (err) {
1223
1213
  return reject(err);
@@ -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
+ // $match
14
+ if (params?.$match) {
15
+ pipeline.push({
16
+ $match: params.$match,
17
+ });
18
+ }
19
+
20
+ // project
21
+ if (params?.$project) {
22
+ pipeline.push({
23
+ $project: params.$project,
24
+ });
25
+ }
26
+
13
27
  // sorted
14
28
  if (!params?.$sort?.createdAt) {
15
29
  pipeline.push({
@@ -20,14 +34,10 @@ function buildPipeline(params: findParam, col?: Collection | undefined | null) {
20
34
  });
21
35
  } else {
22
36
  pipeline.push({
23
- $sort: params?.$sort,
24
- });
25
- }
26
-
27
- // $match
28
- if (params?.$match) {
29
- pipeline.push({
30
- $match: params.$match,
37
+ $sort: {
38
+ createdAt: -1,
39
+ ...(params?.$sort || {}),
40
+ },
31
41
  });
32
42
  }
33
43
 
@@ -129,10 +139,9 @@ function buildPipeline(params: findParam, col?: Collection | undefined | null) {
129
139
  });
130
140
  }
131
141
 
132
- // project
133
- if (params?.$project) {
142
+ if (params?.$projectInclude) {
134
143
  pipeline.push({
135
- $project: params.$project,
144
+ $project: params.$projectInclude,
136
145
  });
137
146
  }
138
147
 
package/lib/collection.ts CHANGED
@@ -190,16 +190,50 @@ async function syncCollectionDatabase() {
190
190
  // console.error(err?.message);
191
191
  });
192
192
 
193
- for await (let dbIndex of allIndexes || []) {
193
+ let foundTimeStamIndex = allIndexes?.find((el) => {
194
+ return deepEqual(el.key, {
195
+ createdAt: -1,
196
+ updatedAt: -1,
197
+ });
198
+ });
199
+
200
+ let foundTimeStampIndexDesc = allIndexes?.find((el) => {
201
+ return deepEqual(el.key, {
202
+ createdAt: 1,
203
+ updatedAt: 1,
204
+ });
205
+ });
206
+
207
+ if (foundTimeStampIndexDesc) {
208
+ await t.database.db
209
+ ?.collection(c.slug)
210
+ .dropIndex("createdAt_1_updatedAt_1")
211
+ .catch((err) => {
212
+ // console.error(err?.message);
213
+ });
214
+ }
215
+
216
+ if (!foundTimeStamIndex) {
217
+ await t.database.db?.collection(c.slug).createIndex({
218
+ createdAt: -1,
219
+ updatedAt: -1,
220
+ });
221
+ }
222
+
223
+ /* for await (let dbIndex of allIndexes || []) {
194
224
  // creation des indexes createdAt / updatedAt
225
+
195
226
  if (!dbIndex?.key?.createdAt && !dbIndex?.key?.updatedAt) {
196
227
  await t.database.db
197
228
  ?.collection(c.slug)
198
- .createIndex(["createdAt", "updatedAt"])
229
+ .createIndex({
230
+ createdAt: -1,
231
+ updatedAt: -1,
232
+ })
199
233
  .then((e) => {})
200
234
  .catch((err) => {});
201
235
  }
202
- }
236
+ } */
203
237
 
204
238
  // 2- Creation des indexes par champs unique/random
205
239
  c.fields?.map((f) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.69.13",
3
+ "version": "0.69.14",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {},
package/types/index.ts CHANGED
@@ -237,7 +237,7 @@ export type hooksCtx = (ctx: {
237
237
  sharedData?: any;
238
238
  action?: Actions;
239
239
  c?: Context;
240
- meta?: { ms:number; [key: string]: any };
240
+ meta?: { ms:number; [key: string]: any }|{};
241
241
  rest: InstanceType<typeof useRest>;
242
242
  session?: sessionCtx;
243
243
  io: socketIoType;