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.cjs CHANGED
@@ -43,11 +43,16 @@ var init_schema_plan_executor = __esm({
43
43
  // src/index.ts
44
44
  var index_exports = {};
45
45
  __export(index_exports, {
46
+ Alphanumeric: () => Alphanumeric,
46
47
  AsyncLocalStorage: () => AsyncLocalStorage,
47
48
  BelongsTo: () => BelongsTo,
48
49
  BelongsToMany: () => BelongsToMany,
49
50
  BigIntTypeStrategy: () => BigIntTypeStrategy,
50
51
  BooleanTypeStrategy: () => BooleanTypeStrategy,
52
+ CEP: () => CEP,
53
+ CNPJ: () => CNPJ,
54
+ CPF: () => CPF,
55
+ Capitalize: () => Capitalize,
51
56
  Column: () => Column,
52
57
  ConstructorMaterializationStrategy: () => ConstructorMaterializationStrategy,
53
58
  DateTimeTypeStrategy: () => DateTimeTypeStrategy,
@@ -59,6 +64,7 @@ __export(index_exports, {
59
64
  DefaultTypeStrategy: () => DefaultTypeStrategy,
60
65
  DeleteQueryBuilder: () => DeleteQueryBuilder,
61
66
  DomainEventBus: () => DomainEventBus,
67
+ Email: () => Email,
62
68
  Entity: () => Entity,
63
69
  EntityStatus: () => EntityStatus,
64
70
  HasMany: () => HasMany,
@@ -66,9 +72,12 @@ __export(index_exports, {
66
72
  InsertQueryBuilder: () => InsertQueryBuilder,
67
73
  IntegerTypeStrategy: () => IntegerTypeStrategy,
68
74
  InterceptorPipeline: () => InterceptorPipeline,
75
+ Length: () => Length,
76
+ Lower: () => Lower,
69
77
  MySqlDialect: () => MySqlDialect,
70
78
  Orm: () => Orm,
71
79
  OrmSession: () => OrmSession,
80
+ Pattern: () => Pattern,
72
81
  Pool: () => Pool,
73
82
  PostgresDialect: () => PostgresDialect,
74
83
  PrimaryKey: () => PrimaryKey,
@@ -79,9 +88,12 @@ __export(index_exports, {
79
88
  SqlServerDialect: () => SqlServerDialect,
80
89
  SqliteDialect: () => SqliteDialect,
81
90
  StringTypeStrategy: () => StringTypeStrategy,
91
+ Title: () => Title,
92
+ Trim: () => Trim,
82
93
  TypeMappingService: () => TypeMappingService,
83
94
  TypeScriptGenerator: () => TypeScriptGenerator,
84
95
  UpdateQueryBuilder: () => UpdateQueryBuilder,
96
+ Upper: () => Upper,
85
97
  UuidTypeStrategy: () => UuidTypeStrategy,
86
98
  abs: () => abs,
87
99
  acos: () => acos,
@@ -199,6 +211,7 @@ __export(index_exports, {
199
211
  getDecoratorMetadata: () => getDecoratorMetadata,
200
212
  getDeterministicComponentName: () => getDeterministicComponentName,
201
213
  getOpenApiVersionForDialect: () => getOpenApiVersionForDialect,
214
+ getRegisteredValidators: () => getRegisteredValidators,
202
215
  getSchemaIntrospector: () => getSchemaIntrospector,
203
216
  getTableDefFromEntity: () => getTableDefFromEntity,
204
217
  greatest: () => greatest,
@@ -209,6 +222,7 @@ __export(index_exports, {
209
222
  hasNextPageMeta: () => hasNextPage,
210
223
  hasOne: () => hasOne,
211
224
  hasPrevPageMeta: () => hasPrevPage,
225
+ hasValidator: () => hasValidator,
212
226
  hour: () => hour,
213
227
  hydrateRows: () => hydrateRows,
214
228
  ifNull: () => ifNull,
@@ -302,6 +316,7 @@ __export(index_exports, {
302
316
  registerExpressionDispatcher: () => registerExpressionDispatcher,
303
317
  registerOperandDispatcher: () => registerOperandDispatcher,
304
318
  registerSchemaIntrospector: () => registerSchemaIntrospector,
319
+ registerValidator: () => registerValidator,
305
320
  relationFilterToOpenApiSchema: () => relationFilterToOpenApiSchema,
306
321
  relationLoaderCache: () => relationLoaderCache,
307
322
  renderColumnDefinition: () => renderColumnDefinition,
@@ -309,6 +324,7 @@ __export(index_exports, {
309
324
  repeat: () => repeat,
310
325
  replace: () => replace,
311
326
  replaceWithRefs: () => replaceWithRefs,
327
+ resolveValidator: () => resolveValidator,
312
328
  responseToRef: () => responseToRef,
313
329
  reverse: () => reverse,
314
330
  right: () => right,
@@ -6483,7 +6499,8 @@ var ensureEntityMetadata = (target) => {
6483
6499
  target,
6484
6500
  tableName: target.name || "unknown",
6485
6501
  columns: {},
6486
- relations: {}
6502
+ relations: {},
6503
+ transformers: {}
6487
6504
  };
6488
6505
  metadataMap.set(target, meta);
6489
6506
  }
@@ -6503,6 +6520,10 @@ var addRelationMetadata = (target, propertyKey, relation) => {
6503
6520
  const meta = ensureEntityMetadata(target);
6504
6521
  meta.relations[propertyKey] = relation;
6505
6522
  };
6523
+ var addTransformerMetadata = (target, propertyKey, transformer) => {
6524
+ const meta = ensureEntityMetadata(target);
6525
+ meta.transformers[propertyKey] = transformer;
6526
+ };
6506
6527
  var setEntityTableName = (target, tableName, hooks) => {
6507
6528
  const meta = ensureEntityMetadata(target);
6508
6529
  if (tableName && tableName.length > 0) {
@@ -7863,6 +7884,28 @@ var isTableDef = (value) => {
7863
7884
  return true;
7864
7885
  };
7865
7886
 
7887
+ // src/decorators/decorator-metadata.ts
7888
+ var METADATA_KEY = "metal-orm:decorators";
7889
+ var getOrCreateMetadataBag = (context) => {
7890
+ const metadata = context.metadata || (context.metadata = {});
7891
+ let bag = metadata[METADATA_KEY];
7892
+ if (!bag) {
7893
+ bag = { columns: [], relations: [], transformers: [] };
7894
+ metadata[METADATA_KEY] = bag;
7895
+ }
7896
+ return bag;
7897
+ };
7898
+ var readMetadataBag = (context) => {
7899
+ return context.metadata?.[METADATA_KEY];
7900
+ };
7901
+ var readMetadataBagFromConstructor = (ctor) => {
7902
+ const metadataSymbol = Symbol.metadata;
7903
+ if (!metadataSymbol) return void 0;
7904
+ const metadata = Reflect.get(ctor, metadataSymbol);
7905
+ return metadata?.[METADATA_KEY];
7906
+ };
7907
+ var getDecoratorMetadata = (ctor) => readMetadataBagFromConstructor(ctor);
7908
+
7866
7909
  // src/decorators/bootstrap.ts
7867
7910
  var unwrapTarget = (target) => {
7868
7911
  if (typeof target === "function" && target.prototype === void 0) {
@@ -7959,6 +8002,12 @@ var bootstrapEntities = () => {
7959
8002
  const metas = getAllEntityMetadata();
7960
8003
  const tableMap = /* @__PURE__ */ new Map();
7961
8004
  for (const meta of metas) {
8005
+ const decoratorMetadata = getDecoratorMetadata(meta.target);
8006
+ if (decoratorMetadata?.transformers) {
8007
+ for (const { propertyName, metadata } of decoratorMetadata.transformers) {
8008
+ addTransformerMetadata(meta.target, propertyName, metadata);
8009
+ }
8010
+ }
7962
8011
  const table = buildTableDef(meta);
7963
8012
  tableMap.set(meta.target, table);
7964
8013
  }
@@ -12612,28 +12661,6 @@ var jsonify = (value) => {
12612
12661
  return result;
12613
12662
  };
12614
12663
 
12615
- // src/decorators/decorator-metadata.ts
12616
- var METADATA_KEY = "metal-orm:decorators";
12617
- var getOrCreateMetadataBag = (context) => {
12618
- const metadata = context.metadata || (context.metadata = {});
12619
- let bag = metadata[METADATA_KEY];
12620
- if (!bag) {
12621
- bag = { columns: [], relations: [] };
12622
- metadata[METADATA_KEY] = bag;
12623
- }
12624
- return bag;
12625
- };
12626
- var readMetadataBag = (context) => {
12627
- return context.metadata?.[METADATA_KEY];
12628
- };
12629
- var readMetadataBagFromConstructor = (ctor) => {
12630
- const metadataSymbol = Symbol.metadata;
12631
- if (!metadataSymbol) return void 0;
12632
- const metadata = Reflect.get(ctor, metadataSymbol);
12633
- return metadata?.[METADATA_KEY];
12634
- };
12635
- var getDecoratorMetadata = (ctor) => readMetadataBagFromConstructor(ctor);
12636
-
12637
12664
  // src/decorators/entity.ts
12638
12665
  var toSnakeCase2 = (value) => {
12639
12666
  return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-z0-9_]+/gi, "_").replace(/__+/g, "_").replace(/^_|_$/g, "").toLowerCase();
@@ -12806,6 +12833,668 @@ function BelongsToMany(options) {
12806
12833
  }));
12807
12834
  }
12808
12835
 
12836
+ // src/decorators/transformers/built-in/string-transformers.ts
12837
+ var TrimTransformer = class {
12838
+ constructor(options = {}) {
12839
+ this.options = options;
12840
+ }
12841
+ name = "trim";
12842
+ sanitize(value) {
12843
+ if (typeof value !== "string") return value;
12844
+ if (this.options.trimAll) {
12845
+ return value.trim();
12846
+ }
12847
+ let result = value;
12848
+ if (this.options.trimStart) {
12849
+ result = result.trimStart();
12850
+ }
12851
+ if (this.options.trimEnd) {
12852
+ result = result.trimEnd();
12853
+ }
12854
+ if (!this.options.trimStart && !this.options.trimEnd && !this.options.trimAll) {
12855
+ result = result.trim();
12856
+ }
12857
+ return result;
12858
+ }
12859
+ };
12860
+ var CaseTransformer = class {
12861
+ constructor(caseType) {
12862
+ this.caseType = caseType;
12863
+ this.name = `case-${caseType}`;
12864
+ }
12865
+ name;
12866
+ sanitize(value) {
12867
+ if (typeof value !== "string") return value;
12868
+ switch (this.caseType) {
12869
+ case "lower":
12870
+ return value.toLowerCase();
12871
+ case "upper":
12872
+ return value.toUpperCase();
12873
+ case "capitalize":
12874
+ return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
12875
+ case "title":
12876
+ return value.split(" ").map(
12877
+ (word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
12878
+ ).join(" ");
12879
+ default:
12880
+ return value;
12881
+ }
12882
+ }
12883
+ };
12884
+ var AlphanumericValidator = class {
12885
+ constructor(options = {}) {
12886
+ this.options = options;
12887
+ }
12888
+ name = "alphanumeric";
12889
+ validate(value) {
12890
+ if (typeof value !== "string") {
12891
+ return { isValid: false, error: "Value must be a string" };
12892
+ }
12893
+ const pattern = new RegExp(
12894
+ `^[a-zA-Z0-9${this.options.allowSpaces ? " " : ""}${this.options.allowUnderscores ? "_" : ""}${this.options.allowHyphens ? "-" : ""}]*$`
12895
+ );
12896
+ return pattern.test(value) ? { isValid: true } : { isValid: false, error: "Value must contain only alphanumeric characters" };
12897
+ }
12898
+ autoTransform(value) {
12899
+ if (typeof value !== "string") {
12900
+ return { success: false };
12901
+ }
12902
+ let result = value;
12903
+ result = result.replace(/[^a-zA-Z0-9]/g, (char2) => {
12904
+ if (char2 === " " && this.options.allowSpaces) return " ";
12905
+ if (char2 === "_" && this.options.allowUnderscores) return "_";
12906
+ if (char2 === "-" && this.options.allowHyphens) return "-";
12907
+ return "";
12908
+ });
12909
+ return {
12910
+ success: true,
12911
+ correctedValue: result,
12912
+ message: "Removed non-alphanumeric characters"
12913
+ };
12914
+ }
12915
+ };
12916
+ var EmailValidator = class {
12917
+ constructor(options = {}) {
12918
+ this.options = options;
12919
+ }
12920
+ name = "email";
12921
+ validate(value) {
12922
+ if (typeof value !== "string") {
12923
+ return { isValid: false, error: "Value must be a string" };
12924
+ }
12925
+ const emailPattern = this.options.allowPlus ? /^[^\s@]+@[^\s@]+\.[^\s@]+$/ : /^[^\s@+]+@[^\s@]+\.[^\s@]+$/;
12926
+ if (!emailPattern.test(value)) {
12927
+ return { isValid: false, error: "Value must be a valid email address" };
12928
+ }
12929
+ if (this.options.requireTLD) {
12930
+ const parts = value.split(".");
12931
+ if (parts.length < 3 || parts[parts.length - 1].length < 2) {
12932
+ return { isValid: false, error: "Email must have a valid top-level domain" };
12933
+ }
12934
+ }
12935
+ return { isValid: true };
12936
+ }
12937
+ autoTransform(value) {
12938
+ if (typeof value !== "string") {
12939
+ return { success: false };
12940
+ }
12941
+ let result = value.trim().toLowerCase();
12942
+ if (!this.options.allowPlus) {
12943
+ result = result.replace(/\+.*@/, "@");
12944
+ }
12945
+ return {
12946
+ success: true,
12947
+ correctedValue: result,
12948
+ message: "Trimmed and lowercased email"
12949
+ };
12950
+ }
12951
+ };
12952
+ var LengthValidator = class {
12953
+ constructor(options = {}) {
12954
+ this.options = options;
12955
+ }
12956
+ name = "length";
12957
+ validate(value) {
12958
+ if (typeof value !== "string") {
12959
+ return { isValid: false, error: "Value must be a string" };
12960
+ }
12961
+ if (this.options.exact !== void 0 && value.length !== this.options.exact) {
12962
+ return { isValid: false, error: `Value must be exactly ${this.options.exact} characters long` };
12963
+ }
12964
+ if (this.options.min !== void 0 && value.length < this.options.min) {
12965
+ return { isValid: false, error: `Value must be at least ${this.options.min} characters long` };
12966
+ }
12967
+ if (this.options.max !== void 0 && value.length > this.options.max) {
12968
+ return { isValid: false, error: `Value must be at most ${this.options.max} characters long` };
12969
+ }
12970
+ return { isValid: true };
12971
+ }
12972
+ autoTransform(value) {
12973
+ if (typeof value !== "string") {
12974
+ return { success: false };
12975
+ }
12976
+ let result = value;
12977
+ if (this.options.max !== void 0 && result.length > this.options.max) {
12978
+ result = result.slice(0, this.options.max);
12979
+ }
12980
+ if (this.options.min !== void 0 && result.length < this.options.min) {
12981
+ result = result.padEnd(this.options.min);
12982
+ }
12983
+ return {
12984
+ success: true,
12985
+ correctedValue: result,
12986
+ message: "Adjusted string length"
12987
+ };
12988
+ }
12989
+ };
12990
+ var PatternValidator = class {
12991
+ constructor(options = { pattern: /.*/ }) {
12992
+ this.options = options;
12993
+ }
12994
+ name = "pattern";
12995
+ validate(value) {
12996
+ if (typeof value !== "string") {
12997
+ return { isValid: false, error: "Value must be a string" };
12998
+ }
12999
+ const pattern = new RegExp(this.options.pattern.source, this.options.flags);
13000
+ if (!pattern.test(value)) {
13001
+ return { isValid: false, error: this.options.errorMessage || "Value does not match required pattern" };
13002
+ }
13003
+ return { isValid: true };
13004
+ }
13005
+ autoTransform(value) {
13006
+ if (typeof value !== "string" || !this.options.replacement) {
13007
+ return { success: false };
13008
+ }
13009
+ const pattern = new RegExp(this.options.pattern.source, this.options.flags);
13010
+ const result = value.replace(pattern, this.options.replacement);
13011
+ return {
13012
+ success: true,
13013
+ correctedValue: result,
13014
+ message: "Replaced pattern matches"
13015
+ };
13016
+ }
13017
+ };
13018
+
13019
+ // src/decorators/transformers/transformer-decorators.ts
13020
+ var normalizePropertyName3 = (name) => {
13021
+ if (typeof name === "symbol") {
13022
+ return name.description ?? name.toString();
13023
+ }
13024
+ return name;
13025
+ };
13026
+ var registerTransformerMetadata = (context, metadata) => {
13027
+ const propertyName = normalizePropertyName3(context.name);
13028
+ const bag = getOrCreateMetadataBag(context);
13029
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13030
+ if (!existing) {
13031
+ existing = {
13032
+ propertyName,
13033
+ metadata: {
13034
+ propertyName,
13035
+ transformers: [],
13036
+ validators: [],
13037
+ sanitizers: [],
13038
+ executionOrder: "both"
13039
+ }
13040
+ };
13041
+ bag.transformers.push(existing);
13042
+ }
13043
+ if (metadata.transformers) {
13044
+ existing.metadata.transformers.push(...metadata.transformers);
13045
+ }
13046
+ if (metadata.validators) {
13047
+ existing.metadata.validators.push(...metadata.validators);
13048
+ }
13049
+ if (metadata.sanitizers) {
13050
+ existing.metadata.sanitizers.push(...metadata.sanitizers);
13051
+ }
13052
+ if (metadata.executionOrder) {
13053
+ existing.metadata.executionOrder = metadata.executionOrder;
13054
+ }
13055
+ };
13056
+ function Trim(options) {
13057
+ return function(_value, context) {
13058
+ registerTransformerMetadata(context, {
13059
+ sanitizers: [new TrimTransformer(options)]
13060
+ });
13061
+ };
13062
+ }
13063
+ function Lower() {
13064
+ return function(_value, context) {
13065
+ registerTransformerMetadata(context, {
13066
+ sanitizers: [new CaseTransformer("lower")]
13067
+ });
13068
+ };
13069
+ }
13070
+ function Upper() {
13071
+ return function(_value, context) {
13072
+ registerTransformerMetadata(context, {
13073
+ sanitizers: [new CaseTransformer("upper")]
13074
+ });
13075
+ };
13076
+ }
13077
+ function Capitalize() {
13078
+ return function(_value, context) {
13079
+ registerTransformerMetadata(context, {
13080
+ sanitizers: [new CaseTransformer("capitalize")]
13081
+ });
13082
+ };
13083
+ }
13084
+ function Title() {
13085
+ return function(_value, context) {
13086
+ registerTransformerMetadata(context, {
13087
+ sanitizers: [new CaseTransformer("title")]
13088
+ });
13089
+ };
13090
+ }
13091
+ function Alphanumeric(options) {
13092
+ return function(_value, context) {
13093
+ registerTransformerMetadata(context, {
13094
+ validators: [new AlphanumericValidator(options)]
13095
+ });
13096
+ };
13097
+ }
13098
+ function Email(options) {
13099
+ return function(_value, context) {
13100
+ registerTransformerMetadata(context, {
13101
+ validators: [new EmailValidator(options)]
13102
+ });
13103
+ };
13104
+ }
13105
+ function Length(options) {
13106
+ return function(_value, context) {
13107
+ registerTransformerMetadata(context, {
13108
+ validators: [new LengthValidator(options)]
13109
+ });
13110
+ };
13111
+ }
13112
+ function Pattern(options) {
13113
+ return function(_value, context) {
13114
+ registerTransformerMetadata(context, {
13115
+ validators: [new PatternValidator(options)]
13116
+ });
13117
+ };
13118
+ }
13119
+
13120
+ // src/decorators/validators/country-validator-registry.ts
13121
+ var VALIDATOR_FACTORIES = /* @__PURE__ */ new Map();
13122
+ var registerValidator = (countryCode, identifierType, factory) => {
13123
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
13124
+ if (!countryCode) throw new Error("countryCode is required");
13125
+ if (!identifierType) throw new Error("identifierType is required");
13126
+ if (typeof factory !== "function") {
13127
+ throw new Error("factory must be a function that returns a validator");
13128
+ }
13129
+ VALIDATOR_FACTORIES.set(key, factory);
13130
+ };
13131
+ var resolveValidator = (countryCode, identifierType) => {
13132
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
13133
+ const factory = VALIDATOR_FACTORIES.get(key);
13134
+ return factory ? factory() : void 0;
13135
+ };
13136
+ var getRegisteredValidators = () => {
13137
+ return Array.from(VALIDATOR_FACTORIES.keys());
13138
+ };
13139
+ var hasValidator = (countryCode, identifierType) => {
13140
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
13141
+ return VALIDATOR_FACTORIES.has(key);
13142
+ };
13143
+
13144
+ // src/decorators/validators/built-in/br-cpf-validator.ts
13145
+ var CPFValidator = class {
13146
+ countryCode = "BR";
13147
+ identifierType = "cpf";
13148
+ name = "br-cpf";
13149
+ validate(value, options = {}) {
13150
+ const normalized = this.normalize(value);
13151
+ if (!/^\d{11}$/.test(normalized)) {
13152
+ return {
13153
+ isValid: false,
13154
+ error: options.errorMessage || "CPF must contain exactly 11 numeric digits"
13155
+ };
13156
+ }
13157
+ if (this.isKnownInvalid(normalized) && options.strict !== false) {
13158
+ return {
13159
+ isValid: false,
13160
+ error: options.errorMessage || "Invalid CPF number"
13161
+ };
13162
+ }
13163
+ if (!this.validateChecksum(normalized)) {
13164
+ return {
13165
+ isValid: false,
13166
+ error: options.errorMessage || "Invalid CPF checksum"
13167
+ };
13168
+ }
13169
+ return {
13170
+ isValid: true,
13171
+ normalizedValue: normalized,
13172
+ formattedValue: this.format(value)
13173
+ };
13174
+ }
13175
+ normalize(value) {
13176
+ return value.replace(/[^0-9]/g, "");
13177
+ }
13178
+ format(value) {
13179
+ const normalized = this.normalize(value);
13180
+ if (normalized.length !== 11) return value;
13181
+ return normalized.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
13182
+ }
13183
+ autoCorrect(value) {
13184
+ const normalized = this.normalize(value);
13185
+ if (normalized.length === 11) {
13186
+ return { success: true, correctedValue: this.format(normalized) };
13187
+ }
13188
+ if (normalized.length < 11) {
13189
+ const padded = normalized.padEnd(11, "0");
13190
+ return { success: true, correctedValue: this.format(padded) };
13191
+ }
13192
+ const truncated = normalized.slice(0, 11);
13193
+ return { success: true, correctedValue: this.format(truncated) };
13194
+ }
13195
+ isKnownInvalid(cpf) {
13196
+ return /^(\d)\1{10}$/.test(cpf);
13197
+ }
13198
+ validateChecksum(cpf) {
13199
+ const digits = cpf.split("").map(Number);
13200
+ let sum2 = 0;
13201
+ for (let i = 0; i < 9; i++) {
13202
+ sum2 += digits[i] * (10 - i);
13203
+ }
13204
+ let check1 = sum2 % 11;
13205
+ check1 = check1 < 2 ? 0 : 11 - check1;
13206
+ if (check1 !== digits[9]) {
13207
+ return false;
13208
+ }
13209
+ sum2 = 0;
13210
+ for (let i = 0; i < 10; i++) {
13211
+ sum2 += digits[i] * (11 - i);
13212
+ }
13213
+ let check2 = sum2 % 11;
13214
+ check2 = check2 < 2 ? 0 : 11 - check2;
13215
+ return check2 === digits[10];
13216
+ }
13217
+ };
13218
+
13219
+ // src/decorators/validators/built-in/br-cnpj-validator.ts
13220
+ var CNPJValidator = class {
13221
+ countryCode = "BR";
13222
+ identifierType = "cnpj";
13223
+ name = "br-cnpj";
13224
+ validate(value, options = {}) {
13225
+ const normalized = this.normalize(value);
13226
+ if (!/^\d{14}$/.test(normalized)) {
13227
+ return {
13228
+ isValid: false,
13229
+ error: options.errorMessage || "CNPJ must contain exactly 14 numeric digits"
13230
+ };
13231
+ }
13232
+ if (this.isKnownInvalid(normalized) && options.strict !== false) {
13233
+ return {
13234
+ isValid: false,
13235
+ error: options.errorMessage || "Invalid CNPJ number"
13236
+ };
13237
+ }
13238
+ if (!this.validateChecksum(normalized)) {
13239
+ return {
13240
+ isValid: false,
13241
+ error: options.errorMessage || "Invalid CNPJ checksum"
13242
+ };
13243
+ }
13244
+ return {
13245
+ isValid: true,
13246
+ normalizedValue: normalized,
13247
+ formattedValue: this.format(value)
13248
+ };
13249
+ }
13250
+ normalize(value) {
13251
+ return value.replace(/[^0-9]/g, "");
13252
+ }
13253
+ format(value) {
13254
+ const normalized = this.normalize(value);
13255
+ if (normalized.length !== 14) return value;
13256
+ return normalized.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "$1.$2.$3/$4-$5");
13257
+ }
13258
+ autoCorrect(value) {
13259
+ const normalized = this.normalize(value);
13260
+ if (normalized.length === 14) {
13261
+ return { success: true, correctedValue: this.format(normalized) };
13262
+ }
13263
+ if (normalized.length < 14) {
13264
+ const padded = normalized.padEnd(14, "0");
13265
+ return { success: true, correctedValue: this.format(padded) };
13266
+ }
13267
+ const truncated = normalized.slice(0, 14);
13268
+ return { success: true, correctedValue: this.format(truncated) };
13269
+ }
13270
+ isKnownInvalid(cnpj) {
13271
+ return /^(\d)\1{13}$/.test(cnpj);
13272
+ }
13273
+ validateChecksum(cnpj) {
13274
+ const digits = cnpj.split("").map(Number);
13275
+ const weights1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
13276
+ const weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
13277
+ let sum2 = 0;
13278
+ for (let i = 0; i < 12; i++) {
13279
+ sum2 += digits[i] * weights1[i];
13280
+ }
13281
+ let check1 = sum2 % 11;
13282
+ check1 = check1 < 2 ? 0 : 11 - check1;
13283
+ if (check1 !== digits[12]) {
13284
+ return false;
13285
+ }
13286
+ sum2 = 0;
13287
+ for (let i = 0; i < 13; i++) {
13288
+ sum2 += digits[i] * weights2[i];
13289
+ }
13290
+ let check2 = sum2 % 11;
13291
+ check2 = check2 < 2 ? 0 : 11 - check2;
13292
+ return check2 === digits[13];
13293
+ }
13294
+ };
13295
+
13296
+ // src/decorators/validators/built-in/br-cep-validator.ts
13297
+ var CEPValidator = class {
13298
+ countryCode = "BR";
13299
+ identifierType = "cep";
13300
+ name = "br-cep";
13301
+ validate(value, options = {}) {
13302
+ const normalized = this.normalize(value);
13303
+ if (!/^\d{8}$/.test(normalized)) {
13304
+ return {
13305
+ isValid: false,
13306
+ error: options.errorMessage || "CEP must contain exactly 8 numeric digits"
13307
+ };
13308
+ }
13309
+ return {
13310
+ isValid: true,
13311
+ normalizedValue: normalized,
13312
+ formattedValue: this.format(value)
13313
+ };
13314
+ }
13315
+ normalize(value) {
13316
+ return value.replace(/[^0-9]/g, "");
13317
+ }
13318
+ format(value) {
13319
+ const normalized = this.normalize(value);
13320
+ if (normalized.length !== 8) return value;
13321
+ return normalized.replace(/(\d{5})(\d{3})/, "$1-$2");
13322
+ }
13323
+ autoCorrect(value) {
13324
+ const normalized = this.normalize(value);
13325
+ if (normalized.length === 8) {
13326
+ return { success: true, correctedValue: this.format(normalized) };
13327
+ }
13328
+ if (normalized.length < 8) {
13329
+ const padded = normalized.padEnd(8, "0");
13330
+ return { success: true, correctedValue: this.format(padded) };
13331
+ }
13332
+ const truncated = normalized.slice(0, 8);
13333
+ return { success: true, correctedValue: this.format(truncated) };
13334
+ }
13335
+ };
13336
+
13337
+ // src/decorators/validators/country-validators-decorators.ts
13338
+ registerValidator("BR", "cpf", () => new CPFValidator());
13339
+ registerValidator("BR", "cnpj", () => new CNPJValidator());
13340
+ registerValidator("BR", "cep", () => new CEPValidator());
13341
+ var normalizePropertyName4 = (name) => {
13342
+ if (typeof name === "symbol") {
13343
+ return name.description ?? name.toString();
13344
+ }
13345
+ return name;
13346
+ };
13347
+ function CPF(options) {
13348
+ return function(_value, context) {
13349
+ const propertyName = normalizePropertyName4(context.name);
13350
+ const bag = getOrCreateMetadataBag(context);
13351
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13352
+ if (!existing) {
13353
+ existing = {
13354
+ propertyName,
13355
+ metadata: {
13356
+ propertyName,
13357
+ transformers: [],
13358
+ validators: [],
13359
+ sanitizers: [],
13360
+ executionOrder: "both"
13361
+ }
13362
+ };
13363
+ bag.transformers.push(existing);
13364
+ }
13365
+ const validator = new CPFValidator();
13366
+ existing.metadata.validators.push({
13367
+ name: validator.name,
13368
+ validate: (value) => {
13369
+ const result = validator.validate(value, {
13370
+ strict: options?.strict ?? true,
13371
+ errorMessage: options?.errorMessage
13372
+ });
13373
+ return {
13374
+ isValid: result.isValid,
13375
+ error: result.error,
13376
+ message: result.error
13377
+ };
13378
+ },
13379
+ autoTransform: (value) => {
13380
+ const correction = validator.autoCorrect(value);
13381
+ if (correction?.success) {
13382
+ return {
13383
+ success: true,
13384
+ correctedValue: correction.correctedValue,
13385
+ message: correction.message
13386
+ };
13387
+ }
13388
+ return { success: false };
13389
+ }
13390
+ });
13391
+ existing.metadata.sanitizers.push({
13392
+ name: "cpf-formatter",
13393
+ sanitize: (value) => validator.format(value)
13394
+ });
13395
+ };
13396
+ }
13397
+ function CNPJ(options) {
13398
+ return function(_value, context) {
13399
+ const propertyName = normalizePropertyName4(context.name);
13400
+ const bag = getOrCreateMetadataBag(context);
13401
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13402
+ if (!existing) {
13403
+ existing = {
13404
+ propertyName,
13405
+ metadata: {
13406
+ propertyName,
13407
+ transformers: [],
13408
+ validators: [],
13409
+ sanitizers: [],
13410
+ executionOrder: "both"
13411
+ }
13412
+ };
13413
+ bag.transformers.push(existing);
13414
+ }
13415
+ const validator = new CNPJValidator();
13416
+ existing.metadata.validators.push({
13417
+ name: validator.name,
13418
+ validate: (value) => {
13419
+ const result = validator.validate(value, {
13420
+ strict: options?.strict ?? true,
13421
+ errorMessage: options?.errorMessage
13422
+ });
13423
+ return {
13424
+ isValid: result.isValid,
13425
+ error: result.error,
13426
+ message: result.error
13427
+ };
13428
+ },
13429
+ autoTransform: (value) => {
13430
+ const correction = validator.autoCorrect(value);
13431
+ if (correction?.success) {
13432
+ return {
13433
+ success: true,
13434
+ correctedValue: correction.correctedValue,
13435
+ message: correction.message
13436
+ };
13437
+ }
13438
+ return { success: false };
13439
+ }
13440
+ });
13441
+ existing.metadata.sanitizers.push({
13442
+ name: "cnpj-formatter",
13443
+ sanitize: (value) => validator.format(value)
13444
+ });
13445
+ };
13446
+ }
13447
+ function CEP(options) {
13448
+ return function(_value, context) {
13449
+ const propertyName = normalizePropertyName4(context.name);
13450
+ const bag = getOrCreateMetadataBag(context);
13451
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13452
+ if (!existing) {
13453
+ existing = {
13454
+ propertyName,
13455
+ metadata: {
13456
+ propertyName,
13457
+ transformers: [],
13458
+ validators: [],
13459
+ sanitizers: [],
13460
+ executionOrder: "both"
13461
+ }
13462
+ };
13463
+ bag.transformers.push(existing);
13464
+ }
13465
+ const validator = new CEPValidator();
13466
+ existing.metadata.validators.push({
13467
+ name: validator.name,
13468
+ validate: (value) => {
13469
+ const result = validator.validate(value, {
13470
+ strict: options?.strict ?? true,
13471
+ errorMessage: options?.errorMessage
13472
+ });
13473
+ return {
13474
+ isValid: result.isValid,
13475
+ error: result.error,
13476
+ message: result.error
13477
+ };
13478
+ },
13479
+ autoTransform: (value) => {
13480
+ const correction = validator.autoCorrect(value);
13481
+ if (correction?.success) {
13482
+ return {
13483
+ success: true,
13484
+ correctedValue: correction.correctedValue,
13485
+ message: correction.message
13486
+ };
13487
+ }
13488
+ return { success: false };
13489
+ }
13490
+ });
13491
+ existing.metadata.sanitizers.push({
13492
+ name: "cep-formatter",
13493
+ sanitize: (value) => validator.format(value)
13494
+ });
13495
+ };
13496
+ }
13497
+
12809
13498
  // src/core/execution/db-executor.ts
12810
13499
  function rowsToQueryResult(rows) {
12811
13500
  if (rows.length === 0) {
@@ -14621,11 +15310,16 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14621
15310
  }
14622
15311
  // Annotate the CommonJS export names for ESM import in node:
14623
15312
  0 && (module.exports = {
15313
+ Alphanumeric,
14624
15314
  AsyncLocalStorage,
14625
15315
  BelongsTo,
14626
15316
  BelongsToMany,
14627
15317
  BigIntTypeStrategy,
14628
15318
  BooleanTypeStrategy,
15319
+ CEP,
15320
+ CNPJ,
15321
+ CPF,
15322
+ Capitalize,
14629
15323
  Column,
14630
15324
  ConstructorMaterializationStrategy,
14631
15325
  DateTimeTypeStrategy,
@@ -14637,6 +15331,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14637
15331
  DefaultTypeStrategy,
14638
15332
  DeleteQueryBuilder,
14639
15333
  DomainEventBus,
15334
+ Email,
14640
15335
  Entity,
14641
15336
  EntityStatus,
14642
15337
  HasMany,
@@ -14644,9 +15339,12 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14644
15339
  InsertQueryBuilder,
14645
15340
  IntegerTypeStrategy,
14646
15341
  InterceptorPipeline,
15342
+ Length,
15343
+ Lower,
14647
15344
  MySqlDialect,
14648
15345
  Orm,
14649
15346
  OrmSession,
15347
+ Pattern,
14650
15348
  Pool,
14651
15349
  PostgresDialect,
14652
15350
  PrimaryKey,
@@ -14657,9 +15355,12 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14657
15355
  SqlServerDialect,
14658
15356
  SqliteDialect,
14659
15357
  StringTypeStrategy,
15358
+ Title,
15359
+ Trim,
14660
15360
  TypeMappingService,
14661
15361
  TypeScriptGenerator,
14662
15362
  UpdateQueryBuilder,
15363
+ Upper,
14663
15364
  UuidTypeStrategy,
14664
15365
  abs,
14665
15366
  acos,
@@ -14777,6 +15478,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14777
15478
  getDecoratorMetadata,
14778
15479
  getDeterministicComponentName,
14779
15480
  getOpenApiVersionForDialect,
15481
+ getRegisteredValidators,
14780
15482
  getSchemaIntrospector,
14781
15483
  getTableDefFromEntity,
14782
15484
  greatest,
@@ -14787,6 +15489,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14787
15489
  hasNextPageMeta,
14788
15490
  hasOne,
14789
15491
  hasPrevPageMeta,
15492
+ hasValidator,
14790
15493
  hour,
14791
15494
  hydrateRows,
14792
15495
  ifNull,
@@ -14880,6 +15583,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14880
15583
  registerExpressionDispatcher,
14881
15584
  registerOperandDispatcher,
14882
15585
  registerSchemaIntrospector,
15586
+ registerValidator,
14883
15587
  relationFilterToOpenApiSchema,
14884
15588
  relationLoaderCache,
14885
15589
  renderColumnDefinition,
@@ -14887,6 +15591,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14887
15591
  repeat,
14888
15592
  replace,
14889
15593
  replaceWithRefs,
15594
+ resolveValidator,
14890
15595
  responseToRef,
14891
15596
  reverse,
14892
15597
  right,