@dnax/core 0.30.5 → 0.31.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/app/hono.ts +43 -16
- package/package.json +1 -1
- package/types/index.ts +20 -1
- package/utils/index.ts +6 -0
package/app/hono.ts
CHANGED
|
@@ -421,13 +421,12 @@ function HonoInstance(): typeof app {
|
|
|
421
421
|
let allFiles = parseBody?.file;
|
|
422
422
|
for await (let file of allFiles) {
|
|
423
423
|
let d;
|
|
424
|
-
if (Array.isArray(data)) {
|
|
424
|
+
if (Array.isArray(data) && data.length) {
|
|
425
425
|
d = data[indexedData];
|
|
426
426
|
} else {
|
|
427
427
|
d = data;
|
|
428
428
|
}
|
|
429
429
|
let insertedFile = await drive.write(file.name, file);
|
|
430
|
-
|
|
431
430
|
insertedFiles.push({
|
|
432
431
|
...d,
|
|
433
432
|
_file: insertedFile,
|
|
@@ -464,23 +463,50 @@ function HonoInstance(): typeof app {
|
|
|
464
463
|
}
|
|
465
464
|
// find
|
|
466
465
|
if (action == "find") {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
466
|
+
if (col?.cache?.enabled && useCache) {
|
|
467
|
+
let keyCache = bentoKey({
|
|
468
|
+
data: body,
|
|
469
|
+
query: c.req.query,
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
// if customCache
|
|
473
|
+
if (col?.cache?.customCache) {
|
|
474
|
+
let fetchFromCache = await col?.cache?.customCache({
|
|
475
|
+
action: action,
|
|
476
|
+
rest: rest,
|
|
477
|
+
session: sessionStorage(),
|
|
478
|
+
c: c,
|
|
478
479
|
});
|
|
479
|
-
|
|
480
|
+
|
|
481
|
+
if (!fetchFromCache.isStale) {
|
|
482
|
+
response = fetchFromCache.data;
|
|
483
|
+
} else {
|
|
484
|
+
response = await rest.find(collection, body?.params || {}, {
|
|
485
|
+
withMeta: body?.withMeta || false,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// if not customCache
|
|
490
|
+
if (!col?.cache?.customCache) {
|
|
491
|
+
let responseFromCache = await cache.get({
|
|
480
492
|
key: keyCache,
|
|
481
|
-
value: response,
|
|
482
|
-
ttl: col?.cache?.ttl || "1m",
|
|
483
493
|
});
|
|
494
|
+
if (responseFromCache) {
|
|
495
|
+
response = responseFromCache;
|
|
496
|
+
} else {
|
|
497
|
+
response = await rest.find(collection, body?.params || {}, {
|
|
498
|
+
withMeta: body?.withMeta || false,
|
|
499
|
+
});
|
|
500
|
+
await cache.set({
|
|
501
|
+
key: keyCache,
|
|
502
|
+
value: response,
|
|
503
|
+
ttl: col?.cache?.ttl || "1m",
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/* response = await rest.find(collection, body?.params || {}, {
|
|
508
|
+
withMeta: body?.withMeta || false,
|
|
509
|
+
}); */
|
|
484
510
|
}
|
|
485
511
|
} else {
|
|
486
512
|
response = await rest.find(collection, body?.params || {}, {
|
|
@@ -581,6 +607,7 @@ function HonoInstance(): typeof app {
|
|
|
581
607
|
|
|
582
608
|
// Obtenir le type MIME du fichier
|
|
583
609
|
const mimeType = mime.lookup(filePath);
|
|
610
|
+
|
|
584
611
|
// Si ce n'est pas une image, retourner le fichier original
|
|
585
612
|
if (!mimeType || !mimeType?.startsWith("image/")) {
|
|
586
613
|
const originalFile = fs.readFileSync(filePath);
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -276,8 +276,27 @@ export type Collection = {
|
|
|
276
276
|
findOne?: (ctx: ctxApi) => object;
|
|
277
277
|
count?: (ctx: ctxApi) => number;
|
|
278
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* Cache available for action 'find' | 'findOne'
|
|
281
|
+
*/
|
|
279
282
|
cache?: {
|
|
280
|
-
|
|
283
|
+
enabled?: boolean;
|
|
284
|
+
ttl: string;
|
|
285
|
+
triggerEvents: ["find", "findOne"];
|
|
286
|
+
/**
|
|
287
|
+
* Overwrite cache bahavior
|
|
288
|
+
* @param ctx
|
|
289
|
+
* @returns <any>
|
|
290
|
+
*/
|
|
291
|
+
customCache?: (ctx: {
|
|
292
|
+
action: "find" | "findOne";
|
|
293
|
+
rest: InstanceType<typeof useRest>;
|
|
294
|
+
c: Context;
|
|
295
|
+
session: sessionCtx;
|
|
296
|
+
}) => {
|
|
297
|
+
isStale: boolean;
|
|
298
|
+
data: any;
|
|
299
|
+
};
|
|
281
300
|
};
|
|
282
301
|
schema?: object;
|
|
283
302
|
auth?: {
|
package/utils/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import generateUniqueId from "generate-unique-id";
|
|
|
10
10
|
import dayjs from "dayjs";
|
|
11
11
|
import { Otp } from "../lib/opt";
|
|
12
12
|
import collect from "collect.js";
|
|
13
|
+
import mime from "mime-types";
|
|
13
14
|
import * as uuid from "uuid";
|
|
14
15
|
import * as urlencode from "urlencode";
|
|
15
16
|
import dotJson from "dot-object";
|
|
@@ -108,11 +109,15 @@ function isDate(date: string): boolean {
|
|
|
108
109
|
const dateRegex3 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
|
|
109
110
|
// le regex pour cette forme 2024-11-30T21:36:12+00:00
|
|
110
111
|
const dateRegex4 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}$/;
|
|
112
|
+
const dateRegex5 = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2}$/;
|
|
113
|
+
const dateRegex6 = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}$/;
|
|
111
114
|
let isDate_ =
|
|
112
115
|
!isNaN(Date.parse(date)) &&
|
|
113
116
|
(dateRegex.test(date) ||
|
|
114
117
|
dateRegex2.test(date) ||
|
|
115
118
|
dateRegex4.test(date) ||
|
|
119
|
+
dateRegex5.test(date) ||
|
|
120
|
+
dateRegex6.test(date) ||
|
|
116
121
|
dateRegex3.test(date));
|
|
117
122
|
if (isDate_) return true;
|
|
118
123
|
try {
|
|
@@ -369,6 +374,7 @@ const password = {
|
|
|
369
374
|
|
|
370
375
|
const contextError = ContextError;
|
|
371
376
|
export {
|
|
377
|
+
mime,
|
|
372
378
|
dotJson,
|
|
373
379
|
uuid,
|
|
374
380
|
pick,
|