@carno.js/core 0.2.11 → 1.0.2

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.
Files changed (314) hide show
  1. package/LICENSE +673 -673
  2. package/README.md +188 -0
  3. package/dist/Carno.js +272 -333
  4. package/dist/Carno.mjs +268 -0
  5. package/dist/DefaultRoutes.js +51 -0
  6. package/dist/DefaultRoutes.mjs +34 -0
  7. package/dist/bun/index.js +183 -0
  8. package/dist/bun/index.js.map +86 -0
  9. package/dist/cache/CacheDriver.js +13 -0
  10. package/dist/cache/CacheDriver.mjs +0 -0
  11. package/dist/cache/CacheService.js +113 -0
  12. package/dist/cache/CacheService.mjs +93 -0
  13. package/dist/cache/MemoryDriver.js +66 -0
  14. package/dist/cache/MemoryDriver.mjs +46 -0
  15. package/dist/cache/RedisDriver.js +81 -0
  16. package/dist/cache/RedisDriver.mjs +61 -0
  17. package/dist/compiler/JITCompiler.js +111 -0
  18. package/dist/compiler/JITCompiler.mjs +89 -0
  19. package/dist/container/Container.js +99 -0
  20. package/dist/container/Container.mjs +78 -0
  21. package/dist/context/Context.js +97 -0
  22. package/dist/context/Context.mjs +77 -0
  23. package/dist/cors/CorsHandler.js +90 -0
  24. package/dist/cors/CorsHandler.mjs +68 -0
  25. package/dist/decorators/Controller.js +42 -0
  26. package/dist/decorators/Controller.mjs +22 -0
  27. package/dist/decorators/Inject.js +30 -0
  28. package/dist/decorators/Inject.mjs +10 -0
  29. package/dist/decorators/Middleware.js +35 -0
  30. package/dist/decorators/Middleware.mjs +15 -0
  31. package/dist/decorators/Service.js +31 -0
  32. package/dist/decorators/Service.mjs +12 -0
  33. package/dist/decorators/methods.js +60 -0
  34. package/dist/decorators/methods.mjs +34 -0
  35. package/dist/decorators/params.js +63 -0
  36. package/dist/decorators/params.mjs +37 -0
  37. package/dist/events/Lifecycle.js +69 -0
  38. package/dist/events/Lifecycle.mjs +41 -0
  39. package/dist/exceptions/HttpException.js +112 -26
  40. package/dist/exceptions/HttpException.mjs +82 -0
  41. package/dist/index.js +129 -31
  42. package/dist/index.mjs +94 -0
  43. package/dist/metadata.js +34 -0
  44. package/dist/metadata.mjs +9 -0
  45. package/dist/middleware/CarnoMiddleware.js +13 -0
  46. package/dist/middleware/CarnoMiddleware.mjs +0 -0
  47. package/dist/router/RadixRouter.js +121 -0
  48. package/dist/router/RadixRouter.mjs +101 -0
  49. package/dist/testing/TestHarness.js +81 -0
  50. package/dist/testing/TestHarness.mjs +60 -0
  51. package/dist/utils/Metadata.js +53 -0
  52. package/dist/utils/Metadata.mjs +31 -0
  53. package/dist/validation/ValibotAdapter.js +67 -0
  54. package/dist/validation/ValibotAdapter.mjs +48 -0
  55. package/dist/validation/ValidatorAdapter.js +35 -19
  56. package/dist/validation/ValidatorAdapter.mjs +14 -0
  57. package/dist/validation/ZodAdapter.js +80 -0
  58. package/dist/validation/ZodAdapter.mjs +59 -0
  59. package/package.json +21 -63
  60. package/src/Carno.ts +605 -0
  61. package/src/DefaultRoutes.ts +34 -0
  62. package/src/cache/CacheDriver.ts +50 -0
  63. package/src/cache/CacheService.ts +139 -0
  64. package/src/cache/MemoryDriver.ts +104 -0
  65. package/src/cache/RedisDriver.ts +116 -0
  66. package/src/compiler/JITCompiler.ts +167 -0
  67. package/src/container/Container.ts +168 -0
  68. package/src/context/Context.ts +128 -0
  69. package/src/cors/CorsHandler.ts +145 -0
  70. package/src/decorators/Controller.ts +63 -0
  71. package/src/decorators/Inject.ts +16 -0
  72. package/src/decorators/Middleware.ts +22 -0
  73. package/src/decorators/Service.ts +18 -0
  74. package/src/decorators/methods.ts +58 -0
  75. package/src/decorators/params.ts +47 -0
  76. package/src/events/Lifecycle.ts +97 -0
  77. package/src/exceptions/HttpException.ts +99 -0
  78. package/src/index.ts +92 -0
  79. package/src/metadata.ts +46 -0
  80. package/src/middleware/CarnoMiddleware.ts +14 -0
  81. package/src/router/RadixRouter.ts +225 -0
  82. package/src/testing/TestHarness.ts +177 -0
  83. package/src/utils/Metadata.ts +43 -0
  84. package/src/validation/ValibotAdapter.ts +95 -0
  85. package/src/validation/ValidatorAdapter.ts +69 -0
  86. package/src/validation/ZodAdapter.ts +102 -0
  87. package/dist/Carno.d.ts +0 -75
  88. package/dist/cache/bento-cache.driver.d.ts +0 -13
  89. package/dist/cache/bento-cache.driver.js +0 -55
  90. package/dist/cache/cache.service.d.ts +0 -8
  91. package/dist/cache/cache.service.js +0 -6
  92. package/dist/commons/decorators/Injectable.decorator.d.ts +0 -20
  93. package/dist/commons/decorators/Injectable.decorator.js +0 -33
  94. package/dist/commons/decorators/controller.decorator.d.ts +0 -8
  95. package/dist/commons/decorators/controller.decorator.js +0 -22
  96. package/dist/commons/decorators/http.decorators.d.ts +0 -13
  97. package/dist/commons/decorators/http.decorators.js +0 -63
  98. package/dist/commons/decorators/index.d.ts +0 -6
  99. package/dist/commons/decorators/index.js +0 -22
  100. package/dist/commons/decorators/inject.decorator.d.ts +0 -1
  101. package/dist/commons/decorators/inject.decorator.js +0 -5
  102. package/dist/commons/decorators/middleware.decorator.d.ts +0 -2
  103. package/dist/commons/decorators/middleware.decorator.js +0 -30
  104. package/dist/commons/decorators/service.decorator.d.ts +0 -2
  105. package/dist/commons/decorators/service.decorator.js +0 -7
  106. package/dist/commons/decorators/validation.decorator.d.ts +0 -32
  107. package/dist/commons/decorators/validation.decorator.js +0 -40
  108. package/dist/commons/http-code.enum.d.ts +0 -50
  109. package/dist/commons/http-code.enum.js +0 -54
  110. package/dist/commons/index.d.ts +0 -3
  111. package/dist/commons/index.js +0 -19
  112. package/dist/commons/registries/ProviderControl.d.ts +0 -77
  113. package/dist/commons/registries/ProviderControl.js +0 -112
  114. package/dist/commons/registries/ProviderRegistry.d.ts +0 -7
  115. package/dist/commons/registries/ProviderRegistry.js +0 -20
  116. package/dist/constants.d.ts +0 -8
  117. package/dist/constants.js +0 -11
  118. package/dist/container/ContainerConfiguration.d.ts +0 -45
  119. package/dist/container/ContainerConfiguration.js +0 -121
  120. package/dist/container/DependencyResolver.d.ts +0 -20
  121. package/dist/container/DependencyResolver.js +0 -85
  122. package/dist/container/InjectorService.d.ts +0 -58
  123. package/dist/container/InjectorService.js +0 -286
  124. package/dist/container/MethodInvoker.d.ts +0 -21
  125. package/dist/container/MethodInvoker.js +0 -83
  126. package/dist/container/RouteResolver.d.ts +0 -27
  127. package/dist/container/RouteResolver.js +0 -173
  128. package/dist/container/container.d.ts +0 -41
  129. package/dist/container/container.js +0 -71
  130. package/dist/container/createContainer.d.ts +0 -3
  131. package/dist/container/createContainer.js +0 -12
  132. package/dist/container/createInjector.d.ts +0 -2
  133. package/dist/container/createInjector.js +0 -7
  134. package/dist/container/index.d.ts +0 -6
  135. package/dist/container/index.js +0 -22
  136. package/dist/container/middleware.resolver.d.ts +0 -9
  137. package/dist/container/middleware.resolver.js +0 -35
  138. package/dist/default-routes-carno.d.ts +0 -3
  139. package/dist/default-routes-carno.js +0 -29
  140. package/dist/domain/BaseContext.d.ts +0 -15
  141. package/dist/domain/BaseContext.js +0 -2
  142. package/dist/domain/CarnoClosure.d.ts +0 -1
  143. package/dist/domain/CarnoClosure.js +0 -2
  144. package/dist/domain/CarnoMiddleware.d.ts +0 -5
  145. package/dist/domain/CarnoMiddleware.js +0 -2
  146. package/dist/domain/Context.d.ts +0 -58
  147. package/dist/domain/Context.js +0 -188
  148. package/dist/domain/FastContext.d.ts +0 -34
  149. package/dist/domain/FastContext.js +0 -59
  150. package/dist/domain/LocalsContainer.d.ts +0 -4
  151. package/dist/domain/LocalsContainer.js +0 -10
  152. package/dist/domain/Metadata.d.ts +0 -449
  153. package/dist/domain/Metadata.js +0 -511
  154. package/dist/domain/cors-config.d.ts +0 -12
  155. package/dist/domain/cors-config.js +0 -18
  156. package/dist/domain/cors-headers-cache.d.ts +0 -17
  157. package/dist/domain/cors-headers-cache.js +0 -101
  158. package/dist/domain/http-method.d.ts +0 -7
  159. package/dist/domain/http-method.js +0 -11
  160. package/dist/domain/index.d.ts +0 -10
  161. package/dist/domain/index.js +0 -26
  162. package/dist/domain/provider-scope.d.ts +0 -5
  163. package/dist/domain/provider-scope.js +0 -9
  164. package/dist/domain/provider-type.d.ts +0 -6
  165. package/dist/domain/provider-type.js +0 -10
  166. package/dist/domain/provider.d.ts +0 -37
  167. package/dist/domain/provider.js +0 -70
  168. package/dist/events/hooks.decorator.d.ts +0 -3
  169. package/dist/events/hooks.decorator.js +0 -29
  170. package/dist/events/index.d.ts +0 -2
  171. package/dist/events/index.js +0 -18
  172. package/dist/events/on-event.d.ts +0 -13
  173. package/dist/events/on-event.js +0 -11
  174. package/dist/exceptions/HttpException.d.ts +0 -9
  175. package/dist/exceptions/index.d.ts +0 -1
  176. package/dist/exceptions/index.js +0 -17
  177. package/dist/index.d.ts +0 -16
  178. package/dist/route/CompiledRoute.d.ts +0 -23
  179. package/dist/route/CompiledRoute.js +0 -9
  180. package/dist/route/FastPathExecutor.d.ts +0 -12
  181. package/dist/route/FastPathExecutor.js +0 -50
  182. package/dist/route/JITCompiler.d.ts +0 -28
  183. package/dist/route/JITCompiler.js +0 -245
  184. package/dist/route/Matcher.d.ts +0 -11
  185. package/dist/route/Matcher.js +0 -48
  186. package/dist/route/ParamResolverFactory.d.ts +0 -14
  187. package/dist/route/ParamResolverFactory.js +0 -49
  188. package/dist/route/RouteCompiler.d.ts +0 -28
  189. package/dist/route/RouteCompiler.js +0 -157
  190. package/dist/route/RouteExecutor.d.ts +0 -12
  191. package/dist/route/RouteExecutor.js +0 -84
  192. package/dist/route/memoirist.d.ts +0 -31
  193. package/dist/route/memoirist.js +0 -373
  194. package/dist/services/logger.service.d.ts +0 -23
  195. package/dist/services/logger.service.js +0 -47
  196. package/dist/testing/core-testing.d.ts +0 -24
  197. package/dist/testing/core-testing.js +0 -102
  198. package/dist/testing/index.d.ts +0 -1
  199. package/dist/testing/index.js +0 -17
  200. package/dist/utils/ValidationCache.d.ts +0 -5
  201. package/dist/utils/ValidationCache.js +0 -35
  202. package/dist/utils/ancestorOf.d.ts +0 -2
  203. package/dist/utils/ancestorOf.js +0 -10
  204. package/dist/utils/ancestorsOf.d.ts +0 -6
  205. package/dist/utils/ancestorsOf.js +0 -20
  206. package/dist/utils/classOf.d.ts +0 -13
  207. package/dist/utils/classOf.js +0 -21
  208. package/dist/utils/cleanObject.d.ts +0 -6
  209. package/dist/utils/cleanObject.js +0 -22
  210. package/dist/utils/constructorOf.d.ts +0 -11
  211. package/dist/utils/constructorOf.js +0 -18
  212. package/dist/utils/createInstance.d.ts +0 -1
  213. package/dist/utils/createInstance.js +0 -7
  214. package/dist/utils/decoratorTypeOf.d.ts +0 -11
  215. package/dist/utils/decoratorTypeOf.js +0 -32
  216. package/dist/utils/deepClone.d.ts +0 -6
  217. package/dist/utils/deepClone.js +0 -63
  218. package/dist/utils/deepMerge.d.ts +0 -9
  219. package/dist/utils/deepMerge.js +0 -62
  220. package/dist/utils/descriptorOf.d.ts +0 -8
  221. package/dist/utils/descriptorOf.js +0 -16
  222. package/dist/utils/formatValidationErrors.d.ts +0 -5
  223. package/dist/utils/formatValidationErrors.js +0 -80
  224. package/dist/utils/getClassOrSymbol.d.ts +0 -1
  225. package/dist/utils/getClassOrSymbol.js +0 -8
  226. package/dist/utils/getConstructorArgNames.d.ts +0 -1
  227. package/dist/utils/getConstructorArgNames.js +0 -12
  228. package/dist/utils/getMethodArgTypes.d.ts +0 -1
  229. package/dist/utils/getMethodArgTypes.js +0 -9
  230. package/dist/utils/getValue.d.ts +0 -32
  231. package/dist/utils/getValue.js +0 -47
  232. package/dist/utils/hasJsonMethod.d.ts +0 -1
  233. package/dist/utils/hasJsonMethod.js +0 -6
  234. package/dist/utils/index.d.ts +0 -15
  235. package/dist/utils/index.js +0 -31
  236. package/dist/utils/isArray.d.ts +0 -13
  237. package/dist/utils/isArray.js +0 -21
  238. package/dist/utils/isArrowFn.d.ts +0 -1
  239. package/dist/utils/isArrowFn.js +0 -7
  240. package/dist/utils/isBoolean.d.ts +0 -7
  241. package/dist/utils/isBoolean.js +0 -15
  242. package/dist/utils/isBuffer.d.ts +0 -7
  243. package/dist/utils/isBuffer.js +0 -19
  244. package/dist/utils/isClass.d.ts +0 -1
  245. package/dist/utils/isClass.js +0 -26
  246. package/dist/utils/isCollection.d.ts +0 -6
  247. package/dist/utils/isCollection.js +0 -20
  248. package/dist/utils/isDate.d.ts +0 -6
  249. package/dist/utils/isDate.js +0 -11
  250. package/dist/utils/isEmpty.d.ts +0 -6
  251. package/dist/utils/isEmpty.js +0 -12
  252. package/dist/utils/isFunction.d.ts +0 -1
  253. package/dist/utils/isFunction.js +0 -6
  254. package/dist/utils/isInheritedFrom.d.ts +0 -1
  255. package/dist/utils/isInheritedFrom.js +0 -24
  256. package/dist/utils/isMomentObject.d.ts +0 -1
  257. package/dist/utils/isMomentObject.js +0 -6
  258. package/dist/utils/isMongooseObject.d.ts +0 -2
  259. package/dist/utils/isMongooseObject.js +0 -11
  260. package/dist/utils/isNil.d.ts +0 -1
  261. package/dist/utils/isNil.js +0 -6
  262. package/dist/utils/isNumber.d.ts +0 -7
  263. package/dist/utils/isNumber.js +0 -15
  264. package/dist/utils/isObject.d.ts +0 -1
  265. package/dist/utils/isObject.js +0 -6
  266. package/dist/utils/isObservable.d.ts +0 -1
  267. package/dist/utils/isObservable.js +0 -6
  268. package/dist/utils/isPlainObject.d.ts +0 -7
  269. package/dist/utils/isPlainObject.js +0 -16
  270. package/dist/utils/isPrimitive.d.ts +0 -14
  271. package/dist/utils/isPrimitive.js +0 -28
  272. package/dist/utils/isPrimitiveType.d.ts +0 -1
  273. package/dist/utils/isPrimitiveType.js +0 -11
  274. package/dist/utils/isPromise.d.ts +0 -7
  275. package/dist/utils/isPromise.js +0 -14
  276. package/dist/utils/isProtectedKey.d.ts +0 -5
  277. package/dist/utils/isProtectedKey.js +0 -10
  278. package/dist/utils/isRegExp.d.ts +0 -1
  279. package/dist/utils/isRegExp.js +0 -6
  280. package/dist/utils/isRequestScope.d.ts +0 -11
  281. package/dist/utils/isRequestScope.js +0 -23
  282. package/dist/utils/isSerializable.d.ts +0 -1
  283. package/dist/utils/isSerializable.js +0 -11
  284. package/dist/utils/isStream.d.ts +0 -1
  285. package/dist/utils/isStream.js +0 -6
  286. package/dist/utils/isString.d.ts +0 -6
  287. package/dist/utils/isString.js +0 -14
  288. package/dist/utils/isSymbol.d.ts +0 -6
  289. package/dist/utils/isSymbol.js +0 -14
  290. package/dist/utils/methodsOf.d.ts +0 -9
  291. package/dist/utils/methodsOf.js +0 -24
  292. package/dist/utils/nameOf.d.ts +0 -14
  293. package/dist/utils/nameOf.js +0 -31
  294. package/dist/utils/objectKeys.d.ts +0 -1
  295. package/dist/utils/objectKeys.js +0 -7
  296. package/dist/utils/primitiveOf.d.ts +0 -1
  297. package/dist/utils/primitiveOf.js +0 -18
  298. package/dist/utils/prototypeOf.d.ts +0 -6
  299. package/dist/utils/prototypeOf.js +0 -12
  300. package/dist/utils/setValue.d.ts +0 -1
  301. package/dist/utils/setValue.js +0 -32
  302. package/dist/utils/toMap.d.ts +0 -3
  303. package/dist/utils/toMap.js +0 -34
  304. package/dist/utils/toStringConstructor.d.ts +0 -1
  305. package/dist/utils/toStringConstructor.js +0 -10
  306. package/dist/validation/ValidatorAdapter.d.ts +0 -66
  307. package/dist/validation/adapters/ClassValidatorAdapter.d.ts +0 -23
  308. package/dist/validation/adapters/ClassValidatorAdapter.js +0 -47
  309. package/dist/validation/adapters/ZodAdapter.d.ts +0 -14
  310. package/dist/validation/adapters/ZodAdapter.js +0 -56
  311. package/dist/validation/adapters/index.d.ts +0 -4
  312. package/dist/validation/adapters/index.js +0 -7
  313. package/dist/validation/index.d.ts +0 -3
  314. package/dist/validation/index.js +0 -20
@@ -0,0 +1,60 @@
1
+ import { Carno } from "../Carno.mjs";
2
+ async function createTestHarness(options = {}) {
3
+ const config = {
4
+ ...options.config,
5
+ disableStartupLog: !0
6
+ }, app = new Carno(config);
7
+ options.controllers && app.controllers(options.controllers), options.services && app.services(options.services);
8
+ const port = resolvePort(options);
9
+ let server;
10
+ shouldListen(options.listen) && (app.listen(port), server = app.server);
11
+ const actualPort = server?.port ?? port, container = app.container, baseUrl = `http://127.0.0.1:${actualPort}`, request = async (path, init) => {
12
+ if (!server)
13
+ throw new Error("Server not running. Set listen: true in options.");
14
+ const url = path.startsWith("http") ? path : `${baseUrl}${path.startsWith("/") ? path : "/" + path}`;
15
+ return fetch(url, init);
16
+ };
17
+ return {
18
+ app,
19
+ container,
20
+ server,
21
+ port: actualPort,
22
+ resolve: (token) => container.get(token),
23
+ request,
24
+ get: (path, init) => request(path, { ...init, method: "GET" }),
25
+ post: (path, body, init) => request(path, {
26
+ ...init,
27
+ method: "POST",
28
+ body: body ? JSON.stringify(body) : void 0,
29
+ headers: { "Content-Type": "application/json", ...init?.headers }
30
+ }),
31
+ put: (path, body, init) => request(path, {
32
+ ...init,
33
+ method: "PUT",
34
+ body: body ? JSON.stringify(body) : void 0,
35
+ headers: { "Content-Type": "application/json", ...init?.headers }
36
+ }),
37
+ delete: (path, init) => request(path, { ...init, method: "DELETE" }),
38
+ close: async () => {
39
+ app.stop();
40
+ }
41
+ };
42
+ }
43
+ async function withTestApp(routine, options = {}) {
44
+ const harness = await createTestHarness(options);
45
+ try {
46
+ await routine(harness);
47
+ } finally {
48
+ await harness.close();
49
+ }
50
+ }
51
+ function shouldListen(value) {
52
+ return typeof value == "number" || !!value;
53
+ }
54
+ function resolvePort(options) {
55
+ return typeof options.listen == "number" ? options.listen : typeof options.port == "number" ? options.port : 0;
56
+ }
57
+ export {
58
+ createTestHarness,
59
+ withTestApp
60
+ };
@@ -0,0 +1,53 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var Metadata_exports = {};
16
+ __export(Metadata_exports, {
17
+ Metadata: () => Metadata,
18
+ isObject: () => isObject,
19
+ isString: () => isString
20
+ });
21
+ module.exports = __toCommonJS(Metadata_exports);
22
+ class Metadata {
23
+ static get(key, target) {
24
+ return Reflect.getMetadata(key, target);
25
+ }
26
+ static set(key, value, target) {
27
+ Reflect.defineMetadata(key, value, target);
28
+ }
29
+ static has(key, target) {
30
+ return Reflect.hasMetadata(key, target);
31
+ }
32
+ static delete(key, target) {
33
+ return Reflect.deleteMetadata(key, target);
34
+ }
35
+ static keys(target) {
36
+ return Reflect.getMetadataKeys(target);
37
+ }
38
+ static getType(target, propertyKey) {
39
+ return Reflect.getMetadata("design:type", target, propertyKey);
40
+ }
41
+ }
42
+ function isObject(value) {
43
+ return typeof value == "object" && value !== null && !Array.isArray(value);
44
+ }
45
+ function isString(value) {
46
+ return typeof value == "string";
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ Metadata,
51
+ isObject,
52
+ isString
53
+ });
@@ -0,0 +1,31 @@
1
+ class Metadata {
2
+ static get(key, target) {
3
+ return Reflect.getMetadata(key, target);
4
+ }
5
+ static set(key, value, target) {
6
+ Reflect.defineMetadata(key, value, target);
7
+ }
8
+ static has(key, target) {
9
+ return Reflect.hasMetadata(key, target);
10
+ }
11
+ static delete(key, target) {
12
+ return Reflect.deleteMetadata(key, target);
13
+ }
14
+ static keys(target) {
15
+ return Reflect.getMetadataKeys(target);
16
+ }
17
+ static getType(target, propertyKey) {
18
+ return Reflect.getMetadata("design:type", target, propertyKey);
19
+ }
20
+ }
21
+ function isObject(value) {
22
+ return typeof value == "object" && value !== null && !Array.isArray(value);
23
+ }
24
+ function isString(value) {
25
+ return typeof value == "string";
26
+ }
27
+ export {
28
+ Metadata,
29
+ isObject,
30
+ isString
31
+ };
@@ -0,0 +1,67 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var ValibotAdapter_exports = {};
16
+ __export(ValibotAdapter_exports, {
17
+ ValibotAdapter: () => ValibotAdapter
18
+ });
19
+ module.exports = __toCommonJS(ValibotAdapter_exports);
20
+ var import_ValidatorAdapter = require('./ValidatorAdapter.js'), import_ZodAdapter = require('./ZodAdapter.js');
21
+ class ValibotAdapter {
22
+ constructor() {
23
+ this.name = "ValibotAdapter";
24
+ this.schemaCache = /* @__PURE__ */ new Map();
25
+ this.valibot = null;
26
+ try {
27
+ this.valibot = require("valibot");
28
+ } catch {
29
+ }
30
+ }
31
+ ensureValibot() {
32
+ return this.valibot || (this.valibot = require("valibot")), this.valibot;
33
+ }
34
+ hasValidation(target) {
35
+ return (0, import_ValidatorAdapter.getSchema)(target) !== void 0;
36
+ }
37
+ validate(target, value) {
38
+ const schema = this.getOrCacheSchema(target);
39
+ if (!schema)
40
+ return { success: !0, data: value };
41
+ const result = this.ensureValibot().safeParse(schema, value);
42
+ return result.success ? { success: !0, data: result.output } : {
43
+ success: !1,
44
+ errors: this.formatErrors(result.issues)
45
+ };
46
+ }
47
+ validateOrThrow(target, value) {
48
+ const result = this.validate(target, value);
49
+ if (result.success)
50
+ return result.data;
51
+ throw new import_ZodAdapter.ValidationException(result.errors);
52
+ }
53
+ getOrCacheSchema(target) {
54
+ let schema = this.schemaCache.get(target);
55
+ return schema === void 0 && (schema = (0, import_ValidatorAdapter.getSchema)(target) ?? null, this.schemaCache.set(target, schema)), schema;
56
+ }
57
+ formatErrors(issues) {
58
+ return issues.map((issue) => ({
59
+ path: issue.path?.map((p) => p.key).join(".") || "",
60
+ message: issue.message
61
+ }));
62
+ }
63
+ }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ ValibotAdapter
67
+ });
@@ -0,0 +1,48 @@
1
+ import { getSchema } from "./ValidatorAdapter.mjs";
2
+ import { ValidationException } from "./ZodAdapter.mjs";
3
+ class ValibotAdapter {
4
+ constructor() {
5
+ this.name = "ValibotAdapter";
6
+ this.schemaCache = /* @__PURE__ */ new Map();
7
+ this.valibot = null;
8
+ try {
9
+ this.valibot = require("valibot");
10
+ } catch {
11
+ }
12
+ }
13
+ ensureValibot() {
14
+ return this.valibot || (this.valibot = require("valibot")), this.valibot;
15
+ }
16
+ hasValidation(target) {
17
+ return getSchema(target) !== void 0;
18
+ }
19
+ validate(target, value) {
20
+ const schema = this.getOrCacheSchema(target);
21
+ if (!schema)
22
+ return { success: !0, data: value };
23
+ const result = this.ensureValibot().safeParse(schema, value);
24
+ return result.success ? { success: !0, data: result.output } : {
25
+ success: !1,
26
+ errors: this.formatErrors(result.issues)
27
+ };
28
+ }
29
+ validateOrThrow(target, value) {
30
+ const result = this.validate(target, value);
31
+ if (result.success)
32
+ return result.data;
33
+ throw new ValidationException(result.errors);
34
+ }
35
+ getOrCacheSchema(target) {
36
+ let schema = this.schemaCache.get(target);
37
+ return schema === void 0 && (schema = getSchema(target) ?? null, this.schemaCache.set(target, schema)), schema;
38
+ }
39
+ formatErrors(issues) {
40
+ return issues.map((issue) => ({
41
+ path: issue.path?.map((p) => p.key).join(".") || "",
42
+ message: issue.message
43
+ }));
44
+ }
45
+ }
46
+ export {
47
+ ValibotAdapter
48
+ };
@@ -1,20 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineValidation = defineValidation;
4
- /**
5
- * Helper function to create a strongly-typed validation config.
6
- * Use this to get proper autocomplete for adapter options.
7
- *
8
- * @example
9
- * ```typescript
10
- * const app = new Carno({
11
- * validation: defineValidation({
12
- * adapter: ClassValidatorAdapter,
13
- * options: { whitelist: true } // ✓ Autocomplete works!
14
- * })
15
- * });
16
- * ```
17
- */
18
- function defineValidation(config) {
19
- return config;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var ValidatorAdapter_exports = {};
16
+ __export(ValidatorAdapter_exports, {
17
+ Schema: () => Schema,
18
+ VALIDATION_SCHEMA: () => VALIDATION_SCHEMA,
19
+ getSchema: () => getSchema
20
+ });
21
+ module.exports = __toCommonJS(ValidatorAdapter_exports);
22
+ const VALIDATION_SCHEMA = /* @__PURE__ */ Symbol("turbo:validation");
23
+ function Schema(schema) {
24
+ return (target) => {
25
+ Reflect.defineMetadata(VALIDATION_SCHEMA, schema, target);
26
+ };
20
27
  }
28
+ function getSchema(target) {
29
+ return Reflect.getMetadata(VALIDATION_SCHEMA, target);
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ Schema,
34
+ VALIDATION_SCHEMA,
35
+ getSchema
36
+ });
@@ -0,0 +1,14 @@
1
+ const VALIDATION_SCHEMA = /* @__PURE__ */ Symbol("turbo:validation");
2
+ function Schema(schema) {
3
+ return (target) => {
4
+ Reflect.defineMetadata(VALIDATION_SCHEMA, schema, target);
5
+ };
6
+ }
7
+ function getSchema(target) {
8
+ return Reflect.getMetadata(VALIDATION_SCHEMA, target);
9
+ }
10
+ export {
11
+ Schema,
12
+ VALIDATION_SCHEMA,
13
+ getSchema
14
+ };
@@ -0,0 +1,80 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var ZodAdapter_exports = {};
16
+ __export(ZodAdapter_exports, {
17
+ ValidationException: () => ValidationException,
18
+ ZodAdapter: () => ZodAdapter
19
+ });
20
+ module.exports = __toCommonJS(ZodAdapter_exports);
21
+ var import_ValidatorAdapter = require('./ValidatorAdapter.js');
22
+ class ZodAdapter {
23
+ constructor() {
24
+ this.name = "ZodAdapter";
25
+ // Cache parsed schemas for performance
26
+ this.schemaCache = /* @__PURE__ */ new Map();
27
+ }
28
+ hasValidation(target) {
29
+ return (0, import_ValidatorAdapter.getSchema)(target) !== void 0;
30
+ }
31
+ validate(target, value) {
32
+ const schema = this.getOrCacheSchema(target);
33
+ if (!schema)
34
+ return { success: !0, data: value };
35
+ const result = schema.safeParse(value);
36
+ return result.success ? { success: !0, data: result.data } : {
37
+ success: !1,
38
+ errors: this.formatErrors(result.error)
39
+ };
40
+ }
41
+ validateOrThrow(target, value) {
42
+ const schema = this.getOrCacheSchema(target);
43
+ if (!schema)
44
+ return value;
45
+ const result = schema.safeParse(value);
46
+ if (result.success)
47
+ return result.data;
48
+ const errors = this.formatErrors(result.error);
49
+ throw new ValidationException(errors);
50
+ }
51
+ getOrCacheSchema(target) {
52
+ let schema = this.schemaCache.get(target);
53
+ return schema === void 0 && (schema = (0, import_ValidatorAdapter.getSchema)(target) ?? null, this.schemaCache.set(target, schema)), schema;
54
+ }
55
+ formatErrors(zodError) {
56
+ return zodError.issues.map((issue) => ({
57
+ path: issue.path.join("."),
58
+ message: issue.message
59
+ }));
60
+ }
61
+ }
62
+ class ValidationException extends Error {
63
+ constructor(errors) {
64
+ super(`Validation failed: ${errors.map((e) => `${e.path}: ${e.message}`).join(", ")}`);
65
+ this.errors = errors;
66
+ this.name = "ValidationException";
67
+ }
68
+ toResponse() {
69
+ return Response.json({
70
+ statusCode: 400,
71
+ message: "Validation failed",
72
+ errors: this.errors
73
+ }, { status: 400 });
74
+ }
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ ValidationException,
79
+ ZodAdapter
80
+ });
@@ -0,0 +1,59 @@
1
+ import { getSchema } from "./ValidatorAdapter.mjs";
2
+ class ZodAdapter {
3
+ constructor() {
4
+ this.name = "ZodAdapter";
5
+ // Cache parsed schemas for performance
6
+ this.schemaCache = /* @__PURE__ */ new Map();
7
+ }
8
+ hasValidation(target) {
9
+ return getSchema(target) !== void 0;
10
+ }
11
+ validate(target, value) {
12
+ const schema = this.getOrCacheSchema(target);
13
+ if (!schema)
14
+ return { success: !0, data: value };
15
+ const result = schema.safeParse(value);
16
+ return result.success ? { success: !0, data: result.data } : {
17
+ success: !1,
18
+ errors: this.formatErrors(result.error)
19
+ };
20
+ }
21
+ validateOrThrow(target, value) {
22
+ const schema = this.getOrCacheSchema(target);
23
+ if (!schema)
24
+ return value;
25
+ const result = schema.safeParse(value);
26
+ if (result.success)
27
+ return result.data;
28
+ const errors = this.formatErrors(result.error);
29
+ throw new ValidationException(errors);
30
+ }
31
+ getOrCacheSchema(target) {
32
+ let schema = this.schemaCache.get(target);
33
+ return schema === void 0 && (schema = getSchema(target) ?? null, this.schemaCache.set(target, schema)), schema;
34
+ }
35
+ formatErrors(zodError) {
36
+ return zodError.issues.map((issue) => ({
37
+ path: issue.path.join("."),
38
+ message: issue.message
39
+ }));
40
+ }
41
+ }
42
+ class ValidationException extends Error {
43
+ constructor(errors) {
44
+ super(`Validation failed: ${errors.map((e) => `${e.path}: ${e.message}`).join(", ")}`);
45
+ this.errors = errors;
46
+ this.name = "ValidationException";
47
+ }
48
+ toResponse() {
49
+ return Response.json({
50
+ statusCode: 400,
51
+ message: "Validation failed",
52
+ errors: this.errors
53
+ }, { status: 400 });
54
+ }
55
+ }
56
+ export {
57
+ ValidationException,
58
+ ZodAdapter
59
+ };
package/package.json CHANGED
@@ -1,66 +1,24 @@
1
1
  {
2
- "name": "@carno.js/core",
3
- "version": "0.2.11",
4
- "description": "Carno.js is a framework for building web applications object oriented with TypeScript and Bun.sh",
5
- "keywords": [
6
- "bun",
7
- "framework",
8
- "typescript",
9
- "carno",
10
- "carno.js",
11
- "object oriented",
12
- "oop"
13
- ],
14
- "type": "commonjs",
15
- "scripts": {
16
- "compile": "rm -rf ./dist tsconfig.tsbuildinfo && tsc --build --force",
17
- "build": "tsc --build --force",
18
- "prepublishOnly": "bun run build"
19
- },
20
- "main": "dist/index.js",
21
- "types": "dist/index.d.ts",
22
- "exports": {
23
- "./package.json": "./package.json",
24
- ".": {
25
- "require": "./dist/index.js",
26
- "default": "./dist/index.js"
27
- }
28
- },
29
- "repository": {
30
- "type": "git",
31
- "url": "git+ssh://git@github.com:carnojs/carno.js.git"
32
- },
33
- "license": "MIT",
34
- "dependencies": {
35
- "bentocache": "^1.0.0-beta.5",
36
- "globby": "^10.0.2",
37
- "parseurl-fast": "^1.2.0",
38
- "pino": "^8.16.1",
39
- "pino-pretty": "^10.2.3",
40
- "reflect-metadata": "^0.1.13",
41
- "zod": "^4.3.4"
42
- },
43
- "devDependencies": {
44
- "@types/globby": "^9.1.0",
45
- "bun-types": "latest",
46
- "class-transformer": "^0.5.1",
47
- "class-validator": "^0.14.3"
48
- },
49
- "peerDependencies": {
50
- "class-transformer": "^0.5.1",
51
- "class-validator": "^0.14.0",
52
- "typescript": "^5.0.0"
53
- },
54
- "peerDependenciesMeta": {
55
- "class-validator": {
56
- "optional": true
2
+ "name": "@carno.js/core",
3
+ "version": "1.0.2",
4
+ "description": "Ultra-fast HTTP framework with aggressive AOT/JIT compilation",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "scripts": {
8
+ "build": "bun run build.ts",
9
+ "compile": "rm -rf ./dist tsconfig.tsbuildinfo && tsc --build --force",
10
+ "prepublishOnly": "bun run build"
57
11
  },
58
- "class-transformer": {
59
- "optional": true
60
- }
61
- },
62
- "publishConfig": {
63
- "access": "public"
64
- },
65
- "gitHead": "495ba33561d058107b1bb76d737a0d38a361f5b2"
12
+ "peerDependencies": {
13
+ "bun": ">=1.0.0",
14
+ "valibot": "^1.2.0"
15
+ },
16
+ "dependencies": {
17
+ "zod": "^4.3.5"
18
+ },
19
+ "devDependencies": {
20
+ "esbuild-fix-imports-plugin": "^1.0.23",
21
+ "tsup": "^8.5.1"
22
+ },
23
+ "gitHead": "963e66fb0ac345fbc71c8cc81c73c71eb160d0d5"
66
24
  }