alepha 0.14.1 → 0.14.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 (97) hide show
  1. package/README.md +3 -3
  2. package/dist/api/audits/index.d.ts +342 -342
  3. package/dist/api/audits/index.d.ts.map +1 -1
  4. package/dist/api/audits/index.js.map +1 -1
  5. package/dist/api/files/index.js.map +1 -1
  6. package/dist/api/jobs/index.d.ts +161 -161
  7. package/dist/api/jobs/index.js.map +1 -1
  8. package/dist/api/parameters/index.js.map +1 -1
  9. package/dist/api/users/index.d.ts +791 -791
  10. package/dist/api/users/index.d.ts.map +1 -1
  11. package/dist/api/users/index.js +4 -0
  12. package/dist/api/users/index.js.map +1 -1
  13. package/dist/api/verifications/index.d.ts +128 -128
  14. package/dist/api/verifications/index.d.ts.map +1 -1
  15. package/dist/batch/index.js.map +1 -1
  16. package/dist/cache/core/index.js.map +1 -1
  17. package/dist/cli/index.d.ts +173 -167
  18. package/dist/cli/index.d.ts.map +1 -1
  19. package/dist/cli/index.js +427 -409
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/command/index.d.ts +5 -5
  22. package/dist/command/index.js.map +1 -1
  23. package/dist/core/index.browser.js.map +1 -1
  24. package/dist/core/index.d.ts.map +1 -1
  25. package/dist/core/index.js +7 -6
  26. package/dist/core/index.js.map +1 -1
  27. package/dist/core/index.native.js +7 -6
  28. package/dist/core/index.native.js.map +1 -1
  29. package/dist/datetime/index.js.map +1 -1
  30. package/dist/fake/index.js.map +1 -1
  31. package/dist/file/index.js.map +1 -1
  32. package/dist/lock/redis/index.js.map +1 -1
  33. package/dist/logger/index.js.map +1 -1
  34. package/dist/mcp/index.js.map +1 -1
  35. package/dist/orm/index.browser.js +26 -5
  36. package/dist/orm/index.browser.js.map +1 -1
  37. package/dist/orm/index.d.ts +115 -90
  38. package/dist/orm/index.d.ts.map +1 -1
  39. package/dist/orm/index.js +37 -12
  40. package/dist/orm/index.js.map +1 -1
  41. package/dist/redis/index.js.map +1 -1
  42. package/dist/retry/index.js.map +1 -1
  43. package/dist/router/index.js.map +1 -1
  44. package/dist/scheduler/index.d.ts +6 -6
  45. package/dist/scheduler/index.js.map +1 -1
  46. package/dist/security/index.d.ts +28 -28
  47. package/dist/security/index.d.ts.map +1 -1
  48. package/dist/security/index.js.map +1 -1
  49. package/dist/server/auth/index.d.ts +155 -155
  50. package/dist/server/auth/index.js.map +1 -1
  51. package/dist/server/cache/index.js.map +1 -1
  52. package/dist/server/cookies/index.browser.js.map +1 -1
  53. package/dist/server/cookies/index.js.map +1 -1
  54. package/dist/server/core/index.browser.js.map +1 -1
  55. package/dist/server/core/index.js.map +1 -1
  56. package/dist/server/health/index.d.ts +17 -17
  57. package/dist/server/helmet/index.js.map +1 -1
  58. package/dist/server/links/index.browser.js.map +1 -1
  59. package/dist/server/links/index.js.map +1 -1
  60. package/dist/server/multipart/index.js.map +1 -1
  61. package/dist/server/rate-limit/index.js.map +1 -1
  62. package/dist/server/security/index.d.ts +9 -9
  63. package/dist/server/security/index.js.map +1 -1
  64. package/dist/server/swagger/index.js.map +1 -1
  65. package/dist/thread/index.js.map +1 -1
  66. package/dist/topic/core/index.js.map +1 -1
  67. package/dist/vite/index.js.map +1 -1
  68. package/dist/websocket/index.browser.js.map +1 -1
  69. package/dist/websocket/index.d.ts +7 -7
  70. package/dist/websocket/index.js.map +1 -1
  71. package/package.json +3 -3
  72. package/src/api/users/index.ts +4 -0
  73. package/src/cli/apps/AlephaCli.ts +31 -14
  74. package/src/cli/apps/AlephaPackageBuilderCli.ts +2 -1
  75. package/src/cli/assets/appRouterTs.ts +1 -1
  76. package/src/cli/commands/{ViteCommands.ts → build.ts} +2 -105
  77. package/src/cli/commands/{ChangelogCommands.ts → changelog.ts} +7 -22
  78. package/src/cli/commands/clean.ts +14 -0
  79. package/src/cli/commands/{DrizzleCommands.ts → db.ts} +10 -117
  80. package/src/cli/commands/{DeployCommands.ts → deploy.ts} +1 -1
  81. package/src/cli/commands/dev.ts +57 -0
  82. package/src/cli/commands/format.ts +17 -0
  83. package/src/cli/commands/{CoreCommands.ts → init.ts} +2 -40
  84. package/src/cli/commands/lint.ts +17 -0
  85. package/src/cli/commands/root.ts +32 -0
  86. package/src/cli/commands/run.ts +24 -0
  87. package/src/cli/commands/test.ts +42 -0
  88. package/src/cli/commands/typecheck.ts +19 -0
  89. package/src/cli/commands/{VerifyCommands.ts → verify.ts} +1 -13
  90. package/src/cli/defineConfig.ts +10 -1
  91. package/src/cli/index.ts +16 -7
  92. package/src/cli/services/GitMessageParser.ts +1 -1
  93. package/src/core/Alepha.ts +7 -4
  94. package/src/orm/index.browser.ts +1 -1
  95. package/src/orm/index.ts +10 -6
  96. package/src/orm/providers/{PostgresTypeProvider.ts → DatabaseTypeProvider.ts} +25 -3
  97. package/src/cli/commands/BiomeCommands.ts +0 -29
@@ -1,4 +1,4 @@
1
- import * as alepha224 from "alepha";
1
+ import * as alepha226 from "alepha";
2
2
  import { Alepha, Async, KIND, Primitive, Static, TNull, TObject, TOptional, TSchema, TUnion } from "alepha";
3
3
  import * as alepha_server0 from "alepha/server";
4
4
  import * as alepha_orm0 from "alepha/orm";
@@ -238,7 +238,7 @@ type PgAttr<T extends TSchema, TAttr extends PgSymbolKeys> = T & { [K in TAttr]:
238
238
  declare module "alepha" {
239
239
  interface Env extends Partial<Static<typeof envSchema$2>> {}
240
240
  }
241
- declare const envSchema$2: alepha224.TObject<{
241
+ declare const envSchema$2: alepha226.TObject<{
242
242
  /**
243
243
  * Main configuration for database connection.
244
244
  * Accept a string in the format of a Postgres connection URL.
@@ -246,11 +246,11 @@ declare const envSchema$2: alepha224.TObject<{
246
246
  * or
247
247
  * Example: postgres://user:password@localhost:5432/database?sslmode=require
248
248
  */
249
- DATABASE_URL: alepha224.TOptional<alepha224.TString>;
249
+ DATABASE_URL: alepha226.TOptional<alepha226.TString>;
250
250
  /**
251
251
  * In addition to the DATABASE_URL, you can specify the postgres schema name.
252
252
  */
253
- POSTGRES_SCHEMA: alepha224.TOptional<alepha224.TString>;
253
+ POSTGRES_SCHEMA: alepha226.TOptional<alepha226.TString>;
254
254
  }>;
255
255
  /**
256
256
  * Bun PostgreSQL provider using Drizzle ORM with Bun's native SQL client.
@@ -275,8 +275,8 @@ declare const envSchema$2: alepha224.TObject<{
275
275
  /**
276
276
  * Configuration options for the Bun SQLite database provider.
277
277
  */
278
- declare const bunSqliteOptions: alepha224.Atom<alepha224.TObject<{
279
- path: alepha224.TOptional<alepha224.TString>;
278
+ declare const bunSqliteOptions: alepha226.Atom<alepha226.TObject<{
279
+ path: alepha226.TOptional<alepha226.TString>;
280
280
  }>, "alepha.postgres.bun-sqlite.options">;
281
281
  type BunSqliteProviderOptions = Static<typeof bunSqliteOptions.schema>;
282
282
  declare module "alepha" {
@@ -313,7 +313,7 @@ declare module "alepha" {
313
313
  declare module "alepha" {
314
314
  interface Env extends Partial<Static<typeof envSchema$1>> {}
315
315
  }
316
- declare const envSchema$1: alepha224.TObject<{
316
+ declare const envSchema$1: alepha226.TObject<{
317
317
  /**
318
318
  * Main configuration for database connection.
319
319
  * Accept a string in the format of a Postgres connection URL.
@@ -321,21 +321,21 @@ declare const envSchema$1: alepha224.TObject<{
321
321
  * or
322
322
  * Example: postgres://user:password@localhost:5432/database?sslmode=require
323
323
  */
324
- DATABASE_URL: alepha224.TOptional<alepha224.TString>;
324
+ DATABASE_URL: alepha226.TOptional<alepha226.TString>;
325
325
  /**
326
326
  * In addition to the DATABASE_URL, you can specify the postgres schema name.
327
327
  *
328
328
  * It will monkey patch drizzle tables.
329
329
  */
330
- POSTGRES_SCHEMA: alepha224.TOptional<alepha224.TString>;
330
+ POSTGRES_SCHEMA: alepha226.TOptional<alepha226.TString>;
331
331
  }>;
332
332
  //#endregion
333
333
  //#region ../../src/orm/providers/drivers/NodeSqliteProvider.d.ts
334
334
  /**
335
335
  * Configuration options for the Node.js SQLite database provider.
336
336
  */
337
- declare const nodeSqliteOptions: alepha224.Atom<alepha224.TObject<{
338
- path: alepha224.TOptional<alepha224.TString>;
337
+ declare const nodeSqliteOptions: alepha226.Atom<alepha226.TObject<{
338
+ path: alepha226.TOptional<alepha226.TString>;
339
339
  }>, "alepha.postgres.node-sqlite.options">;
340
340
  type NodeSqliteProviderOptions = Static<typeof nodeSqliteOptions.schema>;
341
341
  declare module "alepha" {
@@ -419,76 +419,76 @@ declare module "alepha" {
419
419
  }
420
420
  //#endregion
421
421
  //#region ../../src/api/jobs/schemas/jobExecutionQuerySchema.d.ts
422
- declare const jobExecutionQuerySchema: alepha224.TObject<{
423
- page: alepha224.TOptional<alepha224.TInteger>;
424
- size: alepha224.TOptional<alepha224.TInteger>;
425
- sort: alepha224.TOptional<alepha224.TString>;
426
- status: alepha224.TOptional<alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
427
- job: alepha224.TOptional<alepha224.TString>;
422
+ declare const jobExecutionQuerySchema: alepha226.TObject<{
423
+ page: alepha226.TOptional<alepha226.TInteger>;
424
+ size: alepha226.TOptional<alepha226.TInteger>;
425
+ sort: alepha226.TOptional<alepha226.TString>;
426
+ status: alepha226.TOptional<alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
427
+ job: alepha226.TOptional<alepha226.TString>;
428
428
  }>;
429
429
  type JobExecutionQuery = Static<typeof jobExecutionQuerySchema>;
430
430
  //#endregion
431
431
  //#region ../../src/api/jobs/services/JobService.d.ts
432
432
  declare class JobService {
433
433
  protected readonly alepha: Alepha;
434
- protected readonly executionRepository: alepha_orm0.Repository<alepha224.TObject<{
435
- id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
436
- version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
437
- createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
438
- updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
439
- finishedAt: alepha224.TOptional<alepha224.TString>;
440
- job: alepha224.TString;
441
- status: alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
442
- error: alepha224.TOptional<alepha224.TString>;
443
- logs: alepha224.TOptional<alepha224.TArray<alepha224.TObject<{
444
- level: alepha224.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
445
- message: alepha224.TString;
446
- service: alepha224.TString;
447
- module: alepha224.TString;
448
- context: alepha224.TOptional<alepha224.TString>;
449
- app: alepha224.TOptional<alepha224.TString>;
450
- data: alepha224.TOptional<alepha224.TAny>;
451
- timestamp: alepha224.TNumber;
434
+ protected readonly executionRepository: alepha_orm0.Repository<alepha226.TObject<{
435
+ id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
436
+ version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
437
+ createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
438
+ updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
439
+ finishedAt: alepha226.TOptional<alepha226.TString>;
440
+ job: alepha226.TString;
441
+ status: alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
442
+ error: alepha226.TOptional<alepha226.TString>;
443
+ logs: alepha226.TOptional<alepha226.TArray<alepha226.TObject<{
444
+ level: alepha226.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
445
+ message: alepha226.TString;
446
+ service: alepha226.TString;
447
+ module: alepha226.TString;
448
+ context: alepha226.TOptional<alepha226.TString>;
449
+ app: alepha226.TOptional<alepha226.TString>;
450
+ data: alepha226.TOptional<alepha226.TAny>;
451
+ timestamp: alepha226.TNumber;
452
452
  }>>>;
453
453
  }>>;
454
454
  getJobs(): Promise<string[]>;
455
- getJobExecutions(query?: JobExecutionQuery): Promise<alepha224.Page<alepha_orm0.PgStatic<alepha224.TObject<{
456
- id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
457
- version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
458
- createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
459
- updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
460
- finishedAt: alepha224.TOptional<alepha224.TString>;
461
- job: alepha224.TString;
462
- status: alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
463
- error: alepha224.TOptional<alepha224.TString>;
464
- logs: alepha224.TOptional<alepha224.TArray<alepha224.TObject<{
465
- level: alepha224.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
466
- message: alepha224.TString;
467
- service: alepha224.TString;
468
- module: alepha224.TString;
469
- context: alepha224.TOptional<alepha224.TString>;
470
- app: alepha224.TOptional<alepha224.TString>;
471
- data: alepha224.TOptional<alepha224.TAny>;
472
- timestamp: alepha224.TNumber;
455
+ getJobExecutions(query?: JobExecutionQuery): Promise<alepha226.Page<alepha_orm0.PgStatic<alepha226.TObject<{
456
+ id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
457
+ version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
458
+ createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
459
+ updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
460
+ finishedAt: alepha226.TOptional<alepha226.TString>;
461
+ job: alepha226.TString;
462
+ status: alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
463
+ error: alepha226.TOptional<alepha226.TString>;
464
+ logs: alepha226.TOptional<alepha226.TArray<alepha226.TObject<{
465
+ level: alepha226.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
466
+ message: alepha226.TString;
467
+ service: alepha226.TString;
468
+ module: alepha226.TString;
469
+ context: alepha226.TOptional<alepha226.TString>;
470
+ app: alepha226.TOptional<alepha226.TString>;
471
+ data: alepha226.TOptional<alepha226.TAny>;
472
+ timestamp: alepha226.TNumber;
473
473
  }>>>;
474
- }>, alepha_orm0.PgRelationMap<alepha224.TObject<{
475
- id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
476
- version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
477
- createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
478
- updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
479
- finishedAt: alepha224.TOptional<alepha224.TString>;
480
- job: alepha224.TString;
481
- status: alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
482
- error: alepha224.TOptional<alepha224.TString>;
483
- logs: alepha224.TOptional<alepha224.TArray<alepha224.TObject<{
484
- level: alepha224.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
485
- message: alepha224.TString;
486
- service: alepha224.TString;
487
- module: alepha224.TString;
488
- context: alepha224.TOptional<alepha224.TString>;
489
- app: alepha224.TOptional<alepha224.TString>;
490
- data: alepha224.TOptional<alepha224.TAny>;
491
- timestamp: alepha224.TNumber;
474
+ }>, alepha_orm0.PgRelationMap<alepha226.TObject<{
475
+ id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
476
+ version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
477
+ createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
478
+ updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
479
+ finishedAt: alepha226.TOptional<alepha226.TString>;
480
+ job: alepha226.TString;
481
+ status: alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
482
+ error: alepha226.TOptional<alepha226.TString>;
483
+ logs: alepha226.TOptional<alepha226.TArray<alepha226.TObject<{
484
+ level: alepha226.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
485
+ message: alepha226.TString;
486
+ service: alepha226.TString;
487
+ module: alepha226.TString;
488
+ context: alepha226.TOptional<alepha226.TString>;
489
+ app: alepha226.TOptional<alepha226.TString>;
490
+ data: alepha226.TOptional<alepha226.TAny>;
491
+ timestamp: alepha226.TNumber;
492
492
  }>>>;
493
493
  }>>>>>;
494
494
  triggerJob(name: string): Promise<{
@@ -502,75 +502,75 @@ declare class JobController {
502
502
  protected readonly group: string;
503
503
  protected readonly jobService: JobService;
504
504
  readonly getJobs: alepha_server0.ActionPrimitiveFn<{
505
- response: alepha224.TArray<alepha224.TString>;
505
+ response: alepha226.TArray<alepha226.TString>;
506
506
  }>;
507
507
  readonly getJobExecutions: alepha_server0.ActionPrimitiveFn<{
508
- query: alepha224.TObject<{
509
- page: alepha224.TOptional<alepha224.TInteger>;
510
- size: alepha224.TOptional<alepha224.TInteger>;
511
- sort: alepha224.TOptional<alepha224.TString>;
512
- status: alepha224.TOptional<alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
513
- job: alepha224.TOptional<alepha224.TString>;
508
+ query: alepha226.TObject<{
509
+ page: alepha226.TOptional<alepha226.TInteger>;
510
+ size: alepha226.TOptional<alepha226.TInteger>;
511
+ sort: alepha226.TOptional<alepha226.TString>;
512
+ status: alepha226.TOptional<alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">>;
513
+ job: alepha226.TOptional<alepha226.TString>;
514
514
  }>;
515
- response: alepha224.TPage<alepha224.TObject<{
516
- id: PgAttr<PgAttr<alepha224.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
517
- version: PgAttr<PgAttr<alepha224.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
518
- createdAt: PgAttr<PgAttr<alepha224.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
519
- updatedAt: PgAttr<PgAttr<alepha224.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
520
- finishedAt: alepha224.TOptional<alepha224.TString>;
521
- job: alepha224.TString;
522
- status: alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
523
- error: alepha224.TOptional<alepha224.TString>;
524
- logs: alepha224.TOptional<alepha224.TArray<alepha224.TObject<{
525
- level: alepha224.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
526
- message: alepha224.TString;
527
- service: alepha224.TString;
528
- module: alepha224.TString;
529
- context: alepha224.TOptional<alepha224.TString>;
530
- app: alepha224.TOptional<alepha224.TString>;
531
- data: alepha224.TOptional<alepha224.TAny>;
532
- timestamp: alepha224.TNumber;
515
+ response: alepha226.TPage<alepha226.TObject<{
516
+ id: PgAttr<PgAttr<alepha226.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
517
+ version: PgAttr<PgAttr<alepha226.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
518
+ createdAt: PgAttr<PgAttr<alepha226.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
519
+ updatedAt: PgAttr<PgAttr<alepha226.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
520
+ finishedAt: alepha226.TOptional<alepha226.TString>;
521
+ job: alepha226.TString;
522
+ status: alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
523
+ error: alepha226.TOptional<alepha226.TString>;
524
+ logs: alepha226.TOptional<alepha226.TArray<alepha226.TObject<{
525
+ level: alepha226.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
526
+ message: alepha226.TString;
527
+ service: alepha226.TString;
528
+ module: alepha226.TString;
529
+ context: alepha226.TOptional<alepha226.TString>;
530
+ app: alepha226.TOptional<alepha226.TString>;
531
+ data: alepha226.TOptional<alepha226.TAny>;
532
+ timestamp: alepha226.TNumber;
533
533
  }>>>;
534
534
  }>>;
535
535
  }>;
536
536
  readonly triggerJob: alepha_server0.ActionPrimitiveFn<{
537
- body: alepha224.TObject<{
538
- name: alepha224.TString;
537
+ body: alepha226.TObject<{
538
+ name: alepha226.TString;
539
539
  }>;
540
- response: alepha224.TObject<{
541
- ok: alepha224.TBoolean;
542
- id: alepha224.TOptional<alepha224.TUnion<[alepha224.TString, alepha224.TInteger]>>;
543
- count: alepha224.TOptional<alepha224.TNumber>;
540
+ response: alepha226.TObject<{
541
+ ok: alepha226.TBoolean;
542
+ id: alepha226.TOptional<alepha226.TUnion<[alepha226.TString, alepha226.TInteger]>>;
543
+ count: alepha226.TOptional<alepha226.TNumber>;
544
544
  }>;
545
545
  }>;
546
546
  }
547
547
  //#endregion
548
548
  //#region ../../src/api/jobs/entities/jobExecutions.d.ts
549
- declare const jobExecutions: alepha_orm0.EntityPrimitive<alepha224.TObject<{
550
- id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
551
- version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
552
- createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
553
- updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
554
- finishedAt: alepha224.TOptional<alepha224.TString>;
555
- job: alepha224.TString;
556
- status: alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
557
- error: alepha224.TOptional<alepha224.TString>;
558
- logs: alepha224.TOptional<alepha224.TArray<alepha224.TObject<{
559
- level: alepha224.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
560
- message: alepha224.TString;
561
- service: alepha224.TString;
562
- module: alepha224.TString;
563
- context: alepha224.TOptional<alepha224.TString>;
564
- app: alepha224.TOptional<alepha224.TString>;
565
- data: alepha224.TOptional<alepha224.TAny>;
566
- timestamp: alepha224.TNumber;
549
+ declare const jobExecutions: alepha_orm0.EntityPrimitive<alepha226.TObject<{
550
+ id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
551
+ version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
552
+ createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
553
+ updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
554
+ finishedAt: alepha226.TOptional<alepha226.TString>;
555
+ job: alepha226.TString;
556
+ status: alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
557
+ error: alepha226.TOptional<alepha226.TString>;
558
+ logs: alepha226.TOptional<alepha226.TArray<alepha226.TObject<{
559
+ level: alepha226.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
560
+ message: alepha226.TString;
561
+ service: alepha226.TString;
562
+ module: alepha226.TString;
563
+ context: alepha226.TOptional<alepha226.TString>;
564
+ app: alepha226.TOptional<alepha226.TString>;
565
+ data: alepha226.TOptional<alepha226.TAny>;
566
+ timestamp: alepha226.TNumber;
567
567
  }>>>;
568
568
  }>>;
569
569
  type JobExecutionEntity = Static<typeof jobExecutions.schema>;
570
570
  //#endregion
571
571
  //#region ../../src/api/jobs/providers/JobProvider.d.ts
572
- declare const envSchema: alepha224.TObject<{
573
- JOB_PREFIX: alepha224.TOptional<alepha224.TString>;
572
+ declare const envSchema: alepha226.TObject<{
573
+ JOB_PREFIX: alepha226.TOptional<alepha226.TString>;
574
574
  }>;
575
575
  declare module "alepha" {
576
576
  interface Env extends Partial<Static<typeof envSchema>> {}
@@ -583,24 +583,24 @@ declare class JobProvider {
583
583
  protected readonly alepha: Alepha;
584
584
  protected readonly dateTimeProvider: DateTimeProvider;
585
585
  protected readonly cronProvider: CronProvider;
586
- protected readonly executionRepository: alepha_orm0.Repository<alepha224.TObject<{
587
- id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
588
- version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
589
- createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
590
- updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha224.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
591
- finishedAt: alepha224.TOptional<alepha224.TString>;
592
- job: alepha224.TString;
593
- status: alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
594
- error: alepha224.TOptional<alepha224.TString>;
595
- logs: alepha224.TOptional<alepha224.TArray<alepha224.TObject<{
596
- level: alepha224.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
597
- message: alepha224.TString;
598
- service: alepha224.TString;
599
- module: alepha224.TString;
600
- context: alepha224.TOptional<alepha224.TString>;
601
- app: alepha224.TOptional<alepha224.TString>;
602
- data: alepha224.TOptional<alepha224.TAny>;
603
- timestamp: alepha224.TNumber;
586
+ protected readonly executionRepository: alepha_orm0.Repository<alepha226.TObject<{
587
+ id: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_PRIMARY_KEY>, typeof alepha_orm0.PG_DEFAULT>;
588
+ version: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TInteger, typeof alepha_orm0.PG_VERSION>, typeof alepha_orm0.PG_DEFAULT>;
589
+ createdAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_CREATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
590
+ updatedAt: alepha_orm0.PgAttr<alepha_orm0.PgAttr<alepha226.TString, typeof alepha_orm0.PG_UPDATED_AT>, typeof alepha_orm0.PG_DEFAULT>;
591
+ finishedAt: alepha226.TOptional<alepha226.TString>;
592
+ job: alepha226.TString;
593
+ status: alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
594
+ error: alepha226.TOptional<alepha226.TString>;
595
+ logs: alepha226.TOptional<alepha226.TArray<alepha226.TObject<{
596
+ level: alepha226.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
597
+ message: alepha226.TString;
598
+ service: alepha226.TString;
599
+ module: alepha226.TString;
600
+ context: alepha226.TOptional<alepha226.TString>;
601
+ app: alepha226.TOptional<alepha226.TString>;
602
+ data: alepha226.TOptional<alepha226.TAny>;
603
+ timestamp: alepha226.TNumber;
604
604
  }>>>;
605
605
  }>>;
606
606
  protected readonly env: {
@@ -694,31 +694,31 @@ interface JobHandlerArguments {
694
694
  }
695
695
  //#endregion
696
696
  //#region ../../src/api/jobs/schemas/jobExecutionResourceSchema.d.ts
697
- declare const jobExecutionResourceSchema: alepha224.TObject<{
698
- id: PgAttr<PgAttr<alepha224.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
699
- version: PgAttr<PgAttr<alepha224.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
700
- createdAt: PgAttr<PgAttr<alepha224.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
701
- updatedAt: PgAttr<PgAttr<alepha224.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
702
- finishedAt: alepha224.TOptional<alepha224.TString>;
703
- job: alepha224.TString;
704
- status: alepha224.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
705
- error: alepha224.TOptional<alepha224.TString>;
706
- logs: alepha224.TOptional<alepha224.TArray<alepha224.TObject<{
707
- level: alepha224.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
708
- message: alepha224.TString;
709
- service: alepha224.TString;
710
- module: alepha224.TString;
711
- context: alepha224.TOptional<alepha224.TString>;
712
- app: alepha224.TOptional<alepha224.TString>;
713
- data: alepha224.TOptional<alepha224.TAny>;
714
- timestamp: alepha224.TNumber;
697
+ declare const jobExecutionResourceSchema: alepha226.TObject<{
698
+ id: PgAttr<PgAttr<alepha226.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
699
+ version: PgAttr<PgAttr<alepha226.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
700
+ createdAt: PgAttr<PgAttr<alepha226.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
701
+ updatedAt: PgAttr<PgAttr<alepha226.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
702
+ finishedAt: alepha226.TOptional<alepha226.TString>;
703
+ job: alepha226.TString;
704
+ status: alepha226.TUnsafe<"STARTED" | "FAILED" | "COMPLETED">;
705
+ error: alepha226.TOptional<alepha226.TString>;
706
+ logs: alepha226.TOptional<alepha226.TArray<alepha226.TObject<{
707
+ level: alepha226.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
708
+ message: alepha226.TString;
709
+ service: alepha226.TString;
710
+ module: alepha226.TString;
711
+ context: alepha226.TOptional<alepha226.TString>;
712
+ app: alepha226.TOptional<alepha226.TString>;
713
+ data: alepha226.TOptional<alepha226.TAny>;
714
+ timestamp: alepha226.TNumber;
715
715
  }>>>;
716
716
  }>;
717
717
  type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;
718
718
  //#endregion
719
719
  //#region ../../src/api/jobs/schemas/triggerJobSchema.d.ts
720
- declare const triggerJobSchema: alepha224.TObject<{
721
- name: alepha224.TString;
720
+ declare const triggerJobSchema: alepha226.TObject<{
721
+ name: alepha226.TString;
722
722
  }>;
723
723
  type TriggerJob = Static<typeof triggerJobSchema>;
724
724
  //#endregion
@@ -731,7 +731,7 @@ type TriggerJob = Static<typeof triggerJobSchema>;
731
731
  *
732
732
  * @module alepha.api.jobs
733
733
  */
734
- declare const AlephaApiJobs: alepha224.Service<alepha224.Module>;
734
+ declare const AlephaApiJobs: alepha226.Service<alepha226.Module>;
735
735
  //#endregion
736
736
  export { $job, AlephaApiJobs, Job, JobController, JobExecutionEntity, JobExecutionQuery, JobExecutionResource, JobHandlerArguments, JobPrimitive, JobPrimitiveOptions, JobProvider, JobRegistration, JobService, TriggerJob, jobExecutionQuerySchema, jobExecutionResourceSchema, jobExecutions, triggerJobSchema };
737
737
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["registration: JobRegistration"],"sources":["../../../src/api/jobs/schemas/jobExecutionQuerySchema.ts","../../../src/api/jobs/entities/jobExecutions.ts","../../../src/api/jobs/schemas/jobExecutionResourceSchema.ts","../../../src/api/jobs/schemas/triggerJobSchema.ts","../../../src/api/jobs/providers/JobProvider.ts","../../../src/api/jobs/primitives/$job.ts","../../../src/api/jobs/services/JobService.ts","../../../src/api/jobs/controllers/JobController.ts","../../../src/api/jobs/index.ts"],"sourcesContent":["import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { pageQuerySchema } from \"alepha/orm\";\n\nexport const jobExecutionQuerySchema = t.extend(pageQuerySchema, {\n status: t.optional(t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"])),\n job: t.optional(\n t.text({\n description: \"Filter by job name\",\n }),\n ),\n});\n\nexport type JobExecutionQuery = Static<typeof jobExecutionQuerySchema>;\n","import { type Static, t } from \"alepha\";\nimport { logEntrySchema } from \"alepha/logger\";\nimport { $entity, pg } from \"alepha/orm\";\n\nexport const jobExecutions = $entity({\n name: \"job_executions\",\n schema: t.object({\n id: pg.primaryKey(t.uuid()),\n version: pg.version(),\n createdAt: pg.createdAt(),\n updatedAt: pg.updatedAt(),\n finishedAt: t.optional(t.datetime()),\n job: t.string(),\n status: t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"]),\n error: t.optional(t.string()),\n logs: t.optional(t.array(logEntrySchema)),\n }),\n});\n\nexport type JobExecutionEntity = Static<typeof jobExecutions.schema>;\n","import { type Static, t } from \"alepha\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nexport const jobExecutionResourceSchema = t.extend(\n jobExecutions.schema,\n {},\n {\n title: \"JobExecutionResource\",\n description:\n \"A job execution resource representing the execution details of a job.\",\n },\n);\n\nexport type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const triggerJobSchema = t.object({\n name: t.string(),\n});\n\nexport type TriggerJob = Static<typeof triggerJobSchema>;\n","import { $env, $inject, Alepha, type Async, type Static, t } from \"alepha\";\nimport { type DateTime, DateTimeProvider } from \"alepha/datetime\";\nimport { $lock, type LockPrimitive } from \"alepha/lock\";\nimport type { LogEntry } from \"alepha/logger\";\nimport { $repository } from \"alepha/orm\";\nimport { CronProvider } from \"alepha/scheduler\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nconst envSchema = t.object({\n JOB_PREFIX: t.optional(\n t.text({\n description: \"Prefix for job lock keys\",\n }),\n ),\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\n/**\n * Provider for job management and execution.\n * Handles job lifecycle, execution tracking, log capturing, and event emission.\n */\nexport class JobProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly cronProvider = $inject(CronProvider);\n protected readonly executionRepository = $repository(jobExecutions);\n protected readonly env = $env(envSchema);\n protected readonly logs = new Map<string, LogEntry[]>();\n protected readonly jobs = new Map<string, JobRegistration>();\n\n /**\n * Register and set up a job for execution (called during primitive initialization).\n */\n public registerJob(options: Job): JobRegistration {\n const jobName = options.name;\n\n // Set up log capturing for this job (only once)\n if (this.jobs.size === 0) {\n this.alepha.events.on(\"log\", ({ entry }) => {\n const context = entry.context;\n if (!context) {\n return;\n }\n\n const entries = this.logs.get(context);\n if (!entries) {\n return;\n }\n\n entries.push(entry);\n this.logs.set(context, entries);\n });\n }\n\n // Create lock primitive if locking is enabled\n const lockPrimitive =\n options.lock !== false\n ? $lock({\n name: () => {\n const prefix = this.env.JOB_PREFIX\n ? `${this.env.JOB_PREFIX}:`\n : \"\";\n return `${prefix}job:${jobName}`;\n },\n handler: async () => {\n await this.executeJob(jobName, options.handler);\n },\n })\n : null;\n\n const registration: JobRegistration = {\n name: jobName,\n options,\n lockPrimitive,\n };\n\n this.jobs.set(jobName, registration);\n\n // Set up cron scheduling if provided\n if (options.cron) {\n this.cronProvider.createCronJob(jobName, options.cron, () =>\n this.triggerJob(jobName),\n );\n }\n\n return registration;\n }\n\n /**\n * Trigger a job by name.\n */\n public async triggerJob(jobName: string): Promise<void> {\n const registration = this.jobs.get(jobName);\n if (!registration) {\n throw new Error(`Job not registered: ${jobName}`);\n }\n\n // Execute handler with or without lock\n if (registration.options.lock !== false && registration.lockPrimitive) {\n await registration.lockPrimitive.run();\n } else {\n await this.executeJob(jobName, registration.options.handler);\n }\n }\n\n /**\n * Execute a job handler (called by the job primitive).\n */\n public async executeJob(\n jobName: string,\n handler: (args: { now: DateTime }) => Async<void>,\n ): Promise<void> {\n if (!this.alepha.isStarted()) {\n return;\n }\n\n const context = this.alepha.context.createContextId();\n\n await this.alepha.context.run(\n async () => {\n try {\n const now = this.dateTimeProvider.now();\n\n // Initialize log collection for this context\n this.logs.set(context, []);\n\n // Create execution record\n await this.executionRepository.create({\n job: jobName,\n status: \"STARTED\",\n });\n\n await this.alepha.events.emit(\"scheduler:begin\", {\n name: jobName,\n now,\n context,\n });\n\n // Execute the handler\n await handler({ now });\n\n // Update execution as completed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"COMPLETED\";\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:success\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n } catch (error) {\n // Update execution as failed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"FAILED\";\n exec.error = (error as Error).message;\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:error\",\n {\n name: jobName,\n error: error as Error,\n context,\n },\n {\n catch: true,\n },\n );\n\n // Don't re-throw, jobs should handle errors gracefully\n }\n\n // Clean up logs\n this.logs.delete(context);\n\n await this.alepha.events.emit(\n \"scheduler:end\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n },\n {\n context,\n },\n );\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface Job {\n /**\n * Name of the job.\n */\n name: string;\n\n /**\n * Optional description of the job.\n */\n description?: string;\n\n /**\n * Function to run on schedule.\n */\n handler: (args: { now: DateTime }) => Async<void>;\n\n /**\n * Cron expression to run the job.\n */\n cron?: string;\n\n /**\n * If true, the job will be locked and only one instance will run at a time.\n * You probably need to import {@link AlephaLockRedis} for distributed locking.\n *\n * @default true\n */\n lock?: boolean;\n\n /**\n * Optional prefix for job lock keys.\n */\n lockPrefix?: string;\n}\n\nexport interface JobRegistration {\n name: string;\n options: Job;\n lockPrimitive: LockPrimitive<() => Promise<void>> | null;\n}\n","import { $inject, createPrimitive, KIND, Primitive } from \"alepha\";\nimport type { DateTime } from \"alepha/datetime\";\nimport { type Job, JobProvider } from \"../providers/JobProvider.ts\";\n\n/**\n * Job primitive - a drop-in replacement for $scheduler with built-in execution tracking.\n */\nexport const $job = (options: JobPrimitiveOptions): JobPrimitive => {\n return createPrimitive(JobPrimitive, options);\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type JobPrimitiveOptions = Omit<Job, \"name\"> & {\n /**\n * Name of the job. Defaults to the primitive property name.\n */\n name?: string;\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class JobPrimitive extends Primitive<JobPrimitiveOptions> {\n protected readonly jobProvider = $inject(JobProvider);\n\n public get name(): string {\n return (\n this.options.name ??\n `${this.config.service.name}.${this.config.propertyKey}`\n );\n }\n\n protected onInit() {\n // Register job with JobProvider\n this.jobProvider.registerJob({\n ...this.options,\n name: this.name,\n });\n }\n\n public async trigger(): Promise<void> {\n await this.jobProvider.triggerJob(this.name);\n }\n}\n\n$job[KIND] = JobPrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface JobHandlerArguments {\n now: DateTime;\n}\n","import { $inject, Alepha } from \"alepha\";\nimport { $repository } from \"alepha/orm\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\nimport { $job } from \"../primitives/$job.ts\";\nimport type { JobExecutionQuery } from \"../schemas/jobExecutionQuerySchema.ts\";\n\nexport class JobService {\n protected readonly alepha = $inject(Alepha);\n protected readonly executionRepository = $repository(jobExecutions);\n\n public async getJobs(): Promise<string[]> {\n const jobPrimitives = this.alepha.primitives($job);\n return jobPrimitives.map((job) => job.name);\n }\n\n public async getJobExecutions(query: JobExecutionQuery = {}) {\n query.sort ??= \"-createdAt\";\n\n const where = this.executionRepository.createQueryWhere();\n\n if (query.job) {\n where.job = { eq: query.job };\n }\n\n if (query.status) {\n where.status = { eq: query.status };\n }\n\n return await this.executionRepository.paginate(\n query,\n { where },\n { count: true },\n );\n }\n\n public async triggerJob(name: string): Promise<{ ok: boolean }> {\n const jobPrimitives = this.alepha.primitives($job);\n const job = jobPrimitives.find((j) => j.name === name);\n\n if (!job) {\n throw new Error(`Job not found: ${name}`);\n }\n\n await job.trigger();\n return { ok: true };\n }\n}\n","import { $inject, t } from \"alepha\";\nimport { $action, okSchema } from \"alepha/server\";\nimport { jobExecutionQuerySchema } from \"../schemas/jobExecutionQuerySchema.ts\";\nimport { jobExecutionResourceSchema } from \"../schemas/jobExecutionResourceSchema.ts\";\nimport { triggerJobSchema } from \"../schemas/triggerJobSchema.ts\";\nimport { JobService } from \"../services/JobService.ts\";\n\nexport class JobController {\n protected readonly url: string = \"/jobs\";\n protected readonly group: string = \"jobs\";\n protected readonly jobService = $inject(JobService);\n\n public readonly getJobs = $action({\n path: this.url,\n group: this.group,\n schema: {\n response: t.array(t.string()),\n },\n handler: () => this.jobService.getJobs(),\n });\n\n public readonly getJobExecutions = $action({\n path: `${this.url}/executions`,\n group: this.group,\n schema: {\n query: jobExecutionQuerySchema,\n response: t.page(jobExecutionResourceSchema),\n },\n handler: ({ query }) => this.jobService.getJobExecutions(query),\n });\n\n public readonly triggerJob = $action({\n method: \"POST\",\n path: `${this.url}/trigger`,\n group: this.group,\n schema: {\n body: triggerJobSchema,\n response: okSchema,\n },\n handler: ({ body }) => this.jobService.triggerJob(body.name),\n });\n}\n","import { $module } from \"alepha\";\nimport { JobController } from \"./controllers/JobController.ts\";\nimport { JobProvider } from \"./providers/JobProvider.ts\";\nimport { JobService } from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./controllers/JobController.ts\";\nexport * from \"./entities/jobExecutions.ts\";\nexport * from \"./primitives/$job.ts\";\nexport * from \"./providers/JobProvider.ts\";\nexport * from \"./schemas/jobExecutionQuerySchema.ts\";\nexport * from \"./schemas/jobExecutionResourceSchema.ts\";\nexport * from \"./schemas/triggerJobSchema.ts\";\nexport * from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides job management API endpoints for Alepha applications.\n *\n * This module includes job queue operations, job status monitoring,\n * and background task management capabilities.\n *\n * @module alepha.api.jobs\n */\nexport const AlephaApiJobs = $module({\n name: \"alepha.api.jobs\",\n services: [JobController, JobProvider, JobService],\n});\n"],"mappings":";;;;;;;;;AAIA,MAAa,0BAA0B,EAAE,OAAO,iBAAiB;CAC/D,QAAQ,EAAE,SAAS,EAAE,KAAK;EAAC;EAAW;EAAU;EAAY,CAAC,CAAC;CAC9D,KAAK,EAAE,SACL,EAAE,KAAK,EACL,aAAa,sBACd,CAAC,CACH;CACF,CAAC;;;;ACPF,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,QAAQ,EAAE,OAAO;EACf,IAAI,GAAG,WAAW,EAAE,MAAM,CAAC;EAC3B,SAAS,GAAG,SAAS;EACrB,WAAW,GAAG,WAAW;EACzB,WAAW,GAAG,WAAW;EACzB,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC;EACpC,KAAK,EAAE,QAAQ;EACf,QAAQ,EAAE,KAAK;GAAC;GAAW;GAAU;GAAY,CAAC;EAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;EAC7B,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;EAC1C,CAAC;CACH,CAAC;;;;ACdF,MAAa,6BAA6B,EAAE,OAC1C,cAAc,QACd,EAAE,EACF;CACE,OAAO;CACP,aACE;CACH,CACF;;;;ACRD,MAAa,mBAAmB,EAAE,OAAO,EACvC,MAAM,EAAE,QAAQ,EACjB,CAAC;;;;ACGF,MAAM,YAAY,EAAE,OAAO,EACzB,YAAY,EAAE,SACZ,EAAE,KAAK,EACL,aAAa,4BACd,CAAC,CACH,EACF,CAAC;;;;;AAUF,IAAa,cAAb,MAAyB;CACvB,AAAmB,SAAS,QAAQ,OAAO;CAC3C,AAAmB,mBAAmB,QAAQ,iBAAiB;CAC/D,AAAmB,eAAe,QAAQ,aAAa;CACvD,AAAmB,sBAAs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X,OAAO,KAAK;EACZ,QAAQ,EACN,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAC9B;EACD,eAAe,KAAK,WAAW,SAAS;EACzC,CAAC;CAEF,AAAgB,mBAAmB,QAAQ;EACzC,MAAM,GAAG,KAAK,IAAI;EAClB,OAAO,KAAK;EACZ,QAAQ;GACN,OAAO;GACP,UAAU,EAAE,KAAK,2BAA2B;GAC7C;EACD,UAAU,EAAE,YAAY,KAAK,WAAW,iBAAiB,MAAM;EAChE,CAAC;CAEF,AAAgB,aAAa,QAAQ;EACnC,QAAQ;EACR,MAAM,GAAG,KAAK,IAAI;EAClB,OAAO,KAAK;EACZ,QAAQ;GACN,MAAM;GACN,UAAU;GACX;EACD,UAAU,EAAE,WAAW,KAAK,WAAW,WAAW,KAAK,KAAK;EAC7D,CAAC;;;;;;;;;;;;;ACdJ,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,UAAU;EAAC;EAAe;EAAa;EAAW;CACnD,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/api/jobs/schemas/jobExecutionQuerySchema.ts","../../../src/api/jobs/entities/jobExecutions.ts","../../../src/api/jobs/schemas/jobExecutionResourceSchema.ts","../../../src/api/jobs/schemas/triggerJobSchema.ts","../../../src/api/jobs/providers/JobProvider.ts","../../../src/api/jobs/primitives/$job.ts","../../../src/api/jobs/services/JobService.ts","../../../src/api/jobs/controllers/JobController.ts","../../../src/api/jobs/index.ts"],"sourcesContent":["import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { pageQuerySchema } from \"alepha/orm\";\n\nexport const jobExecutionQuerySchema = t.extend(pageQuerySchema, {\n status: t.optional(t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"])),\n job: t.optional(\n t.text({\n description: \"Filter by job name\",\n }),\n ),\n});\n\nexport type JobExecutionQuery = Static<typeof jobExecutionQuerySchema>;\n","import { type Static, t } from \"alepha\";\nimport { logEntrySchema } from \"alepha/logger\";\nimport { $entity, pg } from \"alepha/orm\";\n\nexport const jobExecutions = $entity({\n name: \"job_executions\",\n schema: t.object({\n id: pg.primaryKey(t.uuid()),\n version: pg.version(),\n createdAt: pg.createdAt(),\n updatedAt: pg.updatedAt(),\n finishedAt: t.optional(t.datetime()),\n job: t.string(),\n status: t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"]),\n error: t.optional(t.string()),\n logs: t.optional(t.array(logEntrySchema)),\n }),\n});\n\nexport type JobExecutionEntity = Static<typeof jobExecutions.schema>;\n","import { type Static, t } from \"alepha\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nexport const jobExecutionResourceSchema = t.extend(\n jobExecutions.schema,\n {},\n {\n title: \"JobExecutionResource\",\n description:\n \"A job execution resource representing the execution details of a job.\",\n },\n);\n\nexport type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const triggerJobSchema = t.object({\n name: t.string(),\n});\n\nexport type TriggerJob = Static<typeof triggerJobSchema>;\n","import { $env, $inject, Alepha, type Async, type Static, t } from \"alepha\";\nimport { type DateTime, DateTimeProvider } from \"alepha/datetime\";\nimport { $lock, type LockPrimitive } from \"alepha/lock\";\nimport type { LogEntry } from \"alepha/logger\";\nimport { $repository } from \"alepha/orm\";\nimport { CronProvider } from \"alepha/scheduler\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nconst envSchema = t.object({\n JOB_PREFIX: t.optional(\n t.text({\n description: \"Prefix for job lock keys\",\n }),\n ),\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\n/**\n * Provider for job management and execution.\n * Handles job lifecycle, execution tracking, log capturing, and event emission.\n */\nexport class JobProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly cronProvider = $inject(CronProvider);\n protected readonly executionRepository = $repository(jobExecutions);\n protected readonly env = $env(envSchema);\n protected readonly logs = new Map<string, LogEntry[]>();\n protected readonly jobs = new Map<string, JobRegistration>();\n\n /**\n * Register and set up a job for execution (called during primitive initialization).\n */\n public registerJob(options: Job): JobRegistration {\n const jobName = options.name;\n\n // Set up log capturing for this job (only once)\n if (this.jobs.size === 0) {\n this.alepha.events.on(\"log\", ({ entry }) => {\n const context = entry.context;\n if (!context) {\n return;\n }\n\n const entries = this.logs.get(context);\n if (!entries) {\n return;\n }\n\n entries.push(entry);\n this.logs.set(context, entries);\n });\n }\n\n // Create lock primitive if locking is enabled\n const lockPrimitive =\n options.lock !== false\n ? $lock({\n name: () => {\n const prefix = this.env.JOB_PREFIX\n ? `${this.env.JOB_PREFIX}:`\n : \"\";\n return `${prefix}job:${jobName}`;\n },\n handler: async () => {\n await this.executeJob(jobName, options.handler);\n },\n })\n : null;\n\n const registration: JobRegistration = {\n name: jobName,\n options,\n lockPrimitive,\n };\n\n this.jobs.set(jobName, registration);\n\n // Set up cron scheduling if provided\n if (options.cron) {\n this.cronProvider.createCronJob(jobName, options.cron, () =>\n this.triggerJob(jobName),\n );\n }\n\n return registration;\n }\n\n /**\n * Trigger a job by name.\n */\n public async triggerJob(jobName: string): Promise<void> {\n const registration = this.jobs.get(jobName);\n if (!registration) {\n throw new Error(`Job not registered: ${jobName}`);\n }\n\n // Execute handler with or without lock\n if (registration.options.lock !== false && registration.lockPrimitive) {\n await registration.lockPrimitive.run();\n } else {\n await this.executeJob(jobName, registration.options.handler);\n }\n }\n\n /**\n * Execute a job handler (called by the job primitive).\n */\n public async executeJob(\n jobName: string,\n handler: (args: { now: DateTime }) => Async<void>,\n ): Promise<void> {\n if (!this.alepha.isStarted()) {\n return;\n }\n\n const context = this.alepha.context.createContextId();\n\n await this.alepha.context.run(\n async () => {\n try {\n const now = this.dateTimeProvider.now();\n\n // Initialize log collection for this context\n this.logs.set(context, []);\n\n // Create execution record\n await this.executionRepository.create({\n job: jobName,\n status: \"STARTED\",\n });\n\n await this.alepha.events.emit(\"scheduler:begin\", {\n name: jobName,\n now,\n context,\n });\n\n // Execute the handler\n await handler({ now });\n\n // Update execution as completed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"COMPLETED\";\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:success\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n } catch (error) {\n // Update execution as failed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"FAILED\";\n exec.error = (error as Error).message;\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:error\",\n {\n name: jobName,\n error: error as Error,\n context,\n },\n {\n catch: true,\n },\n );\n\n // Don't re-throw, jobs should handle errors gracefully\n }\n\n // Clean up logs\n this.logs.delete(context);\n\n await this.alepha.events.emit(\n \"scheduler:end\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n },\n {\n context,\n },\n );\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface Job {\n /**\n * Name of the job.\n */\n name: string;\n\n /**\n * Optional description of the job.\n */\n description?: string;\n\n /**\n * Function to run on schedule.\n */\n handler: (args: { now: DateTime }) => Async<void>;\n\n /**\n * Cron expression to run the job.\n */\n cron?: string;\n\n /**\n * If true, the job will be locked and only one instance will run at a time.\n * You probably need to import {@link AlephaLockRedis} for distributed locking.\n *\n * @default true\n */\n lock?: boolean;\n\n /**\n * Optional prefix for job lock keys.\n */\n lockPrefix?: string;\n}\n\nexport interface JobRegistration {\n name: string;\n options: Job;\n lockPrimitive: LockPrimitive<() => Promise<void>> | null;\n}\n","import { $inject, createPrimitive, KIND, Primitive } from \"alepha\";\nimport type { DateTime } from \"alepha/datetime\";\nimport { type Job, JobProvider } from \"../providers/JobProvider.ts\";\n\n/**\n * Job primitive - a drop-in replacement for $scheduler with built-in execution tracking.\n */\nexport const $job = (options: JobPrimitiveOptions): JobPrimitive => {\n return createPrimitive(JobPrimitive, options);\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type JobPrimitiveOptions = Omit<Job, \"name\"> & {\n /**\n * Name of the job. Defaults to the primitive property name.\n */\n name?: string;\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class JobPrimitive extends Primitive<JobPrimitiveOptions> {\n protected readonly jobProvider = $inject(JobProvider);\n\n public get name(): string {\n return (\n this.options.name ??\n `${this.config.service.name}.${this.config.propertyKey}`\n );\n }\n\n protected onInit() {\n // Register job with JobProvider\n this.jobProvider.registerJob({\n ...this.options,\n name: this.name,\n });\n }\n\n public async trigger(): Promise<void> {\n await this.jobProvider.triggerJob(this.name);\n }\n}\n\n$job[KIND] = JobPrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface JobHandlerArguments {\n now: DateTime;\n}\n","import { $inject, Alepha } from \"alepha\";\nimport { $repository } from \"alepha/orm\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\nimport { $job } from \"../primitives/$job.ts\";\nimport type { JobExecutionQuery } from \"../schemas/jobExecutionQuerySchema.ts\";\n\nexport class JobService {\n protected readonly alepha = $inject(Alepha);\n protected readonly executionRepository = $repository(jobExecutions);\n\n public async getJobs(): Promise<string[]> {\n const jobPrimitives = this.alepha.primitives($job);\n return jobPrimitives.map((job) => job.name);\n }\n\n public async getJobExecutions(query: JobExecutionQuery = {}) {\n query.sort ??= \"-createdAt\";\n\n const where = this.executionRepository.createQueryWhere();\n\n if (query.job) {\n where.job = { eq: query.job };\n }\n\n if (query.status) {\n where.status = { eq: query.status };\n }\n\n return await this.executionRepository.paginate(\n query,\n { where },\n { count: true },\n );\n }\n\n public async triggerJob(name: string): Promise<{ ok: boolean }> {\n const jobPrimitives = this.alepha.primitives($job);\n const job = jobPrimitives.find((j) => j.name === name);\n\n if (!job) {\n throw new Error(`Job not found: ${name}`);\n }\n\n await job.trigger();\n return { ok: true };\n }\n}\n","import { $inject, t } from \"alepha\";\nimport { $action, okSchema } from \"alepha/server\";\nimport { jobExecutionQuerySchema } from \"../schemas/jobExecutionQuerySchema.ts\";\nimport { jobExecutionResourceSchema } from \"../schemas/jobExecutionResourceSchema.ts\";\nimport { triggerJobSchema } from \"../schemas/triggerJobSchema.ts\";\nimport { JobService } from \"../services/JobService.ts\";\n\nexport class JobController {\n protected readonly url: string = \"/jobs\";\n protected readonly group: string = \"jobs\";\n protected readonly jobService = $inject(JobService);\n\n public readonly getJobs = $action({\n path: this.url,\n group: this.group,\n schema: {\n response: t.array(t.string()),\n },\n handler: () => this.jobService.getJobs(),\n });\n\n public readonly getJobExecutions = $action({\n path: `${this.url}/executions`,\n group: this.group,\n schema: {\n query: jobExecutionQuerySchema,\n response: t.page(jobExecutionResourceSchema),\n },\n handler: ({ query }) => this.jobService.getJobExecutions(query),\n });\n\n public readonly triggerJob = $action({\n method: \"POST\",\n path: `${this.url}/trigger`,\n group: this.group,\n schema: {\n body: triggerJobSchema,\n response: okSchema,\n },\n handler: ({ body }) => this.jobService.triggerJob(body.name),\n });\n}\n","import { $module } from \"alepha\";\nimport { JobController } from \"./controllers/JobController.ts\";\nimport { JobProvider } from \"./providers/JobProvider.ts\";\nimport { JobService } from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./controllers/JobController.ts\";\nexport * from \"./entities/jobExecutions.ts\";\nexport * from \"./primitives/$job.ts\";\nexport * from \"./providers/JobProvider.ts\";\nexport * from \"./schemas/jobExecutionQuerySchema.ts\";\nexport * from \"./schemas/jobExecutionResourceSchema.ts\";\nexport * from \"./schemas/triggerJobSchema.ts\";\nexport * from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides job management API endpoints for Alepha applications.\n *\n * This module includes job queue operations, job status monitoring,\n * and background task management capabilities.\n *\n * @module alepha.api.jobs\n */\nexport const AlephaApiJobs = $module({\n name: \"alepha.api.jobs\",\n services: [JobController, JobProvider, JobService],\n});\n"],"mappings":";;;;;;;;;AAIA,MAAa,0BAA0B,EAAE,OAAO,iBAAiB;CAC/D,QAAQ,EAAE,SAAS,EAAE,KAAK;EAAC;EAAW;EAAU;EAAY,CAAC,CAAC;CAC9D,KAAK,EAAE,SACL,EAAE,KAAK,EACL,aAAa,sBACd,CAAC,CACH;CACF,CAAC;;;;ACPF,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,QAAQ,EAAE,OAAO;EACf,IAAI,GAAG,WAAW,EAAE,MAAM,CAAC;EAC3B,SAAS,GAAG,SAAS;EACrB,WAAW,GAAG,WAAW;EACzB,WAAW,GAAG,WAAW;EACzB,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC;EACpC,KAAK,EAAE,QAAQ;EACf,QAAQ,EAAE,KAAK;GAAC;GAAW;GAAU;GAAY,CAAC;EAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;EAC7B,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;EAC1C,CAAC;CACH,CAAC;;;;ACdF,MAAa,6BAA6B,EAAE,OAC1C,cAAc,QACd,EAAE,EACF;CACE,OAAO;CACP,aACE;CACH,CACF;;;;ACRD,MAAa,mBAAmB,EAAE,OAAO,EACvC,MAAM,EAAE,QAAQ,EACjB,CAAC;;;;ACGF,MAAM,YAAY,EAAE,OAAO,EACzB,YAAY,EAAE,SACZ,EAAE,KAAK,EACL,aAAa,4BACd,CAAC,CACH,EACF,CAAC;;;;;AAUF,IAAa,cAAb,MAAyB;CACvB,AAAmB,SAAS,QAAQ,OAAO;CAC3C,AAAmB,mBAAmB,QAAQ,iBAAiB;CAC/D,AAAmB,eAAe,QAAQ,aAAa;CACvD,AAAmB,sBAAsB,YAAY,cAAc;CACnE,AAAmB,MAAM,KAAK,UAA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