metal-orm 1.0.92 → 1.0.94

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.js CHANGED
@@ -6142,7 +6142,8 @@ var ensureEntityMetadata = (target) => {
6142
6142
  target,
6143
6143
  tableName: target.name || "unknown",
6144
6144
  columns: {},
6145
- relations: {}
6145
+ relations: {},
6146
+ transformers: {}
6146
6147
  };
6147
6148
  metadataMap.set(target, meta);
6148
6149
  }
@@ -6162,6 +6163,10 @@ var addRelationMetadata = (target, propertyKey, relation) => {
6162
6163
  const meta = ensureEntityMetadata(target);
6163
6164
  meta.relations[propertyKey] = relation;
6164
6165
  };
6166
+ var addTransformerMetadata = (target, propertyKey, transformer) => {
6167
+ const meta = ensureEntityMetadata(target);
6168
+ meta.transformers[propertyKey] = transformer;
6169
+ };
6165
6170
  var setEntityTableName = (target, tableName, hooks) => {
6166
6171
  const meta = ensureEntityMetadata(target);
6167
6172
  if (tableName && tableName.length > 0) {
@@ -7522,6 +7527,28 @@ var isTableDef = (value) => {
7522
7527
  return true;
7523
7528
  };
7524
7529
 
7530
+ // src/decorators/decorator-metadata.ts
7531
+ var METADATA_KEY = "metal-orm:decorators";
7532
+ var getOrCreateMetadataBag = (context) => {
7533
+ const metadata = context.metadata || (context.metadata = {});
7534
+ let bag = metadata[METADATA_KEY];
7535
+ if (!bag) {
7536
+ bag = { columns: [], relations: [], transformers: [] };
7537
+ metadata[METADATA_KEY] = bag;
7538
+ }
7539
+ return bag;
7540
+ };
7541
+ var readMetadataBag = (context) => {
7542
+ return context.metadata?.[METADATA_KEY];
7543
+ };
7544
+ var readMetadataBagFromConstructor = (ctor) => {
7545
+ const metadataSymbol = Symbol.metadata;
7546
+ if (!metadataSymbol) return void 0;
7547
+ const metadata = Reflect.get(ctor, metadataSymbol);
7548
+ return metadata?.[METADATA_KEY];
7549
+ };
7550
+ var getDecoratorMetadata = (ctor) => readMetadataBagFromConstructor(ctor);
7551
+
7525
7552
  // src/decorators/bootstrap.ts
7526
7553
  var unwrapTarget = (target) => {
7527
7554
  if (typeof target === "function" && target.prototype === void 0) {
@@ -7618,6 +7645,12 @@ var bootstrapEntities = () => {
7618
7645
  const metas = getAllEntityMetadata();
7619
7646
  const tableMap = /* @__PURE__ */ new Map();
7620
7647
  for (const meta of metas) {
7648
+ const decoratorMetadata = getDecoratorMetadata(meta.target);
7649
+ if (decoratorMetadata?.transformers) {
7650
+ for (const { propertyName, metadata } of decoratorMetadata.transformers) {
7651
+ addTransformerMetadata(meta.target, propertyName, metadata);
7652
+ }
7653
+ }
7621
7654
  const table = buildTableDef(meta);
7622
7655
  tableMap.set(meta.target, table);
7623
7656
  }
@@ -12271,28 +12304,6 @@ var jsonify = (value) => {
12271
12304
  return result;
12272
12305
  };
12273
12306
 
12274
- // src/decorators/decorator-metadata.ts
12275
- var METADATA_KEY = "metal-orm:decorators";
12276
- var getOrCreateMetadataBag = (context) => {
12277
- const metadata = context.metadata || (context.metadata = {});
12278
- let bag = metadata[METADATA_KEY];
12279
- if (!bag) {
12280
- bag = { columns: [], relations: [] };
12281
- metadata[METADATA_KEY] = bag;
12282
- }
12283
- return bag;
12284
- };
12285
- var readMetadataBag = (context) => {
12286
- return context.metadata?.[METADATA_KEY];
12287
- };
12288
- var readMetadataBagFromConstructor = (ctor) => {
12289
- const metadataSymbol = Symbol.metadata;
12290
- if (!metadataSymbol) return void 0;
12291
- const metadata = Reflect.get(ctor, metadataSymbol);
12292
- return metadata?.[METADATA_KEY];
12293
- };
12294
- var getDecoratorMetadata = (ctor) => readMetadataBagFromConstructor(ctor);
12295
-
12296
12307
  // src/decorators/entity.ts
12297
12308
  var toSnakeCase2 = (value) => {
12298
12309
  return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-z0-9_]+/gi, "_").replace(/__+/g, "_").replace(/^_|_$/g, "").toLowerCase();
@@ -12465,6 +12476,668 @@ function BelongsToMany(options) {
12465
12476
  }));
12466
12477
  }
12467
12478
 
12479
+ // src/decorators/transformers/built-in/string-transformers.ts
12480
+ var TrimTransformer = class {
12481
+ constructor(options = {}) {
12482
+ this.options = options;
12483
+ }
12484
+ name = "trim";
12485
+ sanitize(value) {
12486
+ if (typeof value !== "string") return value;
12487
+ if (this.options.trimAll) {
12488
+ return value.trim();
12489
+ }
12490
+ let result = value;
12491
+ if (this.options.trimStart) {
12492
+ result = result.trimStart();
12493
+ }
12494
+ if (this.options.trimEnd) {
12495
+ result = result.trimEnd();
12496
+ }
12497
+ if (!this.options.trimStart && !this.options.trimEnd && !this.options.trimAll) {
12498
+ result = result.trim();
12499
+ }
12500
+ return result;
12501
+ }
12502
+ };
12503
+ var CaseTransformer = class {
12504
+ constructor(caseType) {
12505
+ this.caseType = caseType;
12506
+ this.name = `case-${caseType}`;
12507
+ }
12508
+ name;
12509
+ sanitize(value) {
12510
+ if (typeof value !== "string") return value;
12511
+ switch (this.caseType) {
12512
+ case "lower":
12513
+ return value.toLowerCase();
12514
+ case "upper":
12515
+ return value.toUpperCase();
12516
+ case "capitalize":
12517
+ return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
12518
+ case "title":
12519
+ return value.split(" ").map(
12520
+ (word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
12521
+ ).join(" ");
12522
+ default:
12523
+ return value;
12524
+ }
12525
+ }
12526
+ };
12527
+ var AlphanumericValidator = class {
12528
+ constructor(options = {}) {
12529
+ this.options = options;
12530
+ }
12531
+ name = "alphanumeric";
12532
+ validate(value) {
12533
+ if (typeof value !== "string") {
12534
+ return { isValid: false, error: "Value must be a string" };
12535
+ }
12536
+ const pattern = new RegExp(
12537
+ `^[a-zA-Z0-9${this.options.allowSpaces ? " " : ""}${this.options.allowUnderscores ? "_" : ""}${this.options.allowHyphens ? "-" : ""}]*$`
12538
+ );
12539
+ return pattern.test(value) ? { isValid: true } : { isValid: false, error: "Value must contain only alphanumeric characters" };
12540
+ }
12541
+ autoTransform(value) {
12542
+ if (typeof value !== "string") {
12543
+ return { success: false };
12544
+ }
12545
+ let result = value;
12546
+ result = result.replace(/[^a-zA-Z0-9]/g, (char2) => {
12547
+ if (char2 === " " && this.options.allowSpaces) return " ";
12548
+ if (char2 === "_" && this.options.allowUnderscores) return "_";
12549
+ if (char2 === "-" && this.options.allowHyphens) return "-";
12550
+ return "";
12551
+ });
12552
+ return {
12553
+ success: true,
12554
+ correctedValue: result,
12555
+ message: "Removed non-alphanumeric characters"
12556
+ };
12557
+ }
12558
+ };
12559
+ var EmailValidator = class {
12560
+ constructor(options = {}) {
12561
+ this.options = options;
12562
+ }
12563
+ name = "email";
12564
+ validate(value) {
12565
+ if (typeof value !== "string") {
12566
+ return { isValid: false, error: "Value must be a string" };
12567
+ }
12568
+ const emailPattern = this.options.allowPlus ? /^[^\s@]+@[^\s@]+\.[^\s@]+$/ : /^[^\s@+]+@[^\s@]+\.[^\s@]+$/;
12569
+ if (!emailPattern.test(value)) {
12570
+ return { isValid: false, error: "Value must be a valid email address" };
12571
+ }
12572
+ if (this.options.requireTLD) {
12573
+ const parts = value.split(".");
12574
+ if (parts.length < 3 || parts[parts.length - 1].length < 2) {
12575
+ return { isValid: false, error: "Email must have a valid top-level domain" };
12576
+ }
12577
+ }
12578
+ return { isValid: true };
12579
+ }
12580
+ autoTransform(value) {
12581
+ if (typeof value !== "string") {
12582
+ return { success: false };
12583
+ }
12584
+ let result = value.trim().toLowerCase();
12585
+ if (!this.options.allowPlus) {
12586
+ result = result.replace(/\+.*@/, "@");
12587
+ }
12588
+ return {
12589
+ success: true,
12590
+ correctedValue: result,
12591
+ message: "Trimmed and lowercased email"
12592
+ };
12593
+ }
12594
+ };
12595
+ var LengthValidator = class {
12596
+ constructor(options = {}) {
12597
+ this.options = options;
12598
+ }
12599
+ name = "length";
12600
+ validate(value) {
12601
+ if (typeof value !== "string") {
12602
+ return { isValid: false, error: "Value must be a string" };
12603
+ }
12604
+ if (this.options.exact !== void 0 && value.length !== this.options.exact) {
12605
+ return { isValid: false, error: `Value must be exactly ${this.options.exact} characters long` };
12606
+ }
12607
+ if (this.options.min !== void 0 && value.length < this.options.min) {
12608
+ return { isValid: false, error: `Value must be at least ${this.options.min} characters long` };
12609
+ }
12610
+ if (this.options.max !== void 0 && value.length > this.options.max) {
12611
+ return { isValid: false, error: `Value must be at most ${this.options.max} characters long` };
12612
+ }
12613
+ return { isValid: true };
12614
+ }
12615
+ autoTransform(value) {
12616
+ if (typeof value !== "string") {
12617
+ return { success: false };
12618
+ }
12619
+ let result = value;
12620
+ if (this.options.max !== void 0 && result.length > this.options.max) {
12621
+ result = result.slice(0, this.options.max);
12622
+ }
12623
+ if (this.options.min !== void 0 && result.length < this.options.min) {
12624
+ result = result.padEnd(this.options.min);
12625
+ }
12626
+ return {
12627
+ success: true,
12628
+ correctedValue: result,
12629
+ message: "Adjusted string length"
12630
+ };
12631
+ }
12632
+ };
12633
+ var PatternValidator = class {
12634
+ constructor(options = { pattern: /.*/ }) {
12635
+ this.options = options;
12636
+ }
12637
+ name = "pattern";
12638
+ validate(value) {
12639
+ if (typeof value !== "string") {
12640
+ return { isValid: false, error: "Value must be a string" };
12641
+ }
12642
+ const pattern = new RegExp(this.options.pattern.source, this.options.flags);
12643
+ if (!pattern.test(value)) {
12644
+ return { isValid: false, error: this.options.errorMessage || "Value does not match required pattern" };
12645
+ }
12646
+ return { isValid: true };
12647
+ }
12648
+ autoTransform(value) {
12649
+ if (typeof value !== "string" || !this.options.replacement) {
12650
+ return { success: false };
12651
+ }
12652
+ const pattern = new RegExp(this.options.pattern.source, this.options.flags);
12653
+ const result = value.replace(pattern, this.options.replacement);
12654
+ return {
12655
+ success: true,
12656
+ correctedValue: result,
12657
+ message: "Replaced pattern matches"
12658
+ };
12659
+ }
12660
+ };
12661
+
12662
+ // src/decorators/transformers/transformer-decorators.ts
12663
+ var normalizePropertyName3 = (name) => {
12664
+ if (typeof name === "symbol") {
12665
+ return name.description ?? name.toString();
12666
+ }
12667
+ return name;
12668
+ };
12669
+ var registerTransformerMetadata = (context, metadata) => {
12670
+ const propertyName = normalizePropertyName3(context.name);
12671
+ const bag = getOrCreateMetadataBag(context);
12672
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
12673
+ if (!existing) {
12674
+ existing = {
12675
+ propertyName,
12676
+ metadata: {
12677
+ propertyName,
12678
+ transformers: [],
12679
+ validators: [],
12680
+ sanitizers: [],
12681
+ executionOrder: "both"
12682
+ }
12683
+ };
12684
+ bag.transformers.push(existing);
12685
+ }
12686
+ if (metadata.transformers) {
12687
+ existing.metadata.transformers.push(...metadata.transformers);
12688
+ }
12689
+ if (metadata.validators) {
12690
+ existing.metadata.validators.push(...metadata.validators);
12691
+ }
12692
+ if (metadata.sanitizers) {
12693
+ existing.metadata.sanitizers.push(...metadata.sanitizers);
12694
+ }
12695
+ if (metadata.executionOrder) {
12696
+ existing.metadata.executionOrder = metadata.executionOrder;
12697
+ }
12698
+ };
12699
+ function Trim(options) {
12700
+ return function(_value, context) {
12701
+ registerTransformerMetadata(context, {
12702
+ sanitizers: [new TrimTransformer(options)]
12703
+ });
12704
+ };
12705
+ }
12706
+ function Lower() {
12707
+ return function(_value, context) {
12708
+ registerTransformerMetadata(context, {
12709
+ sanitizers: [new CaseTransformer("lower")]
12710
+ });
12711
+ };
12712
+ }
12713
+ function Upper() {
12714
+ return function(_value, context) {
12715
+ registerTransformerMetadata(context, {
12716
+ sanitizers: [new CaseTransformer("upper")]
12717
+ });
12718
+ };
12719
+ }
12720
+ function Capitalize() {
12721
+ return function(_value, context) {
12722
+ registerTransformerMetadata(context, {
12723
+ sanitizers: [new CaseTransformer("capitalize")]
12724
+ });
12725
+ };
12726
+ }
12727
+ function Title() {
12728
+ return function(_value, context) {
12729
+ registerTransformerMetadata(context, {
12730
+ sanitizers: [new CaseTransformer("title")]
12731
+ });
12732
+ };
12733
+ }
12734
+ function Alphanumeric(options) {
12735
+ return function(_value, context) {
12736
+ registerTransformerMetadata(context, {
12737
+ validators: [new AlphanumericValidator(options)]
12738
+ });
12739
+ };
12740
+ }
12741
+ function Email(options) {
12742
+ return function(_value, context) {
12743
+ registerTransformerMetadata(context, {
12744
+ validators: [new EmailValidator(options)]
12745
+ });
12746
+ };
12747
+ }
12748
+ function Length(options) {
12749
+ return function(_value, context) {
12750
+ registerTransformerMetadata(context, {
12751
+ validators: [new LengthValidator(options)]
12752
+ });
12753
+ };
12754
+ }
12755
+ function Pattern(options) {
12756
+ return function(_value, context) {
12757
+ registerTransformerMetadata(context, {
12758
+ validators: [new PatternValidator(options)]
12759
+ });
12760
+ };
12761
+ }
12762
+
12763
+ // src/decorators/validators/country-validator-registry.ts
12764
+ var VALIDATOR_FACTORIES = /* @__PURE__ */ new Map();
12765
+ var registerValidator = (countryCode, identifierType, factory) => {
12766
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
12767
+ if (!countryCode) throw new Error("countryCode is required");
12768
+ if (!identifierType) throw new Error("identifierType is required");
12769
+ if (typeof factory !== "function") {
12770
+ throw new Error("factory must be a function that returns a validator");
12771
+ }
12772
+ VALIDATOR_FACTORIES.set(key, factory);
12773
+ };
12774
+ var resolveValidator = (countryCode, identifierType) => {
12775
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
12776
+ const factory = VALIDATOR_FACTORIES.get(key);
12777
+ return factory ? factory() : void 0;
12778
+ };
12779
+ var getRegisteredValidators = () => {
12780
+ return Array.from(VALIDATOR_FACTORIES.keys());
12781
+ };
12782
+ var hasValidator = (countryCode, identifierType) => {
12783
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
12784
+ return VALIDATOR_FACTORIES.has(key);
12785
+ };
12786
+
12787
+ // src/decorators/validators/built-in/br-cpf-validator.ts
12788
+ var CPFValidator = class {
12789
+ countryCode = "BR";
12790
+ identifierType = "cpf";
12791
+ name = "br-cpf";
12792
+ validate(value, options = {}) {
12793
+ const normalized = this.normalize(value);
12794
+ if (!/^\d{11}$/.test(normalized)) {
12795
+ return {
12796
+ isValid: false,
12797
+ error: options.errorMessage || "CPF must contain exactly 11 numeric digits"
12798
+ };
12799
+ }
12800
+ if (this.isKnownInvalid(normalized) && options.strict !== false) {
12801
+ return {
12802
+ isValid: false,
12803
+ error: options.errorMessage || "Invalid CPF number"
12804
+ };
12805
+ }
12806
+ if (!this.validateChecksum(normalized)) {
12807
+ return {
12808
+ isValid: false,
12809
+ error: options.errorMessage || "Invalid CPF checksum"
12810
+ };
12811
+ }
12812
+ return {
12813
+ isValid: true,
12814
+ normalizedValue: normalized,
12815
+ formattedValue: this.format(value)
12816
+ };
12817
+ }
12818
+ normalize(value) {
12819
+ return value.replace(/[^0-9]/g, "");
12820
+ }
12821
+ format(value) {
12822
+ const normalized = this.normalize(value);
12823
+ if (normalized.length !== 11) return value;
12824
+ return normalized.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
12825
+ }
12826
+ autoCorrect(value) {
12827
+ const normalized = this.normalize(value);
12828
+ if (normalized.length === 11) {
12829
+ return { success: true, correctedValue: this.format(normalized) };
12830
+ }
12831
+ if (normalized.length < 11) {
12832
+ const padded = normalized.padEnd(11, "0");
12833
+ return { success: true, correctedValue: this.format(padded) };
12834
+ }
12835
+ const truncated = normalized.slice(0, 11);
12836
+ return { success: true, correctedValue: this.format(truncated) };
12837
+ }
12838
+ isKnownInvalid(cpf) {
12839
+ return /^(\d)\1{10}$/.test(cpf);
12840
+ }
12841
+ validateChecksum(cpf) {
12842
+ const digits = cpf.split("").map(Number);
12843
+ let sum2 = 0;
12844
+ for (let i = 0; i < 9; i++) {
12845
+ sum2 += digits[i] * (10 - i);
12846
+ }
12847
+ let check1 = sum2 % 11;
12848
+ check1 = check1 < 2 ? 0 : 11 - check1;
12849
+ if (check1 !== digits[9]) {
12850
+ return false;
12851
+ }
12852
+ sum2 = 0;
12853
+ for (let i = 0; i < 10; i++) {
12854
+ sum2 += digits[i] * (11 - i);
12855
+ }
12856
+ let check2 = sum2 % 11;
12857
+ check2 = check2 < 2 ? 0 : 11 - check2;
12858
+ return check2 === digits[10];
12859
+ }
12860
+ };
12861
+
12862
+ // src/decorators/validators/built-in/br-cnpj-validator.ts
12863
+ var CNPJValidator = class {
12864
+ countryCode = "BR";
12865
+ identifierType = "cnpj";
12866
+ name = "br-cnpj";
12867
+ validate(value, options = {}) {
12868
+ const normalized = this.normalize(value);
12869
+ if (!/^\d{14}$/.test(normalized)) {
12870
+ return {
12871
+ isValid: false,
12872
+ error: options.errorMessage || "CNPJ must contain exactly 14 numeric digits"
12873
+ };
12874
+ }
12875
+ if (this.isKnownInvalid(normalized) && options.strict !== false) {
12876
+ return {
12877
+ isValid: false,
12878
+ error: options.errorMessage || "Invalid CNPJ number"
12879
+ };
12880
+ }
12881
+ if (!this.validateChecksum(normalized)) {
12882
+ return {
12883
+ isValid: false,
12884
+ error: options.errorMessage || "Invalid CNPJ checksum"
12885
+ };
12886
+ }
12887
+ return {
12888
+ isValid: true,
12889
+ normalizedValue: normalized,
12890
+ formattedValue: this.format(value)
12891
+ };
12892
+ }
12893
+ normalize(value) {
12894
+ return value.replace(/[^0-9]/g, "");
12895
+ }
12896
+ format(value) {
12897
+ const normalized = this.normalize(value);
12898
+ if (normalized.length !== 14) return value;
12899
+ return normalized.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "$1.$2.$3/$4-$5");
12900
+ }
12901
+ autoCorrect(value) {
12902
+ const normalized = this.normalize(value);
12903
+ if (normalized.length === 14) {
12904
+ return { success: true, correctedValue: this.format(normalized) };
12905
+ }
12906
+ if (normalized.length < 14) {
12907
+ const padded = normalized.padEnd(14, "0");
12908
+ return { success: true, correctedValue: this.format(padded) };
12909
+ }
12910
+ const truncated = normalized.slice(0, 14);
12911
+ return { success: true, correctedValue: this.format(truncated) };
12912
+ }
12913
+ isKnownInvalid(cnpj) {
12914
+ return /^(\d)\1{13}$/.test(cnpj);
12915
+ }
12916
+ validateChecksum(cnpj) {
12917
+ const digits = cnpj.split("").map(Number);
12918
+ const weights1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
12919
+ const weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
12920
+ let sum2 = 0;
12921
+ for (let i = 0; i < 12; i++) {
12922
+ sum2 += digits[i] * weights1[i];
12923
+ }
12924
+ let check1 = sum2 % 11;
12925
+ check1 = check1 < 2 ? 0 : 11 - check1;
12926
+ if (check1 !== digits[12]) {
12927
+ return false;
12928
+ }
12929
+ sum2 = 0;
12930
+ for (let i = 0; i < 13; i++) {
12931
+ sum2 += digits[i] * weights2[i];
12932
+ }
12933
+ let check2 = sum2 % 11;
12934
+ check2 = check2 < 2 ? 0 : 11 - check2;
12935
+ return check2 === digits[13];
12936
+ }
12937
+ };
12938
+
12939
+ // src/decorators/validators/built-in/br-cep-validator.ts
12940
+ var CEPValidator = class {
12941
+ countryCode = "BR";
12942
+ identifierType = "cep";
12943
+ name = "br-cep";
12944
+ validate(value, options = {}) {
12945
+ const normalized = this.normalize(value);
12946
+ if (!/^\d{8}$/.test(normalized)) {
12947
+ return {
12948
+ isValid: false,
12949
+ error: options.errorMessage || "CEP must contain exactly 8 numeric digits"
12950
+ };
12951
+ }
12952
+ return {
12953
+ isValid: true,
12954
+ normalizedValue: normalized,
12955
+ formattedValue: this.format(value)
12956
+ };
12957
+ }
12958
+ normalize(value) {
12959
+ return value.replace(/[^0-9]/g, "");
12960
+ }
12961
+ format(value) {
12962
+ const normalized = this.normalize(value);
12963
+ if (normalized.length !== 8) return value;
12964
+ return normalized.replace(/(\d{5})(\d{3})/, "$1-$2");
12965
+ }
12966
+ autoCorrect(value) {
12967
+ const normalized = this.normalize(value);
12968
+ if (normalized.length === 8) {
12969
+ return { success: true, correctedValue: this.format(normalized) };
12970
+ }
12971
+ if (normalized.length < 8) {
12972
+ const padded = normalized.padEnd(8, "0");
12973
+ return { success: true, correctedValue: this.format(padded) };
12974
+ }
12975
+ const truncated = normalized.slice(0, 8);
12976
+ return { success: true, correctedValue: this.format(truncated) };
12977
+ }
12978
+ };
12979
+
12980
+ // src/decorators/validators/country-validators-decorators.ts
12981
+ registerValidator("BR", "cpf", () => new CPFValidator());
12982
+ registerValidator("BR", "cnpj", () => new CNPJValidator());
12983
+ registerValidator("BR", "cep", () => new CEPValidator());
12984
+ var normalizePropertyName4 = (name) => {
12985
+ if (typeof name === "symbol") {
12986
+ return name.description ?? name.toString();
12987
+ }
12988
+ return name;
12989
+ };
12990
+ function CPF(options) {
12991
+ return function(_value, context) {
12992
+ const propertyName = normalizePropertyName4(context.name);
12993
+ const bag = getOrCreateMetadataBag(context);
12994
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
12995
+ if (!existing) {
12996
+ existing = {
12997
+ propertyName,
12998
+ metadata: {
12999
+ propertyName,
13000
+ transformers: [],
13001
+ validators: [],
13002
+ sanitizers: [],
13003
+ executionOrder: "both"
13004
+ }
13005
+ };
13006
+ bag.transformers.push(existing);
13007
+ }
13008
+ const validator = new CPFValidator();
13009
+ existing.metadata.validators.push({
13010
+ name: validator.name,
13011
+ validate: (value) => {
13012
+ const result = validator.validate(value, {
13013
+ strict: options?.strict ?? true,
13014
+ errorMessage: options?.errorMessage
13015
+ });
13016
+ return {
13017
+ isValid: result.isValid,
13018
+ error: result.error,
13019
+ message: result.error
13020
+ };
13021
+ },
13022
+ autoTransform: (value) => {
13023
+ const correction = validator.autoCorrect(value);
13024
+ if (correction?.success) {
13025
+ return {
13026
+ success: true,
13027
+ correctedValue: correction.correctedValue,
13028
+ message: correction.message
13029
+ };
13030
+ }
13031
+ return { success: false };
13032
+ }
13033
+ });
13034
+ existing.metadata.sanitizers.push({
13035
+ name: "cpf-formatter",
13036
+ sanitize: (value) => validator.format(value)
13037
+ });
13038
+ };
13039
+ }
13040
+ function CNPJ(options) {
13041
+ return function(_value, context) {
13042
+ const propertyName = normalizePropertyName4(context.name);
13043
+ const bag = getOrCreateMetadataBag(context);
13044
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13045
+ if (!existing) {
13046
+ existing = {
13047
+ propertyName,
13048
+ metadata: {
13049
+ propertyName,
13050
+ transformers: [],
13051
+ validators: [],
13052
+ sanitizers: [],
13053
+ executionOrder: "both"
13054
+ }
13055
+ };
13056
+ bag.transformers.push(existing);
13057
+ }
13058
+ const validator = new CNPJValidator();
13059
+ existing.metadata.validators.push({
13060
+ name: validator.name,
13061
+ validate: (value) => {
13062
+ const result = validator.validate(value, {
13063
+ strict: options?.strict ?? true,
13064
+ errorMessage: options?.errorMessage
13065
+ });
13066
+ return {
13067
+ isValid: result.isValid,
13068
+ error: result.error,
13069
+ message: result.error
13070
+ };
13071
+ },
13072
+ autoTransform: (value) => {
13073
+ const correction = validator.autoCorrect(value);
13074
+ if (correction?.success) {
13075
+ return {
13076
+ success: true,
13077
+ correctedValue: correction.correctedValue,
13078
+ message: correction.message
13079
+ };
13080
+ }
13081
+ return { success: false };
13082
+ }
13083
+ });
13084
+ existing.metadata.sanitizers.push({
13085
+ name: "cnpj-formatter",
13086
+ sanitize: (value) => validator.format(value)
13087
+ });
13088
+ };
13089
+ }
13090
+ function CEP(options) {
13091
+ return function(_value, context) {
13092
+ const propertyName = normalizePropertyName4(context.name);
13093
+ const bag = getOrCreateMetadataBag(context);
13094
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13095
+ if (!existing) {
13096
+ existing = {
13097
+ propertyName,
13098
+ metadata: {
13099
+ propertyName,
13100
+ transformers: [],
13101
+ validators: [],
13102
+ sanitizers: [],
13103
+ executionOrder: "both"
13104
+ }
13105
+ };
13106
+ bag.transformers.push(existing);
13107
+ }
13108
+ const validator = new CEPValidator();
13109
+ existing.metadata.validators.push({
13110
+ name: validator.name,
13111
+ validate: (value) => {
13112
+ const result = validator.validate(value, {
13113
+ strict: options?.strict ?? true,
13114
+ errorMessage: options?.errorMessage
13115
+ });
13116
+ return {
13117
+ isValid: result.isValid,
13118
+ error: result.error,
13119
+ message: result.error
13120
+ };
13121
+ },
13122
+ autoTransform: (value) => {
13123
+ const correction = validator.autoCorrect(value);
13124
+ if (correction?.success) {
13125
+ return {
13126
+ success: true,
13127
+ correctedValue: correction.correctedValue,
13128
+ message: correction.message
13129
+ };
13130
+ }
13131
+ return { success: false };
13132
+ }
13133
+ });
13134
+ existing.metadata.sanitizers.push({
13135
+ name: "cep-formatter",
13136
+ sanitize: (value) => validator.format(value)
13137
+ });
13138
+ };
13139
+ }
13140
+
12468
13141
  // src/core/execution/db-executor.ts
12469
13142
  function rowsToQueryResult(rows) {
12470
13143
  if (rows.length === 0) {
@@ -14279,11 +14952,16 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14279
14952
  };
14280
14953
  }
14281
14954
  export {
14955
+ Alphanumeric,
14282
14956
  AsyncLocalStorage,
14283
14957
  BelongsTo,
14284
14958
  BelongsToMany,
14285
14959
  BigIntTypeStrategy,
14286
14960
  BooleanTypeStrategy,
14961
+ CEP,
14962
+ CNPJ,
14963
+ CPF,
14964
+ Capitalize,
14287
14965
  Column,
14288
14966
  ConstructorMaterializationStrategy,
14289
14967
  DateTimeTypeStrategy,
@@ -14295,6 +14973,7 @@ export {
14295
14973
  DefaultTypeStrategy,
14296
14974
  DeleteQueryBuilder,
14297
14975
  DomainEventBus,
14976
+ Email,
14298
14977
  Entity,
14299
14978
  EntityStatus,
14300
14979
  HasMany,
@@ -14302,9 +14981,12 @@ export {
14302
14981
  InsertQueryBuilder,
14303
14982
  IntegerTypeStrategy,
14304
14983
  InterceptorPipeline,
14984
+ Length,
14985
+ Lower,
14305
14986
  MySqlDialect,
14306
14987
  Orm,
14307
14988
  OrmSession,
14989
+ Pattern,
14308
14990
  Pool,
14309
14991
  PostgresDialect,
14310
14992
  PrimaryKey,
@@ -14315,9 +14997,12 @@ export {
14315
14997
  SqlServerDialect,
14316
14998
  SqliteDialect,
14317
14999
  StringTypeStrategy,
15000
+ Title,
15001
+ Trim,
14318
15002
  TypeMappingService,
14319
15003
  TypeScriptGenerator,
14320
15004
  UpdateQueryBuilder,
15005
+ Upper,
14321
15006
  UuidTypeStrategy,
14322
15007
  abs,
14323
15008
  acos,
@@ -14435,6 +15120,7 @@ export {
14435
15120
  getDecoratorMetadata,
14436
15121
  getDeterministicComponentName,
14437
15122
  getOpenApiVersionForDialect,
15123
+ getRegisteredValidators,
14438
15124
  getSchemaIntrospector,
14439
15125
  getTableDefFromEntity,
14440
15126
  greatest,
@@ -14445,6 +15131,7 @@ export {
14445
15131
  hasNextPage as hasNextPageMeta,
14446
15132
  hasOne,
14447
15133
  hasPrevPage as hasPrevPageMeta,
15134
+ hasValidator,
14448
15135
  hour,
14449
15136
  hydrateRows,
14450
15137
  ifNull,
@@ -14538,6 +15225,7 @@ export {
14538
15225
  registerExpressionDispatcher,
14539
15226
  registerOperandDispatcher,
14540
15227
  registerSchemaIntrospector,
15228
+ registerValidator,
14541
15229
  relationFilterToOpenApiSchema,
14542
15230
  relationLoaderCache,
14543
15231
  renderColumnDefinition,
@@ -14545,6 +15233,7 @@ export {
14545
15233
  repeat,
14546
15234
  replace,
14547
15235
  replaceWithRefs,
15236
+ resolveValidator,
14548
15237
  responseToRef,
14549
15238
  reverse,
14550
15239
  right,