alepha 0.14.1 → 0.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/api/audits/index.browser.js +5 -5
- package/dist/api/audits/index.browser.js.map +1 -1
- package/dist/api/audits/index.d.ts +784 -784
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +13 -13
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.browser.js +5 -5
- package/dist/api/files/index.browser.js.map +1 -1
- package/dist/api/files/index.d.ts +57 -57
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +71 -71
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.browser.js +5 -5
- package/dist/api/jobs/index.browser.js.map +1 -1
- package/dist/api/jobs/index.d.ts +165 -165
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +10 -10
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/notifications/index.browser.js +10 -10
- package/dist/api/notifications/index.browser.js.map +1 -1
- package/dist/api/notifications/index.d.ts +583 -171
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js +12 -12
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/parameters/index.browser.js +163 -10
- package/dist/api/parameters/index.browser.js.map +1 -1
- package/dist/api/parameters/index.d.ts +281 -276
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/parameters/index.js +196 -91
- package/dist/api/parameters/index.js.map +1 -1
- package/dist/api/users/index.browser.js +19 -19
- package/dist/api/users/index.browser.js.map +1 -1
- package/dist/api/users/index.d.ts +778 -764
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +831 -596
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.browser.js +6 -6
- package/dist/api/verifications/index.browser.js.map +1 -1
- package/dist/api/verifications/index.d.ts +125 -125
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/api/verifications/index.js +6 -6
- package/dist/api/verifications/index.js.map +1 -1
- package/dist/batch/index.js.map +1 -1
- package/dist/bin/index.d.ts +1 -2
- package/dist/bin/index.js +0 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cli/index.d.ts +249 -218
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +951 -821
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +40 -0
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +97 -17
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +14 -18
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +29 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +21 -24
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +21 -24
- package/dist/core/index.native.js.map +1 -1
- package/dist/datetime/index.js.map +1 -1
- package/dist/fake/index.js +195 -168
- package/dist/fake/index.js.map +1 -1
- package/dist/file/index.d.ts +8 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +3 -0
- 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.d.ts.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 +146 -121
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +49 -24
- package/dist/orm/index.js.map +1 -1
- 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.d.ts +6 -6
- package/dist/scheduler/index.js.map +1 -1
- package/dist/security/index.d.ts +29 -29
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +171 -155
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +0 -1
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cache/index.js.map +1 -1
- package/dist/server/compress/index.d.ts.map +1 -1
- package/dist/server/compress/index.js +2 -0
- package/dist/server/compress/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.map +1 -1
- package/dist/server/core/index.js +1 -1
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/health/index.d.ts +17 -17
- package/dist/server/helmet/index.js.map +1 -1
- package/dist/server/links/index.browser.js +22 -6
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +46 -44
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +24 -41
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/multipart/index.js.map +1 -1
- package/dist/server/rate-limit/index.js.map +1 -1
- package/dist/server/security/index.js.map +1 -1
- package/dist/server/swagger/index.d.ts +2 -1
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js +8 -3
- 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/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +12 -4
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.browser.js.map +1 -1
- package/dist/websocket/index.js.map +1 -1
- package/package.json +7 -7
- package/src/api/audits/controllers/{AuditController.ts → AdminAuditController.ts} +5 -6
- package/src/api/audits/entities/audits.ts +5 -5
- package/src/api/audits/index.browser.ts +1 -1
- package/src/api/audits/index.ts +3 -3
- package/src/api/audits/primitives/$audit.spec.ts +276 -0
- package/src/api/audits/services/AuditService.spec.ts +495 -0
- package/src/api/files/__tests__/$bucket.spec.ts +91 -0
- package/src/api/files/controllers/AdminFileStatsController.spec.ts +166 -0
- package/src/api/files/controllers/{StorageStatsController.ts → AdminFileStatsController.ts} +2 -2
- package/src/api/files/controllers/FileController.spec.ts +558 -0
- package/src/api/files/controllers/FileController.ts +4 -5
- package/src/api/files/entities/files.ts +5 -5
- package/src/api/files/index.browser.ts +1 -1
- package/src/api/files/index.ts +4 -4
- package/src/api/files/jobs/FileJobs.spec.ts +52 -0
- package/src/api/files/services/FileService.spec.ts +109 -0
- package/src/api/jobs/__tests__/JobController.spec.ts +343 -0
- package/src/api/jobs/controllers/{JobController.ts → AdminJobController.ts} +2 -2
- package/src/api/jobs/entities/jobExecutions.ts +5 -5
- package/src/api/jobs/index.ts +3 -3
- package/src/api/jobs/primitives/$job.spec.ts +476 -0
- package/src/api/notifications/controllers/{NotificationController.ts → AdminNotificationController.ts} +4 -5
- package/src/api/notifications/entities/notifications.ts +5 -5
- package/src/api/notifications/index.browser.ts +1 -1
- package/src/api/notifications/index.ts +4 -4
- package/src/api/parameters/controllers/{ConfigController.ts → AdminConfigController.ts} +46 -107
- package/src/api/parameters/entities/parameters.ts +7 -17
- package/src/api/parameters/index.ts +3 -3
- package/src/api/parameters/primitives/$config.spec.ts +356 -0
- package/src/api/parameters/schemas/activateConfigBodySchema.ts +12 -0
- package/src/api/parameters/schemas/checkScheduledResponseSchema.ts +8 -0
- package/src/api/parameters/schemas/configCurrentResponseSchema.ts +13 -0
- package/src/api/parameters/schemas/configHistoryResponseSchema.ts +9 -0
- package/src/api/parameters/schemas/configNameParamSchema.ts +10 -0
- package/src/api/parameters/schemas/configNamesResponseSchema.ts +8 -0
- package/src/api/parameters/schemas/configTreeNodeSchema.ts +13 -0
- package/src/api/parameters/schemas/configVersionParamSchema.ts +9 -0
- package/src/api/parameters/schemas/configVersionResponseSchema.ts +9 -0
- package/src/api/parameters/schemas/configsByStatusResponseSchema.ts +9 -0
- package/src/api/parameters/schemas/createConfigVersionBodySchema.ts +24 -0
- package/src/api/parameters/schemas/index.ts +15 -0
- package/src/api/parameters/schemas/parameterResponseSchema.ts +26 -0
- package/src/api/parameters/schemas/parameterStatusSchema.ts +13 -0
- package/src/api/parameters/schemas/rollbackConfigBodySchema.ts +15 -0
- package/src/api/parameters/schemas/statusParamSchema.ts +9 -0
- package/src/api/users/__tests__/EmailVerification.spec.ts +369 -0
- package/src/api/users/__tests__/PasswordReset.spec.ts +550 -0
- package/src/api/users/controllers/AdminIdentityController.spec.ts +365 -0
- package/src/api/users/controllers/{IdentityController.ts → AdminIdentityController.ts} +3 -4
- package/src/api/users/controllers/AdminSessionController.spec.ts +274 -0
- package/src/api/users/controllers/{SessionController.ts → AdminSessionController.ts} +3 -4
- package/src/api/users/controllers/AdminUserController.spec.ts +372 -0
- package/src/api/users/controllers/AdminUserController.ts +116 -0
- package/src/api/users/controllers/UserController.ts +4 -107
- package/src/api/users/controllers/UserRealmController.ts +3 -0
- package/src/api/users/entities/identities.ts +6 -6
- package/src/api/users/entities/sessions.ts +6 -6
- package/src/api/users/entities/users.ts +9 -9
- package/src/api/users/index.ts +13 -6
- package/src/api/users/primitives/$userRealm.ts +13 -8
- package/src/api/users/services/CredentialService.spec.ts +509 -0
- package/src/api/users/services/CredentialService.ts +46 -0
- package/src/api/users/services/IdentityService.ts +15 -0
- package/src/api/users/services/RegistrationService.spec.ts +630 -0
- package/src/api/users/services/RegistrationService.ts +18 -0
- package/src/api/users/services/SessionService.spec.ts +301 -0
- package/src/api/users/services/SessionService.ts +110 -1
- package/src/api/users/services/UserService.ts +67 -2
- package/src/api/verifications/__tests__/CodeVerification.spec.ts +318 -0
- package/src/api/verifications/__tests__/LinkVerification.spec.ts +279 -0
- package/src/api/verifications/entities/verifications.ts +6 -6
- package/src/api/verifications/jobs/VerificationJobs.spec.ts +50 -0
- package/src/batch/__tests__/startup-buffering.spec.ts +458 -0
- package/src/batch/primitives/$batch.spec.ts +766 -0
- package/src/batch/providers/BatchProvider.spec.ts +786 -0
- package/src/bin/index.ts +0 -1
- package/src/bucket/__tests__/shared.ts +194 -0
- package/src/bucket/primitives/$bucket.spec.ts +104 -0
- package/src/bucket/providers/FileStorageProvider.spec.ts +13 -0
- package/src/bucket/providers/LocalFileStorageProvider.spec.ts +77 -0
- package/src/bucket/providers/MemoryFileStorageProvider.spec.ts +82 -0
- package/src/cache/core/__tests__/shared.ts +377 -0
- package/src/cache/core/primitives/$cache.spec.ts +111 -0
- package/src/cache/redis/__tests__/cache-redis.spec.ts +70 -0
- package/src/cli/apps/AlephaCli.ts +54 -16
- package/src/cli/apps/AlephaPackageBuilderCli.ts +2 -1
- package/src/cli/assets/appRouterTs.ts +1 -1
- package/src/cli/commands/{ViteCommands.ts → build.ts} +2 -105
- package/src/cli/commands/clean.ts +14 -0
- package/src/cli/commands/{DrizzleCommands.ts → db.ts} +10 -117
- package/src/cli/commands/{DeployCommands.ts → deploy.ts} +1 -1
- package/src/cli/commands/dev.ts +69 -0
- package/src/cli/commands/format.ts +17 -0
- package/src/cli/commands/gen/changelog.spec.ts +315 -0
- package/src/cli/commands/{ChangelogCommands.ts → gen/changelog.ts} +16 -31
- package/src/cli/commands/gen/openapi.ts +71 -0
- package/src/cli/commands/gen.ts +18 -0
- package/src/cli/commands/{CoreCommands.ts → init.ts} +4 -40
- package/src/cli/commands/lint.ts +17 -0
- package/src/cli/commands/root.ts +41 -0
- package/src/cli/commands/run.ts +24 -0
- package/src/cli/commands/test.ts +42 -0
- package/src/cli/commands/typecheck.ts +24 -0
- package/src/cli/commands/{VerifyCommands.ts → verify.ts} +1 -13
- package/src/cli/defineConfig.ts +10 -1
- package/src/cli/index.ts +17 -7
- package/src/cli/services/AlephaCliUtils.ts +71 -32
- package/src/cli/services/GitMessageParser.ts +1 -1
- package/src/command/helpers/Asker.spec.ts +127 -0
- package/src/command/helpers/Runner.spec.ts +126 -0
- package/src/command/primitives/$command.spec.ts +1588 -0
- package/src/command/providers/CliProvider.ts +74 -24
- package/src/core/Alepha.ts +52 -4
- package/src/core/__tests__/Alepha-emit.spec.ts +22 -0
- package/src/core/__tests__/Alepha-graph.spec.ts +93 -0
- package/src/core/__tests__/Alepha-has.spec.ts +41 -0
- package/src/core/__tests__/Alepha-inject.spec.ts +93 -0
- package/src/core/__tests__/Alepha-register.spec.ts +81 -0
- package/src/core/__tests__/Alepha-start.spec.ts +176 -0
- package/src/core/__tests__/Alepha-with.spec.ts +14 -0
- package/src/core/__tests__/TypeBox-usecases.spec.ts +35 -0
- package/src/core/__tests__/TypeBoxLocale.spec.ts +15 -0
- package/src/core/__tests__/descriptor.spec.ts +34 -0
- package/src/core/__tests__/fixtures/A.ts +5 -0
- package/src/core/__tests__/pagination.spec.ts +77 -0
- package/src/core/helpers/jsonSchemaToTypeBox.ts +2 -2
- package/src/core/primitives/$atom.spec.ts +43 -0
- package/src/core/primitives/$hook.spec.ts +130 -0
- package/src/core/primitives/$inject.spec.ts +175 -0
- package/src/core/primitives/$module.spec.ts +115 -0
- package/src/core/providers/CodecManager.spec.ts +740 -0
- package/src/core/providers/EventManager.spec.ts +762 -0
- package/src/core/providers/EventManager.ts +4 -0
- package/src/core/providers/StateManager.spec.ts +365 -0
- package/src/core/providers/TypeProvider.spec.ts +1607 -0
- package/src/core/providers/TypeProvider.ts +20 -26
- package/src/datetime/primitives/$interval.spec.ts +103 -0
- package/src/datetime/providers/DateTimeProvider.spec.ts +86 -0
- package/src/email/primitives/$email.spec.ts +175 -0
- package/src/email/providers/LocalEmailProvider.spec.ts +341 -0
- package/src/fake/__tests__/keyName.example.ts +40 -0
- package/src/fake/__tests__/keyName.spec.ts +152 -0
- package/src/fake/__tests__/module.example.ts +32 -0
- package/src/fake/providers/FakeProvider.spec.ts +438 -0
- package/src/file/providers/FileSystemProvider.ts +8 -0
- package/src/file/providers/NodeFileSystemProvider.spec.ts +418 -0
- package/src/file/providers/NodeFileSystemProvider.ts +5 -0
- package/src/file/services/FileDetector.spec.ts +591 -0
- package/src/lock/core/__tests__/shared.ts +190 -0
- package/src/lock/core/providers/MemoryLockProvider.spec.ts +25 -0
- package/src/lock/redis/providers/RedisLockProvider.spec.ts +25 -0
- package/src/logger/__tests__/SimpleFormatterProvider.spec.ts +109 -0
- package/src/logger/primitives/$logger.spec.ts +108 -0
- package/src/logger/services/Logger.spec.ts +295 -0
- package/src/mcp/__tests__/errors.spec.ts +175 -0
- package/src/mcp/__tests__/integration.spec.ts +450 -0
- package/src/mcp/helpers/jsonrpc.spec.ts +380 -0
- package/src/mcp/primitives/$prompt.spec.ts +468 -0
- package/src/mcp/primitives/$resource.spec.ts +390 -0
- package/src/mcp/primitives/$tool.spec.ts +406 -0
- package/src/mcp/providers/McpServerProvider.spec.ts +797 -0
- package/src/orm/__tests__/$repository-crud.spec.ts +276 -0
- package/src/orm/__tests__/$repository-hooks.spec.ts +325 -0
- package/src/orm/__tests__/$repository-orderBy.spec.ts +128 -0
- package/src/orm/__tests__/$repository-pagination-sort.spec.ts +149 -0
- package/src/orm/__tests__/$repository-save.spec.ts +37 -0
- package/src/orm/__tests__/ModelBuilder-integration.spec.ts +490 -0
- package/src/orm/__tests__/ModelBuilder-types.spec.ts +186 -0
- package/src/orm/__tests__/PostgresProvider.spec.ts +46 -0
- package/src/orm/__tests__/delete-returning.spec.ts +256 -0
- package/src/orm/__tests__/deletedAt.spec.ts +80 -0
- package/src/orm/__tests__/enums.spec.ts +315 -0
- package/src/orm/__tests__/execute.spec.ts +72 -0
- package/src/orm/__tests__/fixtures/bigEntitySchema.ts +65 -0
- package/src/orm/__tests__/fixtures/userEntitySchema.ts +27 -0
- package/src/orm/__tests__/joins.spec.ts +1114 -0
- package/src/orm/__tests__/page.spec.ts +287 -0
- package/src/orm/__tests__/primaryKey.spec.ts +87 -0
- package/src/orm/__tests__/query-date-encoding.spec.ts +402 -0
- package/src/orm/__tests__/ref-auto-onDelete.spec.ts +156 -0
- package/src/orm/__tests__/references.spec.ts +102 -0
- package/src/orm/__tests__/security.spec.ts +710 -0
- package/src/orm/__tests__/sqlite.spec.ts +111 -0
- package/src/orm/__tests__/string-operators.spec.ts +429 -0
- package/src/orm/__tests__/timestamps.spec.ts +388 -0
- package/src/orm/__tests__/validation.spec.ts +183 -0
- package/src/orm/__tests__/version.spec.ts +64 -0
- package/src/orm/helpers/parseQueryString.spec.ts +196 -0
- package/src/orm/index.browser.ts +1 -1
- package/src/orm/index.ts +10 -6
- package/src/orm/primitives/$repository.spec.ts +137 -0
- package/src/orm/primitives/$sequence.spec.ts +29 -0
- package/src/orm/primitives/$transaction.spec.ts +82 -0
- package/src/orm/providers/{PostgresTypeProvider.ts → DatabaseTypeProvider.ts} +25 -3
- package/src/orm/providers/drivers/BunPostgresProvider.ts +3 -3
- package/src/orm/providers/drivers/BunSqliteProvider.ts +1 -1
- package/src/orm/providers/drivers/CloudflareD1Provider.ts +1 -1
- package/src/orm/providers/drivers/DatabaseProvider.ts +1 -1
- package/src/orm/providers/drivers/NodePostgresProvider.ts +3 -3
- package/src/orm/providers/drivers/NodeSqliteProvider.ts +1 -1
- package/src/orm/providers/drivers/PglitePostgresProvider.ts +2 -2
- package/src/orm/services/ModelBuilder.spec.ts +575 -0
- package/src/orm/services/Repository.spec.ts +137 -0
- package/src/queue/core/__tests__/shared.ts +143 -0
- package/src/queue/core/providers/MemoryQueueProvider.spec.ts +23 -0
- package/src/queue/core/providers/WorkerProvider.spec.ts +378 -0
- package/src/queue/redis/providers/RedisQueueProvider.spec.ts +23 -0
- package/src/redis/__tests__/redis.spec.ts +58 -0
- package/src/retry/primitives/$retry.spec.ts +234 -0
- package/src/retry/providers/RetryProvider.spec.ts +438 -0
- package/src/router/__tests__/match.spec.ts +252 -0
- package/src/router/providers/RouterProvider.spec.ts +197 -0
- package/src/scheduler/__tests__/$scheduler-cron.spec.ts +25 -0
- package/src/scheduler/__tests__/$scheduler-interval.spec.ts +25 -0
- package/src/scheduler/__tests__/shared.ts +77 -0
- package/src/security/__tests__/bug-1-wildcard-after-start.spec.ts +229 -0
- package/src/security/__tests__/bug-2-password-validation.spec.ts +245 -0
- package/src/security/__tests__/bug-3-regex-vulnerability.spec.ts +407 -0
- package/src/security/__tests__/bug-4-oauth2-validation.spec.ts +439 -0
- package/src/security/__tests__/multi-layer-permissions.spec.ts +522 -0
- package/src/security/primitives/$permission.spec.ts +30 -0
- package/src/security/primitives/$permission.ts +2 -2
- package/src/security/primitives/$realm.spec.ts +101 -0
- package/src/security/primitives/$role.spec.ts +52 -0
- package/src/security/primitives/$serviceAccount.spec.ts +61 -0
- package/src/security/providers/SecurityProvider.spec.ts +350 -0
- package/src/server/auth/providers/ServerAuthProvider.ts +0 -2
- package/src/server/cache/providers/ServerCacheProvider.spec.ts +942 -0
- package/src/server/compress/providers/ServerCompressProvider.spec.ts +31 -0
- package/src/server/compress/providers/ServerCompressProvider.ts +2 -0
- package/src/server/cookies/providers/ServerCookiesProvider.spec.ts +253 -0
- package/src/server/core/__tests__/ServerRouterProvider-getRoutes.spec.ts +334 -0
- package/src/server/core/__tests__/ServerRouterProvider-requestId.spec.ts +129 -0
- package/src/server/core/primitives/$action.spec.ts +191 -0
- package/src/server/core/primitives/$route.spec.ts +65 -0
- package/src/server/core/providers/ServerBodyParserProvider.spec.ts +93 -0
- package/src/server/core/providers/ServerLoggerProvider.spec.ts +100 -0
- package/src/server/core/providers/ServerProvider.ts +3 -1
- package/src/server/core/services/HttpClient.spec.ts +123 -0
- package/src/server/core/services/UserAgentParser.spec.ts +111 -0
- package/src/server/cors/providers/ServerCorsProvider.spec.ts +481 -0
- package/src/server/health/providers/ServerHealthProvider.spec.ts +22 -0
- package/src/server/helmet/providers/ServerHelmetProvider.spec.ts +105 -0
- package/src/server/links/__tests__/$action.spec.ts +238 -0
- package/src/server/links/__tests__/fixtures/CrudApp.ts +122 -0
- package/src/server/links/__tests__/requestId.spec.ts +120 -0
- package/src/server/links/primitives/$remote.spec.ts +228 -0
- package/src/server/links/providers/LinkProvider.spec.ts +54 -0
- package/src/server/links/providers/LinkProvider.ts +49 -3
- package/src/server/links/providers/ServerLinksProvider.ts +1 -53
- package/src/server/links/schemas/apiLinksResponseSchema.ts +7 -0
- package/src/server/metrics/providers/ServerMetricsProvider.spec.ts +25 -0
- package/src/server/multipart/providers/ServerMultipartProvider.spec.ts +528 -0
- package/src/server/proxy/primitives/$proxy.spec.ts +87 -0
- package/src/server/rate-limit/__tests__/ActionRateLimit.spec.ts +211 -0
- package/src/server/rate-limit/providers/ServerRateLimitProvider.spec.ts +344 -0
- package/src/server/security/__tests__/BasicAuth.spec.ts +684 -0
- package/src/server/security/__tests__/ServerSecurityProvider-realm.spec.ts +388 -0
- package/src/server/security/providers/ServerSecurityProvider.spec.ts +123 -0
- package/src/server/static/primitives/$serve.spec.ts +193 -0
- package/src/server/swagger/__tests__/ui.spec.ts +52 -0
- package/src/server/swagger/primitives/$swagger.spec.ts +193 -0
- package/src/server/swagger/providers/ServerSwaggerProvider.ts +18 -8
- package/src/sms/primitives/$sms.spec.ts +165 -0
- package/src/sms/providers/LocalSmsProvider.spec.ts +224 -0
- package/src/sms/providers/MemorySmsProvider.spec.ts +193 -0
- package/src/thread/primitives/$thread.spec.ts +186 -0
- package/src/topic/core/__tests__/shared.ts +144 -0
- package/src/topic/core/providers/MemoryTopicProvider.spec.ts +23 -0
- package/src/topic/redis/providers/RedisTopicProvider.spec.ts +23 -0
- package/src/vite/plugins/viteAlephaDev.ts +16 -4
- package/src/vite/tasks/runAlepha.ts +7 -1
- package/src/websocket/__tests__/$websocket-new.spec.ts +195 -0
- package/src/websocket/primitives/$channel.spec.ts +30 -0
- package/src/cli/commands/BiomeCommands.ts +0 -29
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { Alepha, type Env, type Service } from "alepha";
|
|
3
|
+
import { $cache, CacheProvider, MemoryCacheProvider } from "alepha/cache";
|
|
4
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
5
|
+
import { expect } from "vitest";
|
|
6
|
+
|
|
7
|
+
export class TestCache {
|
|
8
|
+
cursor_a = 0;
|
|
9
|
+
cursor_b = 0;
|
|
10
|
+
|
|
11
|
+
a = $cache({
|
|
12
|
+
key: (args) => args.name,
|
|
13
|
+
ttl: [5, "seconds"],
|
|
14
|
+
handler: async (user: { name: string }) => {
|
|
15
|
+
return `${user.name}:${this.cursor_a++}`;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
b = $cache({
|
|
20
|
+
provider: "memory",
|
|
21
|
+
key: (args) => args.name,
|
|
22
|
+
ttl: 0,
|
|
23
|
+
handler: async (user: { name: string }) => {
|
|
24
|
+
return `${user.name}:${this.cursor_b++}`;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const testCacheBasic = async (
|
|
30
|
+
env: Env = {},
|
|
31
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
32
|
+
): Promise<void> => {
|
|
33
|
+
const app = Alepha.create({
|
|
34
|
+
env,
|
|
35
|
+
}).with({
|
|
36
|
+
provide: CacheProvider,
|
|
37
|
+
use: cacheProvider,
|
|
38
|
+
});
|
|
39
|
+
const test = app.inject(TestCache);
|
|
40
|
+
const time = app.inject(DateTimeProvider);
|
|
41
|
+
await app.start();
|
|
42
|
+
|
|
43
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
44
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
45
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
46
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
47
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
48
|
+
|
|
49
|
+
if (!(app.inject(CacheProvider) instanceof MemoryCacheProvider)) {
|
|
50
|
+
return; // we can mock only MemoryCacheProvider
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await time.travel([2, "seconds"]);
|
|
54
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
55
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
56
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
57
|
+
|
|
58
|
+
await time.travel([4, "seconds"]);
|
|
59
|
+
expect(await test.a({ name: "A" })).toBe("A:2");
|
|
60
|
+
expect(await test.a({ name: "A" })).toBe("A:2");
|
|
61
|
+
expect(await test.a({ name: "B" })).toBe("B:3");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const testCacheStop = async (
|
|
65
|
+
env: Env = {},
|
|
66
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
67
|
+
): Promise<void> => {
|
|
68
|
+
const app = Alepha.create({
|
|
69
|
+
env,
|
|
70
|
+
}).with({
|
|
71
|
+
provide: CacheProvider,
|
|
72
|
+
use: cacheProvider,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const test = app.inject(TestCache);
|
|
76
|
+
await app.start();
|
|
77
|
+
await app.stop();
|
|
78
|
+
|
|
79
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
80
|
+
expect(await test.a({ name: "A" })).toBe("A:1");
|
|
81
|
+
expect(await test.a({ name: "A" })).toBe("A:2");
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const testCacheMissingProvider = async (
|
|
85
|
+
env: Env = {},
|
|
86
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
87
|
+
): Promise<void> => {
|
|
88
|
+
const app = Alepha.create({
|
|
89
|
+
env,
|
|
90
|
+
}).with({
|
|
91
|
+
provide: CacheProvider,
|
|
92
|
+
use: cacheProvider,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const test = app.inject(TestCache);
|
|
96
|
+
|
|
97
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
98
|
+
expect(await test.a({ name: "A" })).toBe("A:1");
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const testCacheDisabled = async (
|
|
102
|
+
env: Env = {},
|
|
103
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
104
|
+
): Promise<void> => {
|
|
105
|
+
const app = Alepha.create({
|
|
106
|
+
env: {
|
|
107
|
+
REDIS_CACHE_PREFIX: randomUUID(),
|
|
108
|
+
CACHE_ENABLED: false,
|
|
109
|
+
...env,
|
|
110
|
+
},
|
|
111
|
+
}).with({
|
|
112
|
+
provide: CacheProvider,
|
|
113
|
+
use: cacheProvider,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const test = app.inject(TestCache);
|
|
117
|
+
await app.start();
|
|
118
|
+
|
|
119
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
120
|
+
expect(await test.a({ name: "A" })).toBe("A:1");
|
|
121
|
+
expect(await test.a({ name: "B" })).toBe("B:2");
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const testCacheInvalidateByKey = async (
|
|
125
|
+
env: Env = {},
|
|
126
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
127
|
+
): Promise<void> => {
|
|
128
|
+
const app = Alepha.create({
|
|
129
|
+
env,
|
|
130
|
+
}).with({
|
|
131
|
+
provide: CacheProvider,
|
|
132
|
+
use: cacheProvider,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const test = app.inject(TestCache);
|
|
136
|
+
await app.start();
|
|
137
|
+
|
|
138
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
139
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
140
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
141
|
+
|
|
142
|
+
await test.a.invalidate("A");
|
|
143
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
144
|
+
expect(await test.a({ name: "A" })).toBe("A:2");
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const testCacheInvalidateByArgs = async (
|
|
148
|
+
env: Env = {},
|
|
149
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
150
|
+
): Promise<void> => {
|
|
151
|
+
const app = Alepha.create({
|
|
152
|
+
env,
|
|
153
|
+
}).with({
|
|
154
|
+
provide: CacheProvider,
|
|
155
|
+
use: cacheProvider,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const test = app.inject(TestCache);
|
|
159
|
+
await app.start();
|
|
160
|
+
|
|
161
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
162
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
163
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
164
|
+
|
|
165
|
+
await test.a.invalidate(test.a.key({ name: "A" }));
|
|
166
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
167
|
+
expect(await test.a({ name: "A" })).toBe("A:2");
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const testCacheInvalidateAll = async (
|
|
171
|
+
env: Env = {},
|
|
172
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
173
|
+
): Promise<void> => {
|
|
174
|
+
const app = Alepha.create({
|
|
175
|
+
env,
|
|
176
|
+
}).with({
|
|
177
|
+
provide: CacheProvider,
|
|
178
|
+
use: cacheProvider,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const test = app.inject(TestCache);
|
|
182
|
+
await app.start();
|
|
183
|
+
|
|
184
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
185
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
186
|
+
|
|
187
|
+
await test.a.invalidate();
|
|
188
|
+
expect(await test.a({ name: "A" })).toBe("A:1");
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const testCacheClear = async (
|
|
192
|
+
env: Env = {},
|
|
193
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
194
|
+
): Promise<void> => {
|
|
195
|
+
const app = Alepha.create({
|
|
196
|
+
env,
|
|
197
|
+
}).with({
|
|
198
|
+
provide: CacheProvider,
|
|
199
|
+
use: cacheProvider,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const test = app.inject(TestCache);
|
|
203
|
+
await app.start();
|
|
204
|
+
|
|
205
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
206
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
207
|
+
expect(await test.b({ name: "A" })).toBe("A:0");
|
|
208
|
+
expect(await test.b({ name: "A" })).toBe("A:0");
|
|
209
|
+
|
|
210
|
+
await Promise.all(app.primitives($cache).map((cache) => cache.invalidate()));
|
|
211
|
+
|
|
212
|
+
expect(await test.a({ name: "A" })).toBe("A:1");
|
|
213
|
+
expect(await test.b({ name: "A" })).toBe("A:1");
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export const testCacheReturnTypes = async (
|
|
217
|
+
env: Env = {},
|
|
218
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
219
|
+
): Promise<void> => {
|
|
220
|
+
class Types {
|
|
221
|
+
json = $cache({
|
|
222
|
+
handler: () => ({ a: 1 }),
|
|
223
|
+
});
|
|
224
|
+
int = $cache({
|
|
225
|
+
handler: () => 1,
|
|
226
|
+
});
|
|
227
|
+
bool = $cache({
|
|
228
|
+
handler: () => true,
|
|
229
|
+
});
|
|
230
|
+
string = $cache({
|
|
231
|
+
handler: () => '{ "a": 1 }',
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const app = Alepha.create({
|
|
236
|
+
env,
|
|
237
|
+
}).with({
|
|
238
|
+
provide: CacheProvider,
|
|
239
|
+
use: cacheProvider,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const test = app.inject(Types);
|
|
243
|
+
|
|
244
|
+
expect(await test.json()).toEqual({ a: 1 });
|
|
245
|
+
expect(await test.json()).toEqual({ a: 1 });
|
|
246
|
+
expect(await test.json()).toEqual({ a: 1 });
|
|
247
|
+
expect(await test.int()).toBe(1);
|
|
248
|
+
expect(await test.int()).toBe(1);
|
|
249
|
+
expect(await test.int()).toBe(1);
|
|
250
|
+
expect(await test.bool()).toBe(true);
|
|
251
|
+
expect(await test.bool()).toBe(true);
|
|
252
|
+
expect(await test.bool()).toBe(true);
|
|
253
|
+
expect(await test.string()).toBe('{ "a": 1 }');
|
|
254
|
+
expect(await test.string()).toBe('{ "a": 1 }');
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export const testCacheKeys = async (
|
|
258
|
+
env: Env = {},
|
|
259
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
260
|
+
) => {
|
|
261
|
+
const alepha = Alepha.create({
|
|
262
|
+
env,
|
|
263
|
+
}).with({
|
|
264
|
+
provide: CacheProvider,
|
|
265
|
+
use: cacheProvider,
|
|
266
|
+
});
|
|
267
|
+
class TestApp {
|
|
268
|
+
cache = $cache<string>();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const app = alepha.inject(TestApp);
|
|
272
|
+
const provider = alepha.inject(CacheProvider);
|
|
273
|
+
await alepha.start();
|
|
274
|
+
|
|
275
|
+
app.cache.set("test:A", "A");
|
|
276
|
+
app.cache.set("test:B", "B");
|
|
277
|
+
app.cache.set("hello", "C");
|
|
278
|
+
expect(await provider.keys("TestApp:cache").then((it) => it.length)).toEqual(
|
|
279
|
+
3,
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
await app.cache.invalidate("test:*");
|
|
283
|
+
expect(await provider.keys("TestApp:cache").then((it) => it.length)).toEqual(
|
|
284
|
+
1,
|
|
285
|
+
);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export const testSimpleKeyMappingHandler = async (
|
|
289
|
+
env: Env = {},
|
|
290
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
291
|
+
): Promise<void> => {
|
|
292
|
+
class App {
|
|
293
|
+
i = 0;
|
|
294
|
+
run = $cache({
|
|
295
|
+
key: (name: string) => name,
|
|
296
|
+
ttl: [5, "seconds"],
|
|
297
|
+
handler: async (name: string) => {
|
|
298
|
+
this.i++;
|
|
299
|
+
return `${name}=${this.i}`;
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
const alepha = Alepha.create({
|
|
304
|
+
env,
|
|
305
|
+
})
|
|
306
|
+
.with({
|
|
307
|
+
provide: CacheProvider,
|
|
308
|
+
use: cacheProvider,
|
|
309
|
+
})
|
|
310
|
+
.with(App);
|
|
311
|
+
|
|
312
|
+
await alepha.start();
|
|
313
|
+
const app = alepha.inject(App);
|
|
314
|
+
expect(await app.run("A")).toBe("A=1");
|
|
315
|
+
expect(await app.run("A")).toBe("A=1");
|
|
316
|
+
expect(await app.run("A")).toBe("A=1");
|
|
317
|
+
expect(await app.run("A")).toBe("A=1");
|
|
318
|
+
expect(await app.run("B")).toBe("B=2");
|
|
319
|
+
expect(await app.run("B")).toBe("B=2");
|
|
320
|
+
expect(await app.run("B")).toBe("B=2");
|
|
321
|
+
expect(await app.run("C")).toBe("C=3");
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export const testCacheProviderClear = async (
|
|
325
|
+
env: Env = {},
|
|
326
|
+
cacheProvider: Service<CacheProvider> = MemoryCacheProvider,
|
|
327
|
+
): Promise<void> => {
|
|
328
|
+
class TestClearCache {
|
|
329
|
+
cursor_a = 0;
|
|
330
|
+
cursor_b = 0;
|
|
331
|
+
|
|
332
|
+
a = $cache({
|
|
333
|
+
key: (args) => args.name,
|
|
334
|
+
ttl: [5, "seconds"],
|
|
335
|
+
handler: async (user: { name: string }) => {
|
|
336
|
+
return `${user.name}:${this.cursor_a++}`;
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
b = $cache({
|
|
341
|
+
key: (args) => args.name,
|
|
342
|
+
handler: async (user: { name: string }) => {
|
|
343
|
+
return `${user.name}:${this.cursor_b++}`;
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const app = Alepha.create({
|
|
349
|
+
env,
|
|
350
|
+
}).with({
|
|
351
|
+
provide: CacheProvider,
|
|
352
|
+
use: cacheProvider,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const test = app.inject(TestClearCache);
|
|
356
|
+
const provider = app.inject(CacheProvider);
|
|
357
|
+
await app.start();
|
|
358
|
+
|
|
359
|
+
// Set some cache values
|
|
360
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
361
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
362
|
+
expect(await test.a({ name: "B" })).toBe("B:1");
|
|
363
|
+
expect(await test.b({ name: "C" })).toBe("C:0");
|
|
364
|
+
expect(await test.b({ name: "C" })).toBe("C:0");
|
|
365
|
+
|
|
366
|
+
// Verify cache is working
|
|
367
|
+
expect(await test.a({ name: "A" })).toBe("A:0");
|
|
368
|
+
expect(await test.b({ name: "C" })).toBe("C:0");
|
|
369
|
+
|
|
370
|
+
// Clear all cache
|
|
371
|
+
await provider.clear();
|
|
372
|
+
|
|
373
|
+
// Verify cache was cleared - new values should be generated
|
|
374
|
+
expect(await test.a({ name: "A" })).toBe("A:2");
|
|
375
|
+
expect(await test.a({ name: "B" })).toBe("B:3");
|
|
376
|
+
expect(await test.b({ name: "C" })).toBe("C:1");
|
|
377
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { Alepha } from "alepha";
|
|
3
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import {
|
|
6
|
+
TestCache,
|
|
7
|
+
testCacheBasic,
|
|
8
|
+
testCacheClear,
|
|
9
|
+
testCacheDisabled,
|
|
10
|
+
testCacheInvalidateAll,
|
|
11
|
+
testCacheInvalidateByArgs,
|
|
12
|
+
testCacheInvalidateByKey,
|
|
13
|
+
testCacheKeys,
|
|
14
|
+
testCacheMissingProvider,
|
|
15
|
+
testCacheProviderClear,
|
|
16
|
+
testCacheReturnTypes,
|
|
17
|
+
testCacheStop,
|
|
18
|
+
testSimpleKeyMappingHandler,
|
|
19
|
+
} from "../__tests__/shared.ts";
|
|
20
|
+
import { $cache, MemoryCacheProvider } from "../index.ts";
|
|
21
|
+
|
|
22
|
+
describe("$cache", () => {
|
|
23
|
+
it("should handle basic caching", async () => {
|
|
24
|
+
await testCacheBasic();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should handle stop lifecycle", async () => {
|
|
28
|
+
await testCacheStop();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should handle missing provider", async () => {
|
|
32
|
+
await testCacheMissingProvider();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should handle disabled cache", async () => {
|
|
36
|
+
await testCacheDisabled();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should invalidate by key", async () => {
|
|
40
|
+
await testCacheInvalidateByKey();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should invalidate by args", async () => {
|
|
44
|
+
await testCacheInvalidateByArgs();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should invalidate all entries", async () => {
|
|
48
|
+
await testCacheInvalidateAll();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should clear cache", async () => {
|
|
52
|
+
await testCacheClear();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should handle different return types", async () => {
|
|
56
|
+
await testCacheReturnTypes();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should generate cache keys correctly", async () => {
|
|
60
|
+
await testCacheKeys();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should handle infinite TTL", async () => {
|
|
64
|
+
const app = Alepha.create({ env: { REDIS_CACHE_PREFIX: randomUUID() } });
|
|
65
|
+
const test = app.inject(TestCache);
|
|
66
|
+
const time = app.inject(DateTimeProvider);
|
|
67
|
+
await app.start();
|
|
68
|
+
|
|
69
|
+
expect(await test.b({ name: "A" })).toBe("A:0");
|
|
70
|
+
expect(await test.b({ name: "A" })).toBe("A:0");
|
|
71
|
+
await time.travel([1, "day"]);
|
|
72
|
+
expect(await test.b({ name: "A" })).toBe("A:0");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should handle unique key without args", async () => {
|
|
76
|
+
let count = 0;
|
|
77
|
+
class A {
|
|
78
|
+
task = $cache({
|
|
79
|
+
handler: () => {
|
|
80
|
+
count++;
|
|
81
|
+
return "DONE";
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const app = Alepha.create();
|
|
86
|
+
const test = app.inject(A);
|
|
87
|
+
await app.start();
|
|
88
|
+
|
|
89
|
+
expect(await test.task()).toBe("DONE");
|
|
90
|
+
expect(await test.task()).toBe("DONE");
|
|
91
|
+
expect(await test.task()).toBe("DONE");
|
|
92
|
+
expect(count).toBe(1);
|
|
93
|
+
|
|
94
|
+
await test.task.invalidate();
|
|
95
|
+
expect(await test.task()).toBe("DONE");
|
|
96
|
+
expect(await test.task()).toBe("DONE");
|
|
97
|
+
expect(count).toBe(2);
|
|
98
|
+
|
|
99
|
+
// [] means no args, it's JSON.stringify([])
|
|
100
|
+
const obj = await app.inject(MemoryCacheProvider).get("A:task", "[]");
|
|
101
|
+
expect(new TextDecoder().decode(obj?.slice(1))).toEqual("DONE");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should handle unique key with args", async () => {
|
|
105
|
+
await testSimpleKeyMappingHandler();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should clear provider cache", async () => {
|
|
109
|
+
await testCacheProviderClear();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { describe, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
testCacheBasic,
|
|
5
|
+
testCacheClear,
|
|
6
|
+
testCacheDisabled,
|
|
7
|
+
testCacheInvalidateAll,
|
|
8
|
+
testCacheInvalidateByArgs,
|
|
9
|
+
testCacheInvalidateByKey,
|
|
10
|
+
testCacheKeys,
|
|
11
|
+
testCacheMissingProvider,
|
|
12
|
+
testCacheProviderClear,
|
|
13
|
+
testCacheReturnTypes,
|
|
14
|
+
testCacheStop,
|
|
15
|
+
testSimpleKeyMappingHandler,
|
|
16
|
+
} from "../../core/__tests__/shared.ts";
|
|
17
|
+
import { RedisCacheProvider } from "../index.ts";
|
|
18
|
+
|
|
19
|
+
const provider = RedisCacheProvider;
|
|
20
|
+
const env = () => ({ REDIS_CACHE_PREFIX: randomUUID() });
|
|
21
|
+
|
|
22
|
+
describe("$cache - redis", () => {
|
|
23
|
+
it("should handle basic caching", async () => {
|
|
24
|
+
await testCacheBasic(env(), provider);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should handle stop lifecycle", async () => {
|
|
28
|
+
await testCacheStop(env(), provider);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should handle missing provider", async () => {
|
|
32
|
+
await testCacheMissingProvider(env(), provider);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should handle disabled cache", async () => {
|
|
36
|
+
await testCacheDisabled(env(), provider);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should invalidate by key", async () => {
|
|
40
|
+
await testCacheInvalidateByKey(env(), provider);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should invalidate by args", async () => {
|
|
44
|
+
await testCacheInvalidateByArgs(env(), provider);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should invalidate all entries", async () => {
|
|
48
|
+
await testCacheInvalidateAll(env(), provider);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should clear cache", async () => {
|
|
52
|
+
await testCacheClear(env(), provider);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should handle different return types", async () => {
|
|
56
|
+
await testCacheReturnTypes(env(), provider);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should generate cache keys correctly", async () => {
|
|
60
|
+
await testCacheKeys(env(), provider);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should handle unique key with args", async () => {
|
|
64
|
+
await testSimpleKeyMappingHandler();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should clear provider cache", async () => {
|
|
68
|
+
await testCacheProviderClear(env(), provider);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -1,13 +1,39 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { $hook, $inject, $module, Alepha } from "alepha";
|
|
3
2
|
import { FileSystemProvider } from "alepha/file";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
3
|
+
import { BuildCommand } from "../commands/build.ts";
|
|
4
|
+
import { CleanCommand } from "../commands/clean.ts";
|
|
5
|
+
import { DbCommand } from "../commands/db.ts";
|
|
6
|
+
import { DeployCommand } from "../commands/deploy.ts";
|
|
7
|
+
import { DevCommand } from "../commands/dev.ts";
|
|
8
|
+
import { FormatCommand } from "../commands/format.ts";
|
|
9
|
+
import { GitProvider } from "../commands/gen/changelog.ts";
|
|
10
|
+
import { GenCommand } from "../commands/gen.ts";
|
|
11
|
+
import { InitCommand } from "../commands/init.ts";
|
|
12
|
+
import { LintCommand } from "../commands/lint.ts";
|
|
13
|
+
import { RootCommand } from "../commands/root.ts";
|
|
14
|
+
import { RunCommand } from "../commands/run.ts";
|
|
15
|
+
import { TestCommand } from "../commands/test.ts";
|
|
16
|
+
import { TypecheckCommand } from "../commands/typecheck.ts";
|
|
17
|
+
import { VerifyCommand } from "../commands/verify.ts";
|
|
18
|
+
|
|
19
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Register `tsx` when running in Node.js, ignore for Bun.
|
|
23
|
+
*
|
|
24
|
+
* It's required to have a full TypeScript support. (mostly .tsx files)
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
if (typeof Bun === "undefined") {
|
|
28
|
+
const { register } = await import("tsx/esm/api");
|
|
29
|
+
register();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Allow to extend Alepha CLI via `alepha.config.ts` file located in the project root.
|
|
36
|
+
*/
|
|
11
37
|
|
|
12
38
|
class AlephaCliExtension {
|
|
13
39
|
protected readonly alepha = $inject(Alepha);
|
|
@@ -17,7 +43,7 @@ class AlephaCliExtension {
|
|
|
17
43
|
on: "configure",
|
|
18
44
|
handler: async () => {
|
|
19
45
|
const root = process.cwd();
|
|
20
|
-
const extensionPath = join(root, "alepha.config.ts");
|
|
46
|
+
const extensionPath = this.fs.join(root, "alepha.config.ts");
|
|
21
47
|
const hasExtension = await this.fs.exists(extensionPath);
|
|
22
48
|
if (!hasExtension) {
|
|
23
49
|
return;
|
|
@@ -36,16 +62,28 @@ class AlephaCliExtension {
|
|
|
36
62
|
});
|
|
37
63
|
}
|
|
38
64
|
|
|
65
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
66
|
+
|
|
39
67
|
export const AlephaCli = $module({
|
|
40
68
|
name: "alepha.cli",
|
|
41
69
|
services: [
|
|
42
70
|
AlephaCliExtension,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
// Commands (one per file)
|
|
72
|
+
BuildCommand,
|
|
73
|
+
CleanCommand,
|
|
74
|
+
DbCommand,
|
|
75
|
+
DeployCommand,
|
|
76
|
+
DevCommand,
|
|
77
|
+
FormatCommand,
|
|
78
|
+
InitCommand,
|
|
79
|
+
LintCommand,
|
|
80
|
+
RootCommand,
|
|
81
|
+
RunCommand,
|
|
82
|
+
TestCommand,
|
|
83
|
+
TypecheckCommand,
|
|
84
|
+
VerifyCommand,
|
|
85
|
+
GenCommand,
|
|
86
|
+
// Support services
|
|
87
|
+
GitProvider,
|
|
50
88
|
],
|
|
51
89
|
});
|
|
@@ -66,7 +66,8 @@ export class AlephaPackageBuilderCli {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (packageName === "@alepha/ui") {
|
|
69
|
-
pkgData.exports["./styles"] = "./styles.css";
|
|
69
|
+
pkgData.exports["./styles"] = "./src/core/styles.css";
|
|
70
|
+
pkgData.exports["./json/styles"] = "./src/json/styles.css";
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
await this.fs.writeFile("package.json", JSON.stringify(pkgData, null, 2));
|