@dnax/core 0.9.0 → 0.9.1
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 +18 -7
- package/package.json +1 -1
- package/utils/index.ts +20 -0
package/app/hono.ts
CHANGED
|
@@ -7,7 +7,14 @@ import { serveStatic, getConnInfo } from "hono/bun";
|
|
|
7
7
|
import { consola } from "consola";
|
|
8
8
|
import { cors } from "hono/cors";
|
|
9
9
|
import { asyncLocalStorage, sessionStorage } from "../lib/asyncLocalStorage";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
cleanPath,
|
|
12
|
+
contextError,
|
|
13
|
+
jwt,
|
|
14
|
+
fn,
|
|
15
|
+
omit,
|
|
16
|
+
stringToBoolean,
|
|
17
|
+
} from "../utils";
|
|
11
18
|
import { getAction } from "./ctrl";
|
|
12
19
|
import { getCollection } from "../lib/collection";
|
|
13
20
|
import { useRest } from "../driver/mongo/rest";
|
|
@@ -39,7 +46,7 @@ function HonoInstance(): typeof app {
|
|
|
39
46
|
action: action,
|
|
40
47
|
collection: collection,
|
|
41
48
|
cleanDeep: cleanDeep,
|
|
42
|
-
useCache: useCache,
|
|
49
|
+
useCache: stringToBoolean(useCache, false),
|
|
43
50
|
method: c.req.method,
|
|
44
51
|
url: c.req.url,
|
|
45
52
|
path: c.req.path,
|
|
@@ -53,7 +60,7 @@ function HonoInstance(): typeof app {
|
|
|
53
60
|
action,
|
|
54
61
|
collection,
|
|
55
62
|
cleanDeep,
|
|
56
|
-
useCache,
|
|
63
|
+
stringToBoolean(useCache, false),
|
|
57
64
|
method: c.req.method,
|
|
58
65
|
url: c.req.url,
|
|
59
66
|
status: c.res.status,
|
|
@@ -299,6 +306,13 @@ function HonoInstance(): typeof app {
|
|
|
299
306
|
c.req.query() as Q;
|
|
300
307
|
const service = getService(name, c.var["tenant-id"]);
|
|
301
308
|
const col = getCollection(collection, c.var["tenant-id"]);
|
|
309
|
+
const body = await c?.req
|
|
310
|
+
?.json()
|
|
311
|
+
.then((e) => e)
|
|
312
|
+
.catch((err) => null);
|
|
313
|
+
|
|
314
|
+
useCache = stringToBoolean(useCache, false);
|
|
315
|
+
if(body?.useCache) useCache = stringToBoolean(body.useCache, false);
|
|
302
316
|
|
|
303
317
|
if (
|
|
304
318
|
c.req.raw?.headers
|
|
@@ -313,10 +327,7 @@ function HonoInstance(): typeof app {
|
|
|
313
327
|
})) || {};
|
|
314
328
|
}
|
|
315
329
|
|
|
316
|
-
|
|
317
|
-
?.json()
|
|
318
|
-
.then((e) => e)
|
|
319
|
-
.catch((err) => null);
|
|
330
|
+
|
|
320
331
|
|
|
321
332
|
const rest = new useRest({
|
|
322
333
|
tenant_id: c.var["tenant-id"],
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -275,6 +275,25 @@ function pick(data: object | object[], keys: string[]): object {
|
|
|
275
275
|
return {};
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
function stringToBoolean(
|
|
279
|
+
input: string | boolean,
|
|
280
|
+
defaultValue: boolean = false
|
|
281
|
+
): boolean {
|
|
282
|
+
if (typeof input === "boolean") {
|
|
283
|
+
return input;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (typeof input === "string") {
|
|
287
|
+
if (input.toLowerCase() === "true") {
|
|
288
|
+
return true;
|
|
289
|
+
} else if (input.toLowerCase() === "false") {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return defaultValue;
|
|
295
|
+
}
|
|
296
|
+
|
|
278
297
|
class contextError extends Error {
|
|
279
298
|
constructor(message: string, code: number) {
|
|
280
299
|
super(message);
|
|
@@ -319,4 +338,5 @@ export {
|
|
|
319
338
|
collect, // Collect utils
|
|
320
339
|
Otp, // Otp utils
|
|
321
340
|
urlencode,
|
|
341
|
+
stringToBoolean,
|
|
322
342
|
};
|