alepha 0.14.0 → 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.
- package/README.md +3 -3
- package/dist/api/audits/index.d.ts +80 -1
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.d.ts +80 -1
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.d.ts +236 -157
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/notifications/index.d.ts +21 -1
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/parameters/index.d.ts +451 -4
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/parameters/index.js.map +1 -1
- package/dist/api/users/index.d.ts +252 -249
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +4 -0
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.d.ts +128 -128
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/batch/index.js.map +1 -1
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cli/index.d.ts +304 -115
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +650 -531
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +210 -13
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +306 -69
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +7 -6
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +7 -6
- package/dist/core/index.native.js.map +1 -1
- package/dist/datetime/index.js.map +1 -1
- package/dist/fake/index.js.map +1 -1
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js.map +1 -1
- package/dist/lock/redis/index.js.map +1 -1
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/index.browser.js +26 -5
- package/dist/orm/index.browser.js.map +1 -1
- package/dist/orm/index.d.ts +294 -215
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +522 -523
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/redis/index.js +2 -4
- package/dist/queue/redis/index.js.map +1 -1
- package/dist/redis/index.d.ts +400 -29
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +412 -21
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.js.map +1 -1
- package/dist/router/index.js.map +1 -1
- package/dist/scheduler/index.js.map +1 -1
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +155 -155
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cache/index.js.map +1 -1
- package/dist/server/cookies/index.browser.js.map +1 -1
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.browser.js.map +1 -1
- package/dist/server/core/index.d.ts +0 -1
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/helmet/index.d.ts +4 -1
- package/dist/server/helmet/index.d.ts.map +1 -1
- package/dist/server/helmet/index.js.map +1 -1
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/multipart/index.d.ts.map +1 -1
- package/dist/server/multipart/index.js.map +1 -1
- package/dist/server/proxy/index.js.map +1 -1
- package/dist/server/rate-limit/index.js.map +1 -1
- package/dist/server/security/index.d.ts +9 -9
- package/dist/server/security/index.js.map +1 -1
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/thread/index.js.map +1 -1
- package/dist/topic/core/index.js.map +1 -1
- package/dist/topic/redis/index.js +3 -3
- package/dist/topic/redis/index.js.map +1 -1
- package/dist/vite/index.js +9 -6
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.browser.js.map +1 -1
- package/dist/websocket/index.d.ts +7 -7
- package/dist/websocket/index.js.map +1 -1
- package/package.json +3 -3
- package/src/api/users/index.ts +4 -0
- package/src/cli/apps/AlephaCli.ts +36 -14
- package/src/cli/apps/AlephaPackageBuilderCli.ts +5 -1
- package/src/cli/assets/appRouterTs.ts +1 -1
- package/src/cli/atoms/changelogOptions.ts +45 -0
- package/src/cli/commands/{ViteCommands.ts → build.ts} +4 -93
- package/src/cli/commands/changelog.ts +244 -0
- package/src/cli/commands/clean.ts +14 -0
- package/src/cli/commands/{DrizzleCommands.ts → db.ts} +37 -124
- package/src/cli/commands/deploy.ts +118 -0
- package/src/cli/commands/dev.ts +57 -0
- package/src/cli/commands/format.ts +17 -0
- package/src/cli/commands/{CoreCommands.ts → init.ts} +2 -40
- package/src/cli/commands/lint.ts +17 -0
- package/src/cli/commands/root.ts +32 -0
- package/src/cli/commands/run.ts +24 -0
- package/src/cli/commands/test.ts +42 -0
- package/src/cli/commands/typecheck.ts +19 -0
- package/src/cli/commands/{VerifyCommands.ts → verify.ts} +1 -13
- package/src/cli/defineConfig.ts +24 -0
- package/src/cli/index.ts +17 -5
- package/src/cli/services/AlephaCliUtils.ts +4 -21
- package/src/cli/services/GitMessageParser.ts +77 -0
- package/src/command/helpers/EnvUtils.ts +37 -0
- package/src/command/index.ts +3 -1
- package/src/command/primitives/$command.ts +172 -6
- package/src/command/providers/CliProvider.ts +424 -91
- package/src/core/Alepha.ts +8 -5
- package/src/file/providers/NodeFileSystemProvider.ts +3 -1
- package/src/orm/index.browser.ts +1 -1
- package/src/orm/index.ts +18 -10
- package/src/orm/interfaces/PgQueryWhere.ts +1 -26
- package/src/orm/providers/{PostgresTypeProvider.ts → DatabaseTypeProvider.ts} +25 -3
- package/src/orm/providers/drivers/BunPostgresProvider.ts +225 -0
- package/src/orm/providers/drivers/BunSqliteProvider.ts +180 -0
- package/src/orm/providers/drivers/DatabaseProvider.ts +25 -0
- package/src/orm/providers/drivers/NodePostgresProvider.ts +0 -25
- package/src/orm/services/QueryManager.ts +10 -125
- package/src/queue/redis/providers/RedisQueueProvider.ts +2 -7
- package/src/redis/index.ts +65 -3
- package/src/redis/providers/BunRedisProvider.ts +304 -0
- package/src/redis/providers/BunRedisSubscriberProvider.ts +94 -0
- package/src/redis/providers/NodeRedisProvider.ts +280 -0
- package/src/redis/providers/NodeRedisSubscriberProvider.ts +94 -0
- package/src/redis/providers/RedisProvider.ts +134 -140
- package/src/redis/providers/RedisSubscriberProvider.ts +58 -49
- package/src/server/core/providers/BunHttpServerProvider.ts +0 -3
- package/src/server/core/providers/ServerBodyParserProvider.ts +3 -1
- package/src/server/core/providers/ServerProvider.ts +7 -4
- package/src/server/multipart/providers/ServerMultipartProvider.ts +3 -1
- package/src/server/proxy/providers/ServerProxyProvider.ts +1 -1
- package/src/topic/redis/providers/RedisTopicProvider.ts +3 -3
- package/src/vite/tasks/buildServer.ts +1 -0
- package/src/cli/commands/BiomeCommands.ts +0 -29
- package/src/cli/commands/ChangelogCommands.ts +0 -389
- package/src/orm/services/PgJsonQueryManager.ts +0 -511
|
@@ -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,e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gB,UAAU,QAAQ;EAChC,MAAM,KAAK;EACX,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,sBAA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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"}
|
|
@@ -9,6 +9,7 @@ import * as alepha_logger0 from "alepha/logger";
|
|
|
9
9
|
import * as alepha_queue0 from "alepha/queue";
|
|
10
10
|
import { EmailProvider } from "alepha/email";
|
|
11
11
|
import { SmsProvider } from "alepha/sms";
|
|
12
|
+
import * as typebox0 from "typebox";
|
|
12
13
|
|
|
13
14
|
//#region ../../src/api/notifications/entities/notifications.d.ts
|
|
14
15
|
declare const notifications: alepha_orm66.EntityPrimitive<alepha133.TObject<{
|
|
@@ -158,7 +159,26 @@ declare class NotificationSenderService {
|
|
|
158
159
|
};
|
|
159
160
|
protected load(notification: NotificationEntity): {
|
|
160
161
|
template: NotificationPrimitive<alepha133.TObject<alepha133.TProperties>>;
|
|
161
|
-
variables:
|
|
162
|
+
variables: typebox0.StaticRecord<[], "Decode", {}, {
|
|
163
|
+
id: alepha_orm66.PgAttr<alepha_orm66.PgAttr<alepha133.TString, typeof alepha_orm66.PG_PRIMARY_KEY>, typeof alepha_orm66.PG_DEFAULT>;
|
|
164
|
+
version: alepha_orm66.PgAttr<alepha_orm66.PgAttr<alepha133.TInteger, typeof alepha_orm66.PG_VERSION>, typeof alepha_orm66.PG_DEFAULT>;
|
|
165
|
+
createdAt: alepha_orm66.PgAttr<alepha_orm66.PgAttr<alepha133.TString, typeof alepha_orm66.PG_CREATED_AT>, typeof alepha_orm66.PG_DEFAULT>;
|
|
166
|
+
updatedAt: alepha_orm66.PgAttr<alepha_orm66.PgAttr<alepha133.TString, typeof alepha_orm66.PG_UPDATED_AT>, typeof alepha_orm66.PG_DEFAULT>;
|
|
167
|
+
type: alepha133.TUnsafe<"email" | "sms">;
|
|
168
|
+
template: alepha133.TString;
|
|
169
|
+
category: alepha133.TOptional<alepha133.TString>;
|
|
170
|
+
critical: alepha133.TOptional<alepha133.TBoolean>;
|
|
171
|
+
sensitive: alepha133.TOptional<alepha133.TBoolean>;
|
|
172
|
+
contact: alepha133.TString;
|
|
173
|
+
variables: alepha133.TOptional<alepha133.TRecord<"^.*$", alepha133.TAny>>;
|
|
174
|
+
scheduledAt: alepha133.TOptional<alepha133.TString>;
|
|
175
|
+
sentAt: alepha133.TOptional<alepha133.TString>;
|
|
176
|
+
error: alepha133.TOptional<alepha133.TObject<{
|
|
177
|
+
at: alepha133.TString;
|
|
178
|
+
name: alepha133.TString;
|
|
179
|
+
message: alepha133.TString;
|
|
180
|
+
}>>;
|
|
181
|
+
}, "^.*$", alepha133.TAny>;
|
|
162
182
|
contact: string;
|
|
163
183
|
};
|
|
164
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/api/notifications/entities/notifications.ts","../../../src/api/notifications/schemas/notificationCreateSchema.ts","../../../src/api/notifications/schemas/notificationQuerySchema.ts","../../../src/api/notifications/primitives/$notification.ts","../../../src/api/notifications/services/NotificationSenderService.ts","../../../src/api/notifications/services/NotificationService.ts","../../../src/api/notifications/controllers/NotificationController.ts","../../../src/api/notifications/jobs/NotificationJobs.ts","../../../src/api/notifications/queues/NotificationQueues.ts","../../../src/api/notifications/schemas/notificationContactPreferencesSchema.ts","../../../src/api/notifications/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/api/notifications/entities/notifications.ts","../../../src/api/notifications/schemas/notificationCreateSchema.ts","../../../src/api/notifications/schemas/notificationQuerySchema.ts","../../../src/api/notifications/primitives/$notification.ts","../../../src/api/notifications/services/NotificationSenderService.ts","../../../src/api/notifications/services/NotificationService.ts","../../../src/api/notifications/controllers/NotificationController.ts","../../../src/api/notifications/jobs/NotificationJobs.ts","../../../src/api/notifications/queues/NotificationQueues.ts","../../../src/api/notifications/schemas/notificationContactPreferencesSchema.ts","../../../src/api/notifications/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAGa,eAAa,YAAA,CAAA,0BAAA;8CAiExB,SAAA,CAAA,OAAA;;;;;;;;;;;;EAjEW,MAAA,qBAiEX,mBAAA;EAAA,KAAA,qBAAA,kBAAA,CAAA;;;;;;KAEU,kBAAA,GAAqB,cAAc,aAAA,CAAc;;;cCnEhD,oCAAwB;QAKnC,SAAA,CAAA;;;;;KAEU,kBAAA,GAAqB,cAAc;;;cCNlC,mCAAuB;4BAMlC,SAAA,CAAA,QAAA;;;;;;;;;KAEU,iBAAA,GAAoB,cAAc;;;;;;;;;;;;;;;AFT9C;;;;;;;;;;;;;;;;cGoCa;aAA2B,kBAC7B,6BAA6B,KAAE,sBAAA;;;UAKzB,uCAAuC,iBAC9C,oBAAoB;;;;;;;oBAQV,oBAAoB;;UAE9B;;cAKG,gCAAgC,iBAAiB,UAC5D,6BAA6B;0CAES;;gBAMX,wBAAwB,KAAE;qBAU3B,QAAQ,6BAA6B;;UAShD,kCAAkC;aACtC,aAAa;;;UAIT,8BAA8B;UH3FrB;IAAA,OAAA,EAAA,MAAA;IAAA,IAAA,EAAA,MAAA,GAAA,CAAA,CAAA,SAAA,EG8FM,MH9FN,CG8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AAA,qBAMX,oBAAA;IAAA,OAAA,mBAAA;;;;;;;;;;wBG8DK,oBACF,QAAQ,KAAK;;;;4BAwCuB,qBAAqB;;;;cC1GjD,sBAAA;;;0CAG2B;;;;6CAKL;;gCALK,SAAA,CAAA,QAAA;;;;MNP3B,QAiEX,qBAAA,mBAAA;MAAA,OAAA,qBAAA,mBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;cOpEW,gBAAA;;;cCIA,kBAAA;gDACiC;gCAIT,aAAA,CAAA,yBAAA;oBAJS,SAAA,CAAA;;;;;cCHjC,gDAAoC;gCAG/C,SAAA,CAAA,OAAA;;;KAEU,8BAAA,GAAiC,cACpC;;;;;;;ATLT;;;;;;cUiCa,wBAAsB,SAAA,CAAA,QAsBjC,SAAA,CAtBiC,MAAA"}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import * as alepha317 from "alepha";
|
|
2
|
-
import { KIND, Primitive, Static, TObject } from "alepha";
|
|
2
|
+
import { KIND, Primitive, Static, TNull, TObject, TOptional, TSchema, TUnion } from "alepha";
|
|
3
3
|
import * as alepha_server0 from "alepha/server";
|
|
4
4
|
import { DateTimeProvider } from "alepha/datetime";
|
|
5
5
|
import * as alepha_logger0 from "alepha/logger";
|
|
6
6
|
import * as alepha_orm14 from "alepha/orm";
|
|
7
7
|
import * as alepha_topic0 from "alepha/topic";
|
|
8
8
|
import * as alepha_scheduler0 from "alepha/scheduler";
|
|
9
|
+
import "bun";
|
|
10
|
+
import "bun:sqlite";
|
|
11
|
+
import "drizzle-orm/bun-sql";
|
|
12
|
+
import "drizzle-orm/bun-sqlite";
|
|
13
|
+
import "drizzle-orm/d1";
|
|
14
|
+
import { BuildExtraConfigColumns, SQL } from "drizzle-orm";
|
|
15
|
+
import { PgColumnBuilderBase, PgSequenceOptions, PgTableExtraConfigValue, UpdateDeleteAction } from "drizzle-orm/pg-core";
|
|
16
|
+
import "alepha/retry";
|
|
17
|
+
import "alepha/lock";
|
|
18
|
+
import * as typebox0 from "typebox";
|
|
19
|
+
import "drizzle-orm/sqlite-core";
|
|
20
|
+
import "drizzle-orm/postgres-js";
|
|
21
|
+
import "postgres";
|
|
9
22
|
import { UserAccount } from "alepha/security";
|
|
10
23
|
|
|
11
24
|
//#region ../../src/api/parameters/entities/parameters.d.ts
|
|
@@ -92,6 +105,406 @@ declare const parameters: alepha_orm14.EntityPrimitive<alepha317.TObject<{
|
|
|
92
105
|
type Parameter = Static<typeof parameters.schema>;
|
|
93
106
|
type ParameterInsert = Omit<Parameter, "id" | "createdAt" | "updatedAt">;
|
|
94
107
|
//#endregion
|
|
108
|
+
//#region ../../src/orm/schemas/insertSchema.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* Transforms a TObject schema for insert operations.
|
|
111
|
+
* All default properties at the root level are made optional.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* Before: { name: string; age: number(default=0); }
|
|
115
|
+
* After: { name: string; age?: number; }
|
|
116
|
+
*/
|
|
117
|
+
type TObjectInsert<T extends TObject> = TObject<{ [K in keyof T["properties"]]: T["properties"][K] extends {
|
|
118
|
+
[PG_DEFAULT]: any;
|
|
119
|
+
} | {
|
|
120
|
+
"~optional": true;
|
|
121
|
+
} ? TOptional<T["properties"][K]> : T["properties"][K] }>;
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region ../../src/orm/schemas/updateSchema.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* Transforms a TObject schema for update operations.
|
|
126
|
+
* All optional properties at the root level are made nullable (i.e., `T | null`).
|
|
127
|
+
* This allows an API endpoint to explicitly accept `null` to clear an optional field in the database.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* Before: { name?: string; age: number; }
|
|
131
|
+
* After: { name?: string | null; age: number; }
|
|
132
|
+
*/
|
|
133
|
+
type TObjectUpdate<T extends TObject> = TObject<{ [K in keyof T["properties"]]: T["properties"][K] extends TOptional<infer U> ? TOptional<TUnion<[U, TNull]>> : T["properties"][K] }>;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region ../../src/orm/primitives/$entity.d.ts
|
|
136
|
+
interface EntityPrimitiveOptions<T extends TObject, Keys = keyof Static<T>> {
|
|
137
|
+
/**
|
|
138
|
+
* The database table name that will be created for this entity.
|
|
139
|
+
* If not provided, name will be inferred from the $repository variable name.
|
|
140
|
+
*/
|
|
141
|
+
name: string;
|
|
142
|
+
/**
|
|
143
|
+
* TypeBox schema defining the table structure and column types.
|
|
144
|
+
*/
|
|
145
|
+
schema: T;
|
|
146
|
+
/**
|
|
147
|
+
* Database indexes to create for query optimization.
|
|
148
|
+
*/
|
|
149
|
+
indexes?: (Keys | {
|
|
150
|
+
/**
|
|
151
|
+
* Single column to index.
|
|
152
|
+
*/
|
|
153
|
+
column: Keys;
|
|
154
|
+
/**
|
|
155
|
+
* Whether this should be a unique index (enforces uniqueness constraint).
|
|
156
|
+
*/
|
|
157
|
+
unique?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Custom name for the index. If not provided, generates name automatically.
|
|
160
|
+
*/
|
|
161
|
+
name?: string;
|
|
162
|
+
} | {
|
|
163
|
+
/**
|
|
164
|
+
* Multiple columns for composite index (order matters for query optimization).
|
|
165
|
+
*/
|
|
166
|
+
columns: Keys[];
|
|
167
|
+
/**
|
|
168
|
+
* Whether this should be a unique index (enforces uniqueness constraint).
|
|
169
|
+
*/
|
|
170
|
+
unique?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Custom name for the index. If not provided, generates name automatically.
|
|
173
|
+
*/
|
|
174
|
+
name?: string;
|
|
175
|
+
})[];
|
|
176
|
+
/**
|
|
177
|
+
* Foreign key constraints to maintain referential integrity.
|
|
178
|
+
*/
|
|
179
|
+
foreignKeys?: Array<{
|
|
180
|
+
/**
|
|
181
|
+
* Optional name for the foreign key constraint.
|
|
182
|
+
*/
|
|
183
|
+
name?: string;
|
|
184
|
+
/**
|
|
185
|
+
* Local columns that reference the foreign table.
|
|
186
|
+
*/
|
|
187
|
+
columns: Array<keyof Static<T>>;
|
|
188
|
+
/**
|
|
189
|
+
* Referenced columns in the foreign table.
|
|
190
|
+
* Must be EntityColumn references from other entities.
|
|
191
|
+
*/
|
|
192
|
+
foreignColumns: Array<() => EntityColumn<any>>;
|
|
193
|
+
}>;
|
|
194
|
+
/**
|
|
195
|
+
* Additional table constraints for data validation.
|
|
196
|
+
*
|
|
197
|
+
* Constraints enforce business rules at the database level, providing
|
|
198
|
+
* an additional layer of data integrity beyond application validation.
|
|
199
|
+
*
|
|
200
|
+
* **Constraint Types**:
|
|
201
|
+
* - **Unique constraints**: Prevent duplicate values across columns
|
|
202
|
+
* - **Check constraints**: Enforce custom validation rules with SQL expressions
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* constraints: [
|
|
207
|
+
* {
|
|
208
|
+
* name: "unique_user_email",
|
|
209
|
+
* columns: ["email"],
|
|
210
|
+
* unique: true
|
|
211
|
+
* },
|
|
212
|
+
* {
|
|
213
|
+
* name: "valid_age_range",
|
|
214
|
+
* columns: ["age"],
|
|
215
|
+
* check: sql`age >= 0 AND age <= 150`
|
|
216
|
+
* },
|
|
217
|
+
* {
|
|
218
|
+
* name: "unique_user_username_per_tenant",
|
|
219
|
+
* columns: ["tenantId", "username"],
|
|
220
|
+
* unique: true
|
|
221
|
+
* }
|
|
222
|
+
* ]
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
constraints?: Array<{
|
|
226
|
+
/**
|
|
227
|
+
* Columns involved in this constraint.
|
|
228
|
+
*/
|
|
229
|
+
columns: Array<keyof Static<T>>;
|
|
230
|
+
/**
|
|
231
|
+
* Optional name for the constraint.
|
|
232
|
+
*/
|
|
233
|
+
name?: string;
|
|
234
|
+
/**
|
|
235
|
+
* Whether this is a unique constraint.
|
|
236
|
+
*/
|
|
237
|
+
unique?: boolean | {};
|
|
238
|
+
/**
|
|
239
|
+
* SQL expression for check constraint validation.
|
|
240
|
+
*/
|
|
241
|
+
check?: SQL;
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* Advanced Drizzle ORM configuration for complex table setups.
|
|
245
|
+
*/
|
|
246
|
+
config?: (self: BuildExtraConfigColumns<string, FromSchema<T>, "pg">) => PgTableExtraConfigValue[];
|
|
247
|
+
}
|
|
248
|
+
declare class EntityPrimitive<T extends TObject = TObject> {
|
|
249
|
+
readonly options: EntityPrimitiveOptions<T>;
|
|
250
|
+
constructor(options: EntityPrimitiveOptions<T>);
|
|
251
|
+
alias(alias: string): this;
|
|
252
|
+
get cols(): EntityColumns<T>;
|
|
253
|
+
get name(): string;
|
|
254
|
+
get schema(): T;
|
|
255
|
+
get insertSchema(): TObjectInsert<T>;
|
|
256
|
+
get updateSchema(): TObjectUpdate<T>;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Convert a schema to columns.
|
|
260
|
+
*/
|
|
261
|
+
type FromSchema<T extends TObject> = { [key in keyof T["properties"]]: PgColumnBuilderBase };
|
|
262
|
+
type EntityColumn<T extends TObject> = {
|
|
263
|
+
name: string;
|
|
264
|
+
entity: EntityPrimitive<T>;
|
|
265
|
+
};
|
|
266
|
+
type EntityColumns<T extends TObject> = { [key in keyof T["properties"]]: EntityColumn<T> };
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region ../../src/orm/constants/PG_SYMBOLS.d.ts
|
|
269
|
+
declare const PG_DEFAULT: unique symbol;
|
|
270
|
+
declare const PG_PRIMARY_KEY: unique symbol;
|
|
271
|
+
declare const PG_CREATED_AT: unique symbol;
|
|
272
|
+
declare const PG_UPDATED_AT: unique symbol;
|
|
273
|
+
declare const PG_DELETED_AT: unique symbol;
|
|
274
|
+
declare const PG_VERSION: unique symbol;
|
|
275
|
+
declare const PG_IDENTITY: unique symbol;
|
|
276
|
+
declare const PG_ENUM: unique symbol;
|
|
277
|
+
declare const PG_REF: unique symbol;
|
|
278
|
+
/**
|
|
279
|
+
* @deprecated Use `PG_IDENTITY` instead.
|
|
280
|
+
*/
|
|
281
|
+
declare const PG_SERIAL: unique symbol;
|
|
282
|
+
type PgSymbols = {
|
|
283
|
+
[PG_DEFAULT]: {};
|
|
284
|
+
[PG_PRIMARY_KEY]: {};
|
|
285
|
+
[PG_CREATED_AT]: {};
|
|
286
|
+
[PG_UPDATED_AT]: {};
|
|
287
|
+
[PG_DELETED_AT]: {};
|
|
288
|
+
[PG_VERSION]: {};
|
|
289
|
+
[PG_IDENTITY]: PgIdentityOptions;
|
|
290
|
+
[PG_REF]: PgRefOptions;
|
|
291
|
+
[PG_ENUM]: PgEnumOptions;
|
|
292
|
+
/**
|
|
293
|
+
* @deprecated Use `PG_IDENTITY` instead.
|
|
294
|
+
*/
|
|
295
|
+
[PG_SERIAL]: {};
|
|
296
|
+
};
|
|
297
|
+
type PgSymbolKeys = keyof PgSymbols;
|
|
298
|
+
type PgIdentityOptions = {
|
|
299
|
+
mode: "always" | "byDefault";
|
|
300
|
+
} & PgSequenceOptions & {
|
|
301
|
+
name?: string;
|
|
302
|
+
};
|
|
303
|
+
interface PgEnumOptions {
|
|
304
|
+
name?: string;
|
|
305
|
+
description?: string;
|
|
306
|
+
}
|
|
307
|
+
interface PgRefOptions {
|
|
308
|
+
ref: () => {
|
|
309
|
+
name: string;
|
|
310
|
+
entity: EntityPrimitive;
|
|
311
|
+
};
|
|
312
|
+
actions?: {
|
|
313
|
+
onUpdate?: UpdateDeleteAction;
|
|
314
|
+
onDelete?: UpdateDeleteAction;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region ../../src/orm/helpers/pgAttr.d.ts
|
|
319
|
+
/**
|
|
320
|
+
* Type representation.
|
|
321
|
+
*/
|
|
322
|
+
type PgAttr<T extends TSchema, TAttr extends PgSymbolKeys> = T & { [K in TAttr]: PgSymbols[K] };
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region ../../src/orm/providers/drivers/BunPostgresProvider.d.ts
|
|
325
|
+
declare module "alepha" {
|
|
326
|
+
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
327
|
+
}
|
|
328
|
+
declare const envSchema$1: alepha317.TObject<{
|
|
329
|
+
/**
|
|
330
|
+
* Main configuration for database connection.
|
|
331
|
+
* Accept a string in the format of a Postgres connection URL.
|
|
332
|
+
* Example: postgres://user:password@localhost:5432/database
|
|
333
|
+
* or
|
|
334
|
+
* Example: postgres://user:password@localhost:5432/database?sslmode=require
|
|
335
|
+
*/
|
|
336
|
+
DATABASE_URL: alepha317.TOptional<alepha317.TString>;
|
|
337
|
+
/**
|
|
338
|
+
* In addition to the DATABASE_URL, you can specify the postgres schema name.
|
|
339
|
+
*/
|
|
340
|
+
POSTGRES_SCHEMA: alepha317.TOptional<alepha317.TString>;
|
|
341
|
+
}>;
|
|
342
|
+
/**
|
|
343
|
+
* Bun PostgreSQL provider using Drizzle ORM with Bun's native SQL client.
|
|
344
|
+
*
|
|
345
|
+
* This provider uses Bun's built-in SQL class for PostgreSQL connections,
|
|
346
|
+
* which provides excellent performance on the Bun runtime.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* // Set DATABASE_URL environment variable
|
|
351
|
+
* // DATABASE_URL=postgres://user:password@localhost:5432/database
|
|
352
|
+
*
|
|
353
|
+
* // Or configure programmatically
|
|
354
|
+
* alepha.with({
|
|
355
|
+
* provide: DatabaseProvider,
|
|
356
|
+
* use: BunPostgresProvider,
|
|
357
|
+
* });
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region ../../src/orm/providers/drivers/BunSqliteProvider.d.ts
|
|
362
|
+
/**
|
|
363
|
+
* Configuration options for the Bun SQLite database provider.
|
|
364
|
+
*/
|
|
365
|
+
declare const bunSqliteOptions: alepha317.Atom<alepha317.TObject<{
|
|
366
|
+
path: alepha317.TOptional<alepha317.TString>;
|
|
367
|
+
}>, "alepha.postgres.bun-sqlite.options">;
|
|
368
|
+
type BunSqliteProviderOptions = Static<typeof bunSqliteOptions.schema>;
|
|
369
|
+
declare module "alepha" {
|
|
370
|
+
interface State {
|
|
371
|
+
[bunSqliteOptions.key]: BunSqliteProviderOptions;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Bun SQLite provider using Drizzle ORM with Bun's native SQLite client.
|
|
376
|
+
*
|
|
377
|
+
* This provider uses Bun's built-in `bun:sqlite` for SQLite connections,
|
|
378
|
+
* which provides excellent performance on the Bun runtime.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```ts
|
|
382
|
+
* // Set DATABASE_URL environment variable
|
|
383
|
+
* // DATABASE_URL=sqlite://./my-database.db
|
|
384
|
+
*
|
|
385
|
+
* // Or configure programmatically
|
|
386
|
+
* alepha.with({
|
|
387
|
+
* provide: DatabaseProvider,
|
|
388
|
+
* use: BunSqliteProvider,
|
|
389
|
+
* });
|
|
390
|
+
*
|
|
391
|
+
* // Or use options atom
|
|
392
|
+
* alepha.store.mut(bunSqliteOptions, (old) => ({
|
|
393
|
+
* ...old,
|
|
394
|
+
* path: ":memory:",
|
|
395
|
+
* }));
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region ../../src/orm/providers/drivers/NodePostgresProvider.d.ts
|
|
400
|
+
declare module "alepha" {
|
|
401
|
+
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
402
|
+
}
|
|
403
|
+
declare const envSchema: alepha317.TObject<{
|
|
404
|
+
/**
|
|
405
|
+
* Main configuration for database connection.
|
|
406
|
+
* Accept a string in the format of a Postgres connection URL.
|
|
407
|
+
* Example: postgres://user:password@localhost:5432/database
|
|
408
|
+
* or
|
|
409
|
+
* Example: postgres://user:password@localhost:5432/database?sslmode=require
|
|
410
|
+
*/
|
|
411
|
+
DATABASE_URL: alepha317.TOptional<alepha317.TString>;
|
|
412
|
+
/**
|
|
413
|
+
* In addition to the DATABASE_URL, you can specify the postgres schema name.
|
|
414
|
+
*
|
|
415
|
+
* It will monkey patch drizzle tables.
|
|
416
|
+
*/
|
|
417
|
+
POSTGRES_SCHEMA: alepha317.TOptional<alepha317.TString>;
|
|
418
|
+
}>;
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region ../../src/orm/providers/drivers/NodeSqliteProvider.d.ts
|
|
421
|
+
/**
|
|
422
|
+
* Configuration options for the Node.js SQLite database provider.
|
|
423
|
+
*/
|
|
424
|
+
declare const nodeSqliteOptions: alepha317.Atom<alepha317.TObject<{
|
|
425
|
+
path: alepha317.TOptional<alepha317.TString>;
|
|
426
|
+
}>, "alepha.postgres.node-sqlite.options">;
|
|
427
|
+
type NodeSqliteProviderOptions = Static<typeof nodeSqliteOptions.schema>;
|
|
428
|
+
declare module "alepha" {
|
|
429
|
+
interface State {
|
|
430
|
+
[nodeSqliteOptions.key]: NodeSqliteProviderOptions;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Add a fake support for SQLite in Node.js based on Postgres interfaces.
|
|
435
|
+
*
|
|
436
|
+
* This is NOT a real SQLite provider, it's a workaround to use SQLite with Drizzle ORM.
|
|
437
|
+
* This is NOT recommended for production use.
|
|
438
|
+
*/
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region ../../src/orm/index.d.ts
|
|
441
|
+
declare module "alepha" {
|
|
442
|
+
interface Hooks {
|
|
443
|
+
/**
|
|
444
|
+
* Fires before creating an entity in the repository.
|
|
445
|
+
*/
|
|
446
|
+
"repository:create:before": {
|
|
447
|
+
tableName: string;
|
|
448
|
+
data: any;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* Fires after creating an entity in the repository.
|
|
452
|
+
*/
|
|
453
|
+
"repository:create:after": {
|
|
454
|
+
tableName: string;
|
|
455
|
+
data: any;
|
|
456
|
+
entity: any;
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* Fires before updating entities in the repository.
|
|
460
|
+
*/
|
|
461
|
+
"repository:update:before": {
|
|
462
|
+
tableName: string;
|
|
463
|
+
where: any;
|
|
464
|
+
data: any;
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* Fires after updating entities in the repository.
|
|
468
|
+
*/
|
|
469
|
+
"repository:update:after": {
|
|
470
|
+
tableName: string;
|
|
471
|
+
where: any;
|
|
472
|
+
data: any;
|
|
473
|
+
entities: any[];
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Fires before deleting entities from the repository.
|
|
477
|
+
*/
|
|
478
|
+
"repository:delete:before": {
|
|
479
|
+
tableName: string;
|
|
480
|
+
where: any;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Fires after deleting entities from the repository.
|
|
484
|
+
*/
|
|
485
|
+
"repository:delete:after": {
|
|
486
|
+
tableName: string;
|
|
487
|
+
where: any;
|
|
488
|
+
ids: Array<string | number>;
|
|
489
|
+
};
|
|
490
|
+
/**
|
|
491
|
+
* Fires before reading entities from the repository.
|
|
492
|
+
*/
|
|
493
|
+
"repository:read:before": {
|
|
494
|
+
tableName: string;
|
|
495
|
+
query: any;
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Fires after reading entities from the repository.
|
|
499
|
+
*/
|
|
500
|
+
"repository:read:after": {
|
|
501
|
+
tableName: string;
|
|
502
|
+
query: any;
|
|
503
|
+
entities: any[];
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
95
508
|
//#region ../../src/api/parameters/primitives/$config.d.ts
|
|
96
509
|
/**
|
|
97
510
|
* Creates a versioned configuration primitive for managing application settings.
|
|
@@ -182,7 +595,7 @@ declare class ConfigPrimitive<T extends TObject> extends Primitive<ConfigPrimiti
|
|
|
182
595
|
/**
|
|
183
596
|
* Get a specific field from the current configuration.
|
|
184
597
|
*/
|
|
185
|
-
get<Key extends keyof Static<T>>(key: Key): Static<T>[Key];
|
|
598
|
+
get<Key$1 extends keyof Static<T>>(key: Key$1): Static<T>[Key$1];
|
|
186
599
|
/**
|
|
187
600
|
* Set a new configuration value.
|
|
188
601
|
*
|
|
@@ -213,13 +626,47 @@ declare class ConfigPrimitive<T extends TObject> extends Primitive<ConfigPrimiti
|
|
|
213
626
|
tags?: string[] | undefined;
|
|
214
627
|
creatorId?: string | undefined;
|
|
215
628
|
creatorName?: string | undefined;
|
|
216
|
-
previousContent?:
|
|
629
|
+
previousContent?: typebox0.StaticRecord<[], "Decode", {}, {
|
|
630
|
+
id: PgAttr<PgAttr<alepha317.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
631
|
+
createdAt: PgAttr<PgAttr<alepha317.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
632
|
+
updatedAt: PgAttr<PgAttr<alepha317.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
633
|
+
name: alepha317.TString;
|
|
634
|
+
content: alepha317.TRecord<string, alepha317.TAny>;
|
|
635
|
+
schemaHash: alepha317.TString;
|
|
636
|
+
status: PgAttr<alepha317.TUnsafe<"expired" | "current" | "next" | "future">, typeof PG_DEFAULT>;
|
|
637
|
+
activationDate: alepha317.TString;
|
|
638
|
+
expiredAt: alepha317.TOptional<alepha317.TString>;
|
|
639
|
+
version: alepha317.TInteger;
|
|
640
|
+
changeDescription: alepha317.TOptional<alepha317.TString>;
|
|
641
|
+
tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
|
|
642
|
+
creatorId: alepha317.TOptional<alepha317.TString>;
|
|
643
|
+
creatorName: alepha317.TOptional<alepha317.TString>;
|
|
644
|
+
previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
|
|
645
|
+
migrationLog: alepha317.TOptional<alepha317.TString>;
|
|
646
|
+
}, string, alepha317.TAny> | undefined;
|
|
217
647
|
migrationLog?: string | undefined;
|
|
218
648
|
id: string;
|
|
219
649
|
createdAt: string;
|
|
220
650
|
updatedAt: string;
|
|
221
651
|
name: string;
|
|
222
|
-
content:
|
|
652
|
+
content: typebox0.StaticRecord<[], "Decode", {}, {
|
|
653
|
+
id: PgAttr<PgAttr<alepha317.TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
654
|
+
createdAt: PgAttr<PgAttr<alepha317.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
655
|
+
updatedAt: PgAttr<PgAttr<alepha317.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
656
|
+
name: alepha317.TString;
|
|
657
|
+
content: alepha317.TRecord<string, alepha317.TAny>;
|
|
658
|
+
schemaHash: alepha317.TString;
|
|
659
|
+
status: PgAttr<alepha317.TUnsafe<"expired" | "current" | "next" | "future">, typeof PG_DEFAULT>;
|
|
660
|
+
activationDate: alepha317.TString;
|
|
661
|
+
expiredAt: alepha317.TOptional<alepha317.TString>;
|
|
662
|
+
version: alepha317.TInteger;
|
|
663
|
+
changeDescription: alepha317.TOptional<alepha317.TString>;
|
|
664
|
+
tags: alepha317.TOptional<alepha317.TArray<alepha317.TString>>;
|
|
665
|
+
creatorId: alepha317.TOptional<alepha317.TString>;
|
|
666
|
+
creatorName: alepha317.TOptional<alepha317.TString>;
|
|
667
|
+
previousContent: alepha317.TOptional<alepha317.TRecord<string, alepha317.TAny>>;
|
|
668
|
+
migrationLog: alepha317.TOptional<alepha317.TString>;
|
|
669
|
+
}, string, alepha317.TAny>;
|
|
223
670
|
schemaHash: string;
|
|
224
671
|
status: "expired" | "current" | "next" | "future";
|
|
225
672
|
activationDate: string;
|