metal-orm 1.0.93 → 1.0.95

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,
@@ -196,9 +208,12 @@ __export(index_exports, {
196
208
  generateSchemaSqlFor: () => generateSchemaSqlFor,
197
209
  getColumn: () => getColumn,
198
210
  getColumnMap: () => getColumnMap,
211
+ getColumnType: () => getColumnType,
212
+ getDateKind: () => getDateKind,
199
213
  getDecoratorMetadata: () => getDecoratorMetadata,
200
214
  getDeterministicComponentName: () => getDeterministicComponentName,
201
215
  getOpenApiVersionForDialect: () => getOpenApiVersionForDialect,
216
+ getRegisteredValidators: () => getRegisteredValidators,
202
217
  getSchemaIntrospector: () => getSchemaIntrospector,
203
218
  getTableDefFromEntity: () => getTableDefFromEntity,
204
219
  greatest: () => greatest,
@@ -209,6 +224,7 @@ __export(index_exports, {
209
224
  hasNextPageMeta: () => hasNextPage,
210
225
  hasOne: () => hasOne,
211
226
  hasPrevPageMeta: () => hasPrevPage,
227
+ hasValidator: () => hasValidator,
212
228
  hour: () => hour,
213
229
  hydrateRows: () => hydrateRows,
214
230
  ifNull: () => ifNull,
@@ -302,6 +318,7 @@ __export(index_exports, {
302
318
  registerExpressionDispatcher: () => registerExpressionDispatcher,
303
319
  registerOperandDispatcher: () => registerOperandDispatcher,
304
320
  registerSchemaIntrospector: () => registerSchemaIntrospector,
321
+ registerValidator: () => registerValidator,
305
322
  relationFilterToOpenApiSchema: () => relationFilterToOpenApiSchema,
306
323
  relationLoaderCache: () => relationLoaderCache,
307
324
  renderColumnDefinition: () => renderColumnDefinition,
@@ -309,6 +326,7 @@ __export(index_exports, {
309
326
  repeat: () => repeat,
310
327
  replace: () => replace,
311
328
  replaceWithRefs: () => replaceWithRefs,
329
+ resolveValidator: () => resolveValidator,
312
330
  responseToRef: () => responseToRef,
313
331
  reverse: () => reverse,
314
332
  right: () => right,
@@ -6483,7 +6501,8 @@ var ensureEntityMetadata = (target) => {
6483
6501
  target,
6484
6502
  tableName: target.name || "unknown",
6485
6503
  columns: {},
6486
- relations: {}
6504
+ relations: {},
6505
+ transformers: {}
6487
6506
  };
6488
6507
  metadataMap.set(target, meta);
6489
6508
  }
@@ -6503,6 +6522,10 @@ var addRelationMetadata = (target, propertyKey, relation) => {
6503
6522
  const meta = ensureEntityMetadata(target);
6504
6523
  meta.relations[propertyKey] = relation;
6505
6524
  };
6525
+ var addTransformerMetadata = (target, propertyKey, transformer) => {
6526
+ const meta = ensureEntityMetadata(target);
6527
+ meta.transformers[propertyKey] = transformer;
6528
+ };
6506
6529
  var setEntityTableName = (target, tableName, hooks) => {
6507
6530
  const meta = ensureEntityMetadata(target);
6508
6531
  if (tableName && tableName.length > 0) {
@@ -7863,6 +7886,28 @@ var isTableDef = (value) => {
7863
7886
  return true;
7864
7887
  };
7865
7888
 
7889
+ // src/decorators/decorator-metadata.ts
7890
+ var METADATA_KEY = "metal-orm:decorators";
7891
+ var getOrCreateMetadataBag = (context) => {
7892
+ const metadata = context.metadata || (context.metadata = {});
7893
+ let bag = metadata[METADATA_KEY];
7894
+ if (!bag) {
7895
+ bag = { columns: [], relations: [], transformers: [] };
7896
+ metadata[METADATA_KEY] = bag;
7897
+ }
7898
+ return bag;
7899
+ };
7900
+ var readMetadataBag = (context) => {
7901
+ return context.metadata?.[METADATA_KEY];
7902
+ };
7903
+ var readMetadataBagFromConstructor = (ctor) => {
7904
+ const metadataSymbol = Symbol.metadata;
7905
+ if (!metadataSymbol) return void 0;
7906
+ const metadata = Reflect.get(ctor, metadataSymbol);
7907
+ return metadata?.[METADATA_KEY];
7908
+ };
7909
+ var getDecoratorMetadata = (ctor) => readMetadataBagFromConstructor(ctor);
7910
+
7866
7911
  // src/decorators/bootstrap.ts
7867
7912
  var unwrapTarget = (target) => {
7868
7913
  if (typeof target === "function" && target.prototype === void 0) {
@@ -7959,6 +8004,12 @@ var bootstrapEntities = () => {
7959
8004
  const metas = getAllEntityMetadata();
7960
8005
  const tableMap = /* @__PURE__ */ new Map();
7961
8006
  for (const meta of metas) {
8007
+ const decoratorMetadata = getDecoratorMetadata(meta.target);
8008
+ if (decoratorMetadata?.transformers) {
8009
+ for (const { propertyName, metadata } of decoratorMetadata.transformers) {
8010
+ addTransformerMetadata(meta.target, propertyName, metadata);
8011
+ }
8012
+ }
7962
8013
  const table = buildTableDef(meta);
7963
8014
  tableMap.set(meta.target, table);
7964
8015
  }
@@ -12601,6 +12652,31 @@ var Orm = class {
12601
12652
  }
12602
12653
  };
12603
12654
 
12655
+ // src/orm/column-introspection.ts
12656
+ var getColumnDefFromTarget = (target, column) => {
12657
+ if (typeof target === "function") {
12658
+ const meta = getEntityMetadata(target);
12659
+ if (!meta?.columns) return void 0;
12660
+ return meta.columns[column];
12661
+ }
12662
+ const table = target;
12663
+ return table.columns[column];
12664
+ };
12665
+ var getColumnType = (target, column) => {
12666
+ const col2 = getColumnDefFromTarget(target, column);
12667
+ if (!col2?.type) return void 0;
12668
+ return normalizeColumnType(col2.type);
12669
+ };
12670
+ var getDateKind = (target, column) => {
12671
+ const type = getColumnType(target, column);
12672
+ if (!type) return void 0;
12673
+ if (type === "date") return "date";
12674
+ if (type === "datetime" || type === "timestamp" || type === "timestamptz") {
12675
+ return "date-time";
12676
+ }
12677
+ return void 0;
12678
+ };
12679
+
12604
12680
  // src/orm/jsonify.ts
12605
12681
  var jsonify = (value) => {
12606
12682
  const record = value;
@@ -12612,28 +12688,6 @@ var jsonify = (value) => {
12612
12688
  return result;
12613
12689
  };
12614
12690
 
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
12691
  // src/decorators/entity.ts
12638
12692
  var toSnakeCase2 = (value) => {
12639
12693
  return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-z0-9_]+/gi, "_").replace(/__+/g, "_").replace(/^_|_$/g, "").toLowerCase();
@@ -12806,6 +12860,668 @@ function BelongsToMany(options) {
12806
12860
  }));
12807
12861
  }
12808
12862
 
12863
+ // src/decorators/transformers/built-in/string-transformers.ts
12864
+ var TrimTransformer = class {
12865
+ constructor(options = {}) {
12866
+ this.options = options;
12867
+ }
12868
+ name = "trim";
12869
+ sanitize(value) {
12870
+ if (typeof value !== "string") return value;
12871
+ if (this.options.trimAll) {
12872
+ return value.trim();
12873
+ }
12874
+ let result = value;
12875
+ if (this.options.trimStart) {
12876
+ result = result.trimStart();
12877
+ }
12878
+ if (this.options.trimEnd) {
12879
+ result = result.trimEnd();
12880
+ }
12881
+ if (!this.options.trimStart && !this.options.trimEnd && !this.options.trimAll) {
12882
+ result = result.trim();
12883
+ }
12884
+ return result;
12885
+ }
12886
+ };
12887
+ var CaseTransformer = class {
12888
+ constructor(caseType) {
12889
+ this.caseType = caseType;
12890
+ this.name = `case-${caseType}`;
12891
+ }
12892
+ name;
12893
+ sanitize(value) {
12894
+ if (typeof value !== "string") return value;
12895
+ switch (this.caseType) {
12896
+ case "lower":
12897
+ return value.toLowerCase();
12898
+ case "upper":
12899
+ return value.toUpperCase();
12900
+ case "capitalize":
12901
+ return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
12902
+ case "title":
12903
+ return value.split(" ").map(
12904
+ (word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
12905
+ ).join(" ");
12906
+ default:
12907
+ return value;
12908
+ }
12909
+ }
12910
+ };
12911
+ var AlphanumericValidator = class {
12912
+ constructor(options = {}) {
12913
+ this.options = options;
12914
+ }
12915
+ name = "alphanumeric";
12916
+ validate(value) {
12917
+ if (typeof value !== "string") {
12918
+ return { isValid: false, error: "Value must be a string" };
12919
+ }
12920
+ const pattern = new RegExp(
12921
+ `^[a-zA-Z0-9${this.options.allowSpaces ? " " : ""}${this.options.allowUnderscores ? "_" : ""}${this.options.allowHyphens ? "-" : ""}]*$`
12922
+ );
12923
+ return pattern.test(value) ? { isValid: true } : { isValid: false, error: "Value must contain only alphanumeric characters" };
12924
+ }
12925
+ autoTransform(value) {
12926
+ if (typeof value !== "string") {
12927
+ return { success: false };
12928
+ }
12929
+ let result = value;
12930
+ result = result.replace(/[^a-zA-Z0-9]/g, (char2) => {
12931
+ if (char2 === " " && this.options.allowSpaces) return " ";
12932
+ if (char2 === "_" && this.options.allowUnderscores) return "_";
12933
+ if (char2 === "-" && this.options.allowHyphens) return "-";
12934
+ return "";
12935
+ });
12936
+ return {
12937
+ success: true,
12938
+ correctedValue: result,
12939
+ message: "Removed non-alphanumeric characters"
12940
+ };
12941
+ }
12942
+ };
12943
+ var EmailValidator = class {
12944
+ constructor(options = {}) {
12945
+ this.options = options;
12946
+ }
12947
+ name = "email";
12948
+ validate(value) {
12949
+ if (typeof value !== "string") {
12950
+ return { isValid: false, error: "Value must be a string" };
12951
+ }
12952
+ const emailPattern = this.options.allowPlus ? /^[^\s@]+@[^\s@]+\.[^\s@]+$/ : /^[^\s@+]+@[^\s@]+\.[^\s@]+$/;
12953
+ if (!emailPattern.test(value)) {
12954
+ return { isValid: false, error: "Value must be a valid email address" };
12955
+ }
12956
+ if (this.options.requireTLD) {
12957
+ const parts = value.split(".");
12958
+ if (parts.length < 3 || parts[parts.length - 1].length < 2) {
12959
+ return { isValid: false, error: "Email must have a valid top-level domain" };
12960
+ }
12961
+ }
12962
+ return { isValid: true };
12963
+ }
12964
+ autoTransform(value) {
12965
+ if (typeof value !== "string") {
12966
+ return { success: false };
12967
+ }
12968
+ let result = value.trim().toLowerCase();
12969
+ if (!this.options.allowPlus) {
12970
+ result = result.replace(/\+.*@/, "@");
12971
+ }
12972
+ return {
12973
+ success: true,
12974
+ correctedValue: result,
12975
+ message: "Trimmed and lowercased email"
12976
+ };
12977
+ }
12978
+ };
12979
+ var LengthValidator = class {
12980
+ constructor(options = {}) {
12981
+ this.options = options;
12982
+ }
12983
+ name = "length";
12984
+ validate(value) {
12985
+ if (typeof value !== "string") {
12986
+ return { isValid: false, error: "Value must be a string" };
12987
+ }
12988
+ if (this.options.exact !== void 0 && value.length !== this.options.exact) {
12989
+ return { isValid: false, error: `Value must be exactly ${this.options.exact} characters long` };
12990
+ }
12991
+ if (this.options.min !== void 0 && value.length < this.options.min) {
12992
+ return { isValid: false, error: `Value must be at least ${this.options.min} characters long` };
12993
+ }
12994
+ if (this.options.max !== void 0 && value.length > this.options.max) {
12995
+ return { isValid: false, error: `Value must be at most ${this.options.max} characters long` };
12996
+ }
12997
+ return { isValid: true };
12998
+ }
12999
+ autoTransform(value) {
13000
+ if (typeof value !== "string") {
13001
+ return { success: false };
13002
+ }
13003
+ let result = value;
13004
+ if (this.options.max !== void 0 && result.length > this.options.max) {
13005
+ result = result.slice(0, this.options.max);
13006
+ }
13007
+ if (this.options.min !== void 0 && result.length < this.options.min) {
13008
+ result = result.padEnd(this.options.min);
13009
+ }
13010
+ return {
13011
+ success: true,
13012
+ correctedValue: result,
13013
+ message: "Adjusted string length"
13014
+ };
13015
+ }
13016
+ };
13017
+ var PatternValidator = class {
13018
+ constructor(options = { pattern: /.*/ }) {
13019
+ this.options = options;
13020
+ }
13021
+ name = "pattern";
13022
+ validate(value) {
13023
+ if (typeof value !== "string") {
13024
+ return { isValid: false, error: "Value must be a string" };
13025
+ }
13026
+ const pattern = new RegExp(this.options.pattern.source, this.options.flags);
13027
+ if (!pattern.test(value)) {
13028
+ return { isValid: false, error: this.options.errorMessage || "Value does not match required pattern" };
13029
+ }
13030
+ return { isValid: true };
13031
+ }
13032
+ autoTransform(value) {
13033
+ if (typeof value !== "string" || !this.options.replacement) {
13034
+ return { success: false };
13035
+ }
13036
+ const pattern = new RegExp(this.options.pattern.source, this.options.flags);
13037
+ const result = value.replace(pattern, this.options.replacement);
13038
+ return {
13039
+ success: true,
13040
+ correctedValue: result,
13041
+ message: "Replaced pattern matches"
13042
+ };
13043
+ }
13044
+ };
13045
+
13046
+ // src/decorators/transformers/transformer-decorators.ts
13047
+ var normalizePropertyName3 = (name) => {
13048
+ if (typeof name === "symbol") {
13049
+ return name.description ?? name.toString();
13050
+ }
13051
+ return name;
13052
+ };
13053
+ var registerTransformerMetadata = (context, metadata) => {
13054
+ const propertyName = normalizePropertyName3(context.name);
13055
+ const bag = getOrCreateMetadataBag(context);
13056
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13057
+ if (!existing) {
13058
+ existing = {
13059
+ propertyName,
13060
+ metadata: {
13061
+ propertyName,
13062
+ transformers: [],
13063
+ validators: [],
13064
+ sanitizers: [],
13065
+ executionOrder: "both"
13066
+ }
13067
+ };
13068
+ bag.transformers.push(existing);
13069
+ }
13070
+ if (metadata.transformers) {
13071
+ existing.metadata.transformers.push(...metadata.transformers);
13072
+ }
13073
+ if (metadata.validators) {
13074
+ existing.metadata.validators.push(...metadata.validators);
13075
+ }
13076
+ if (metadata.sanitizers) {
13077
+ existing.metadata.sanitizers.push(...metadata.sanitizers);
13078
+ }
13079
+ if (metadata.executionOrder) {
13080
+ existing.metadata.executionOrder = metadata.executionOrder;
13081
+ }
13082
+ };
13083
+ function Trim(options) {
13084
+ return function(_value, context) {
13085
+ registerTransformerMetadata(context, {
13086
+ sanitizers: [new TrimTransformer(options)]
13087
+ });
13088
+ };
13089
+ }
13090
+ function Lower() {
13091
+ return function(_value, context) {
13092
+ registerTransformerMetadata(context, {
13093
+ sanitizers: [new CaseTransformer("lower")]
13094
+ });
13095
+ };
13096
+ }
13097
+ function Upper() {
13098
+ return function(_value, context) {
13099
+ registerTransformerMetadata(context, {
13100
+ sanitizers: [new CaseTransformer("upper")]
13101
+ });
13102
+ };
13103
+ }
13104
+ function Capitalize() {
13105
+ return function(_value, context) {
13106
+ registerTransformerMetadata(context, {
13107
+ sanitizers: [new CaseTransformer("capitalize")]
13108
+ });
13109
+ };
13110
+ }
13111
+ function Title() {
13112
+ return function(_value, context) {
13113
+ registerTransformerMetadata(context, {
13114
+ sanitizers: [new CaseTransformer("title")]
13115
+ });
13116
+ };
13117
+ }
13118
+ function Alphanumeric(options) {
13119
+ return function(_value, context) {
13120
+ registerTransformerMetadata(context, {
13121
+ validators: [new AlphanumericValidator(options)]
13122
+ });
13123
+ };
13124
+ }
13125
+ function Email(options) {
13126
+ return function(_value, context) {
13127
+ registerTransformerMetadata(context, {
13128
+ validators: [new EmailValidator(options)]
13129
+ });
13130
+ };
13131
+ }
13132
+ function Length(options) {
13133
+ return function(_value, context) {
13134
+ registerTransformerMetadata(context, {
13135
+ validators: [new LengthValidator(options)]
13136
+ });
13137
+ };
13138
+ }
13139
+ function Pattern(options) {
13140
+ return function(_value, context) {
13141
+ registerTransformerMetadata(context, {
13142
+ validators: [new PatternValidator(options)]
13143
+ });
13144
+ };
13145
+ }
13146
+
13147
+ // src/decorators/validators/country-validator-registry.ts
13148
+ var VALIDATOR_FACTORIES = /* @__PURE__ */ new Map();
13149
+ var registerValidator = (countryCode, identifierType, factory) => {
13150
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
13151
+ if (!countryCode) throw new Error("countryCode is required");
13152
+ if (!identifierType) throw new Error("identifierType is required");
13153
+ if (typeof factory !== "function") {
13154
+ throw new Error("factory must be a function that returns a validator");
13155
+ }
13156
+ VALIDATOR_FACTORIES.set(key, factory);
13157
+ };
13158
+ var resolveValidator = (countryCode, identifierType) => {
13159
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
13160
+ const factory = VALIDATOR_FACTORIES.get(key);
13161
+ return factory ? factory() : void 0;
13162
+ };
13163
+ var getRegisteredValidators = () => {
13164
+ return Array.from(VALIDATOR_FACTORIES.keys());
13165
+ };
13166
+ var hasValidator = (countryCode, identifierType) => {
13167
+ const key = `${countryCode.toLowerCase()}-${identifierType.toLowerCase()}`;
13168
+ return VALIDATOR_FACTORIES.has(key);
13169
+ };
13170
+
13171
+ // src/decorators/validators/built-in/br-cpf-validator.ts
13172
+ var CPFValidator = class {
13173
+ countryCode = "BR";
13174
+ identifierType = "cpf";
13175
+ name = "br-cpf";
13176
+ validate(value, options = {}) {
13177
+ const normalized = this.normalize(value);
13178
+ if (!/^\d{11}$/.test(normalized)) {
13179
+ return {
13180
+ isValid: false,
13181
+ error: options.errorMessage || "CPF must contain exactly 11 numeric digits"
13182
+ };
13183
+ }
13184
+ if (this.isKnownInvalid(normalized) && options.strict !== false) {
13185
+ return {
13186
+ isValid: false,
13187
+ error: options.errorMessage || "Invalid CPF number"
13188
+ };
13189
+ }
13190
+ if (!this.validateChecksum(normalized)) {
13191
+ return {
13192
+ isValid: false,
13193
+ error: options.errorMessage || "Invalid CPF checksum"
13194
+ };
13195
+ }
13196
+ return {
13197
+ isValid: true,
13198
+ normalizedValue: normalized,
13199
+ formattedValue: this.format(value)
13200
+ };
13201
+ }
13202
+ normalize(value) {
13203
+ return value.replace(/[^0-9]/g, "");
13204
+ }
13205
+ format(value) {
13206
+ const normalized = this.normalize(value);
13207
+ if (normalized.length !== 11) return value;
13208
+ return normalized.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
13209
+ }
13210
+ autoCorrect(value) {
13211
+ const normalized = this.normalize(value);
13212
+ if (normalized.length === 11) {
13213
+ return { success: true, correctedValue: this.format(normalized) };
13214
+ }
13215
+ if (normalized.length < 11) {
13216
+ const padded = normalized.padEnd(11, "0");
13217
+ return { success: true, correctedValue: this.format(padded) };
13218
+ }
13219
+ const truncated = normalized.slice(0, 11);
13220
+ return { success: true, correctedValue: this.format(truncated) };
13221
+ }
13222
+ isKnownInvalid(cpf) {
13223
+ return /^(\d)\1{10}$/.test(cpf);
13224
+ }
13225
+ validateChecksum(cpf) {
13226
+ const digits = cpf.split("").map(Number);
13227
+ let sum2 = 0;
13228
+ for (let i = 0; i < 9; i++) {
13229
+ sum2 += digits[i] * (10 - i);
13230
+ }
13231
+ let check1 = sum2 % 11;
13232
+ check1 = check1 < 2 ? 0 : 11 - check1;
13233
+ if (check1 !== digits[9]) {
13234
+ return false;
13235
+ }
13236
+ sum2 = 0;
13237
+ for (let i = 0; i < 10; i++) {
13238
+ sum2 += digits[i] * (11 - i);
13239
+ }
13240
+ let check2 = sum2 % 11;
13241
+ check2 = check2 < 2 ? 0 : 11 - check2;
13242
+ return check2 === digits[10];
13243
+ }
13244
+ };
13245
+
13246
+ // src/decorators/validators/built-in/br-cnpj-validator.ts
13247
+ var CNPJValidator = class {
13248
+ countryCode = "BR";
13249
+ identifierType = "cnpj";
13250
+ name = "br-cnpj";
13251
+ validate(value, options = {}) {
13252
+ const normalized = this.normalize(value);
13253
+ if (!/^\d{14}$/.test(normalized)) {
13254
+ return {
13255
+ isValid: false,
13256
+ error: options.errorMessage || "CNPJ must contain exactly 14 numeric digits"
13257
+ };
13258
+ }
13259
+ if (this.isKnownInvalid(normalized) && options.strict !== false) {
13260
+ return {
13261
+ isValid: false,
13262
+ error: options.errorMessage || "Invalid CNPJ number"
13263
+ };
13264
+ }
13265
+ if (!this.validateChecksum(normalized)) {
13266
+ return {
13267
+ isValid: false,
13268
+ error: options.errorMessage || "Invalid CNPJ checksum"
13269
+ };
13270
+ }
13271
+ return {
13272
+ isValid: true,
13273
+ normalizedValue: normalized,
13274
+ formattedValue: this.format(value)
13275
+ };
13276
+ }
13277
+ normalize(value) {
13278
+ return value.replace(/[^0-9]/g, "");
13279
+ }
13280
+ format(value) {
13281
+ const normalized = this.normalize(value);
13282
+ if (normalized.length !== 14) return value;
13283
+ return normalized.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "$1.$2.$3/$4-$5");
13284
+ }
13285
+ autoCorrect(value) {
13286
+ const normalized = this.normalize(value);
13287
+ if (normalized.length === 14) {
13288
+ return { success: true, correctedValue: this.format(normalized) };
13289
+ }
13290
+ if (normalized.length < 14) {
13291
+ const padded = normalized.padEnd(14, "0");
13292
+ return { success: true, correctedValue: this.format(padded) };
13293
+ }
13294
+ const truncated = normalized.slice(0, 14);
13295
+ return { success: true, correctedValue: this.format(truncated) };
13296
+ }
13297
+ isKnownInvalid(cnpj) {
13298
+ return /^(\d)\1{13}$/.test(cnpj);
13299
+ }
13300
+ validateChecksum(cnpj) {
13301
+ const digits = cnpj.split("").map(Number);
13302
+ const weights1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
13303
+ const weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
13304
+ let sum2 = 0;
13305
+ for (let i = 0; i < 12; i++) {
13306
+ sum2 += digits[i] * weights1[i];
13307
+ }
13308
+ let check1 = sum2 % 11;
13309
+ check1 = check1 < 2 ? 0 : 11 - check1;
13310
+ if (check1 !== digits[12]) {
13311
+ return false;
13312
+ }
13313
+ sum2 = 0;
13314
+ for (let i = 0; i < 13; i++) {
13315
+ sum2 += digits[i] * weights2[i];
13316
+ }
13317
+ let check2 = sum2 % 11;
13318
+ check2 = check2 < 2 ? 0 : 11 - check2;
13319
+ return check2 === digits[13];
13320
+ }
13321
+ };
13322
+
13323
+ // src/decorators/validators/built-in/br-cep-validator.ts
13324
+ var CEPValidator = class {
13325
+ countryCode = "BR";
13326
+ identifierType = "cep";
13327
+ name = "br-cep";
13328
+ validate(value, options = {}) {
13329
+ const normalized = this.normalize(value);
13330
+ if (!/^\d{8}$/.test(normalized)) {
13331
+ return {
13332
+ isValid: false,
13333
+ error: options.errorMessage || "CEP must contain exactly 8 numeric digits"
13334
+ };
13335
+ }
13336
+ return {
13337
+ isValid: true,
13338
+ normalizedValue: normalized,
13339
+ formattedValue: this.format(value)
13340
+ };
13341
+ }
13342
+ normalize(value) {
13343
+ return value.replace(/[^0-9]/g, "");
13344
+ }
13345
+ format(value) {
13346
+ const normalized = this.normalize(value);
13347
+ if (normalized.length !== 8) return value;
13348
+ return normalized.replace(/(\d{5})(\d{3})/, "$1-$2");
13349
+ }
13350
+ autoCorrect(value) {
13351
+ const normalized = this.normalize(value);
13352
+ if (normalized.length === 8) {
13353
+ return { success: true, correctedValue: this.format(normalized) };
13354
+ }
13355
+ if (normalized.length < 8) {
13356
+ const padded = normalized.padEnd(8, "0");
13357
+ return { success: true, correctedValue: this.format(padded) };
13358
+ }
13359
+ const truncated = normalized.slice(0, 8);
13360
+ return { success: true, correctedValue: this.format(truncated) };
13361
+ }
13362
+ };
13363
+
13364
+ // src/decorators/validators/country-validators-decorators.ts
13365
+ registerValidator("BR", "cpf", () => new CPFValidator());
13366
+ registerValidator("BR", "cnpj", () => new CNPJValidator());
13367
+ registerValidator("BR", "cep", () => new CEPValidator());
13368
+ var normalizePropertyName4 = (name) => {
13369
+ if (typeof name === "symbol") {
13370
+ return name.description ?? name.toString();
13371
+ }
13372
+ return name;
13373
+ };
13374
+ function CPF(options) {
13375
+ return function(_value, context) {
13376
+ const propertyName = normalizePropertyName4(context.name);
13377
+ const bag = getOrCreateMetadataBag(context);
13378
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13379
+ if (!existing) {
13380
+ existing = {
13381
+ propertyName,
13382
+ metadata: {
13383
+ propertyName,
13384
+ transformers: [],
13385
+ validators: [],
13386
+ sanitizers: [],
13387
+ executionOrder: "both"
13388
+ }
13389
+ };
13390
+ bag.transformers.push(existing);
13391
+ }
13392
+ const validator = new CPFValidator();
13393
+ existing.metadata.validators.push({
13394
+ name: validator.name,
13395
+ validate: (value) => {
13396
+ const result = validator.validate(value, {
13397
+ strict: options?.strict ?? true,
13398
+ errorMessage: options?.errorMessage
13399
+ });
13400
+ return {
13401
+ isValid: result.isValid,
13402
+ error: result.error,
13403
+ message: result.error
13404
+ };
13405
+ },
13406
+ autoTransform: (value) => {
13407
+ const correction = validator.autoCorrect(value);
13408
+ if (correction?.success) {
13409
+ return {
13410
+ success: true,
13411
+ correctedValue: correction.correctedValue,
13412
+ message: correction.message
13413
+ };
13414
+ }
13415
+ return { success: false };
13416
+ }
13417
+ });
13418
+ existing.metadata.sanitizers.push({
13419
+ name: "cpf-formatter",
13420
+ sanitize: (value) => validator.format(value)
13421
+ });
13422
+ };
13423
+ }
13424
+ function CNPJ(options) {
13425
+ return function(_value, context) {
13426
+ const propertyName = normalizePropertyName4(context.name);
13427
+ const bag = getOrCreateMetadataBag(context);
13428
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13429
+ if (!existing) {
13430
+ existing = {
13431
+ propertyName,
13432
+ metadata: {
13433
+ propertyName,
13434
+ transformers: [],
13435
+ validators: [],
13436
+ sanitizers: [],
13437
+ executionOrder: "both"
13438
+ }
13439
+ };
13440
+ bag.transformers.push(existing);
13441
+ }
13442
+ const validator = new CNPJValidator();
13443
+ existing.metadata.validators.push({
13444
+ name: validator.name,
13445
+ validate: (value) => {
13446
+ const result = validator.validate(value, {
13447
+ strict: options?.strict ?? true,
13448
+ errorMessage: options?.errorMessage
13449
+ });
13450
+ return {
13451
+ isValid: result.isValid,
13452
+ error: result.error,
13453
+ message: result.error
13454
+ };
13455
+ },
13456
+ autoTransform: (value) => {
13457
+ const correction = validator.autoCorrect(value);
13458
+ if (correction?.success) {
13459
+ return {
13460
+ success: true,
13461
+ correctedValue: correction.correctedValue,
13462
+ message: correction.message
13463
+ };
13464
+ }
13465
+ return { success: false };
13466
+ }
13467
+ });
13468
+ existing.metadata.sanitizers.push({
13469
+ name: "cnpj-formatter",
13470
+ sanitize: (value) => validator.format(value)
13471
+ });
13472
+ };
13473
+ }
13474
+ function CEP(options) {
13475
+ return function(_value, context) {
13476
+ const propertyName = normalizePropertyName4(context.name);
13477
+ const bag = getOrCreateMetadataBag(context);
13478
+ let existing = bag.transformers.find((t) => t.propertyName === propertyName);
13479
+ if (!existing) {
13480
+ existing = {
13481
+ propertyName,
13482
+ metadata: {
13483
+ propertyName,
13484
+ transformers: [],
13485
+ validators: [],
13486
+ sanitizers: [],
13487
+ executionOrder: "both"
13488
+ }
13489
+ };
13490
+ bag.transformers.push(existing);
13491
+ }
13492
+ const validator = new CEPValidator();
13493
+ existing.metadata.validators.push({
13494
+ name: validator.name,
13495
+ validate: (value) => {
13496
+ const result = validator.validate(value, {
13497
+ strict: options?.strict ?? true,
13498
+ errorMessage: options?.errorMessage
13499
+ });
13500
+ return {
13501
+ isValid: result.isValid,
13502
+ error: result.error,
13503
+ message: result.error
13504
+ };
13505
+ },
13506
+ autoTransform: (value) => {
13507
+ const correction = validator.autoCorrect(value);
13508
+ if (correction?.success) {
13509
+ return {
13510
+ success: true,
13511
+ correctedValue: correction.correctedValue,
13512
+ message: correction.message
13513
+ };
13514
+ }
13515
+ return { success: false };
13516
+ }
13517
+ });
13518
+ existing.metadata.sanitizers.push({
13519
+ name: "cep-formatter",
13520
+ sanitize: (value) => validator.format(value)
13521
+ });
13522
+ };
13523
+ }
13524
+
12809
13525
  // src/core/execution/db-executor.ts
12810
13526
  function rowsToQueryResult(rows) {
12811
13527
  if (rows.length === 0) {
@@ -14621,11 +15337,16 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14621
15337
  }
14622
15338
  // Annotate the CommonJS export names for ESM import in node:
14623
15339
  0 && (module.exports = {
15340
+ Alphanumeric,
14624
15341
  AsyncLocalStorage,
14625
15342
  BelongsTo,
14626
15343
  BelongsToMany,
14627
15344
  BigIntTypeStrategy,
14628
15345
  BooleanTypeStrategy,
15346
+ CEP,
15347
+ CNPJ,
15348
+ CPF,
15349
+ Capitalize,
14629
15350
  Column,
14630
15351
  ConstructorMaterializationStrategy,
14631
15352
  DateTimeTypeStrategy,
@@ -14637,6 +15358,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14637
15358
  DefaultTypeStrategy,
14638
15359
  DeleteQueryBuilder,
14639
15360
  DomainEventBus,
15361
+ Email,
14640
15362
  Entity,
14641
15363
  EntityStatus,
14642
15364
  HasMany,
@@ -14644,9 +15366,12 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14644
15366
  InsertQueryBuilder,
14645
15367
  IntegerTypeStrategy,
14646
15368
  InterceptorPipeline,
15369
+ Length,
15370
+ Lower,
14647
15371
  MySqlDialect,
14648
15372
  Orm,
14649
15373
  OrmSession,
15374
+ Pattern,
14650
15375
  Pool,
14651
15376
  PostgresDialect,
14652
15377
  PrimaryKey,
@@ -14657,9 +15382,12 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14657
15382
  SqlServerDialect,
14658
15383
  SqliteDialect,
14659
15384
  StringTypeStrategy,
15385
+ Title,
15386
+ Trim,
14660
15387
  TypeMappingService,
14661
15388
  TypeScriptGenerator,
14662
15389
  UpdateQueryBuilder,
15390
+ Upper,
14663
15391
  UuidTypeStrategy,
14664
15392
  abs,
14665
15393
  acos,
@@ -14774,9 +15502,12 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14774
15502
  generateSchemaSqlFor,
14775
15503
  getColumn,
14776
15504
  getColumnMap,
15505
+ getColumnType,
15506
+ getDateKind,
14777
15507
  getDecoratorMetadata,
14778
15508
  getDeterministicComponentName,
14779
15509
  getOpenApiVersionForDialect,
15510
+ getRegisteredValidators,
14780
15511
  getSchemaIntrospector,
14781
15512
  getTableDefFromEntity,
14782
15513
  greatest,
@@ -14787,6 +15518,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14787
15518
  hasNextPageMeta,
14788
15519
  hasOne,
14789
15520
  hasPrevPageMeta,
15521
+ hasValidator,
14790
15522
  hour,
14791
15523
  hydrateRows,
14792
15524
  ifNull,
@@ -14880,6 +15612,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14880
15612
  registerExpressionDispatcher,
14881
15613
  registerOperandDispatcher,
14882
15614
  registerSchemaIntrospector,
15615
+ registerValidator,
14883
15616
  relationFilterToOpenApiSchema,
14884
15617
  relationLoaderCache,
14885
15618
  renderColumnDefinition,
@@ -14887,6 +15620,7 @@ function pagedResponseToOpenApiSchema(itemSchema) {
14887
15620
  repeat,
14888
15621
  replace,
14889
15622
  replaceWithRefs,
15623
+ resolveValidator,
14890
15624
  responseToRef,
14891
15625
  reverse,
14892
15626
  right,