mocody 0.7.0 → 0.7.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/dist/index.cjs CHANGED
@@ -456,14 +456,43 @@ var RepoModel = class {
456
456
  var import_joi2 = __toESM(require("joi"), 1);
457
457
 
458
458
  // src/helpers/base-joi-helper.ts
459
+ var fieldPlaceholderWithLabel = process.env.MOCODY_SCHEMA_VALIDATE_FIELD_PLACEHOLDER_WITH_LABEL || "";
460
+ var fieldPlaceholder = process.env.MOCODY_SCHEMA_VALIDATE_FIELD_PLACEHOLDER || "";
459
461
  function getJoiValidationErrors(err) {
460
462
  if (err?.details?.length) {
463
+ if (fieldPlaceholderWithLabel && fieldPlaceholder) {
464
+ return getJoiValidationErrorAdvanced(err);
465
+ }
461
466
  const details = JSON.parse(JSON.stringify(err.details));
462
467
  const joiData = details.map((x) => x.message.replace(new RegExp('"', "g"), ""));
463
468
  return joiData.join("; ");
464
469
  }
465
470
  return null;
466
471
  }
472
+ function getJoiValidationErrorAdvanced(err) {
473
+ if (err?.details?.length) {
474
+ const details = JSON.parse(JSON.stringify(err.details));
475
+ const joiData = details.map((issue) => {
476
+ const fieldName = issue.path.join(".");
477
+ const issueMessage = __get_val_friendly_validation_message({
478
+ fieldName,
479
+ message: issue.message.replaceAll('"', "")
480
+ });
481
+ return issueMessage;
482
+ });
483
+ return joiData.join("; ");
484
+ }
485
+ return null;
486
+ }
487
+ function __get_val_friendly_validation_message({ fieldName, message }) {
488
+ if (message?.includes(fieldPlaceholderWithLabel)) {
489
+ return message.replaceAll(fieldPlaceholderWithLabel, "");
490
+ }
491
+ if (message?.includes(fieldPlaceholder)) {
492
+ return message.replaceAll(fieldPlaceholder, fieldName);
493
+ }
494
+ return `${fieldName}: ${message}`;
495
+ }
467
496
 
468
497
  // src/core/base-schema.ts
469
498
  var import_joi = __toESM(require("joi"), 1);
package/dist/index.js CHANGED
@@ -421,14 +421,43 @@ var RepoModel = class {
421
421
  import Joi2 from "joi";
422
422
 
423
423
  // src/helpers/base-joi-helper.ts
424
+ var fieldPlaceholderWithLabel = process.env.MOCODY_SCHEMA_VALIDATE_FIELD_PLACEHOLDER_WITH_LABEL || "";
425
+ var fieldPlaceholder = process.env.MOCODY_SCHEMA_VALIDATE_FIELD_PLACEHOLDER || "";
424
426
  function getJoiValidationErrors(err) {
425
427
  if (err?.details?.length) {
428
+ if (fieldPlaceholderWithLabel && fieldPlaceholder) {
429
+ return getJoiValidationErrorAdvanced(err);
430
+ }
426
431
  const details = JSON.parse(JSON.stringify(err.details));
427
432
  const joiData = details.map((x) => x.message.replace(new RegExp('"', "g"), ""));
428
433
  return joiData.join("; ");
429
434
  }
430
435
  return null;
431
436
  }
437
+ function getJoiValidationErrorAdvanced(err) {
438
+ if (err?.details?.length) {
439
+ const details = JSON.parse(JSON.stringify(err.details));
440
+ const joiData = details.map((issue) => {
441
+ const fieldName = issue.path.join(".");
442
+ const issueMessage = __get_val_friendly_validation_message({
443
+ fieldName,
444
+ message: issue.message.replaceAll('"', "")
445
+ });
446
+ return issueMessage;
447
+ });
448
+ return joiData.join("; ");
449
+ }
450
+ return null;
451
+ }
452
+ function __get_val_friendly_validation_message({ fieldName, message }) {
453
+ if (message?.includes(fieldPlaceholderWithLabel)) {
454
+ return message.replaceAll(fieldPlaceholderWithLabel, "");
455
+ }
456
+ if (message?.includes(fieldPlaceholder)) {
457
+ return message.replaceAll(fieldPlaceholder, fieldName);
458
+ }
459
+ return `${fieldName}: ${message}`;
460
+ }
432
461
 
433
462
  // src/core/base-schema.ts
434
463
  import Joi from "joi";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocody",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Implementation of single table design, and unified query access for MongoDB, CouchDB, and dynamoDB",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",