@dnax/core 0.0.6 → 0.0.7

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 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: `@libv/server ${pkg.version}`.italic,
55
+ title: `@dnax/server ${pkg.version}`.italic,
56
56
  padding: 1,
57
57
  dimBorder: true,
58
58
  titleAlignment: "center",
@@ -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);
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {
package/types/index.ts CHANGED
@@ -71,7 +71,8 @@ export type Field = {
71
71
  | "textarea"
72
72
  | "richText"
73
73
  | "json"
74
- | "geojson";
74
+ | "geojson"
75
+ | "uuid";
75
76
  studio?: {
76
77
  display?: string;
77
78
  suffix?: string;