@dnax/core 0.0.6 → 0.0.8
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/index.ts +1 -1
- package/driver/mongo/rest.ts +3 -0
- package/driver/mongo/utils.ts +31 -0
- package/lib/schema.ts +4 -0
- package/package.json +1 -1
- package/types/index.ts +2 -1
package/app/index.ts
CHANGED
|
@@ -52,7 +52,7 @@ async function runApp(config?: any, clb?: Function) {
|
|
|
52
52
|
console.log(
|
|
53
53
|
boxen(info, {
|
|
54
54
|
borderStyle: "round",
|
|
55
|
-
title: `@
|
|
55
|
+
title: `@dnax/server ${pkg.version}`.italic,
|
|
56
56
|
padding: 1,
|
|
57
57
|
dimBorder: true,
|
|
58
58
|
titleAlignment: "center",
|
package/driver/mongo/rest.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
cleanData,
|
|
25
25
|
transformAllDate,
|
|
26
26
|
deepSetId,
|
|
27
|
+
setUUID,
|
|
27
28
|
} from "./utils";
|
|
28
29
|
import { Cfg } from "../../config";
|
|
29
30
|
|
|
@@ -208,6 +209,7 @@ class useRest {
|
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
// Processing before validation
|
|
212
|
+
data = await setUUID(data, col);
|
|
211
213
|
data = await randomCode(data, col);
|
|
212
214
|
data = await hashPasswordAuto(data, col);
|
|
213
215
|
data = transformAllDate(data);
|
|
@@ -309,6 +311,7 @@ class useRest {
|
|
|
309
311
|
|
|
310
312
|
for await (let d of data) {
|
|
311
313
|
// Processing before validation
|
|
314
|
+
d = await setUUID(d, col);
|
|
312
315
|
d = await randomCode(d, col);
|
|
313
316
|
d = await hashPasswordAuto(d, col);
|
|
314
317
|
d = deepSetId(col, d);
|
package/driver/mongo/utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { v4 } from "uuid";
|
|
1
2
|
import type { findParam } from "./@types";
|
|
2
3
|
import type { Actions, Collection } from "../../types";
|
|
3
4
|
import { ObjectId } from "mongodb";
|
|
@@ -327,6 +328,35 @@ async function randomCode(
|
|
|
327
328
|
return data;
|
|
328
329
|
}
|
|
329
330
|
|
|
331
|
+
async function setUUID(
|
|
332
|
+
data: any,
|
|
333
|
+
col: Collection,
|
|
334
|
+
action?: Actions
|
|
335
|
+
): Promise<any> {
|
|
336
|
+
var code = null;
|
|
337
|
+
for await (let f of col?.fields || []) {
|
|
338
|
+
if (f?.type == "uuid") {
|
|
339
|
+
code = v4();
|
|
340
|
+
data[f.name] = code;
|
|
341
|
+
// if unique
|
|
342
|
+
if (f?.unique) {
|
|
343
|
+
let tenant = Cfg.tenants.find((t) => t.id == col.tenant_id);
|
|
344
|
+
if (tenant) {
|
|
345
|
+
let doc = await tenant.database.db
|
|
346
|
+
?.collection(col.slug)
|
|
347
|
+
.findOne({ [f.name]: code });
|
|
348
|
+
|
|
349
|
+
if (doc) {
|
|
350
|
+
code = await setUUID(data, col);
|
|
351
|
+
data[f.name] = code;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return data;
|
|
358
|
+
}
|
|
359
|
+
|
|
330
360
|
function formatData(
|
|
331
361
|
data: any,
|
|
332
362
|
options: {
|
|
@@ -358,4 +388,5 @@ export {
|
|
|
358
388
|
cleanData,
|
|
359
389
|
hashPasswordAuto,
|
|
360
390
|
transformAllDate,
|
|
391
|
+
setUUID,
|
|
361
392
|
};
|
package/lib/schema.ts
CHANGED
|
@@ -12,6 +12,10 @@ function buildSchema(col: Collection) {
|
|
|
12
12
|
propertySchema[f.name] = v.array(v.any());
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
if (f?.type == "uuid" && f?.random?.toNumber) {
|
|
16
|
+
propertySchema[f.name] = v.string();
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
if (f?.type == "random" && f?.random?.toNumber) {
|
|
16
20
|
propertySchema[f.name] = v.number();
|
|
17
21
|
}
|
package/package.json
CHANGED