@cheetah.js/orm 0.1.1 → 0.1.3

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/bun/index.js CHANGED
@@ -9687,7 +9687,7 @@ var require_pino = __commonJS((exports, module) => {
9687
9687
  mixinMergeStrategy,
9688
9688
  useOnlyCustomLevels,
9689
9689
  formatters,
9690
- hooks,
9690
+ hooks: hooks2,
9691
9691
  depthLimit,
9692
9692
  edgeLimit,
9693
9693
  onChild,
@@ -9750,7 +9750,7 @@ var require_pino = __commonJS((exports, module) => {
9750
9750
  [mixinMergeStrategySym]: mixinMergeStrategy,
9751
9751
  [chindingsSym]: chindings,
9752
9752
  [formattersSym]: allFormatters,
9753
- [hooksSym]: hooks,
9753
+ [hooksSym]: hooks2,
9754
9754
  silent: noop,
9755
9755
  onChild,
9756
9756
  [msgPrefixSym]: msgPrefix
@@ -214114,18 +214114,18 @@ var require_postgres_interval = __commonJS((exports, module) => {
214114
214114
  return {};
214115
214115
  var matches = INTERVAL.exec(interval);
214116
214116
  var isNegative = matches[8] === "-";
214117
- return Object.keys(positions).reduce(function(parsed, property3) {
214118
- var position = positions[property3];
214117
+ return Object.keys(positions).reduce(function(parsed, property2) {
214118
+ var position = positions[property2];
214119
214119
  var value = matches[position];
214120
214120
  if (!value)
214121
214121
  return parsed;
214122
- value = property3 === "milliseconds" ? parseMilliseconds(value) : parseInt(value, 10);
214122
+ value = property2 === "milliseconds" ? parseMilliseconds(value) : parseInt(value, 10);
214123
214123
  if (!value)
214124
214124
  return parsed;
214125
- if (isNegative && ~negatives.indexOf(property3)) {
214125
+ if (isNegative && ~negatives.indexOf(property2)) {
214126
214126
  value *= -1;
214127
214127
  }
214128
- parsed[property3] = value;
214128
+ parsed[property2] = value;
214129
214129
  return parsed;
214130
214130
  }, {});
214131
214131
  };
@@ -214139,12 +214139,12 @@ var require_postgres_interval = __commonJS((exports, module) => {
214139
214139
  }
214140
214140
  if (filtered.length === 0)
214141
214141
  return "0";
214142
- return filtered.map(function(property3) {
214143
- var value = this[property3] || 0;
214144
- if (property3 === "seconds" && this.milliseconds) {
214142
+ return filtered.map(function(property2) {
214143
+ var value = this[property2] || 0;
214144
+ if (property2 === "seconds" && this.milliseconds) {
214145
214145
  value = (value + this.milliseconds / 1000).toFixed(6).replace(/\.?0+$/, "");
214146
214146
  }
214147
- return value + " " + property3;
214147
+ return value + " " + property2;
214148
214148
  }, this).join(" ");
214149
214149
  };
214150
214150
  var propertiesISOEquivalent = {
@@ -214161,12 +214161,12 @@ var require_postgres_interval = __commonJS((exports, module) => {
214161
214161
  var datePart = dateProperties.map(buildProperty, this).join("");
214162
214162
  var timePart = timeProperties.map(buildProperty, this).join("");
214163
214163
  return "P" + datePart + "T" + timePart;
214164
- function buildProperty(property3) {
214165
- var value = this[property3] || 0;
214166
- if (property3 === "seconds" && this.milliseconds) {
214164
+ function buildProperty(property2) {
214165
+ var value = this[property2] || 0;
214166
+ if (property2 === "seconds" && this.milliseconds) {
214167
214167
  value = (value + this.milliseconds / 1000).toFixed(6).replace(/0+$/, "");
214168
214168
  }
214169
- return value + propertiesISOEquivalent[property3];
214169
+ return value + propertiesISOEquivalent[property2];
214170
214170
  }
214171
214171
  };
214172
214172
  var NUMBER = "([+-]?\\d+)";
@@ -215565,12 +215565,12 @@ var require_result = __commonJS((exports, module) => {
215565
215565
  var require_query = __commonJS((exports, module) => {
215566
215566
  var { EventEmitter } = import.meta.require("events");
215567
215567
  var Result = require_result();
215568
- var utils10 = require_utils5();
215568
+ var utils8 = require_utils5();
215569
215569
 
215570
215570
  class Query3 extends EventEmitter {
215571
215571
  constructor(config, values, callback) {
215572
215572
  super();
215573
- config = utils10.normalizeQueryConfig(config, values, callback);
215573
+ config = utils8.normalizeQueryConfig(config, values, callback);
215574
215574
  this.text = config.text;
215575
215575
  this.values = config.values;
215576
215576
  this.rows = config.rows;
@@ -215721,7 +215721,7 @@ var require_query = __commonJS((exports, module) => {
215721
215721
  statement: this.name,
215722
215722
  values: this.values,
215723
215723
  binary: this.binary,
215724
- valueMapper: utils10.prepareValue
215724
+ valueMapper: utils8.prepareValue
215725
215725
  });
215726
215726
  } catch (err) {
215727
215727
  this.handleError(err, connection);
@@ -217025,7 +217025,7 @@ var require_lib = __commonJS((exports, module) => {
217025
217025
  // /export/htdocs/p/framework/node_modules/pg/lib/client.js
217026
217026
  var require_client = __commonJS((exports, module) => {
217027
217027
  var EventEmitter = import.meta.require("events").EventEmitter;
217028
- var utils10 = require_utils5();
217028
+ var utils8 = require_utils5();
217029
217029
  var sasl = require_sasl();
217030
217030
  var TypeOverrides = require_type_overrides();
217031
217031
  var ConnectionParameters = require_connection_parameters();
@@ -217391,10 +217391,10 @@ var require_client = __commonJS((exports, module) => {
217391
217391
  return this._types.getTypeParser(oid, format);
217392
217392
  }
217393
217393
  escapeIdentifier(str) {
217394
- return utils10.escapeIdentifier(str);
217394
+ return utils8.escapeIdentifier(str);
217395
217395
  }
217396
217396
  escapeLiteral(str) {
217397
- return utils10.escapeLiteral(str);
217397
+ return utils8.escapeLiteral(str);
217398
217398
  }
217399
217399
  _pulseQueryQueue() {
217400
217400
  if (this.readyForQuery === true) {
@@ -217896,10 +217896,10 @@ var require_pg_pool = __commonJS((exports, module) => {
217896
217896
  var require_query2 = __commonJS((exports, module) => {
217897
217897
  var EventEmitter = import.meta.require("events").EventEmitter;
217898
217898
  var util = import.meta.require("util");
217899
- var utils10 = require_utils5();
217899
+ var utils8 = require_utils5();
217900
217900
  var NativeQuery = module.exports = function(config, values, callback) {
217901
217901
  EventEmitter.call(this);
217902
- config = utils10.normalizeQueryConfig(config, values, callback);
217902
+ config = utils8.normalizeQueryConfig(config, values, callback);
217903
217903
  this.text = config.text;
217904
217904
  this.values = config.values;
217905
217905
  this.name = config.name;
@@ -217998,7 +217998,7 @@ var require_query2 = __commonJS((exports, module) => {
217998
217998
  console.error("You supplied %s (%s)", this.name, this.name.length);
217999
217999
  console.error("This can cause conflicts and silent errors executing queries");
218000
218000
  }
218001
- var values = (this.values || []).map(utils10.prepareValue);
218001
+ var values = (this.values || []).map(utils8.prepareValue);
218002
218002
  if (client.namedQueries[this.name]) {
218003
218003
  if (this.text && client.namedQueries[this.name] !== this.text) {
218004
218004
  const err = new Error(`Prepared statements must be unique - '${this.name}' was used for a different statement`);
@@ -218017,7 +218017,7 @@ var require_query2 = __commonJS((exports, module) => {
218017
218017
  const err = new Error("Query values must be an array");
218018
218018
  return after(err);
218019
218019
  }
218020
- var vals = this.values.map(utils10.prepareValue);
218020
+ var vals = this.values.map(utils8.prepareValue);
218021
218021
  client.native.query(this.text, vals, after);
218022
218022
  } else {
218023
218023
  client.native.query(this.text, after);
@@ -219096,11 +219096,17 @@ var ProviderScope2;
219096
219096
 
219097
219097
  // /export/htdocs/p/framework/packages/core/dist/domain/provider.js
219098
219098
  class Provider {
219099
+ type = ProviderType2.PROVIDER;
219100
+ deps = [];
219101
+ instance;
219102
+ _provide;
219103
+ _useClass;
219104
+ hooks;
219105
+ path;
219106
+ scope = ProviderScope2.SINGLETON;
219107
+ children = [];
219108
+ parent;
219099
219109
  constructor(token, options = {}) {
219100
- this.type = ProviderType2.PROVIDER;
219101
- this.deps = [];
219102
- this.scope = ProviderScope2.SINGLETON;
219103
- this.children = [];
219104
219110
  this.provide = token;
219105
219111
  this.useClass = token;
219106
219112
  Object.assign(this, options);
@@ -219144,10 +219150,7 @@ class Provider {
219144
219150
 
219145
219151
  // /export/htdocs/p/framework/packages/core/dist/commons/registries/ProviderControl.js
219146
219152
  class ProviderControl extends Map {
219147
- constructor() {
219148
- super(...arguments);
219149
- this.settings = new Map;
219150
- }
219153
+ settings = new Map;
219151
219154
  get(key) {
219152
219155
  return super.get(getClassOrSymbol(key));
219153
219156
  }
@@ -219584,9 +219587,9 @@ class Container extends Map {
219584
219587
  }
219585
219588
  // /export/htdocs/p/framework/packages/core/dist/container/ContainerConfiguration.js
219586
219589
  class ContainerConfiguration {
219590
+ default = new Map;
219591
+ map = new Map;
219587
219592
  constructor(initialProps = {}) {
219588
- this.default = new Map;
219589
- this.map = new Map;
219590
219593
  Object.entries({
219591
219594
  scopes: {},
219592
219595
  resolvers: [],
@@ -221252,10 +221255,12 @@ var createParamNode = (paramName) => ({
221252
221255
  });
221253
221256
 
221254
221257
  class Memoirist {
221255
- constructor() {
221256
- this.root = {};
221257
- this.history = [];
221258
- }
221258
+ root = {};
221259
+ history = [];
221260
+ static regex = {
221261
+ static: /:.+?(?=\/|$)/,
221262
+ params: /:.+?(?=\/|$)/g
221263
+ };
221259
221264
  add(method, path2, store) {
221260
221265
  if (typeof path2 !== "string")
221261
221266
  throw new TypeError("Route path must be a string");
@@ -221355,10 +221360,6 @@ class Memoirist {
221355
221360
  return matchRoute(url, url.length, root, 0);
221356
221361
  }
221357
221362
  }
221358
- Memoirist.regex = {
221359
- static: /:.+?(?=\/|$)/,
221360
- params: /:.+?(?=\/|$)/g
221361
- };
221362
221363
  var matchRoute = (url, urlLength, node, startIndex) => {
221363
221364
  const part = node?.part;
221364
221365
  const endIndex = startIndex + part.length;
@@ -221439,21 +221440,19 @@ var __decorate = function(decorators4, target, key, desc) {
221439
221440
  };
221440
221441
  var InjectorService_1;
221441
221442
  var InjectorService = InjectorService_1 = class InjectorService2 {
221442
- constructor() {
221443
- this.settings = new ContainerConfiguration;
221444
- this.container = new Container;
221445
- this.applicationConfig = {};
221446
- this.router = new memoirist_default;
221447
- this.historyMethods = new Map;
221448
- }
221443
+ settings = new ContainerConfiguration;
221444
+ container = new Container;
221445
+ applicationConfig = {};
221446
+ router = new memoirist_default;
221447
+ historyMethods = new Map;
221449
221448
  loadModule(container5, applicationConfig, router) {
221450
221449
  this.container = container5;
221451
221450
  this.router = router;
221452
221451
  this.applicationConfig = applicationConfig;
221453
221452
  this.removeUnknownProviders();
221454
- this.callHook(EventType.OnApplicationInit);
221455
221453
  this.saveInjector();
221456
221454
  this.resolveControllers();
221455
+ this.callHook(EventType.OnApplicationInit);
221457
221456
  }
221458
221457
  resolveControllers() {
221459
221458
  if (!this.settings)
@@ -221734,13 +221733,13 @@ var __metadata = function(k, v) {
221734
221733
  };
221735
221734
  var Context_1;
221736
221735
  var Context = Context_1 = class Context2 {
221736
+ query = {};
221737
+ body = {};
221738
+ param = {};
221739
+ req = {};
221740
+ headers = {};
221741
+ locals = {};
221737
221742
  constructor() {
221738
- this.query = {};
221739
- this.body = {};
221740
- this.param = {};
221741
- this.req = {};
221742
- this.headers = {};
221743
- this.locals = {};
221744
221743
  }
221745
221744
  static async createFromRequest(url, request, server) {
221746
221745
  const context = new Context_1;
@@ -221823,6 +221822,7 @@ class Metadata {
221823
221822
  static setParamTypes(target, propertyKey, value) {
221824
221823
  return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);
221825
221824
  }
221825
+ static getTargetsFromPropertyKey = (metadataKey) => PROPERTIES2.has(metadataKey) ? PROPERTIES2.get(metadataKey) || [] : [];
221826
221826
  static set(key, value, target, propertyKey) {
221827
221827
  const targets = PROPERTIES2.has(key) ? PROPERTIES2.get(key) || [] : [];
221828
221828
  const classConstructor = classOf(target);
@@ -221842,7 +221842,6 @@ class Metadata {
221842
221842
  return Reflect.getMetadata(ROUTE_PARAM, target.constructor, propertyKey);
221843
221843
  }
221844
221844
  }
221845
- Metadata.getTargetsFromPropertyKey = (metadataKey) => PROPERTIES2.has(metadataKey) ? PROPERTIES2.get(metadataKey) || [] : [];
221846
221845
  // /export/htdocs/p/framework/packages/core/dist/domain/http-method.js
221847
221846
  var HttpMethod;
221848
221847
  (function(HttpMethod2) {
@@ -221927,6 +221926,9 @@ class Router {
221927
221926
  var RouteExecutor = new Router;
221928
221927
  // /export/htdocs/p/framework/packages/core/dist/exceptions/HttpException.js
221929
221928
  class HttpException {
221929
+ response;
221930
+ statusCode;
221931
+ message;
221930
221932
  constructor(response, statusCode) {
221931
221933
  this.response = response;
221932
221934
  this.statusCode = statusCode;
@@ -221951,23 +221953,14 @@ import process3 from "process";
221951
221953
  var parseUrl2 = require_parseurl_fast();
221952
221954
 
221953
221955
  class Cheetah {
221956
+ config;
221957
+ router = new memoirist_default;
221958
+ injector = createInjector();
221959
+ fetch = (request, server) => this.fetcher(request, server);
221960
+ server;
221954
221961
  constructor(config = {}) {
221955
221962
  this.config = config;
221956
- this.router = new memoirist_default;
221957
- this.injector = createInjector();
221958
- this.fetch = (request, server) => this.fetcher(request, server);
221959
- this.catcher = (error) => {
221960
- if (error instanceof HttpException) {
221961
- return new Response(JSON.stringify({
221962
- message: error.getResponse(),
221963
- statusCode: error.getStatus()
221964
- }), {
221965
- status: error.statusCode,
221966
- headers: { "Content-Type": "application/json" }
221967
- });
221968
- }
221969
- return new Response(error.message, { status: 500 });
221970
- };
221963
+ this.injector.callHook(EventType.OnApplicationBoot, {});
221971
221964
  }
221972
221965
  use(plugin) {
221973
221966
  if (!this.config.providers) {
@@ -222007,6 +222000,18 @@ class Cheetah {
222007
222000
  local.set(Context, context);
222008
222001
  return RouteExecutor.executeRoute(route.store, this.injector, context, local);
222009
222002
  }
222003
+ catcher = (error) => {
222004
+ if (error instanceof HttpException) {
222005
+ return new Response(JSON.stringify({
222006
+ message: error.getResponse(),
222007
+ statusCode: error.getStatus()
222008
+ }), {
222009
+ status: error.statusCode,
222010
+ headers: { "Content-Type": "application/json" }
222011
+ });
222012
+ }
222013
+ return new Response(error.message, { status: 500 });
222014
+ };
222010
222015
  close(closeActiveConnections = false) {
222011
222016
  this.server.stop(closeActiveConnections);
222012
222017
  }
@@ -222014,12 +222019,13 @@ class Cheetah {
222014
222019
  // /export/htdocs/p/framework/packages/core/dist/events/on-event.js
222015
222020
  var EventType;
222016
222021
  (function(EventType2) {
222022
+ EventType2["OnApplicationBoot"] = "OnApplicationBoot";
222017
222023
  EventType2["OnApplicationInit"] = "OnApplicationInit";
222018
222024
  EventType2["OnApplicationShutdown"] = "OnApplicationShutdown";
222019
222025
  EventType2["OnRequest"] = "OnRequest";
222020
222026
  EventType2["OnResponse"] = "OnResponse";
222021
222027
  })(EventType || (EventType = {}));
222022
- // /export/htdocs/p/framework/packages/core/dist/events/on-application-init.decorator.js
222028
+ // /export/htdocs/p/framework/packages/core/dist/events/hooks.decorator.js
222023
222029
  function OnApplicationInit() {
222024
222030
  return (target, propertyKey) => {
222025
222031
  const anotherEvents = Metadata.get(CONTROLLER_EVENTS, Reflect) || [];
@@ -222287,6 +222293,8 @@ var __metadata3 = function(k, v) {
222287
222293
  return Reflect.metadata(k, v);
222288
222294
  };
222289
222295
  var LoggerService = class LoggerService2 {
222296
+ injector;
222297
+ logger;
222290
222298
  constructor(injector) {
222291
222299
  this.injector = injector;
222292
222300
  const pinoConfig = this.injector.applicationConfig.logger || {};
@@ -222317,10 +222325,17 @@ LoggerService = __decorate4([
222317
222325
  ], LoggerService);
222318
222326
  // ../../node_modules/balanced-match/index.jsodules/mini
222319
222327
  class Provider2 {
222328
+ type = ProviderType.PROVIDER;
222329
+ deps = [];
222330
+ instance;
222331
+ _provide;
222332
+ _useClass;
222333
+ hooks;
222334
+ path;
222335
+ scope = ProviderScope.SINGLETON;
222336
+ children = [];
222337
+ parent;
222320
222338
  constructor(token, options = {}) {
222321
- this.type = ProviderType.PROVIDER;
222322
- this.deps = [];
222323
- this.scope = ProviderScope.SINGLETON;
222324
222339
  this.provide = token;
222325
222340
  this.useClass = token;
222326
222341
  Object.assign(this, options);
@@ -222334,14 +222349,14 @@ class Provider2 {
222334
222349
  set useClass(value) {
222335
222350
  if (isClass(value)) {
222336
222351
  this._useClass = classOf(value);
222337
- this.hooks = methodsOf(this._useClass).reduce((hooks, { propertyKey }) => {
222352
+ this.hooks = methodsOf(this._useClass).reduce((hooks2, { propertyKey }) => {
222338
222353
  if (String(propertyKey).startsWith("$")) {
222339
222354
  return {
222340
- ...hooks,
222355
+ ...hooks2,
222341
222356
  [propertyKey]: (instance, ...args) => instance[propertyKey](...args)
222342
222357
  };
222343
222358
  }
222344
- return hooks;
222359
+ return hooks2;
222345
222360
  }, {});
222346
222361
  }
222347
222362
  }
@@ -222357,14 +222372,14 @@ class Provider2 {
222357
222372
  clone() {
222358
222373
  return new (classOf(this))(this._provide, this);
222359
222374
  }
222375
+ isChild() {
222376
+ return !!this.parent;
222377
+ }
222360
222378
  }
222361
222379
 
222362
222380
  // ../../node_modules/balanced-match/index.jsodules/minimatch/dist/cjs/unes
222363
222381
  class ProviderControl5 extends Map {
222364
- constructor() {
222365
- super(...arguments);
222366
- this.settings = new Map;
222367
- }
222382
+ settings = new Map;
222368
222383
  get(key) {
222369
222384
  return super.get(getClassOrSymbol(key));
222370
222385
  }
@@ -222470,7 +222485,7 @@ var Body2 = createParamDecorator2((context, data) => data ? context.body[data] :
222470
222485
  var Query2 = createParamDecorator2((context, data) => data ? context.query[data] : context.query || {});
222471
222486
  var Param2 = createParamDecorator2((context, data) => data ? context.param[data] : null);
222472
222487
  var Req2 = createParamDecorator2((context) => context.req);
222473
- var Headers2 = createParamDecorator2((context, data) => data ? context.headers.get(data) : context.headers || {});
222488
+ var Headers2 = createParamDecorator2((context, data) => data ? context.headers[data] : context.headers || {});
222474
222489
  var Locals2 = createParamDecorator2((context) => context.locals || {});
222475
222490
  var Get2 = createMethodDecorator2("GET");
222476
222491
  var Post2 = createMethodDecorator2("POST");
@@ -222513,9 +222528,9 @@ class Container2 extends Map {
222513
222528
  }
222514
222529
  // ../../node_modules/balanced-match/index.jsodules/minimatch/dist/cjs/un
222515
222530
  class ContainerConfiguration4 {
222531
+ default = new Map;
222532
+ map = new Map;
222516
222533
  constructor(initialProps = {}) {
222517
- this.default = new Map;
222518
- this.map = new Map;
222519
222534
  Object.entries({
222520
222535
  scopes: {},
222521
222536
  resolvers: [],
@@ -222610,10 +222625,12 @@ var createParamNode2 = (paramName) => ({
222610
222625
  });
222611
222626
 
222612
222627
  class Memoirist2 {
222613
- constructor() {
222614
- this.root = {};
222615
- this.history = [];
222616
- }
222628
+ root = {};
222629
+ history = [];
222630
+ static regex = {
222631
+ static: /:.+?(?=\/|$)/,
222632
+ params: /:.+?(?=\/|$)/g
222633
+ };
222617
222634
  add(method, path2, store) {
222618
222635
  if (typeof path2 !== "string")
222619
222636
  throw new TypeError("Route path must be a string");
@@ -222713,10 +222730,6 @@ class Memoirist2 {
222713
222730
  return matchRoute2(url, url.length, root, 0);
222714
222731
  }
222715
222732
  }
222716
- Memoirist2.regex = {
222717
- static: /:.+?(?=\/|$)/,
222718
- params: /:.+?(?=\/|$)/g
222719
- };
222720
222733
  var matchRoute2 = (url, urlLength, node, startIndex) => {
222721
222734
  const part = node?.part;
222722
222735
  const endIndex = startIndex + part.length;
@@ -222797,26 +222810,24 @@ var __decorate5 = function(decorators5, target, key, desc) {
222797
222810
  };
222798
222811
  var InjectorService_12;
222799
222812
  var InjectorService5 = InjectorService_12 = class InjectorService6 {
222800
- constructor() {
222801
- this.settings = new ContainerConfiguration4;
222802
- this.container = new Container2;
222803
- this.applicationConfig = {};
222804
- this.router = new memoirist_default2;
222805
- this.historyMethods = new Map;
222806
- }
222813
+ settings = new ContainerConfiguration4;
222814
+ container = new Container2;
222815
+ applicationConfig = {};
222816
+ router = new memoirist_default2;
222817
+ historyMethods = new Map;
222807
222818
  loadModule(container9, applicationConfig, router) {
222808
222819
  this.container = container9;
222809
222820
  this.router = router;
222810
222821
  this.applicationConfig = applicationConfig;
222811
222822
  this.removeUnknownProviders();
222812
- this.callHook(EventType.OnApplicationInit);
222813
222823
  this.saveInjector();
222814
222824
  this.resolveControllers();
222825
+ this.callHook(EventType.OnApplicationInit);
222815
222826
  }
222816
222827
  resolveControllers() {
222817
222828
  if (!this.settings)
222818
222829
  return {};
222819
- const controllers = GlobalProvider.getByType(ProviderType2.CONTROLLER);
222830
+ const controllers = GlobalProvider.getByType(ProviderType2.CONTROLLER).filter((controller3) => !controller3.isChild());
222820
222831
  let hydrateRoute = new Map;
222821
222832
  for (const controller3 of controllers) {
222822
222833
  let routes = Metadata.get(CONTROLLER_ROUTES, controller3.token);
@@ -222848,11 +222859,68 @@ var InjectorService5 = InjectorService_12 = class InjectorService6 {
222848
222859
  }))
222849
222860
  ]);
222850
222861
  }
222862
+ if (controller3.children) {
222863
+ const childrenRoutes = this.resolveChildrenRoutes(controller3.path ?? "", controller3.children, controllerMiddleware);
222864
+ childrenRoutes.forEach((route) => {
222865
+ hydrateRoute.set(route.method.toLowerCase(), [
222866
+ ...hydrateRoute.get(route.method.toLowerCase()) || [],
222867
+ route
222868
+ ]);
222869
+ });
222870
+ }
222851
222871
  }
222852
222872
  hydrateRoute.forEach((method) => {
222853
222873
  method.forEach((route) => this.router.add(route.method.toLowerCase(), route.path, route));
222854
222874
  });
222855
222875
  }
222876
+ resolveChildrenRoutes(parentPath, children, parentMiddlewares) {
222877
+ let childrenRoutes = [];
222878
+ for (const childController of children) {
222879
+ let controller3 = GlobalProvider.get(childController);
222880
+ if (!controller3)
222881
+ throw new Error(`Child ${childController} not is an controller. Please, check the providers configuration.`);
222882
+ let childRoutes = Metadata.get(CONTROLLER_ROUTES, controller3.token);
222883
+ const childMiddlewares = Metadata.get(CONTROLLER_MIDDLEWARES, controller3.token) || [];
222884
+ if (childRoutes.length === 0)
222885
+ continue;
222886
+ if (parentPath) {
222887
+ childRoutes = childRoutes.map((route) => {
222888
+ let controllerPath = controller3?.path ?? "";
222889
+ if (controllerPath.endsWith("/")) {
222890
+ controllerPath = controller3.path.slice(0, -1);
222891
+ }
222892
+ if (!controllerPath.startsWith("/")) {
222893
+ controllerPath = `/${controller3.path}`;
222894
+ }
222895
+ route.path = `${parentPath}${controllerPath ?? ""}${route.path}`;
222896
+ if (route.path.endsWith("/")) {
222897
+ route.path = route.path.slice(0, -1);
222898
+ }
222899
+ if (!route.path.startsWith("/")) {
222900
+ route.path = `/${route.path}`;
222901
+ }
222902
+ return route;
222903
+ });
222904
+ }
222905
+ for (const method of Object.keys(HttpMethod).map((key) => HttpMethod[key])) {
222906
+ if (!childRoutes.some((route) => route.method.toLowerCase() === method))
222907
+ continue;
222908
+ childrenRoutes = [
222909
+ ...childrenRoutes,
222910
+ ...childRoutes.filter((route) => route.method.toLowerCase() === method).map((route) => ({
222911
+ ...route,
222912
+ provider: controller3.token,
222913
+ route,
222914
+ middlewares: [...parentMiddlewares, ...childMiddlewares, ...Metadata.get(ROUTE_MIDDLEWARES, controller3.token, route.methodName) || []]
222915
+ }))
222916
+ ];
222917
+ }
222918
+ if (controller3.children) {
222919
+ childrenRoutes = [...childrenRoutes, ...this.resolveChildrenRoutes(controller3.path, controller3.children, childMiddlewares)];
222920
+ }
222921
+ }
222922
+ return childrenRoutes;
222923
+ }
222856
222924
  ensureProvider(token) {
222857
222925
  if (!this.container.has(token) && GlobalProvider.has(token)) {
222858
222926
  this.container.addProvider(token);
@@ -222950,10 +223018,10 @@ var InjectorService5 = InjectorService_12 = class InjectorService6 {
222950
223018
  return Metadata.getOwn("override:ctor:design:paramtypes", target, propertyKey) || [...Metadata.getParamTypes(target, propertyKey)];
222951
223019
  }
222952
223020
  callHook(event, data = null) {
222953
- const hooks = Metadata.get(CONTROLLER_EVENTS, Reflect);
222954
- if (!hooks)
223021
+ const hooks2 = Metadata.get(CONTROLLER_EVENTS, Reflect);
223022
+ if (!hooks2)
222955
223023
  return;
222956
- hooks.filter((hook) => hook.eventName === event).forEach(async (hook) => {
223024
+ hooks2.filter((hook) => hook.eventName === event).forEach(async (hook) => {
222957
223025
  const instance = this.invoke(hook.target);
222958
223026
  await instance[hook.methodName](data ?? {});
222959
223027
  });
@@ -222972,13 +223040,13 @@ var InjectorService5 = InjectorService_12 = class InjectorService6 {
222972
223040
  ];
222973
223041
  this.applicationConfig.providers = this.applicationConfig.providers || [];
222974
223042
  this.applicationConfig.providers.push(...defaults);
222975
- let hooks = Metadata.get(CONTROLLER_EVENTS, Reflect);
223043
+ let hooks2 = Metadata.get(CONTROLLER_EVENTS, Reflect);
222976
223044
  for (let [token] of GlobalProvider.entries()) {
222977
223045
  if (!this.applicationConfig.providers || !this.applicationConfig.providers.includes(token)) {
222978
223046
  GlobalProvider.delete(token);
222979
- if (hooks) {
222980
- hooks = hooks.filter((hook) => hook.target !== token);
222981
- Metadata.set(CONTROLLER_EVENTS, hooks, Reflect);
223047
+ if (hooks2) {
223048
+ hooks2 = hooks2.filter((hook) => hook.target !== token);
223049
+ Metadata.set(CONTROLLER_EVENTS, hooks2, Reflect);
222982
223050
  }
222983
223051
  }
222984
223052
  }
@@ -223030,13 +223098,13 @@ var __metadata4 = function(k, v) {
223030
223098
  };
223031
223099
  var Context_12;
223032
223100
  var Context4 = Context_12 = class Context5 {
223101
+ query = {};
223102
+ body = {};
223103
+ param = {};
223104
+ req = {};
223105
+ headers = {};
223106
+ locals = {};
223033
223107
  constructor() {
223034
- this.query = {};
223035
- this.body = {};
223036
- this.param = {};
223037
- this.req = {};
223038
- this.headers = {};
223039
- this.locals = {};
223040
223108
  }
223041
223109
  static async createFromRequest(url, request, server) {
223042
223110
  const context = new Context_12;
@@ -223114,6 +223182,7 @@ class Metadata3 {
223114
223182
  static setParamTypes(target, propertyKey, value) {
223115
223183
  return this.set(DESIGN_PARAM_TYPES2, value, target.prototype, propertyKey);
223116
223184
  }
223185
+ static getTargetsFromPropertyKey = (metadataKey) => PROPERTIES3.has(metadataKey) ? PROPERTIES3.get(metadataKey) || [] : [];
223117
223186
  static set(key, value, target, propertyKey) {
223118
223187
  const targets = PROPERTIES3.has(key) ? PROPERTIES3.get(key) || [] : [];
223119
223188
  const classConstructor = classOf(target);
@@ -223133,7 +223202,6 @@ class Metadata3 {
223133
223202
  return Reflect.getMetadata(ROUTE_PARAM, target.constructor, propertyKey);
223134
223203
  }
223135
223204
  }
223136
- Metadata3.getTargetsFromPropertyKey = (metadataKey) => PROPERTIES3.has(metadataKey) ? PROPERTIES3.get(metadataKey) || [] : [];
223137
223205
  // ../../node_modules/balanced-match/index.jsodules/minimat
223138
223206
  var HttpMethod2;
223139
223207
  (function(HttpMethod3) {
@@ -223219,9 +223287,75 @@ var RouteExecutor4 = new Router2;
223219
223287
  // ../../node_modules/balanced-match/index.jsodu
223220
223288
  import process4 from "process";
223221
223289
  var parseUrl4 = require_parseurl_fast();
223290
+
223291
+ class Cheetah3 {
223292
+ config;
223293
+ router = new memoirist_default2;
223294
+ injector = createInjector();
223295
+ fetch = (request, server) => this.fetcher(request, server);
223296
+ server;
223297
+ constructor(config = {}) {
223298
+ this.config = config;
223299
+ this.injector.callHook(EventType.OnApplicationBoot, {});
223300
+ }
223301
+ use(plugin) {
223302
+ if (!this.config.providers) {
223303
+ this.config.providers = [];
223304
+ }
223305
+ for (const provider7 of plugin.config.exports || []) {
223306
+ this.config.providers.push(provider7);
223307
+ }
223308
+ return this;
223309
+ }
223310
+ useLogger(provider7) {
223311
+ registerProvider({ provide: LoggerService, useClass: provider7 });
223312
+ return this;
223313
+ }
223314
+ async listen(port = 3000) {
223315
+ process4.on("SIGTERM", () => this.injector.callHook(EventType.OnApplicationShutdown));
223316
+ this.injector.loadModule(createContainer(), this.config, this.router);
223317
+ this.createHttpServer(port);
223318
+ }
223319
+ getInjector() {
223320
+ return this.injector;
223321
+ }
223322
+ createHttpServer(port) {
223323
+ this.server = Bun.serve({ port, fetch: this.fetch, error: this.catcher });
223324
+ console.log(`Server running on port ${port}`);
223325
+ }
223326
+ async fetcher(request, server) {
223327
+ const urlParsed = parseUrl4(request);
223328
+ const context = await Context.createFromRequest(urlParsed, request, server);
223329
+ this.injector.callHook(EventType.OnRequest, { context });
223330
+ const local = new LocalsContainer;
223331
+ const route = this.router.find(request.method.toLowerCase(), urlParsed.path);
223332
+ if (!route) {
223333
+ throw new HttpException("Method not allowed", 404);
223334
+ }
223335
+ context.param = route.params;
223336
+ local.set(Context, context);
223337
+ return RouteExecutor4.executeRoute(route.store, this.injector, context, local);
223338
+ }
223339
+ catcher = (error) => {
223340
+ if (error instanceof HttpException) {
223341
+ return new Response(JSON.stringify({
223342
+ message: error.getResponse(),
223343
+ statusCode: error.getStatus()
223344
+ }), {
223345
+ status: error.statusCode,
223346
+ headers: { "Content-Type": "application/json" }
223347
+ });
223348
+ }
223349
+ return new Response(error.message, { status: 500 });
223350
+ };
223351
+ close(closeActiveConnections = false) {
223352
+ this.server.stop(closeActiveConnections);
223353
+ }
223354
+ }
223222
223355
  // ../../node_modules/balanced-match/index.jsodules/mini
223223
223356
  var EventType2;
223224
223357
  (function(EventType3) {
223358
+ EventType3["OnApplicationBoot"] = "OnApplicationBoot";
223225
223359
  EventType3["OnApplicationInit"] = "OnApplicationInit";
223226
223360
  EventType3["OnApplicationShutdown"] = "OnApplicationShutdown";
223227
223361
  EventType3["OnRequest"] = "OnRequest";
@@ -223273,6 +223407,8 @@ var __metadata6 = function(k, v) {
223273
223407
  return Reflect.metadata(k, v);
223274
223408
  };
223275
223409
  var LoggerService3 = class LoggerService4 {
223410
+ injector;
223411
+ logger;
223276
223412
  constructor(injector) {
223277
223413
  this.injector = injector;
223278
223414
  const pinoConfig = this.injector.applicationConfig.logger || {};
@@ -223847,7 +223983,9 @@ class SqlBuilder {
223847
223983
  if (!entity) {
223848
223984
  return;
223849
223985
  }
223850
- if (entitiesOptions.get(alias).showProperties.hasOwnProperty(prop)) {
223986
+ const entityProperty = entitiesOptions.get(alias).showProperties[prop];
223987
+ if (entityProperty) {
223988
+ console.log(typeof value, entityProperty.type);
223851
223989
  entity[prop] = value;
223852
223990
  }
223853
223991
  });
@@ -223945,625 +224083,14 @@ Orm = __legacyDecorateClassTS([
223945
224083
  ])
223946
224084
  ], Orm);
223947
224085
  // ../../node_modules
223948
- var import_ts_morph2 = __toESM(require_ts_morph(), 1);
223949
-
223950
- // ../../node_module
223951
- var ENTITIES2 = "cheetah:entities";
223952
- var PROPERTIES_METADATA2 = "cheetah:properties:metadata";
223953
- var PROPERTIES_RELATIONS2 = "cheetah:properties:relations";
223954
- // ../../node_mo
223955
- function getDefaultLength2(type) {
223956
- if (type === "String") {
223957
- return 255;
223958
- }
223959
- if (type === "Number") {
223960
- return 11;
223961
- }
223962
- if (type === "Boolean") {
223963
- return 1;
223964
- }
223965
- if (type === "Date") {
223966
- return 6;
223967
- }
223968
- return 255;
223969
- }
223970
- // ../../node_modules/bala
223971
- var __decorate9 = function(decorators5, target, key, desc) {
223972
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
223973
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
223974
- r = Reflect.decorate(decorators5, target, key, desc);
223975
- else
223976
- for (var i = decorators5.length - 1;i >= 0; i--)
223977
- if (d = decorators5[i])
223978
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
223979
- return c > 3 && r && Object.defineProperty(target, key, r), r;
223980
- };
223981
- var __metadata7 = function(k, v) {
223982
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
223983
- return Reflect.metadata(k, v);
223984
- };
223985
- var EntityStorage_1;
223986
- var EntityStorage2 = EntityStorage_1 = class EntityStorage3 {
223987
- constructor() {
223988
- this.entities = new Map;
223989
- EntityStorage_1.instance = this;
223990
- }
223991
- add(entity, properties, relations) {
223992
- const entityName = entity.options?.tableName || entity.target.name.toLowerCase();
223993
- const indexes = Metadata.get("indexes", entity.target) || [];
223994
- this.entities.set(entity.target, {
223995
- showProperties: properties,
223996
- hideProperties: [],
223997
- relations,
223998
- indexes: indexes.map((index) => {
223999
- return {
224000
- table: entityName,
224001
- indexName: index.name.replace("[TABLE]", entityName),
224002
- columnName: index.properties.join(",")
224003
- };
224004
- }),
224005
- tableName: entityName,
224006
- ...entity.options
224007
- });
224008
- }
224009
- get(entity) {
224010
- return this.entities.get(entity);
224011
- }
224012
- entries() {
224013
- return this.entities.entries();
224014
- }
224015
- static getInstance() {
224016
- return EntityStorage_1.instance;
224017
- }
224018
- async snapshot(values) {
224019
- return {
224020
- tableName: values.tableName,
224021
- schema: values.schema || "public",
224022
- indexes: values.indexes || [],
224023
- columns: this.snapshotColumns(values)
224024
- };
224025
- }
224026
- snapshotColumns(values) {
224027
- let properties = Object.entries(values.showProperties).map(([key, value]) => {
224028
- return {
224029
- name: key,
224030
- type: value.type.name,
224031
- nullable: value.options?.nullable,
224032
- default: value.options?.default,
224033
- primary: value.options?.isPrimary,
224034
- unique: value.options?.unique,
224035
- length: value.options?.length
224036
- };
224037
- });
224038
- let relations = values.relations && values.relations.map((relation) => {
224039
- const type = this.getFkType(relation);
224040
- return {
224041
- name: relation.propertyKey,
224042
- type,
224043
- nullable: relation.nullable,
224044
- unique: relation.unique,
224045
- length: relation.length || getDefaultLength2(type),
224046
- default: relation.default,
224047
- primary: relation.isPrimary,
224048
- foreignKeys: [
224049
- {
224050
- referencedColumnName: this.getFkKey(relation),
224051
- referencedTableName: this.get(relation.entity()).tableName
224052
- }
224053
- ]
224054
- };
224055
- });
224056
- if (!relations) {
224057
- relations = [];
224058
- }
224059
- if (!properties) {
224060
- properties = [];
224061
- }
224062
- return [...properties, ...relations];
224063
- }
224064
- snapshotIndexes(values) {
224065
- return Object.entries(values.showProperties).map(([key, value]) => {
224066
- return {
224067
- indexName: key,
224068
- columnName: key,
224069
- table: values.tableName
224070
- };
224071
- });
224072
- }
224073
- getFkType(relation) {
224074
- const entity = this.get(relation.entity());
224075
- if (!entity) {
224076
- return "unknown";
224077
- }
224078
- return entity.showProperties[this.getFkKey(relation)].type.name;
224079
- }
224080
- getFkKey(relationShip) {
224081
- if (typeof relationShip.fkKey === "undefined") {
224082
- const entity = this.entities.get(relationShip.entity());
224083
- const property3 = Object.entries(entity.showProperties).find(([key, value]) => value.options.isPrimary === true);
224084
- if (!property3) {
224085
- throw new Error(`Entity ${entity.tableName} does not have a primary key`);
224086
- }
224087
- return property3[0];
224088
- }
224089
- if (typeof relationShip.fkKey === "string") {
224090
- return relationShip.fkKey;
224091
- }
224092
- const match = /\.(?<propriedade>[\w]+)/.exec(relationShip.fkKey.toString());
224093
- return match ? match.groups.propriedade : "";
224094
- }
224095
- };
224096
- EntityStorage2 = EntityStorage_1 = __decorate9([
224097
- Service(),
224098
- __metadata7("design:paramtypes", [])
224099
- ], EntityStorage2);
224100
-
224101
- // ../../node_modules
224102
- class SqlBuilder3 {
224103
- constructor(model) {
224104
- this.statements = {};
224105
- this.aliases = new Set;
224106
- this.lastKeyNotOperator = "";
224107
- this.updatedColumns = [];
224108
- const orm = Orm.getInstance();
224109
- this.driver = orm.driverInstance;
224110
- this.logger = orm.logger;
224111
- this.entityStorage = EntityStorage2.getInstance();
224112
- this.getEntity(model);
224113
- }
224114
- select(columns) {
224115
- const tableName = this.entity.tableName || this.model.name.toLowerCase();
224116
- const schema = this.entity.schema || "public";
224117
- this.statements.statement = "select";
224118
- this.statements.columns = columns;
224119
- this.statements.alias = this.getAlias(tableName);
224120
- this.statements.table = `"${schema}"."${tableName}"`;
224121
- return this;
224122
- }
224123
- insert(values) {
224124
- const { tableName, schema } = this.getTableName();
224125
- this.statements.statement = "insert";
224126
- this.statements.alias = this.getAlias(tableName);
224127
- this.statements.table = `"${schema}"."${tableName}"`;
224128
- this.statements.values = this.withUpdatedValues(this.withDefaultValues(values, this.entity), this.entity);
224129
- return this;
224130
- }
224131
- update(values) {
224132
- const { tableName, schema } = this.getTableName();
224133
- this.statements.statement = "update";
224134
- this.statements.alias = this.getAlias(tableName);
224135
- this.statements.table = `${schema}.${tableName}`;
224136
- this.statements.values = this.withUpdatedValues(values, this.entity);
224137
- return this;
224138
- }
224139
- where(where) {
224140
- if (typeof where === "undefined" || Object.entries(where).length === 0) {
224141
- return this;
224142
- }
224143
- this.statements.where = this.conditionToSql(where, this.statements.alias);
224144
- return this;
224145
- }
224146
- orderBy(orderBy) {
224147
- if (typeof orderBy === "undefined") {
224148
- return this;
224149
- }
224150
- this.statements.orderBy = this.objectToStringMap(orderBy);
224151
- return this;
224152
- }
224153
- limit(limit) {
224154
- this.statements.limit = limit;
224155
- return this;
224156
- }
224157
- offset(offset) {
224158
- this.statements.offset = offset;
224159
- return this;
224160
- }
224161
- async executeAndReturnFirst() {
224162
- this.statements.limit = 1;
224163
- const result = await this.execute();
224164
- if (result.query.rows.length === 0) {
224165
- return;
224166
- }
224167
- return this.transformToModel(result.query.rows[0]);
224168
- }
224169
- async executeAndReturnFirstOrFail() {
224170
- this.statements.limit = 1;
224171
- const result = await this.execute();
224172
- if (result.query.rows.length === 0) {
224173
- throw new Error("Result not found");
224174
- }
224175
- return this.transformToModel(result.query.rows[0]);
224176
- }
224177
- async executeAndReturnAll() {
224178
- const result = await this.execute();
224179
- if (result.query.rows.length === 0) {
224180
- return [];
224181
- }
224182
- return result.query.rows.map((row) => this.transformToModel(row));
224183
- }
224184
- async execute() {
224185
- if (!this.statements.columns) {
224186
- let columns = [
224187
- ...this.getColumnsEntity(this.model, this.statements.alias)
224188
- ];
224189
- if (this.statements.join) {
224190
- columns = [
224191
- ...columns,
224192
- ...this.statements.join.flatMap((join) => this.getColumnsEntity(join.joinEntity, join.joinAlias))
224193
- ];
224194
- }
224195
- this.statements.columns = columns;
224196
- } else {
224197
- this.statements.columns = this.statements.columns.map((column) => {
224198
- return this.discoverColumnAlias(column);
224199
- }).flat();
224200
- }
224201
- this.statements.columns.push(...this.updatedColumns);
224202
- const result = await this.driver.executeStatement(this.statements);
224203
- this.logger.debug(`SQL: ${result.sql} [${Date.now() - result.startTime}ms]`);
224204
- return result;
224205
- }
224206
- startTransaction() {
224207
- return this.driver.startTransaction();
224208
- }
224209
- commit() {
224210
- return this.driver.commitTransaction();
224211
- }
224212
- rollback() {
224213
- return this.driver.rollbackTransaction();
224214
- }
224215
- async inTransaction(callback) {
224216
- await this.startTransaction();
224217
- try {
224218
- const result = await callback(this);
224219
- await this.commit();
224220
- return result;
224221
- } catch (e) {
224222
- await this.rollback();
224223
- throw e;
224224
- }
224225
- }
224226
- objectToStringMap(obj, parentKey = "") {
224227
- let result = [];
224228
- for (let key in obj) {
224229
- if (obj.hasOwnProperty(key)) {
224230
- let fullKey = parentKey ? `${parentKey}.${key}` : key;
224231
- if (typeof obj[key] === "object" && obj[key] !== null) {
224232
- result = result.concat(this.objectToStringMap(obj[key], fullKey));
224233
- } else {
224234
- result.push(`${this.discoverColumnAlias(fullKey, true)} ${obj[key]}`);
224235
- }
224236
- }
224237
- }
224238
- return result;
224239
- }
224240
- discoverColumnAlias(column, onlyAlias = false) {
224241
- if (!column.includes(".")) {
224242
- if (onlyAlias) {
224243
- return `${this.statements.alias}."${column}"`;
224244
- }
224245
- return `${this.statements.alias}."${column}" as ${this.statements.alias}_${column}`;
224246
- }
224247
- if (typeof this.statements.join === "undefined") {
224248
- throw new Error("Join not found");
224249
- }
224250
- const entities3 = column.split(".");
224251
- let lastEntity = this.model;
224252
- let lastAlias = this.statements.alias;
224253
- const relationsMap = new Map(this.entity.relations.map((rel) => [rel.propertyKey, rel]));
224254
- const joinMap = new Map(this.statements.join.map((join) => [join.joinProperty, join]));
224255
- for (let i = 0;i < entities3.length; i++) {
224256
- if (i === 0) {
224257
- const relation = relationsMap.get(entities3[i]);
224258
- lastEntity = relation?.entity();
224259
- lastAlias = joinMap.get(entities3[i])?.joinAlias;
224260
- } else {
224261
- if (i + 1 === entities3.length) {
224262
- if (onlyAlias) {
224263
- return `${lastAlias}."${entities3[i]}"`;
224264
- }
224265
- return `${lastAlias}."${entities3[i]}" as ${lastAlias}_${entities3[i]}`;
224266
- }
224267
- const lastStatement = joinMap.get(entities3[i]);
224268
- lastEntity = lastStatement?.joinEntity;
224269
- lastAlias = lastStatement?.joinAlias;
224270
- }
224271
- }
224272
- return "";
224273
- }
224274
- getTableName() {
224275
- const tableName = this.entity.tableName || this.model.name.toLowerCase();
224276
- const schema = this.entity.schema || "public";
224277
- return { tableName, schema };
224278
- }
224279
- addSimpleConditionToSql(key, value, alias = null, operator = "=") {
224280
- const aliasToUse = alias || this.statements.alias;
224281
- const valueByType = typeof value === "string" ? `'${value}'` : value;
224282
- return `${aliasToUse}.${key} ${operator} ${valueByType}`;
224283
- }
224284
- addInConditionToSql(key, values, alias = null) {
224285
- const aliasToUse = alias || this.statements.alias;
224286
- return `${aliasToUse}.${key} IN (${values.map((val) => typeof val === "string" ? `'${val}'` : val).join(", ")})`;
224287
- }
224288
- addLogicalOperatorToSql(conditions, operator) {
224289
- return `(${conditions.join(` ${operator} `)})`;
224290
- }
224291
- conditionToSql(condition, alias) {
224292
- const sqlParts = [];
224293
- const operators = ["$eq", "$ne", "$in", "$nin", "$like", "$gt", "$gte", "$lt", "$lte", "$and", "$or"];
224294
- for (let [key, value] of Object.entries(condition)) {
224295
- if (!operators.includes(key)) {
224296
- this.lastKeyNotOperator = key;
224297
- }
224298
- const relationShip = this.entity.relations?.find((rel) => rel.propertyKey === key);
224299
- if (relationShip) {
224300
- sqlParts.push(this.applyJoin(relationShip, value, alias));
224301
- } else if (typeof value !== "object" || value === null) {
224302
- if (key === "$eq") {
224303
- sqlParts.push(this.addSimpleConditionToSql(this.lastKeyNotOperator, value, alias, "="));
224304
- continue;
224305
- }
224306
- sqlParts.push(this.addSimpleConditionToSql(key, value, alias));
224307
- } else if (!operators.includes(key) && Array.isArray(value)) {
224308
- sqlParts.push(this.addInConditionToSql(key, value, alias));
224309
- } else {
224310
- if (["$or", "$and"].includes(key)) {
224311
- sqlParts.push(this.addLogicalOperatorToSql(value.map((cond) => this.conditionToSql(cond, alias)), key.toUpperCase().replace("$", "")));
224312
- }
224313
- for (const operator of operators) {
224314
- if (operator in value) {
224315
- switch (operator) {
224316
- case "$eq":
224317
- sqlParts.push(this.addSimpleConditionToSql(key, value["$eq"], alias, "="));
224318
- break;
224319
- case "$ne":
224320
- sqlParts.push(this.addSimpleConditionToSql(key, value["$ne"], alias, "!="));
224321
- break;
224322
- case "$in":
224323
- sqlParts.push(this.addInConditionToSql(key, value["$in"], alias));
224324
- break;
224325
- case "$nin":
224326
- sqlParts.push(`${alias}.${key} NOT IN (${value["$nin"].map((val) => this.t(val)).join(", ")})`);
224327
- break;
224328
- case "$like":
224329
- sqlParts.push(`${alias}.${key} LIKE '${value["$like"]}'`);
224330
- break;
224331
- case "$gt":
224332
- sqlParts.push(`${alias}.${key} > ${value["$gt"]}`);
224333
- break;
224334
- case "$gte":
224335
- sqlParts.push(`${alias}.${key} >= ${value["$gte"]}`);
224336
- break;
224337
- case "$lt":
224338
- sqlParts.push(`${alias}.${key} < ${value["$lt"]}`);
224339
- break;
224340
- case "$lte":
224341
- sqlParts.push(`${alias}.${key} <= ${value["$lte"]}`);
224342
- break;
224343
- case "$and":
224344
- case "$or":
224345
- const parts = value[operator].map((cond) => this.conditionToSql(cond, alias));
224346
- sqlParts.push(this.addLogicalOperatorToSql(parts, operator.toUpperCase().replace("$", "")));
224347
- break;
224348
- }
224349
- }
224350
- }
224351
- }
224352
- }
224353
- return this.addLogicalOperatorToSql(sqlParts, "AND");
224354
- }
224355
- t(value) {
224356
- return typeof value === "string" ? `'${value}'` : value;
224357
- }
224358
- applyJoin(relationShip, value, alias) {
224359
- const { tableName, schema } = this.getTableName();
224360
- const { tableName: joinTableName, schema: joinSchema } = this.entityStorage.get(relationShip.entity()) || {
224361
- tableName: relationShip.entity().name.toLowerCase(),
224362
- schema: "public"
224363
- };
224364
- let originPrimaryKey = "id";
224365
- for (const prop in this.entity.showProperties) {
224366
- if (this.entity.showProperties[prop].options.isPrimary) {
224367
- originPrimaryKey = prop;
224368
- break;
224369
- }
224370
- }
224371
- const joinAlias = `${this.getAlias(joinTableName)}`;
224372
- const joinWhere = this.conditionToSql(value, joinAlias);
224373
- this.statements.join = this.statements.join || [];
224374
- let on = "";
224375
- switch (relationShip.relation) {
224376
- case "one-to-many":
224377
- on = `${joinAlias}.${this.getFkKey(relationShip)} = ${alias}.${originPrimaryKey}`;
224378
- break;
224379
- case "many-to-one":
224380
- on = `${alias}.${relationShip.propertyKey} = ${joinAlias}.${this.getFkKey(relationShip)}`;
224381
- break;
224382
- }
224383
- this.statements.join.push({
224384
- joinAlias,
224385
- joinTable: joinTableName,
224386
- joinSchema: joinSchema || "public",
224387
- joinWhere,
224388
- joinProperty: relationShip.propertyKey,
224389
- originAlias: alias,
224390
- originSchema: schema,
224391
- originTable: tableName,
224392
- propertyKey: relationShip.propertyKey,
224393
- joinEntity: relationShip.entity(),
224394
- type: "LEFT",
224395
- on,
224396
- originalEntity: relationShip.originalEntity
224397
- });
224398
- return joinWhere;
224399
- }
224400
- getFkKey(relationShip) {
224401
- if (typeof relationShip.fkKey === "undefined") {
224402
- return "id";
224403
- }
224404
- if (typeof relationShip.fkKey === "string") {
224405
- return relationShip.fkKey;
224406
- }
224407
- const match = /\.(?<propriedade>[\w]+)/.exec(relationShip.fkKey.toString());
224408
- return match ? match.groups.propriedade : "";
224409
- }
224410
- getEntity(model) {
224411
- const entity = this.entityStorage.get(model);
224412
- this.model = model;
224413
- if (!entity) {
224414
- throw new Error("Entity not found");
224415
- }
224416
- this.entity = entity;
224417
- }
224418
- transformToModel(data) {
224419
- const instance = new this.model;
224420
- instance.$_isPersisted = true;
224421
- const entitiesByAlias = {
224422
- [this.statements.alias]: instance
224423
- };
224424
- const entitiesOptions = new Map;
224425
- entitiesOptions.set(this.statements.alias, this.entityStorage.get(instance.constructor));
224426
- if (this.statements.join) {
224427
- this.statements.join.forEach((join) => {
224428
- const joinInstance = new join.joinEntity;
224429
- joinInstance.$_isPersisted = true;
224430
- entitiesByAlias[join.joinAlias] = joinInstance;
224431
- entitiesOptions.set(join.joinAlias, this.entityStorage.get(joinInstance.constructor));
224432
- });
224433
- }
224434
- Object.entries(data).forEach(([key, value]) => {
224435
- const [alias, prop] = key.split("_");
224436
- const entity = entitiesByAlias[alias];
224437
- if (!entity) {
224438
- return;
224439
- }
224440
- if (entitiesOptions.get(alias).showProperties.hasOwnProperty(prop)) {
224441
- entity[prop] = value;
224442
- }
224443
- });
224444
- if (this.statements.join) {
224445
- this.statements.join.forEach((join) => {
224446
- const { joinAlias, originAlias, propertyKey } = join;
224447
- const originEntity = entitiesByAlias[originAlias];
224448
- const joinEntity = entitiesByAlias[joinAlias];
224449
- const property3 = entitiesOptions.get(originAlias).relations.find((rel) => rel.propertyKey === propertyKey);
224450
- if (!originEntity || !joinEntity) {
224451
- return;
224452
- }
224453
- originEntity[propertyKey] = property3.type === Array ? originEntity[propertyKey] ? [...originEntity[propertyKey], joinEntity] : [joinEntity] : joinEntity;
224454
- });
224455
- }
224456
- return instance;
224457
- }
224458
- getAlias(tableName) {
224459
- const alias = tableName.split("").shift() || "";
224460
- let counter = 1;
224461
- let uniqueAlias = `${alias}${counter}`;
224462
- while (this.aliases.has(uniqueAlias)) {
224463
- counter++;
224464
- uniqueAlias = `${alias}${counter}`;
224465
- }
224466
- this.aliases.add(uniqueAlias);
224467
- return uniqueAlias;
224468
- }
224469
- getColumnsEntity(entity, alias) {
224470
- const e = this.entityStorage.get(entity);
224471
- if (!e) {
224472
- throw new Error("Entity not found");
224473
- }
224474
- return Object.keys(e.showProperties).map((key) => `${alias}."${key}" as "${alias}_${key}"`);
224475
- }
224476
- withDefaultValues(values, entityOptions) {
224477
- const property3 = Object.entries(entityOptions.showProperties).filter(([_, value]) => value.options.onInsert);
224478
- const defaultProperties = Object.entries(entityOptions.showProperties).filter(([_, value]) => value.options.default);
224479
- for (const [key, property4] of defaultProperties) {
224480
- if (typeof values[key] === "undefined") {
224481
- if (typeof property4.options.default === "function") {
224482
- values[key] = (0, eval)(property4.options.default());
224483
- } else {
224484
- values[key] = (0, eval)(property4.options.default);
224485
- }
224486
- }
224487
- }
224488
- property3.forEach(([key, property4]) => {
224489
- values[key] = property4.options.onInsert();
224490
- this.updatedColumns.push(`${this.statements.alias}."${key}" as "${this.statements.alias}_${key}"`);
224491
- });
224492
- return values;
224493
- }
224494
- withUpdatedValues(values, entityOptions) {
224495
- const property3 = Object.entries(entityOptions.showProperties).filter(([_, value]) => value.options.onUpdate);
224496
- property3.forEach(([key, property4]) => {
224497
- values[key] = property4.options.onUpdate();
224498
- this.updatedColumns.push(`${this.statements.alias}."${key}" as "${this.statements.alias}_${key}"`);
224499
- });
224500
- return values;
224501
- }
224502
- }
224503
-
224504
- // ../../node_
224505
- var __decorate10 = function(decorators5, target, key, desc) {
224506
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
224507
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
224508
- r = Reflect.decorate(decorators5, target, key, desc);
224509
- else
224510
- for (var i = decorators5.length - 1;i >= 0; i--)
224511
- if (d = decorators5[i])
224512
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
224513
- return c > 3 && r && Object.defineProperty(target, key, r), r;
224514
- };
224515
- var __metadata8 = function(k, v) {
224516
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
224517
- return Reflect.metadata(k, v);
224518
- };
224519
- var Orm_1;
224520
- var Orm2 = Orm_1 = class Orm3 {
224521
- constructor(logger3) {
224522
- this.logger = logger3;
224523
- Orm_1.instance = this;
224524
- }
224525
- static getInstance() {
224526
- return Orm_1.instance;
224527
- }
224528
- setConnection(connection) {
224529
- this.connection = connection;
224530
- this.driverInstance = new this.connection.driver(connection);
224531
- }
224532
- createQueryBuilder(model) {
224533
- return new SqlBuilder3(model);
224534
- }
224535
- connect() {
224536
- return this.driverInstance.connect();
224537
- }
224538
- disconnect() {
224539
- return this.driverInstance.disconnect();
224540
- }
224541
- };
224542
- Orm2 = Orm_1 = __decorate10([
224543
- Service(),
224544
- __metadata8("design:paramtypes", [LoggerService])
224545
- ], Orm2);
224546
- // ../../node_modules/
224547
224086
  var import_ts_morph = __toESM(require_ts_morph(), 1);
224548
- var __decorate11 = function(decorators5, target, key, desc) {
224549
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
224550
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
224551
- r = Reflect.decorate(decorators5, target, key, desc);
224552
- else
224553
- for (var i = decorators5.length - 1;i >= 0; i--)
224554
- if (d = decorators5[i])
224555
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
224556
- return c > 3 && r && Object.defineProperty(target, key, r), r;
224557
- };
224558
- var __metadata9 = function(k, v) {
224559
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
224560
- return Reflect.metadata(k, v);
224561
- };
224562
- var OrmService = class OrmService2 {
224563
- constructor(orm2, storage2, entityFile = undefined) {
224087
+ class OrmService {
224088
+ orm2;
224089
+ storage2;
224090
+ allEntities = new Map;
224091
+ constructor(orm2, storage2, entityFile) {
224564
224092
  this.orm = orm2;
224565
224093
  this.storage = storage2;
224566
- this.allEntities = new Map;
224567
224094
  console.log("Preparing entities...");
224568
224095
  const files = new import_ts_morph.Project({ skipLoadingLibFiles: true }).addSourceFilesAtPaths(entityFile ?? this.getSourceFilePaths());
224569
224096
  files.forEach((file) => {
@@ -224572,10 +224099,10 @@ var OrmService = class OrmService2 {
224572
224099
  const properties = classDeclaration.getProperties();
224573
224100
  const nullables = [];
224574
224101
  const defaults = {};
224575
- properties.forEach((property3) => {
224576
- const propertyName = property3.getName();
224577
- const isNullable = property3.hasQuestionToken();
224578
- const initializer = property3.getInitializer();
224102
+ properties.forEach((property2) => {
224103
+ const propertyName = property2.getName();
224104
+ const isNullable = property2.hasQuestionToken();
224105
+ const initializer = property2.getInitializer();
224579
224106
  if (isNullable) {
224580
224107
  nullables.push(propertyName);
224581
224108
  }
@@ -224599,14 +224126,15 @@ var OrmService = class OrmService2 {
224599
224126
  });
224600
224127
  });
224601
224128
  }
224602
- async onInit(customConfig = undefined) {
224129
+ async onInit(customConfig = {}) {
224603
224130
  const configFile = globbySync("cheetah.config.ts", { absolute: true });
224604
224131
  if (configFile.length === 0) {
224605
224132
  console.log("No config file found!");
224606
224133
  return;
224607
224134
  }
224608
224135
  const config = await import(configFile[0]);
224609
- this.orm.setConnection(customConfig ?? config.default.connection);
224136
+ const setConfig = Object.keys(customConfig).length > 0 ? customConfig : config.default;
224137
+ this.orm.setConnection(setConfig);
224610
224138
  await this.orm.connect();
224611
224139
  if (typeof config.default.entities === "string") {
224612
224140
  const files = globbySync([config.default.entities, "!node_modules"], { gitignore: true, absolute: true });
@@ -224614,21 +224142,21 @@ var OrmService = class OrmService2 {
224614
224142
  await import(file);
224615
224143
  }
224616
224144
  }
224617
- const entities4 = Metadata.get(ENTITIES2, Reflect);
224618
- if (!entities4) {
224145
+ const entities3 = Metadata.get(ENTITIES, Reflect);
224146
+ if (!entities3) {
224619
224147
  console.log("No entities found!");
224620
224148
  return;
224621
224149
  }
224622
- for (const entity of entities4) {
224150
+ for (const entity of entities3) {
224623
224151
  const nullableDefaultEntity = this.allEntities.get(entity.target.name);
224624
- const properties = Metadata.get(PROPERTIES_METADATA2, entity.target);
224625
- const relationship = Metadata.get(PROPERTIES_RELATIONS2, entity.target);
224626
- for (const property3 in properties) {
224627
- if (nullableDefaultEntity?.nullables.includes(property3)) {
224628
- properties[property3].options.nullable = true;
224152
+ const properties = Metadata.get(PROPERTIES_METADATA, entity.target);
224153
+ const relationship = Metadata.get(PROPERTIES_RELATIONS, entity.target);
224154
+ for (const property2 in properties) {
224155
+ if (nullableDefaultEntity?.nullables.includes(property2)) {
224156
+ properties[property2].options.nullable = true;
224629
224157
  }
224630
- if (nullableDefaultEntity?.defaults[property3]) {
224631
- properties[property3].options.default = nullableDefaultEntity?.defaults[property3];
224158
+ if (nullableDefaultEntity?.defaults[property2]) {
224159
+ properties[property2].options.default = nullableDefaultEntity?.defaults[property2];
224632
224160
  }
224633
224161
  }
224634
224162
  this.storage.add(entity, properties, relationship);
@@ -224648,113 +224176,6 @@ var OrmService = class OrmService2 {
224648
224176
  };
224649
224177
  return getAllFiles(projectRoot);
224650
224178
  }
224651
- };
224652
- __decorate11([
224653
- OnApplicationInit(),
224654
- __metadata9("design:type", Function),
224655
- __metadata9("design:paramtypes", [Object]),
224656
- __metadata9("design:returntype", Promise)
224657
- ], OrmService.prototype, "onInit", null);
224658
- OrmService = __decorate11([
224659
- Service(),
224660
- __metadata9("design:paramtypes", [Orm2, EntityStorage2, Object])
224661
- ], OrmService);
224662
- // ../../node_modules/balan
224663
- var import_pg = __toESM(require_lib2(), 1);
224664
- // ../../node_mo
224665
- var CheetahOrm = new Cheetah({ exports: [Orm2, OrmService, EntityStorage2] });
224666
- // ../../node_modules
224667
- class OrmService3 {
224668
- orm7;
224669
- storage2;
224670
- allEntities = new Map;
224671
- constructor(orm7, storage2, entityFile = undefined) {
224672
- this.orm = orm7;
224673
- this.storage = storage2;
224674
- console.log("Preparing entities...");
224675
- const files = new import_ts_morph2.Project({ skipLoadingLibFiles: true }).addSourceFilesAtPaths(entityFile ?? this.getSourceFilePaths());
224676
- files.forEach((file) => {
224677
- file.getClasses().forEach((classDeclaration) => {
224678
- if (classDeclaration.getDecorator("Entity")) {
224679
- const properties = classDeclaration.getProperties();
224680
- const nullables = [];
224681
- const defaults = {};
224682
- properties.forEach((property4) => {
224683
- const propertyName = property4.getName();
224684
- const isNullable = property4.hasQuestionToken();
224685
- const initializer = property4.getInitializer();
224686
- if (isNullable) {
224687
- nullables.push(propertyName);
224688
- }
224689
- if (initializer) {
224690
- const initializerKind = initializer.getKind();
224691
- switch (initializerKind) {
224692
- case import_ts_morph2.SyntaxKind.StringLiteral:
224693
- defaults[propertyName] = initializer.getText();
224694
- break;
224695
- case import_ts_morph2.SyntaxKind.NumericLiteral:
224696
- defaults[propertyName] = parseFloat(initializer.getText());
224697
- break;
224698
- default:
224699
- defaults[propertyName] = () => initializer.getText();
224700
- break;
224701
- }
224702
- }
224703
- this.allEntities.set(classDeclaration.getName(), { nullables, defaults });
224704
- });
224705
- }
224706
- });
224707
- });
224708
- }
224709
- async onInit(customConfig = undefined) {
224710
- const configFile = globbySync("cheetah.config.ts", { absolute: true });
224711
- if (configFile.length === 0) {
224712
- console.log("No config file found!");
224713
- return;
224714
- }
224715
- const config = await import(configFile[0]);
224716
- this.orm.setConnection(customConfig ?? config.default.connection);
224717
- await this.orm.connect();
224718
- if (typeof config.default.entities === "string") {
224719
- const files = globbySync([config.default.entities, "!node_modules"], { gitignore: true, absolute: true });
224720
- for (const file of files) {
224721
- await import(file);
224722
- }
224723
- }
224724
- const entities6 = Metadata.get(ENTITIES, Reflect);
224725
- if (!entities6) {
224726
- console.log("No entities found!");
224727
- return;
224728
- }
224729
- for (const entity2 of entities6) {
224730
- const nullableDefaultEntity = this.allEntities.get(entity2.target.name);
224731
- const properties = Metadata.get(PROPERTIES_METADATA, entity2.target);
224732
- const relationship = Metadata.get(PROPERTIES_RELATIONS, entity2.target);
224733
- for (const property4 in properties) {
224734
- if (nullableDefaultEntity?.nullables.includes(property4)) {
224735
- properties[property4].options.nullable = true;
224736
- }
224737
- if (nullableDefaultEntity?.defaults[property4]) {
224738
- properties[property4].options.default = nullableDefaultEntity?.defaults[property4];
224739
- }
224740
- }
224741
- this.storage.add(entity2, properties, relationship);
224742
- }
224743
- console.log("Entities prepared!");
224744
- }
224745
- getSourceFilePaths() {
224746
- const projectRoot = process.cwd();
224747
- const getAllFiles = (dir) => {
224748
- const patterns = [`${dir}/**/*.(ts|js)`, "!**/node_modules/**"];
224749
- try {
224750
- return globbySync(patterns, { gitignore: true });
224751
- } catch (error) {
224752
- console.error("Erro ao obter arquivos:", error);
224753
- return [];
224754
- }
224755
- };
224756
- return getAllFiles(projectRoot);
224757
- }
224758
224179
  }
224759
224180
  __legacyDecorateClassTS([
224760
224181
  OnApplicationInit(),
@@ -224763,15 +224184,15 @@ __legacyDecorateClassTS([
224763
224184
  Object
224764
224185
  ]),
224765
224186
  __legacyMetadataTS("design:returntype", Promise)
224766
- ], OrmService3.prototype, "onInit", null);
224767
- OrmService3 = __legacyDecorateClassTS([
224187
+ ], OrmService.prototype, "onInit", null);
224188
+ OrmService = __legacyDecorateClassTS([
224768
224189
  Service(),
224769
224190
  __legacyMetadataTS("design:paramtypes", [
224770
- typeof Orm2 === "undefined" ? Object : Orm2,
224191
+ typeof Orm === "undefined" ? Object : Orm,
224771
224192
  typeof EntityStorage === "undefined" ? Object : EntityStorage,
224772
224193
  String
224773
224194
  ])
224774
- ], OrmService3);
224195
+ ], OrmService);
224775
224196
  // ../../node_modules/balanc
224776
224197
  class BaseEntity {
224777
224198
  _oldValues = {};
@@ -224839,7 +224260,7 @@ class BaseEntity {
224839
224260
  }
224840
224261
  }
224841
224262
  // ../../node_modules/bala
224842
- var import_pg2 = __toESM(require_lib2(), 1);
224263
+ var import_pg = __toESM(require_lib2(), 1);
224843
224264
 
224844
224265
  class PgDriver {
224845
224266
  connectionString;
@@ -224851,7 +224272,7 @@ class PgDriver {
224851
224272
  const { host, port, username, password, database } = options;
224852
224273
  this.connectionString = `postgres://${username}:${password}@${host}:${port}/${database}`;
224853
224274
  }
224854
- this.client = new import_pg2.Client({
224275
+ this.client = new import_pg.Client({
224855
224276
  connectionString: this.connectionString
224856
224277
  });
224857
224278
  }
@@ -225095,20 +224516,20 @@ class PgDriver {
225095
224516
  }
225096
224517
  }
225097
224518
  // ../../node_m
225098
- var CheetahOrm2 = new Cheetah({ exports: [Orm, OrmService3, EntityStorage] });
224519
+ var CheetahOrm = new Cheetah({ exports: [Orm, OrmService, EntityStorage] });
225099
224520
  export {
225100
224521
  getDefaultLength,
225101
224522
  Property,
225102
224523
  PrimaryKey,
225103
224524
  PgDriver,
225104
- OrmService3 as OrmService,
224525
+ OrmService,
225105
224526
  Orm,
225106
224527
  OneToMany,
225107
224528
  ManyToOne,
225108
224529
  Index,
225109
224530
  Entity,
225110
- CheetahOrm2 as CheetahOrm,
224531
+ CheetahOrm,
225111
224532
  BaseEntity
225112
224533
  };
225113
224534
 
225114
- //# debugId=3C714E5DC008C7C264756e2164756e21
224535
+ //# debugId=B31B68854150104864756e2164756e21