mocody 0.6.9 → 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);
@@ -3199,6 +3228,8 @@ var DynamoDataOperation = class extends RepoModel {
3199
3228
  ExpressionAttributeValues: expressionAttributeValues
3200
3229
  }
3201
3230
  });
3231
+ } else {
3232
+ throw this._mocody_createGenericError("Invalid transaction kind");
3202
3233
  }
3203
3234
  }
3204
3235
  await this._mocody_dynamoInit().transactWriteItems(transactData);
package/dist/index.d.cts CHANGED
@@ -130,7 +130,7 @@ interface IMocodyPreparedDeleteTransaction {
130
130
  partitionKeyFieldName: "id";
131
131
  }
132
132
  type IMocodyPreparedTransaction = IMocodyPreparedCreateTransaction | IMocodyPreparedUpdateTransaction | IMocodyPreparedDeleteTransaction;
133
- type IFieldAliases<T> = {
133
+ type IMocodyFieldAliases<T> = {
134
134
  source: keyof T;
135
135
  dest: keyof T;
136
136
  }[];
@@ -156,12 +156,12 @@ declare class MocodyUtilBase {
156
156
  }): (keyof T)[] | undefined;
157
157
  alignFormatFieldAlias<T>({ data, fieldAliases, featureEntity, }: {
158
158
  data: Partial<T>;
159
- fieldAliases: IFieldAliases<T> | undefined | null;
159
+ fieldAliases: IMocodyFieldAliases<T> | undefined | null;
160
160
  featureEntity: string;
161
161
  }): any;
162
162
  validateFieldAlias<T>({ data, fieldAliases, featureEntity, }: {
163
163
  data: Partial<T>;
164
- fieldAliases: IFieldAliases<T> | undefined | null;
164
+ fieldAliases: IMocodyFieldAliases<T> | undefined | null;
165
165
  featureEntity: string;
166
166
  }): void;
167
167
  }
@@ -260,7 +260,7 @@ interface IOptions$3<T> {
260
260
  secondaryIndexOptions: IMocodyIndexDefinition<T>[];
261
261
  baseTableName: string;
262
262
  strictRequiredFields: (keyof T)[] | string[];
263
- fieldAliases?: IFieldAliases<T> | undefined | null;
263
+ fieldAliases?: IMocodyFieldAliases<T> | undefined | null;
264
264
  }
265
265
  declare class DynamoDataOperation<T> extends RepoModel<T> implements RepoModel<T> {
266
266
  private readonly _mocody_partitionKeyFieldName;
@@ -514,7 +514,7 @@ interface IOptions$1<T> {
514
514
  secondaryIndexOptions: IMocodyIndexDefinition<T>[];
515
515
  baseTableName: string;
516
516
  strictRequiredFields: (keyof T)[] | string[];
517
- fieldAliases?: IFieldAliases<T> | undefined | null;
517
+ fieldAliases?: IMocodyFieldAliases<T> | undefined | null;
518
518
  }
519
519
  declare class CouchDataOperation<T> extends RepoModel<T> implements RepoModel<T> {
520
520
  private readonly _mocody_partitionKeyFieldName;
@@ -644,7 +644,7 @@ interface IOptions<T> {
644
644
  secondaryIndexOptions: IMocodyIndexDefinition<T>[];
645
645
  baseTableName: string;
646
646
  strictRequiredFields: (keyof T)[] | string[];
647
- fieldAliases?: IFieldAliases<T> | undefined | null;
647
+ fieldAliases?: IMocodyFieldAliases<T> | undefined | null;
648
648
  }
649
649
  declare class MongoDataOperation<T> extends RepoModel<T> implements RepoModel<T> {
650
650
  private readonly _mocody_partitionKeyFieldName;
@@ -720,4 +720,4 @@ declare class MongoDataOperation<T> extends RepoModel<T> implements RepoModel<T>
720
720
  }): Promise<T>;
721
721
  }
722
722
 
723
- export { CouchDataOperation, DynamoDataOperation, type IFieldAliases, type IMocodyCoreEntityModel, type IMocodyFieldCondition, type IMocodyIndexDefinition, type IMocodyKeyConditionParams, type IMocodyPagingParams, type IMocodyPagingResult, type IMocodyQueryConditionParams, type IMocodyQueryDefinition, type IMocodyQueryIndexOptions, type IMocodyQueryIndexOptionsNoPaging, MocodyGenericError, MocodyInitializerCouch, MocodyInitializerDynamo, MocodyInitializerMongo, MocodyUtil, MongoDataOperation };
723
+ export { CouchDataOperation, DynamoDataOperation, type IMocodyCoreEntityModel, type IMocodyFieldAliases, type IMocodyFieldCondition, type IMocodyIndexDefinition, type IMocodyKeyConditionParams, type IMocodyPagingParams, type IMocodyPagingResult, type IMocodyPreparedTransaction, type IMocodyQueryConditionParams, type IMocodyQueryDefinition, type IMocodyQueryIndexOptions, type IMocodyQueryIndexOptionsNoPaging, MocodyGenericError, MocodyInitializerCouch, MocodyInitializerDynamo, MocodyInitializerMongo, MocodyUtil, MongoDataOperation };
package/dist/index.d.ts CHANGED
@@ -130,7 +130,7 @@ interface IMocodyPreparedDeleteTransaction {
130
130
  partitionKeyFieldName: "id";
131
131
  }
132
132
  type IMocodyPreparedTransaction = IMocodyPreparedCreateTransaction | IMocodyPreparedUpdateTransaction | IMocodyPreparedDeleteTransaction;
133
- type IFieldAliases<T> = {
133
+ type IMocodyFieldAliases<T> = {
134
134
  source: keyof T;
135
135
  dest: keyof T;
136
136
  }[];
@@ -156,12 +156,12 @@ declare class MocodyUtilBase {
156
156
  }): (keyof T)[] | undefined;
157
157
  alignFormatFieldAlias<T>({ data, fieldAliases, featureEntity, }: {
158
158
  data: Partial<T>;
159
- fieldAliases: IFieldAliases<T> | undefined | null;
159
+ fieldAliases: IMocodyFieldAliases<T> | undefined | null;
160
160
  featureEntity: string;
161
161
  }): any;
162
162
  validateFieldAlias<T>({ data, fieldAliases, featureEntity, }: {
163
163
  data: Partial<T>;
164
- fieldAliases: IFieldAliases<T> | undefined | null;
164
+ fieldAliases: IMocodyFieldAliases<T> | undefined | null;
165
165
  featureEntity: string;
166
166
  }): void;
167
167
  }
@@ -260,7 +260,7 @@ interface IOptions$3<T> {
260
260
  secondaryIndexOptions: IMocodyIndexDefinition<T>[];
261
261
  baseTableName: string;
262
262
  strictRequiredFields: (keyof T)[] | string[];
263
- fieldAliases?: IFieldAliases<T> | undefined | null;
263
+ fieldAliases?: IMocodyFieldAliases<T> | undefined | null;
264
264
  }
265
265
  declare class DynamoDataOperation<T> extends RepoModel<T> implements RepoModel<T> {
266
266
  private readonly _mocody_partitionKeyFieldName;
@@ -514,7 +514,7 @@ interface IOptions$1<T> {
514
514
  secondaryIndexOptions: IMocodyIndexDefinition<T>[];
515
515
  baseTableName: string;
516
516
  strictRequiredFields: (keyof T)[] | string[];
517
- fieldAliases?: IFieldAliases<T> | undefined | null;
517
+ fieldAliases?: IMocodyFieldAliases<T> | undefined | null;
518
518
  }
519
519
  declare class CouchDataOperation<T> extends RepoModel<T> implements RepoModel<T> {
520
520
  private readonly _mocody_partitionKeyFieldName;
@@ -644,7 +644,7 @@ interface IOptions<T> {
644
644
  secondaryIndexOptions: IMocodyIndexDefinition<T>[];
645
645
  baseTableName: string;
646
646
  strictRequiredFields: (keyof T)[] | string[];
647
- fieldAliases?: IFieldAliases<T> | undefined | null;
647
+ fieldAliases?: IMocodyFieldAliases<T> | undefined | null;
648
648
  }
649
649
  declare class MongoDataOperation<T> extends RepoModel<T> implements RepoModel<T> {
650
650
  private readonly _mocody_partitionKeyFieldName;
@@ -720,4 +720,4 @@ declare class MongoDataOperation<T> extends RepoModel<T> implements RepoModel<T>
720
720
  }): Promise<T>;
721
721
  }
722
722
 
723
- export { CouchDataOperation, DynamoDataOperation, type IFieldAliases, type IMocodyCoreEntityModel, type IMocodyFieldCondition, type IMocodyIndexDefinition, type IMocodyKeyConditionParams, type IMocodyPagingParams, type IMocodyPagingResult, type IMocodyQueryConditionParams, type IMocodyQueryDefinition, type IMocodyQueryIndexOptions, type IMocodyQueryIndexOptionsNoPaging, MocodyGenericError, MocodyInitializerCouch, MocodyInitializerDynamo, MocodyInitializerMongo, MocodyUtil, MongoDataOperation };
723
+ export { CouchDataOperation, DynamoDataOperation, type IMocodyCoreEntityModel, type IMocodyFieldAliases, type IMocodyFieldCondition, type IMocodyIndexDefinition, type IMocodyKeyConditionParams, type IMocodyPagingParams, type IMocodyPagingResult, type IMocodyPreparedTransaction, type IMocodyQueryConditionParams, type IMocodyQueryDefinition, type IMocodyQueryIndexOptions, type IMocodyQueryIndexOptionsNoPaging, MocodyGenericError, MocodyInitializerCouch, MocodyInitializerDynamo, MocodyInitializerMongo, MocodyUtil, MongoDataOperation };
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";
@@ -3171,6 +3200,8 @@ var DynamoDataOperation = class extends RepoModel {
3171
3200
  ExpressionAttributeValues: expressionAttributeValues
3172
3201
  }
3173
3202
  });
3203
+ } else {
3204
+ throw this._mocody_createGenericError("Invalid transaction kind");
3174
3205
  }
3175
3206
  }
3176
3207
  await this._mocody_dynamoInit().transactWriteItems(transactData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocody",
3
- "version": "0.6.9",
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",