@athosjs/pro 0.1.4-alpha

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 (94) hide show
  1. package/README.md +518 -0
  2. package/bootstrap.cjs +107 -0
  3. package/bootstrap.cjs.map +1 -0
  4. package/bootstrap.d.ts +8 -0
  5. package/bootstrap.d.ts.map +1 -0
  6. package/bootstrap.js +103 -0
  7. package/bootstrap.js.map +1 -0
  8. package/core/athos-application.cjs +362 -0
  9. package/core/athos-application.cjs.map +1 -0
  10. package/core/athos-application.d.ts +17 -0
  11. package/core/athos-application.d.ts.map +1 -0
  12. package/core/athos-application.js +357 -0
  13. package/core/athos-application.js.map +1 -0
  14. package/core/discovery.cjs +47 -0
  15. package/core/discovery.cjs.map +1 -0
  16. package/core/discovery.d.ts +6 -0
  17. package/core/discovery.d.ts.map +1 -0
  18. package/core/discovery.js +45 -0
  19. package/core/discovery.js.map +1 -0
  20. package/core/i18n.cjs +12 -0
  21. package/core/i18n.cjs.map +1 -0
  22. package/core/i18n.d.ts +4 -0
  23. package/core/i18n.d.ts.map +1 -0
  24. package/core/i18n.js +10 -0
  25. package/core/i18n.js.map +1 -0
  26. package/core/pipeline.cjs +251 -0
  27. package/core/pipeline.cjs.map +1 -0
  28. package/core/pipeline.d.ts +11 -0
  29. package/core/pipeline.d.ts.map +1 -0
  30. package/core/pipeline.js +246 -0
  31. package/core/pipeline.js.map +1 -0
  32. package/core/router-initializer.cjs +158 -0
  33. package/core/router-initializer.cjs.map +1 -0
  34. package/core/router-initializer.d.ts +26 -0
  35. package/core/router-initializer.d.ts.map +1 -0
  36. package/core/router-initializer.js +156 -0
  37. package/core/router-initializer.js.map +1 -0
  38. package/core/scanner.cjs +141 -0
  39. package/core/scanner.cjs.map +1 -0
  40. package/core/scanner.d.ts +7 -0
  41. package/core/scanner.d.ts.map +1 -0
  42. package/core/scanner.js +139 -0
  43. package/core/scanner.js.map +1 -0
  44. package/experimental.cjs +23 -0
  45. package/experimental.cjs.map +1 -0
  46. package/experimental.d.ts +9 -0
  47. package/experimental.d.ts.map +1 -0
  48. package/experimental.js +5 -0
  49. package/experimental.js.map +1 -0
  50. package/functions.cjs +67 -0
  51. package/functions.cjs.map +1 -0
  52. package/functions.d.ts +10 -0
  53. package/functions.d.ts.map +1 -0
  54. package/functions.js +62 -0
  55. package/functions.js.map +1 -0
  56. package/http-profile.cjs +48 -0
  57. package/http-profile.cjs.map +1 -0
  58. package/http-profile.d.ts +6 -0
  59. package/http-profile.d.ts.map +1 -0
  60. package/http-profile.js +44 -0
  61. package/http-profile.js.map +1 -0
  62. package/index.cjs +281 -0
  63. package/index.cjs.map +1 -0
  64. package/index.d.ts +23 -0
  65. package/index.d.ts.map +1 -0
  66. package/index.js +23 -0
  67. package/index.js.map +1 -0
  68. package/observability.cjs +191 -0
  69. package/observability.cjs.map +1 -0
  70. package/observability.d.ts +8 -0
  71. package/observability.d.ts.map +1 -0
  72. package/observability.js +188 -0
  73. package/observability.js.map +1 -0
  74. package/package.json +42 -0
  75. package/policies.cjs +30 -0
  76. package/policies.cjs.map +1 -0
  77. package/policies.d.ts +21 -0
  78. package/policies.d.ts.map +1 -0
  79. package/policies.js +27 -0
  80. package/policies.js.map +1 -0
  81. package/resilience.cjs +280 -0
  82. package/resilience.cjs.map +1 -0
  83. package/resilience.d.ts +6 -0
  84. package/resilience.d.ts.map +1 -0
  85. package/resilience.js +276 -0
  86. package/resilience.js.map +1 -0
  87. package/security.cjs +142 -0
  88. package/security.cjs.map +1 -0
  89. package/security.d.ts +11 -0
  90. package/security.d.ts.map +1 -0
  91. package/security.js +136 -0
  92. package/security.js.map +1 -0
  93. package/types.d.ts +3 -0
  94. package/types.d.ts.map +1 -0
package/README.md ADDED
@@ -0,0 +1,518 @@
1
+ # @athosjs/pro
2
+
3
+ The complete Athos.js product — one import gives you the entire stack. Controllers, DI, auth, validation, OpenAPI, observability, modules, database, and migrations. All typed. All runtime-agnostic (Node, Bun, Deno).
4
+
5
+ **Best way to start:** `athos new my-api` — guided CLI scaffolding with everything pre-configured.
6
+
7
+ ```ts
8
+ import { Athos } from "@athosjs/pro";
9
+ await Athos.run({ discovery: { enabled: true, root: "./src" } });
10
+ ```
11
+
12
+ ## Installation
13
+
14
+ ### Via CLI (Recommended)
15
+
16
+ ```bash
17
+ # Guided tour — interactive prompts for template, runtime, database, auth, etc.
18
+ athos new my-api
19
+
20
+ # With flags — skip the prompts
21
+ athos new my-api --template pro --runtime node --database postgres --auth jwt --validation zod
22
+ ```
23
+
24
+ This scaffolds a complete project structure with controllers, services, modules, entities, config, migrations, and seeds — ready to run.
25
+
26
+ ### Via Package Manager
27
+
28
+ ```bash
29
+ npm install @athosjs/pro
30
+ ```
31
+
32
+ Then create `src/main.ts`:
33
+
34
+ ```ts
35
+ import { Athos } from "@athosjs/pro";
36
+ await Athos.run({ discovery: { enabled: true, root: "./src" } });
37
+ ```
38
+
39
+ ## Project Structure
40
+
41
+ ```
42
+ src/
43
+ main.ts # Athos.run()
44
+ app.controller.ts # @Controller — HTTP routes
45
+ app.service.ts # @Service — business logic
46
+ database/
47
+ connection.ts # createConnection — DB config
48
+ entities/
49
+ user.entity.ts # @Entity — ORM model
50
+ modules/
51
+ user/
52
+ user.module.ts # @Module — DI + routes
53
+ user.controller.ts
54
+ user.service.ts
55
+ user.repository.ts
56
+ config/
57
+ app.config.ts # defineAthosConfig — typed config
58
+ auth.config.ts # auth adapter
59
+ migrations/
60
+ 001_create_users.ts # athos migration generate
61
+ seeds/
62
+ seed_users.ts # athos seed create
63
+ ```
64
+
65
+ ## Quick Tour
66
+
67
+ ### 1. Controllers & Routing
68
+
69
+ ```ts
70
+ import { Controller, Get, Post, Put, Delete, Param, Body, Query, HttpStatus } from "@athosjs/pro";
71
+
72
+ @Controller("/users")
73
+ export class UserController {
74
+ constructor(private readonly service: UserService) {}
75
+
76
+ @Get()
77
+ list(@Query("page") page = 1) {
78
+ return this.service.findAll({ page });
79
+ }
80
+
81
+ @Get("/:id")
82
+ getOne(@Param("id") id: number) {
83
+ return this.service.findById(id);
84
+ }
85
+
86
+ @Post()
87
+ @HttpStatus(201)
88
+ create(@Body() body: CreateUserDto) {
89
+ return this.service.create(body);
90
+ }
91
+
92
+ @Put("/:id")
93
+ update(@Param("id") id: number, @Body() body: UpdateUserDto) {
94
+ return this.service.update(id, body);
95
+ }
96
+
97
+ @Delete("/:id")
98
+ @HttpStatus(204)
99
+ async remove(@Param("id") id: number) {
100
+ await this.service.remove(id);
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### 2. Dependency Injection
106
+
107
+ ```ts
108
+ import { Service, Repository, Component, Inject, AthosContainer, createToken } from "@athosjs/pro";
109
+
110
+ export const STRIPE_API_KEY = createToken<string>("STRIPE_API_KEY");
111
+
112
+ @Service()
113
+ export class PaymentService {
114
+ constructor(
115
+ @Inject(STRIPE_API_KEY) private readonly apiKey: string,
116
+ private readonly repo: PaymentRepository,
117
+ ) {}
118
+
119
+ async charge(amount: number) {
120
+ // stripe.charges.create({ ... })
121
+ }
122
+ }
123
+
124
+ @Repository()
125
+ export class PaymentRepository {
126
+ constructor(private readonly db: DatabaseConnection) {}
127
+
128
+ async save(payment: Payment) {
129
+ return this.db.insert("payments").values(payment);
130
+ }
131
+ }
132
+ ```
133
+
134
+ ### 3. Validation (Zod, TypeBox, Yup, class-validator)
135
+
136
+ ```ts
137
+ import { Body, Post } from "@athosjs/pro";
138
+ import { z } from "zod";
139
+
140
+ const createUserSchema = z.object({
141
+ name: z.string().min(2).max(100),
142
+ email: z.string().email(),
143
+ age: z.number().min(0).max(150).optional(),
144
+ role: z.enum(["admin", "user"]).default("user"),
145
+ }).strict();
146
+
147
+ @Controller("/users")
148
+ export class UserController {
149
+ @Post()
150
+ create(@Body(createUserSchema) body: z.infer<typeof createUserSchema>) {
151
+ // body is fully typed and validated — no runtime checks needed
152
+ return { created: true, user: body };
153
+ }
154
+ }
155
+
156
+ // Also supports TypeBox, Yup, class-validator:
157
+ // @Body(TypeBoxSchema), @Body(yupSchema), @Body() with class-validator decorators
158
+ ```
159
+
160
+ ### 4. Authentication & Authorization
161
+
162
+ ```ts
163
+ import { Auth, Roles, definePolicy } from "@athosjs/pro";
164
+
165
+ @Controller("/admin")
166
+ @Auth() // requires authentication
167
+ export class AdminController {
168
+ @Get("/dashboard")
169
+ @Roles("admin") // requires admin role
170
+ dashboard() {
171
+ return { stats: {} };
172
+ }
173
+
174
+ @Get("/settings")
175
+ @Roles("admin", "superadmin")
176
+ settings() {
177
+ return { theme: "dark" };
178
+ }
179
+ }
180
+
181
+ // Policy-based access control
182
+ export const postPolicy = definePolicy({
183
+ "post:write": (ctx) => ctx.user?.role === "admin" || ctx.user?.id === ctx.params.authorId,
184
+ "post:delete": (ctx) => ctx.user?.role === "admin",
185
+ });
186
+
187
+ @Controller("/posts")
188
+ export class PostController {
189
+ @Delete("/:id")
190
+ @UsePolicy("post:delete")
191
+ remove(@Param("id") id: number) {
192
+ return { deleted: id };
193
+ }
194
+ }
195
+ ```
196
+
197
+ ### 5. Database — ORM with Zero-Config Entities
198
+
199
+ ```ts
200
+ import { SolaceEntity, SolaceOrm, hasMany, belongsTo, defineEntityRelations } from "@athosjs/pro";
201
+
202
+ class User extends SolaceEntity {
203
+ static readonly mapping = {
204
+ table: "users",
205
+ columns: { isActive: "is_active" }, // only to override column names
206
+ };
207
+ static readonly relations = defineEntityRelations<User>({
208
+ posts: hasMany(() => Post, { foreignKey: "userId", references: "id" }),
209
+ });
210
+
211
+ id!: number;
212
+ name!: string;
213
+ email!: string;
214
+ isActive!: boolean;
215
+ posts?: Post[];
216
+ }
217
+
218
+ class Post extends SolaceEntity {
219
+ static readonly mapping = { table: "posts" };
220
+ static readonly relations = defineEntityRelations<Post>({
221
+ user: belongsTo(() => User, { foreignKey: "userId", references: "id" }),
222
+ });
223
+
224
+ id!: number;
225
+ title!: string;
226
+ userId!: number;
227
+ user?: User;
228
+ }
229
+
230
+ // Repository usage
231
+ const users = await repo.findAll({ isActive: true, include: ["posts"] });
232
+ const page = await repo.findAll({ limit: 10, offset: 0, orderBy: { createdAt: "desc" } });
233
+ const user = await repo.findOne({ email: "ada@example.com" });
234
+
235
+ // Transactions
236
+ await orm.transaction(async (em) => {
237
+ const user = await em.save(User, { name: "Grace", email: "grace@test.com" });
238
+ await em.save(Post, { title: "First Post", userId: user.id });
239
+ });
240
+
241
+ // Entity Query Builder — fluent and type-safe
242
+ const recent = await orm.query(Post)
243
+ .where("published", true)
244
+ .orderBy("createdAt", "desc")
245
+ .limit(10)
246
+ .include("user")
247
+ .all();
248
+ ```
249
+
250
+ ### 6. OpenAPI — Auto-Generated from Decorators & Schemas
251
+
252
+ ```ts
253
+ // Your controllers, DTOs, and validation schemas become OpenAPI docs automatically.
254
+ // Add a few decorators to enhance the output:
255
+
256
+ import { ApiTag, ApiOperation, ApiProperty } from "@athosjs/pro";
257
+
258
+ @ApiTag("Users")
259
+ @ApiTag("Admin")
260
+ @Controller("/users")
261
+ export class UserController {
262
+
263
+ @Get()
264
+ @ApiOperation({ summary: "List all users", responses: { 200: [UserResponse] } })
265
+ list() {
266
+ return this.service.findAll();
267
+ }
268
+
269
+ @Post()
270
+ @ApiOperation({ summary: "Create a user", responses: { 201: UserResponse, 400: ErrorResponse } })
271
+ create(@Body(createUserSchema) body: any) {
272
+ return this.service.create(body);
273
+ }
274
+ }
275
+
276
+ // Swagger UI at /docs — enabled by default
277
+ // OpenAPI JSON at /docs/json
278
+ ```
279
+
280
+ ### 7. Observability — Logger, Telemetry, Metrics
281
+
282
+ ```ts
283
+ import { AthosLogger, Telemetry, MetricsCollector } from "@athosjs/pro";
284
+
285
+ // Structured logging
286
+ const logger = new AthosLogger({ level: "info", pretty: true });
287
+ logger.info("Server started", { port: 3000 });
288
+ logger.child({ requestId: ctx.id }).info("Request received");
289
+
290
+ // Distributed tracing
291
+ const span = Telemetry.current().startSpan("db.query", {
292
+ attributes: { "db.statement": sql },
293
+ });
294
+ try {
295
+ const result = await db.query(sql);
296
+ span.setStatus("ok");
297
+ } finally {
298
+ span.end();
299
+ }
300
+
301
+ // Metrics
302
+ MetricsCollector.global()
303
+ .counter("http.requests", { method: "GET", status: "200" })
304
+ .gauge("db.pool.active", pool.stats.active)
305
+ .histogram("http.latency", durationMs, { unit: "ms" });
306
+ ```
307
+
308
+ ### 8. Configuration — Typed, Multi-Source
309
+
310
+ ```ts
311
+ import { defineAthosConfig, envConfigSource } from "@athosjs/pro";
312
+
313
+ export const config = defineAthosConfig({
314
+ port: 3000,
315
+ host: "0.0.0.0",
316
+ database: {
317
+ host: "localhost",
318
+ port: 5432,
319
+ user: "postgres",
320
+ password: "", // comes from env
321
+ name: "myapp",
322
+ },
323
+ auth: {
324
+ jwt: {
325
+ secret: "", // comes from env
326
+ expiresIn: "24h",
327
+ },
328
+ },
329
+ cors: {
330
+ origins: ["http://localhost:5173"],
331
+ },
332
+ }).withSources(envConfigSource({ prefix: "APP_" }));
333
+
334
+ // APP_PORT=8080 → overrides port
335
+ // APP_DATABASE_PASSWORD=secret → fills in password
336
+ // APP_AUTH_JWT_SECRET=super-secret → fills in jwt secret
337
+ ```
338
+
339
+ ### 9. Module System
340
+
341
+ ```ts
342
+ import { AthosModule } from "@athosjs/pro";
343
+
344
+ export class UserModule extends AthosModule {
345
+ register(container: AthosContainer) {
346
+ container.register(UserService);
347
+ container.register(UserRepository);
348
+ }
349
+ }
350
+
351
+ export class PaymentModule extends AthosModule {
352
+ register(container: AthosContainer) {
353
+ container.register(STRIPE_API_KEY, { useValue: process.env.STRIPE_KEY });
354
+ container.register(PaymentService);
355
+ }
356
+ }
357
+
358
+ // Auto-discovered from project structure — no manual wiring
359
+ ```
360
+
361
+ ### 10. Health Checks
362
+
363
+ ```ts
364
+ import { HealthCheck, HealthStatus, AthosApplication } from "@athosjs/pro";
365
+
366
+ const dbCheck: HealthCheck = {
367
+ name: "database",
368
+ check: async () => {
369
+ try {
370
+ await db.query("SELECT 1");
371
+ return HealthStatus.UP;
372
+ } catch {
373
+ return HealthStatus.DOWN;
374
+ }
375
+ },
376
+ };
377
+
378
+ app.addHealthCheck(dbCheck);
379
+ app.addHealthCheck(redisCheck);
380
+ app.addHealthCheck(stripeCheck);
381
+
382
+ // GET /health → { status: "UP", checks: { database: "UP", ... } }
383
+ ```
384
+
385
+ ### 11. File Upload
386
+
387
+ ```ts
388
+ import { Post, RequestFile, RequestFiles } from "@athosjs/pro";
389
+
390
+ @Controller("/upload")
391
+ export class UploadController {
392
+ @Post("/single")
393
+ upload(@RequestFile() file: Express.Multer.File) {
394
+ return { name: file.originalname, size: file.size };
395
+ }
396
+
397
+ @Post("/multiple")
398
+ uploadMany(@RequestFiles() files: Express.Multer.File[]) {
399
+ return files.map(f => ({ name: f.originalname, size: f.size }));
400
+ }
401
+ }
402
+ ```
403
+
404
+ ### 12. Interceptors & Middleware
405
+
406
+ ```ts
407
+ import { defineInterceptor, defineMiddleware } from "@athosjs/pro";
408
+
409
+ // Timing interceptor
410
+ const timing = defineInterceptor(async (ctx, next) => {
411
+ const start = Date.now();
412
+ const response = await next();
413
+ ctx.response.headers["X-Response-Time"] = `${Date.now() - start}ms`;
414
+ return response;
415
+ });
416
+
417
+ // Auth middleware
418
+ const auth = defineMiddleware(async (ctx, next) => {
419
+ const token = ctx.headers["authorization"];
420
+ if (!token) return ctx.status(401).json({ error: "Unauthorized" });
421
+ ctx.state.user = await verifyJwt(token);
422
+ return next();
423
+ });
424
+
425
+ app.use(timing, auth);
426
+ ```
427
+
428
+ ### 13. Lifecycle Hooks
429
+
430
+ ```ts
431
+ import { Service, OnStart, OnStop } from "@athosjs/pro";
432
+
433
+ @Service()
434
+ export class CacheService implements OnStart, OnStop {
435
+ private client: Redis;
436
+
437
+ async onStart() {
438
+ this.client = await createRedisClient();
439
+ console.log("Redis connected");
440
+ }
441
+
442
+ async onStop() {
443
+ await this.client.quit();
444
+ }
445
+
446
+ async get<T>(key: string): Promise<T | null> {
447
+ const data = await this.client.get(key);
448
+ return data ? JSON.parse(data) : null;
449
+ }
450
+ }
451
+ ```
452
+
453
+ ### 14. Database Migrations & Seeds
454
+
455
+ ```bash
456
+ # CLI — shipped with @athosjs/cli
457
+ athos migration generate AddEmailToUsers
458
+ athos migration run
459
+ athos migration revert
460
+ athos migration status
461
+
462
+ athos seed create SeedUsers
463
+ athos seed run
464
+
465
+ # Programmatic
466
+ import { MigrationRunner, SeedRunner } from "@athosjs/pro";
467
+
468
+ const runner = new MigrationRunner(connection);
469
+ await runner.run(); // apply pending
470
+ await runner.revert(); // rollback last
471
+
472
+ const seeder = new SeedRunner(connection);
473
+ await seeder.run();
474
+ ```
475
+
476
+ ## Bootstrap
477
+
478
+ ```ts
479
+ import { Athos } from "@athosjs/pro";
480
+
481
+ await Athos.run({
482
+ port: 3000,
483
+ hostname: "0.0.0.0",
484
+ logLevel: "info",
485
+ discovery: {
486
+ enabled: true,
487
+ root: "./src", // auto-discover modules, controllers, entities
488
+ },
489
+ server: {
490
+ cors: {
491
+ origins: ["http://localhost:5173"],
492
+ },
493
+ compression: true,
494
+ uploads: {
495
+ enabled: true,
496
+ maxFileSize: 50 * 1024 * 1024, // 50MB
497
+ maxFiles: 10,
498
+ },
499
+ onError: ({ context, error }) => {
500
+ console.error(`[${context.method} ${context.path}]`, error.message);
501
+ },
502
+ },
503
+ openapi: {
504
+ enabled: true,
505
+ path: "/docs",
506
+ info: {
507
+ title: "My API",
508
+ version: "1.0.0",
509
+ },
510
+ },
511
+ });
512
+ ```
513
+
514
+ For full imperative control, build the application manually:
515
+
516
+ ## What's NOT Included
517
+
518
+ Athos.js is an API framework — it doesn't render views. For full-stack apps, pair it with your preferred frontend (React, Vue, Svelte, HTMX, etc.). The OpenAPI spec makes frontend client generation trivial.
package/bootstrap.cjs ADDED
@@ -0,0 +1,107 @@
1
+ 'use strict';
2
+
3
+ var core = require('@athosjs/core');
4
+ var http = require('@athosjs/http');
5
+ var pipeline = require('./core/pipeline.cjs');
6
+ var functions = require('./functions.cjs');
7
+ var httpProfile = require('./http-profile.cjs');
8
+ var observability = require('./observability.cjs');
9
+
10
+ class ProBootstrap {
11
+ static async create(options) {
12
+ const result = await functions.ProApplication.create(options);
13
+ await result.kernel.start();
14
+ return result;
15
+ }
16
+ static async createHttp(options) {
17
+ const setup = await functions.ProApplication.createSetup(options);
18
+ const setupStartedAt = core.profileStart(setup.builder.profiler);
19
+ const httpProfile$1 = httpProfile.resolveProHttpProfile(options.http?.profile);
20
+ if (!setup.builder.capabilities.has("http-server")) {
21
+ setup.builder.capability("http-server", {
22
+ provider: "pro"
23
+ }, "pro");
24
+ }
25
+ const kernel = setup.builder.build();
26
+ kernel.container = setup.container;
27
+ core.profileEnd(kernel.profiler, "pro.bootstrap.setup", setupStartedAt);
28
+ const createHttpStartedAt = core.profileStart(kernel.profiler);
29
+ const app = http.createHttpApplication(kernel, {
30
+ ...httpProfile$1.router || options.http?.router ? {
31
+ router: {
32
+ ...httpProfile$1.router ?? {},
33
+ ...options.http?.router ?? {}
34
+ }
35
+ } : {}
36
+ });
37
+ core.profileEnd(kernel.profiler, "pro.bootstrap.create_http_app", createHttpStartedAt);
38
+ if (options.observability !== false) {
39
+ const observabilityStartedAt = core.profileStart(kernel.profiler);
40
+ observability.attachProObservability(app, {
41
+ ...httpProfile$1.observability ?? {},
42
+ ...typeof options.observability === "object" ? options.observability : {},
43
+ ...options.logger ? {
44
+ logger: options.logger
45
+ } : {},
46
+ ...options.telemetrySink ? {
47
+ telemetrySink: options.telemetrySink
48
+ } : {}
49
+ });
50
+ core.profileEnd(kernel.profiler, "pro.bootstrap.attach_observability", observabilityStartedAt);
51
+ }
52
+ if (options.middlewares) {
53
+ const middlewaresStartedAt = core.profileStart(kernel.profiler);
54
+ for (const middleware of options.middlewares){
55
+ app.use(await pipeline.normalizeConfiguredProMiddlewareInput(setup.container, middleware));
56
+ }
57
+ core.profileEnd(kernel.profiler, "pro.bootstrap.middlewares", middlewaresStartedAt);
58
+ }
59
+ if (options.validation && options.validation.adapter) {
60
+ const validationStartedAt = core.profileStart(kernel.profiler);
61
+ app.setValidation({
62
+ adapter: options.validation.adapter
63
+ });
64
+ core.profileEnd(kernel.profiler, "pro.bootstrap.validation", validationStartedAt);
65
+ }
66
+ if (options.configure) {
67
+ const configureStartedAt = core.profileStart(kernel.profiler);
68
+ await options.configure(app, {
69
+ ...setup,
70
+ kernel
71
+ });
72
+ core.profileEnd(kernel.profiler, "pro.bootstrap.configure", configureStartedAt);
73
+ }
74
+ if (options.start) {
75
+ const startStartedAt = core.profileStart(kernel.profiler);
76
+ await kernel.start();
77
+ core.profileEnd(kernel.profiler, "pro.bootstrap.start", startStartedAt);
78
+ }
79
+ return {
80
+ ...setup,
81
+ kernel,
82
+ app,
83
+ httpProfile: {
84
+ ...httpProfile$1,
85
+ ...httpProfile$1.router || options.http?.router ? {
86
+ router: {
87
+ ...httpProfile$1.router ?? {},
88
+ ...options.http?.router ?? {}
89
+ }
90
+ } : {},
91
+ ...httpProfile$1.observability || typeof options.observability === "object" ? {
92
+ observability: {
93
+ ...httpProfile$1.observability ?? {},
94
+ ...typeof options.observability === "object" ? options.observability : {}
95
+ }
96
+ } : {}
97
+ }
98
+ };
99
+ }
100
+ }
101
+ const createStartedProApplication = ProBootstrap.create;
102
+ const createProHttpApplication = ProBootstrap.createHttp;
103
+
104
+ exports.ProBootstrap = ProBootstrap;
105
+ exports.createProHttpApplication = createProHttpApplication;
106
+ exports.createStartedProApplication = createStartedProApplication;
107
+ //# sourceMappingURL=bootstrap.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.cjs","sources":["../../../packages/pro/src/bootstrap.ts"],"sourcesContent":["import { profileEnd, profileStart } from \"@athosjs/core\";\nimport { createHttpApplication } from \"@athosjs/http\";\nimport { normalizeConfiguredProMiddlewareInput } from \"./core/pipeline\";\nimport { ProApplication } from \"./functions\";\nimport { resolveProHttpProfile } from \"./http-profile\";\nimport { attachProObservability } from \"./observability\";\nimport type {\n\tProApplicationResult,\n\tProApplicationSetupOptions,\n\tProHttpApplicationOptions,\n\tProHttpApplicationResult,\n} from \"./types\";\n\nexport class ProBootstrap {\n\tstatic async create(options: ProApplicationSetupOptions): Promise<ProApplicationResult> {\n\t\tconst result = await ProApplication.create(options);\n\t\tawait (result as any).kernel.start();\n\t\treturn result;\n\t}\n\n\tstatic async createHttp(options: ProHttpApplicationOptions): Promise<ProHttpApplicationResult> {\n\t\tconst setup = await ProApplication.createSetup(options);\n\t\tconst setupStartedAt = profileStart((setup as any).builder.profiler);\n\t\tconst httpProfile = resolveProHttpProfile(options.http?.profile);\n\n\t\tif (!(setup as any).builder.capabilities.has(\"http-server\")) {\n\t\t\t(setup as any).builder.capability(\"http-server\", { provider: \"pro\" }, \"pro\");\n\t\t}\n\n\t\tconst kernel = (setup as any).builder.build();\n\t\t(kernel as any).container = (setup as any).container;\n\t\tprofileEnd(kernel.profiler, \"pro.bootstrap.setup\", setupStartedAt);\n\t\tconst createHttpStartedAt = profileStart(kernel.profiler);\n\t\tconst app = createHttpApplication(kernel, {\n\t\t\t...(httpProfile.router || options.http?.router\n\t\t\t\t? {\n\t\t\t\t\t\trouter: {\n\t\t\t\t\t\t\t...((httpProfile.router ?? {}) as any),\n\t\t\t\t\t\t\t...((options.http?.router ?? {}) as any),\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t});\n\t\tprofileEnd(kernel.profiler, \"pro.bootstrap.create_http_app\", createHttpStartedAt);\n\n\t\tif (options.observability !== false) {\n\t\t\tconst observabilityStartedAt = profileStart(kernel.profiler);\n\t\t\tattachProObservability(app, {\n\t\t\t\t...(httpProfile.observability ?? {}),\n\t\t\t\t...(typeof options.observability === \"object\" ? options.observability : {}),\n\t\t\t\t...(options.logger ? { logger: options.logger } : {}),\n\t\t\t\t...(options.telemetrySink ? { telemetrySink: options.telemetrySink } : {}),\n\t\t\t});\n\t\t\tprofileEnd(kernel.profiler, \"pro.bootstrap.attach_observability\", observabilityStartedAt);\n\t\t}\n\n\t\tif (options.middlewares) {\n\t\t\tconst middlewaresStartedAt = profileStart(kernel.profiler);\n\t\t\tfor (const middleware of options.middlewares) {\n\t\t\t\tapp.use(await normalizeConfiguredProMiddlewareInput((setup as any).container, middleware));\n\t\t\t}\n\t\t\tprofileEnd(kernel.profiler, \"pro.bootstrap.middlewares\", middlewaresStartedAt);\n\t\t}\n\n\t\tif (options.validation && (options.validation as any).adapter) {\n\t\t\tconst validationStartedAt = profileStart(kernel.profiler);\n\t\t\tapp.setValidation({ adapter: (options.validation as any).adapter });\n\t\t\tprofileEnd(kernel.profiler, \"pro.bootstrap.validation\", validationStartedAt);\n\t\t}\n\n\t\tif (options.configure) {\n\t\t\tconst configureStartedAt = profileStart(kernel.profiler);\n\t\t\tawait options.configure(app, { ...(setup as any), kernel });\n\t\t\tprofileEnd(kernel.profiler, \"pro.bootstrap.configure\", configureStartedAt);\n\t\t}\n\n\t\tif (options.start) {\n\t\t\tconst startStartedAt = profileStart(kernel.profiler);\n\t\t\tawait kernel.start();\n\t\t\tprofileEnd(kernel.profiler, \"pro.bootstrap.start\", startStartedAt);\n\t\t}\n\n\t\treturn {\n\t\t\t...(setup as any),\n\t\t\tkernel,\n\t\t\tapp,\n\t\t\thttpProfile: {\n\t\t\t\t...httpProfile,\n\t\t\t\t...(httpProfile.router || options.http?.router\n\t\t\t\t\t? {\n\t\t\t\t\t\t\trouter: {\n\t\t\t\t\t\t\t\t...((httpProfile.router ?? {}) as any),\n\t\t\t\t\t\t\t\t...((options.http?.router ?? {}) as any),\n\t\t\t\t\t\t\t} as any,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t...(httpProfile.observability || typeof options.observability === \"object\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tobservability: {\n\t\t\t\t\t\t\t\t...(httpProfile.observability ?? {}),\n\t\t\t\t\t\t\t\t...(typeof options.observability === \"object\" ? options.observability : {}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t} as ProHttpApplicationResult;\n\t}\n}\n\nexport const createStartedProApplication = ProBootstrap.create;\nexport const createProHttpApplication = ProBootstrap.createHttp;\n"],"names":["ProBootstrap","create","options","result","ProApplication","kernel","start","createHttp","setup","createSetup","setupStartedAt","profileStart","builder","profiler","httpProfile","resolveProHttpProfile","http","profile","capabilities","has","capability","provider","build","container","profileEnd","createHttpStartedAt","app","createHttpApplication","router","observability","observabilityStartedAt","attachProObservability","logger","telemetrySink","middlewares","middlewaresStartedAt","middleware","use","normalizeConfiguredProMiddlewareInput","validation","adapter","validationStartedAt","setValidation","configure","configureStartedAt","startStartedAt","createStartedProApplication","createProHttpApplication"],"mappings":";;;;;;;;;AAaO,MAAMA,YAAAA,CAAAA;IACZ,aAAaC,MAAAA,CAAOC,OAAmC,EAAiC;AACvF,QAAA,MAAMC,MAAAA,GAAS,MAAMC,wBAAAA,CAAeH,MAAM,CAACC,OAAAA,CAAAA;AAC3C,QAAA,MAAM,MAACC,CAAeE,MAAM,CAACC,KAAK,EAAA;QAClC,OAAOH,MAAAA;AACR,IAAA;IAEA,aAAaI,UAAAA,CAAWL,OAAkC,EAAqC;AAC9F,QAAA,MAAMM,KAAAA,GAAQ,MAAMJ,wBAAAA,CAAeK,WAAW,CAACP,OAAAA,CAAAA;AAC/C,QAAA,MAAMQ,iBAAiBC,iBAAAA,CAAcH,KAAAA,CAAcI,OAAO,CAACC,QAAQ,CAAA;AACnE,QAAA,MAAMC,aAAAA,GAAcC,iCAAAA,CAAsBb,OAAAA,CAAQc,IAAI,EAAEC,OAAAA,CAAAA;QAExD,IAAI,CAAC,KAACT,CAAcI,OAAO,CAACM,YAAY,CAACC,GAAG,CAAC,aAAA,CAAA,EAAgB;AAC3DX,YAAAA,KAAAA,CAAcI,OAAO,CAACQ,UAAU,CAAC,aAAA,EAAe;gBAAEC,QAAAA,EAAU;aAAM,EAAG,KAAA,CAAA;AACvE,QAAA;AAEA,QAAA,MAAMhB,MAAAA,GAAUG,KAAAA,CAAcI,OAAO,C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AAAA,CAAaN,MAAAA,CAAOQ,QAAQ,CAAA;AACnD,YAAA,MAAMR,OAAOC,KAAK,EAAA;YAClBkB,eAAAA,CAAWnB,MAAAA,CAAOQ,QAAQ,EAAE,qBAAA,EAAuBgC,cAAAA,CAAAA;AACpD,QAAA;QAEA,OAAO;AACN,YAAA,GAAIrC,KAAK;AACTH,YAAAA,MAAAA;AACAqB,YAAAA,GAAAA;YACAZ,WAAAA,EAAa;AACZ,gBAAA,GAAGA,aAAW;AACd,gBAAA,GAAIA,cAAYc,MAAM,IAAI1B,OAAAA,CAAQc,IAAI,EAAEY,MAAAA,GACrC;oBACAA,MAAAA,EAAQ;AACP,wBAAA,GAAKd,aAAAA,CAAYc,MAAM,IAAI,EAAE;AAC7B,wBAAA,GAAK1B,OAAAA,CAAQc,IAAI,EAAEY,MAAAA,IAAU;AAC9B;AACD,iBAAA,GACC,EAAE;AACL,gBAAA,GAAId,cAAYe,aAAa,IAAI,OAAO3B,OAAAA,CAAQ2B,aAAa,KAAK,QAAA,GAC/D;oBACAA,aAAAA,EAAe;AACd,wBAAA,GAAIf,aAAAA,CAAYe,aAAa,IAAI,EAAE;wBACnC,GAAI,OAAO3B,QAAQ2B,aAAa,KAAK,WAAW3B,OAAAA,CAAQ2B,aAAa,GAAG;AACzE;AACD,iBAAA,GACC;AACJ;AACD,SAAA;AACD,IAAA;AACD;AAEO,MAAMiB,2BAAAA,GAA8B9C,YAAAA,CAAaC;AACjD,MAAM8C,wBAAAA,GAA2B/C,YAAAA,CAAaO;;;;;;"}
package/bootstrap.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { ProApplicationResult, ProApplicationSetupOptions, ProHttpApplicationOptions, ProHttpApplicationResult } from "./types";
2
+ export declare class ProBootstrap {
3
+ static create(options: ProApplicationSetupOptions): Promise<ProApplicationResult>;
4
+ static createHttp(options: ProHttpApplicationOptions): Promise<ProHttpApplicationResult>;
5
+ }
6
+ export declare const createStartedProApplication: typeof ProBootstrap.create;
7
+ export declare const createProHttpApplication: typeof ProBootstrap.createHttp;
8
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../../../../packages/pro/src/bootstrap.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACX,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,MAAM,SAAS,CAAC;AAEjB,qBAAa,YAAY;WACX,MAAM,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,oBAAoB,CAAC;WAM1E,UAAU,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAuF9F;AAED,eAAO,MAAM,2BAA2B,4BAAsB,CAAC;AAC/D,eAAO,MAAM,wBAAwB,gCAA0B,CAAC"}