alepha 0.21.2 → 0.23.0
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 +0 -1
- package/dist/api/audits/index.browser.js.map +1 -1
- package/dist/api/audits/index.d.ts +393 -403
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +25 -56
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.browser.js +31 -1
- package/dist/api/files/index.browser.js.map +1 -1
- package/dist/api/files/index.d.ts +313 -208
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +152 -42
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.browser.js +2 -2
- package/dist/api/jobs/index.browser.js.map +1 -1
- package/dist/api/jobs/index.d.ts +282 -285
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +39 -33
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/keys/index.d.ts +217 -222
- package/dist/api/keys/index.d.ts.map +1 -1
- package/dist/api/keys/index.js.map +1 -1
- package/dist/api/notifications/index.browser.js.map +1 -1
- package/dist/api/notifications/index.d.ts +188 -195
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/oauth/index.d.ts +71 -76
- package/dist/api/oauth/index.d.ts.map +1 -1
- package/dist/api/oauth/index.js.map +1 -1
- package/dist/api/organizations/index.browser.js.map +1 -1
- package/dist/api/organizations/index.d.ts +104 -109
- package/dist/api/organizations/index.d.ts.map +1 -1
- package/dist/api/organizations/index.js.map +1 -1
- package/dist/api/parameters/index.browser.js +43 -16
- package/dist/api/parameters/index.browser.js.map +1 -1
- package/dist/api/parameters/index.d.ts +488 -344
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/parameters/index.js +175 -35
- package/dist/api/parameters/index.js.map +1 -1
- package/dist/api/payments/index.d.ts +396 -402
- package/dist/api/payments/index.d.ts.map +1 -1
- package/dist/api/payments/index.js.map +1 -1
- package/dist/api/subscriptions/index.d.ts +644 -652
- package/dist/api/subscriptions/index.d.ts.map +1 -1
- package/dist/api/subscriptions/index.js +1 -1
- package/dist/api/subscriptions/index.js.map +1 -1
- package/dist/api/users/index.browser.js +7 -0
- package/dist/api/users/index.browser.js.map +1 -1
- package/dist/api/users/index.d.ts +1106 -1005
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +307 -64
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.browser.js.map +1 -1
- package/dist/api/verifications/index.d.ts +137 -143
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/api/verifications/index.js.map +1 -1
- package/dist/background/index.d.ts +95 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +121 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/index.workerd.js +110 -0
- package/dist/background/index.workerd.js.map +1 -0
- package/dist/batch/index.d.ts +5 -7
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js.map +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/bucket/index.d.ts +76 -54
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/bucket/index.js +58 -11
- package/dist/bucket/index.js.map +1 -1
- package/dist/bucket/index.workerd.js +200 -5
- package/dist/bucket/index.workerd.js.map +1 -1
- package/dist/cache/core/index.d.ts +7 -10
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cache/core/index.workerd.js.map +1 -1
- package/dist/cache/database/index.d.ts +22 -26
- package/dist/cache/database/index.d.ts.map +1 -1
- package/dist/cache/database/index.js.map +1 -1
- package/dist/cache/redis/index.d.ts +4 -7
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cache/redis/index.js.map +1 -1
- package/dist/captcha/index.d.ts +3 -6
- package/dist/captcha/index.d.ts.map +1 -1
- package/dist/captcha/index.js.map +1 -1
- package/dist/cli/config/index.d.ts.map +1 -1
- package/dist/cli/config/index.js.map +1 -1
- package/dist/cli/core/index.d.ts +458 -249
- package/dist/cli/core/index.d.ts.map +1 -1
- package/dist/cli/core/index.js +372 -660
- package/dist/cli/core/index.js.map +1 -1
- package/dist/cli/devtools/index.d.ts +3 -5
- package/dist/cli/devtools/index.d.ts.map +1 -1
- package/dist/cli/devtools/index.js.map +1 -1
- package/dist/cli/i18n/index.d.ts +20 -17
- package/dist/cli/i18n/index.d.ts.map +1 -1
- package/dist/cli/i18n/index.js +45 -11
- package/dist/cli/i18n/index.js.map +1 -1
- package/dist/cli/platform/index.d.ts +126 -1342
- package/dist/cli/platform/index.d.ts.map +1 -1
- package/dist/cli/platform/index.js +136 -2374
- package/dist/cli/platform/index.js.map +1 -1
- package/dist/cli/platform-lib/index.d.ts +1472 -0
- package/dist/cli/platform-lib/index.d.ts.map +1 -0
- package/dist/cli/platform-lib/index.js +2660 -0
- package/dist/cli/platform-lib/index.js.map +1 -0
- package/dist/cli/vendor/index.d.ts +17 -21
- package/dist/cli/vendor/index.d.ts.map +1 -1
- package/dist/cli/vendor/index.js.map +1 -1
- package/dist/command/index.d.ts +20 -19
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +39 -10
- package/dist/command/index.js.map +1 -1
- package/dist/{containers → container}/core/index.d.ts +13 -15
- package/dist/container/core/index.d.ts.map +1 -0
- package/dist/{containers → container}/core/index.js +23 -14
- package/dist/container/core/index.js.map +1 -0
- package/dist/{containers → container}/core/index.workerd.js +37 -22
- package/dist/container/core/index.workerd.js.map +1 -0
- package/dist/core/index.browser.js +27 -1
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +48 -24
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +27 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +27 -1
- package/dist/core/index.native.js.map +1 -1
- package/dist/core/index.workerd.js +27 -1
- package/dist/core/index.workerd.js.map +1 -1
- package/dist/crypto/index.browser.js.map +1 -1
- package/dist/crypto/index.d.ts +5 -8
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js.map +1 -1
- package/dist/datetime/index.d.ts +3 -4
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/brevo/index.d.ts +2 -4
- package/dist/email/brevo/index.d.ts.map +1 -1
- package/dist/email/brevo/index.js.map +1 -1
- package/dist/email/cloudflare/index.d.ts +20 -7
- package/dist/email/cloudflare/index.d.ts.map +1 -1
- package/dist/email/cloudflare/index.js +46 -9
- package/dist/email/cloudflare/index.js.map +1 -1
- package/dist/email/core/index.d.ts +6 -9
- package/dist/email/core/index.d.ts.map +1 -1
- package/dist/email/core/index.js.map +1 -1
- package/dist/email/core/index.workerd.js.map +1 -1
- package/dist/email/smtp/index.d.ts +10 -13
- package/dist/email/smtp/index.d.ts.map +1 -1
- package/dist/email/smtp/index.js +107 -32
- package/dist/email/smtp/index.js.map +1 -1
- package/dist/fake/index.d.ts +1 -2
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/fake/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +9 -14
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/core/index.js.map +1 -1
- package/dist/lock/redis/index.d.ts +2 -4
- package/dist/lock/redis/index.d.ts.map +1 -1
- package/dist/lock/redis/index.js.map +1 -1
- package/dist/logger/index.d.ts +105 -76
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +196 -174
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +25 -20
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +23 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/core/index.browser.js.map +1 -1
- package/dist/orm/core/index.bun.js +19 -1
- package/dist/orm/core/index.bun.js.map +1 -1
- package/dist/orm/core/index.d.ts +76 -62
- package/dist/orm/core/index.d.ts.map +1 -1
- package/dist/orm/core/index.js +20 -2
- package/dist/orm/core/index.js.map +1 -1
- package/dist/orm/postgres/index.bun.js.map +1 -1
- package/dist/orm/postgres/index.d.ts +28 -20
- package/dist/orm/postgres/index.d.ts.map +1 -1
- package/dist/orm/postgres/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +12 -15
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/core/index.js.map +1 -1
- package/dist/queue/core/index.workerd.js.map +1 -1
- package/dist/queue/redis/index.d.ts +3 -5
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/queue/redis/index.js.map +1 -1
- package/dist/react/auth/index.browser.js +9 -2
- package/dist/react/auth/index.browser.js.map +1 -1
- package/dist/react/auth/index.d.ts +14 -9
- package/dist/react/auth/index.d.ts.map +1 -1
- package/dist/react/auth/index.js +9 -2
- package/dist/react/auth/index.js.map +1 -1
- package/dist/react/core/index.d.ts +7 -8
- package/dist/react/core/index.d.ts.map +1 -1
- package/dist/react/core/index.js +6 -3
- package/dist/react/core/index.js.map +1 -1
- package/dist/react/form/index.d.ts +2 -5
- package/dist/react/form/index.d.ts.map +1 -1
- package/dist/react/form/index.js +16 -15
- package/dist/react/form/index.js.map +1 -1
- package/dist/react/head/index.browser.js.map +1 -1
- package/dist/react/head/index.d.ts +2 -4
- package/dist/react/head/index.d.ts.map +1 -1
- package/dist/react/head/index.js.map +1 -1
- package/dist/react/i18n/index.d.ts +90 -11
- package/dist/react/i18n/index.d.ts.map +1 -1
- package/dist/react/i18n/index.js +147 -11
- package/dist/react/i18n/index.js.map +1 -1
- package/dist/react/intro/index.d.ts +1 -2
- package/dist/react/intro/index.d.ts.map +1 -1
- package/dist/react/intro/index.js +2 -2
- package/dist/react/intro/index.js.map +1 -1
- package/dist/react/router/index.browser.js +193 -24
- package/dist/react/router/index.browser.js.map +1 -1
- package/dist/react/router/index.d.ts +434 -222
- package/dist/react/router/index.d.ts.map +1 -1
- package/dist/react/router/index.js +249 -35
- package/dist/react/router/index.js.map +1 -1
- package/dist/react/sitemap/index.browser.js +35 -0
- package/dist/react/sitemap/index.browser.js.map +1 -0
- package/dist/react/sitemap/index.d.ts +92 -0
- package/dist/react/sitemap/index.d.ts.map +1 -0
- package/dist/react/sitemap/index.js +131 -0
- package/dist/react/sitemap/index.js.map +1 -0
- package/dist/react/testing/index.d.ts +1 -2
- package/dist/react/testing/index.d.ts.map +1 -1
- package/dist/react/testing/index.js +16 -17
- package/dist/react/testing/index.js.map +1 -1
- package/dist/react/ui/index.d.ts +20 -25
- package/dist/react/ui/index.d.ts.map +1 -1
- package/dist/react/ui/index.js.map +1 -1
- package/dist/redis/index.bun.js.map +1 -1
- package/dist/redis/index.d.ts +17 -19
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.d.ts +2 -4
- package/dist/retry/index.d.ts.map +1 -1
- package/dist/retry/index.js.map +1 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +10 -13
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js.map +1 -1
- package/dist/scheduler/index.workerd.js.map +1 -1
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +45 -48
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.browser.js.map +1 -1
- package/dist/server/auth/index.d.ts +272 -173
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +1608 -15
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cookies/index.browser.js.map +1 -1
- package/dist/server/cookies/index.d.ts +20 -7
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/cookies/index.js +22 -3
- 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 +106 -73
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +44 -0
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +11 -14
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/cors/index.js.map +1 -1
- package/dist/server/etag/index.d.ts +6 -9
- package/dist/server/etag/index.d.ts.map +1 -1
- package/dist/server/etag/index.js.map +1 -1
- package/dist/server/health/index.d.ts +18 -21
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/health/index.js.map +1 -1
- package/dist/server/links/index.browser.js +2 -0
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +63 -67
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +2 -0
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts +5 -7
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/metrics/index.js.map +1 -1
- package/dist/server/proxy/index.d.ts +3 -5
- package/dist/server/proxy/index.d.ts.map +1 -1
- package/dist/server/proxy/index.js.map +1 -1
- package/dist/server/rate-limit/index.d.ts +10 -13
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.js.map +1 -1
- package/dist/server/static/index.d.ts +3 -5
- package/dist/server/static/index.d.ts.map +1 -1
- package/dist/server/static/index.js.map +1 -1
- package/dist/server/swagger/index.d.ts +5 -8
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.d.ts +3 -5
- package/dist/sms/index.d.ts.map +1 -1
- package/dist/sms/index.js.map +1 -1
- package/dist/system/index.browser.js.map +1 -1
- package/dist/system/index.d.ts +2 -4
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js.map +1 -1
- package/dist/system/index.workerd.js.map +1 -1
- package/dist/topic/core/index.d.ts +4 -6
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/core/index.js.map +1 -1
- package/dist/topic/redis/index.d.ts +5 -8
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/topic/redis/index.js.map +1 -1
- package/package.json +59 -23
- package/src/api/audits/__tests__/AuditService.spec.ts +18 -110
- package/src/api/audits/controllers/AdminAuditController.ts +14 -0
- package/src/api/audits/services/AuditService.ts +21 -88
- package/src/api/files/__tests__/FileService.spec.ts +207 -2
- package/src/api/files/index.ts +3 -0
- package/src/api/files/schemas/fileCreatorSummarySchema.ts +22 -0
- package/src/api/files/schemas/fileResourceSchema.ts +10 -1
- package/src/api/files/services/FileService.ts +170 -72
- package/src/api/jobs/__tests__/$job.spec.ts +24 -1
- package/src/api/jobs/index.ts +4 -3
- package/src/api/jobs/primitives/$job.ts +7 -3
- package/src/api/jobs/providers/DirectJobDispatcher.ts +17 -36
- package/src/api/jobs/providers/JobProvider.ts +53 -24
- package/src/api/jobs/schemas/jobConfigAtom.ts +1 -1
- package/src/api/jobs/schemas/jobExecutionResourceSchema.ts +4 -1
- package/src/api/keys/schemas/adminApiKeyResourceSchema.ts +3 -1
- package/src/api/parameters/__tests__/$parameter.spec.ts +19 -2
- package/src/api/parameters/audits/ParameterAudits.ts +17 -0
- package/src/api/parameters/controllers/AdminParameterController.ts +95 -19
- package/src/api/parameters/index.ts +3 -0
- package/src/api/parameters/schemas/activateParameterBodySchema.ts +3 -3
- package/src/api/parameters/schemas/createParameterVersionBodySchema.ts +3 -2
- package/src/api/parameters/schemas/parameterCreatorSummarySchema.ts +25 -0
- package/src/api/parameters/schemas/parameterResponseSchema.ts +5 -0
- package/src/api/parameters/schemas/rollbackParameterBodySchema.ts +4 -2
- package/src/api/parameters/services/ParameterProvider.ts +69 -6
- package/src/api/subscriptions/jobs/SubscriptionJobs.ts +1 -1
- package/src/api/users/__tests__/AdminSessionController.spec.ts +37 -0
- package/src/api/users/audits/SessionAudits.ts +33 -0
- package/src/api/users/audits/UserAudits.ts +19 -43
- package/src/api/users/controllers/AdminUserController.ts +66 -1
- package/src/api/users/controllers/RealmController.ts +1 -0
- package/src/api/users/entities/sessions.ts +6 -0
- package/src/api/users/entities/users.ts +2 -0
- package/src/api/users/index.ts +9 -1
- package/src/api/users/primitives/$realm.ts +29 -0
- package/src/api/users/providers/RealmProvider.ts +15 -0
- package/src/api/users/schemas/realmConfigSchema.ts +14 -0
- package/src/api/users/schemas/sessionResourceSchema.ts +16 -0
- package/src/api/users/schemas/updateUserSchema.ts +1 -8
- package/src/api/users/schemas/userQuerySchema.ts +7 -0
- package/src/api/users/services/CredentialService.ts +15 -6
- package/src/api/users/services/IdentityService.ts +2 -1
- package/src/api/users/services/RegistrationService.ts +2 -1
- package/src/api/users/services/SessionCrudService.ts +19 -2
- package/src/api/users/services/SessionService.ts +39 -19
- package/src/api/users/services/UserService.ts +106 -8
- package/src/background/__tests__/BackgroundTaskProvider.spec.ts +96 -0
- package/src/background/index.ts +37 -0
- package/src/background/index.workerd.ts +28 -0
- package/src/background/providers/BackgroundTaskProvider.ts +70 -0
- package/src/background/providers/WorkerdBackgroundTaskProvider.ts +43 -0
- package/src/bucket/__tests__/$bucket.spec.ts +18 -0
- package/src/bucket/__tests__/LocalFileStorageProvider.spec.ts +5 -0
- package/src/bucket/__tests__/MemoryFileStorageProvider.spec.ts +5 -0
- package/src/bucket/__tests__/NodeS3BucketProvider.spec.ts +23 -4
- package/src/bucket/__tests__/shared.ts +30 -0
- package/src/bucket/index.ts +5 -5
- package/src/bucket/index.workerd.ts +11 -4
- package/src/bucket/primitives/$bucket.ts +27 -0
- package/src/bucket/providers/FileStorageProvider.ts +13 -0
- package/src/bucket/providers/LocalFileStorageProvider.ts +17 -1
- package/src/bucket/providers/MemoryFileStorageProvider.ts +7 -0
- package/src/bucket/providers/{CloudflareR2Provider.ts → R2FileStorageProvider.ts} +10 -1
- package/src/bucket/providers/{NodeS3BucketProvider.ts → S3FileStorageProvider.ts} +27 -5
- package/src/cli/core/__tests__/BuildDockerTask.spec.ts +25 -1
- package/src/cli/core/__tests__/init.spec.ts +0 -219
- package/src/cli/core/atoms/buildOptions.ts +0 -12
- package/src/cli/core/commands/__tests__/BuildCommand.spec.ts +43 -0
- package/src/cli/core/commands/build.ts +105 -37
- package/src/cli/core/commands/init.ts +0 -12
- package/src/cli/core/commands/pack.ts +133 -0
- package/src/cli/core/index.ts +3 -3
- package/src/cli/core/providers/ViteDevServerProvider.ts +40 -16
- package/src/cli/core/services/PackageManagerUtils.ts +0 -16
- package/src/cli/core/services/ProjectScaffolder.ts +29 -291
- package/src/cli/core/tasks/BuildCloudflareTask.ts +382 -56
- package/src/cli/core/tasks/BuildDockerTask.ts +33 -3
- package/src/cli/core/tasks/BuildPrerenderTask.ts +44 -7
- package/src/cli/core/tasks/BuildTask.ts +34 -0
- package/src/cli/core/templates/apiIndexTs.ts +1 -22
- package/src/cli/core/templates/mainCss.ts +0 -1
- package/src/cli/core/templates/webAppRouterTs.ts +0 -99
- package/src/cli/core/templates/webIndexTs.ts +1 -22
- package/src/cli/i18n/__tests__/I18nCheckService.spec.ts +48 -0
- package/src/cli/i18n/services/I18nCheckService.ts +65 -11
- package/src/cli/platform/__tests__/SecretsCommand.spec.ts +5 -3
- package/src/cli/platform/commands/SecretsCommand.ts +8 -6
- package/src/cli/platform/commands/platform.ts +192 -46
- package/src/cli/platform/index.ts +12 -52
- package/src/cli/{platform → platform-lib}/__tests__/CloudflareAdapter.spec.ts +426 -169
- package/src/cli/{platform → platform-lib}/__tests__/NamingService.spec.ts +91 -4
- package/src/cli/{platform → platform-lib}/__tests__/VercelAdapter.spec.ts +56 -85
- package/src/cli/{platform → platform-lib}/adapters/CloudflareAdapter.ts +519 -190
- package/src/cli/{platform → platform-lib}/adapters/PlatformAdapter.ts +62 -35
- package/src/cli/{platform → platform-lib}/adapters/VercelAdapter.ts +6 -10
- package/src/cli/{platform → platform-lib}/atoms/platformOptions.ts +34 -1
- package/src/cli/platform-lib/index.ts +67 -0
- package/src/cli/platform-lib/services/NamingService.ts +136 -0
- package/src/cli/{platform → platform-lib}/services/PlatformInspector.ts +60 -13
- package/src/cli/{platform → platform-lib}/services/PlatformOrchestrator.ts +54 -43
- package/src/cli/{platform → platform-lib}/services/WranglerApi.ts +4 -2
- package/src/command/__tests__/Runner.spec.ts +20 -0
- package/src/command/helpers/EnvUtils.ts +19 -3
- package/src/command/helpers/Runner.ts +12 -2
- package/src/command/providers/CliProvider.ts +34 -1
- package/src/{containers → container}/core/__tests__/$container.spec.ts +5 -5
- package/src/{containers → container}/core/index.ts +4 -4
- package/src/{containers → container}/core/index.workerd.ts +19 -3
- package/src/{containers → container}/core/primitives/$container.ts +1 -1
- package/src/{containers → container}/core/providers/CloudflareContainerProvider.ts +17 -19
- package/src/{containers → container}/core/providers/ContainerProvider.ts +16 -2
- package/src/{containers → container}/core/providers/MockContainerProvider.ts +1 -1
- package/src/core/Alepha.ts +49 -1
- package/src/core/__tests__/$env.spec.ts +42 -0
- package/src/core/__tests__/dump.spec.ts +47 -0
- package/src/email/cloudflare/__tests__/CloudflareEmailProvider.spec.ts +42 -10
- package/src/email/cloudflare/index.ts +14 -5
- package/src/email/cloudflare/providers/CloudflareEmailProvider.ts +54 -9
- package/src/logger/__tests__/Logger.spec.ts +55 -0
- package/src/logger/index.ts +13 -0
- package/src/logger/services/Logger.ts +31 -1
- package/src/mcp/__tests__/McpServerProvider.spec.ts +71 -0
- package/src/mcp/providers/McpServerProvider.ts +55 -0
- package/src/orm/__tests__/orm-showcase-tests.ts +27 -0
- package/src/orm/__tests__/orm-showcase.spec.ts +12 -0
- package/src/orm/core/interfaces/PgQuery.ts +4 -1
- package/src/orm/core/services/Repository.ts +27 -11
- package/src/react/auth/hooks/useAuth.ts +10 -5
- package/src/react/core/__tests__/useQuery.browser.spec.tsx +25 -0
- package/src/react/core/hooks/useAction.ts +14 -3
- package/src/react/core/hooks/useQuery.ts +24 -4
- package/src/react/form/__tests__/FormModel-submit-loading.spec.ts +71 -0
- package/src/react/form/__tests__/form-submitting-reactive.browser.spec.tsx +96 -0
- package/src/react/form/services/FormModel.ts +57 -39
- package/src/react/i18n/__tests__/I18nProvider.spec.ts +89 -0
- package/src/react/i18n/__tests__/locale-routing.spec.ts +107 -0
- package/src/react/i18n/components/Translate.tsx +47 -0
- package/src/react/i18n/index.ts +2 -0
- package/src/react/i18n/providers/I18nProvider.ts +171 -12
- package/src/react/intro/components/GettingStartedAdminSlide.tsx +2 -2
- package/src/react/router/__tests__/$page.spec.tsx +3 -2
- package/src/react/router/__tests__/RouterLocaleProvider.spec.ts +127 -0
- package/src/react/router/__tests__/page-can.spec.ts +18 -13
- package/src/react/router/hooks/useQueryParams.ts +114 -14
- package/src/react/router/index.browser.ts +4 -0
- package/src/react/router/index.shared.ts +1 -0
- package/src/react/router/index.ts +9 -0
- package/src/react/router/primitives/$page.ts +85 -4
- package/src/react/router/providers/ReactBrowserRouterProvider.ts +18 -8
- package/src/react/router/providers/ReactPageProvider.ts +12 -1
- package/src/react/router/providers/ReactServerProvider.ts +96 -14
- package/src/react/router/providers/RootComponentsProvider.ts +13 -0
- package/src/react/router/providers/RouterLocaleProvider.ts +125 -0
- package/src/react/router/providers/__tests__/RootComponentsProvider.spec.ts +15 -0
- package/src/react/router/providers/__tests__/rootComponents.ssr.browser.spec.tsx +67 -0
- package/src/react/sitemap/__tests__/$sitemap.spec.ts +131 -0
- package/src/react/sitemap/index.browser.ts +21 -0
- package/src/react/sitemap/index.ts +25 -0
- package/src/react/sitemap/primitives/$sitemap.browser.ts +26 -0
- package/src/react/sitemap/primitives/$sitemap.ts +196 -0
- package/src/react/ui/services/SchemaControl.ts +3 -4
- package/src/server/auth/__tests__/appleClientSecret.spec.ts +34 -0
- package/src/server/auth/__tests__/authFederationClient.spec.ts +40 -0
- package/src/server/auth/__tests__/federationAssertion.spec.ts +146 -0
- package/src/server/auth/__tests__/federationRedirectReplay.spec.ts +44 -0
- package/src/server/auth/helpers/appleClientSecret.ts +24 -0
- package/src/server/auth/helpers/federationAssertion.ts +74 -0
- package/src/server/auth/helpers/jtiReplayGuard.ts +41 -0
- package/src/server/auth/helpers/safeRedirectPath.ts +19 -0
- package/src/server/auth/index.ts +4 -0
- package/src/server/auth/primitives/$authFederationBroker.ts +273 -0
- package/src/server/auth/primitives/$authFederationClient.ts +89 -0
- package/src/server/auth/providers/ServerAuthProvider.ts +18 -4
- package/src/server/cookies/__tests__/ServerCookiesProvider.spec.ts +70 -0
- package/src/server/cookies/providers/ServerCookiesProvider.ts +23 -3
- package/src/server/core/interfaces/ServerRequest.ts +8 -0
- package/src/server/core/primitives/$route.ts +27 -0
- package/src/server/core/providers/ServerMultipartProvider.ts +19 -0
- package/src/server/links/providers/LinkProvider.ts +10 -0
- package/dist/containers/core/index.d.ts.map +0 -1
- package/dist/containers/core/index.js.map +0 -1
- package/dist/containers/core/index.workerd.js.map +0 -1
- package/src/cli/core/tasks/BuildSitemapTask.ts +0 -130
- package/src/cli/core/templates/componentsJsonTs.ts +0 -39
- package/src/cli/core/templates/saasAdminLayoutTsx.ts +0 -77
- package/src/cli/core/templates/saasAdminPagesTsx.ts +0 -26
- package/src/cli/core/templates/saasAuthLayoutTsx.ts +0 -22
- package/src/cli/core/templates/saasAuthPagesTsx.ts +0 -62
- package/src/cli/core/templates/saasRealmProviderTs.ts +0 -52
- package/src/cli/platform/services/NamingService.ts +0 -54
- /package/dist/orm/core/{chunk-o8xxKEmq.js → chunk-B4FMCO8f.js} +0 -0
- /package/dist/react/testing/{chunk-6Ep1yQYe.js → chunk-BpyX8vjI.js} +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/GitHubSecretStore.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/PlatformCacheProvider.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/PlatformInspector.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/PlatformOrchestrator.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/SecretFilterService.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/detectResources.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/GitHubSecretStore.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/MemorySecretStore.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/PlatformCacheProvider.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/SecretStoreProvider.ts +0 -0
- /package/src/cli/{platform → platform-lib}/schemas/cloudflare.ts +0 -0
- /package/src/cli/{platform → platform-lib}/schemas/platform.ts +0 -0
- /package/src/cli/{platform → platform-lib}/schemas/vercel.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/CloudflareApi.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/SecretFilterService.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/VercelApi.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/VercelCli.ts +0 -0
- /package/src/{containers → container}/core/interfaces/ContainerOptions.ts +0 -0
- /package/src/{containers → container}/core/providers/NodeContainerProvider.ts +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Alepha } from "alepha";
|
|
2
|
+
|
|
3
|
+
//#region ../../src/background/providers/BackgroundTaskProvider.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runs fire-and-forget work that should outlive the request that scheduled it
|
|
6
|
+
* (sending a welcome email, an audit write, a webhook) without blocking the
|
|
7
|
+
* response.
|
|
8
|
+
*
|
|
9
|
+
* On a long-lived runtime (Node, Vercel) the event loop keeps the promise
|
|
10
|
+
* alive, so the only job here is to detach the task from the caller and never
|
|
11
|
+
* leak an unhandled rejection. On serverless/edge runtimes that freeze the
|
|
12
|
+
* isolate once the response is returned (Cloudflare Workers) the
|
|
13
|
+
* {@link WorkerdBackgroundTaskProvider} variant additionally wraps the task in
|
|
14
|
+
* `executionCtx.waitUntil` — call sites stay platform-agnostic and only ever
|
|
15
|
+
* call {@link defer}.
|
|
16
|
+
*
|
|
17
|
+
* In-flight tasks are tracked and awaited on shutdown (`flush`), so graceful
|
|
18
|
+
* stop, `run({ once })`, and unit tests don't silently drop work.
|
|
19
|
+
*/
|
|
20
|
+
declare class BackgroundTaskProvider {
|
|
21
|
+
protected readonly alepha: Alepha;
|
|
22
|
+
protected readonly log: import("alepha/logger").Logger;
|
|
23
|
+
/** In-flight deferred tasks, awaited on stop. */
|
|
24
|
+
protected readonly pending: Set<Promise<void>>;
|
|
25
|
+
/**
|
|
26
|
+
* Schedule `task` to run in the background. Returns immediately — the task is
|
|
27
|
+
* detached onto a microtask, so the caller (e.g. an HTTP handler) is never
|
|
28
|
+
* blocked and a synchronous throw inside `task` can't escape into it. Errors
|
|
29
|
+
* are caught and logged.
|
|
30
|
+
*/
|
|
31
|
+
defer(task: () => unknown | Promise<unknown>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Hook for platform variants to keep the runtime alive until `promise`
|
|
34
|
+
* settles. No-op on long-lived runtimes (the event loop already does). The
|
|
35
|
+
* Cloudflare variant overrides this with `executionCtx.waitUntil`.
|
|
36
|
+
*/
|
|
37
|
+
protected keepAlive(_promise: Promise<void>): void;
|
|
38
|
+
/**
|
|
39
|
+
* Await all in-flight tasks (best-effort). Called on `stop` so shutdown and
|
|
40
|
+
* tests don't drop deferred work.
|
|
41
|
+
*/
|
|
42
|
+
flush(): Promise<void>;
|
|
43
|
+
protected readonly onStop: import("alepha").HookPrimitive<"stop">;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../../src/background/providers/WorkerdBackgroundTaskProvider.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Cloudflare Workers variant of {@link BackgroundTaskProvider}.
|
|
49
|
+
*
|
|
50
|
+
* Cloudflare freezes the isolate once the response is returned, so a plain
|
|
51
|
+
* fire-and-forget promise would be killed mid-flight. The platform exposes a
|
|
52
|
+
* per-request `executionCtx.waitUntil(promise)` that keeps the isolate alive
|
|
53
|
+
* until `promise` settles; the request entry point (generated by the Cloudflare
|
|
54
|
+
* build) stashes it in the Alepha store under `cloudflare.waitUntil`.
|
|
55
|
+
*
|
|
56
|
+
* This is the ONE place that reads that key — call sites use
|
|
57
|
+
* {@link BackgroundTaskProvider.defer} and stay platform-agnostic.
|
|
58
|
+
*
|
|
59
|
+
* `waitUntil` is request-scoped, so `defer()` must be called within the
|
|
60
|
+
* request's async context (which is where background work is scheduled). Outside
|
|
61
|
+
* a request (e.g. a cron tick) the key is absent and we fall back to the base
|
|
62
|
+
* fire-and-track behaviour.
|
|
63
|
+
*/
|
|
64
|
+
declare class WorkerdBackgroundTaskProvider extends BackgroundTaskProvider {
|
|
65
|
+
protected keepAlive(promise: Promise<void>): void;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region ../../src/background/index.d.ts
|
|
69
|
+
/**
|
|
70
|
+
* Fire-and-forget background work that should outlive the request that
|
|
71
|
+
* scheduled it, without blocking the response.
|
|
72
|
+
*
|
|
73
|
+
* Inject {@link BackgroundTaskProvider} and call `defer(() => …)`:
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* protected readonly background = $inject(BackgroundTaskProvider);
|
|
77
|
+
*
|
|
78
|
+
* createUser = $action({ handler: async ({ body }) => {
|
|
79
|
+
* const user = await this.users.create(body);
|
|
80
|
+
* this.background.defer(() => this.email.send(welcome(user))); // don't block
|
|
81
|
+
* return user;
|
|
82
|
+
* }});
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* On Node/Vercel the event loop keeps the task alive. On Cloudflare Workers the
|
|
86
|
+
* `workerd` build swaps in {@link WorkerdBackgroundTaskProvider}, which wraps
|
|
87
|
+
* the task in `executionCtx.waitUntil` so the isolate isn't frozen at response
|
|
88
|
+
* time — the call site is identical either way.
|
|
89
|
+
*
|
|
90
|
+
* @module alepha.background
|
|
91
|
+
*/
|
|
92
|
+
declare const AlephaBackground: import("alepha").Service<import("alepha").Module>;
|
|
93
|
+
//#endregion
|
|
94
|
+
export { AlephaBackground, BackgroundTaskProvider, WorkerdBackgroundTaskProvider };
|
|
95
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/background/providers/BackgroundTaskProvider.ts","../../src/background/providers/WorkerdBackgroundTaskProvider.ts","../../src/background/index.ts"],"mappings":";;;;;AAmBA;;;;;;;;;;;;;;cAAa,sBAAA;EAAA,mBACQ,MAAA,EAAM,MAAA;EAAA,mBACN,GAAA,0BAAG,MAAA;EAGI;EAAA,mBAAP,OAAA,EAAO,GAAA,CAAA,OAAA;EAQS;;;;;;EAA5B,KAAA,CAAM,IAAA,kBAAsB,OAAA;EAiChB;;;AAAM;;EAAN,UAVT,SAAA,CAAU,QAAA,EAAU,OAAA;;ACpChC;;;ED0Ce,KAAA,IAAS,OAAA;EAAA,mBAIH,MAAA,mBAAM,aAAA;AAAA;;;;;AA9C3B;;;;;;;;;;;;;;;cCAa,6BAAA,SAAsC,sBAAsB;EAAA,UACpD,SAAA,CAAU,OAAA,EAAS,OAAA;AAAA;;;;ADDxC;;;;;;;;;;;;;;;;;;;;;;cEca,gBAAA,mBAAgB,OAAA,kBAAA,MAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { $hook, $inject, $module, Alepha } from "alepha";
|
|
2
|
+
import { $logger } from "alepha/logger";
|
|
3
|
+
//#region ../../src/background/providers/BackgroundTaskProvider.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runs fire-and-forget work that should outlive the request that scheduled it
|
|
6
|
+
* (sending a welcome email, an audit write, a webhook) without blocking the
|
|
7
|
+
* response.
|
|
8
|
+
*
|
|
9
|
+
* On a long-lived runtime (Node, Vercel) the event loop keeps the promise
|
|
10
|
+
* alive, so the only job here is to detach the task from the caller and never
|
|
11
|
+
* leak an unhandled rejection. On serverless/edge runtimes that freeze the
|
|
12
|
+
* isolate once the response is returned (Cloudflare Workers) the
|
|
13
|
+
* {@link WorkerdBackgroundTaskProvider} variant additionally wraps the task in
|
|
14
|
+
* `executionCtx.waitUntil` — call sites stay platform-agnostic and only ever
|
|
15
|
+
* call {@link defer}.
|
|
16
|
+
*
|
|
17
|
+
* In-flight tasks are tracked and awaited on shutdown (`flush`), so graceful
|
|
18
|
+
* stop, `run({ once })`, and unit tests don't silently drop work.
|
|
19
|
+
*/
|
|
20
|
+
var BackgroundTaskProvider = class {
|
|
21
|
+
alepha = $inject(Alepha);
|
|
22
|
+
log = $logger();
|
|
23
|
+
/** In-flight deferred tasks, awaited on stop. */
|
|
24
|
+
pending = /* @__PURE__ */ new Set();
|
|
25
|
+
/**
|
|
26
|
+
* Schedule `task` to run in the background. Returns immediately — the task is
|
|
27
|
+
* detached onto a microtask, so the caller (e.g. an HTTP handler) is never
|
|
28
|
+
* blocked and a synchronous throw inside `task` can't escape into it. Errors
|
|
29
|
+
* are caught and logged.
|
|
30
|
+
*/
|
|
31
|
+
defer(task) {
|
|
32
|
+
const promise = Promise.resolve().then(task).then(() => void 0, (error) => {
|
|
33
|
+
this.log.warn("Background task failed", error);
|
|
34
|
+
});
|
|
35
|
+
this.pending.add(promise);
|
|
36
|
+
promise.finally(() => {
|
|
37
|
+
this.pending.delete(promise);
|
|
38
|
+
});
|
|
39
|
+
this.keepAlive(promise);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Hook for platform variants to keep the runtime alive until `promise`
|
|
43
|
+
* settles. No-op on long-lived runtimes (the event loop already does). The
|
|
44
|
+
* Cloudflare variant overrides this with `executionCtx.waitUntil`.
|
|
45
|
+
*/
|
|
46
|
+
keepAlive(_promise) {}
|
|
47
|
+
/**
|
|
48
|
+
* Await all in-flight tasks (best-effort). Called on `stop` so shutdown and
|
|
49
|
+
* tests don't drop deferred work.
|
|
50
|
+
*/
|
|
51
|
+
async flush() {
|
|
52
|
+
await Promise.allSettled([...this.pending]);
|
|
53
|
+
}
|
|
54
|
+
onStop = $hook({
|
|
55
|
+
on: "stop",
|
|
56
|
+
handler: () => this.flush()
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region ../../src/background/providers/WorkerdBackgroundTaskProvider.ts
|
|
61
|
+
/**
|
|
62
|
+
* Cloudflare Workers variant of {@link BackgroundTaskProvider}.
|
|
63
|
+
*
|
|
64
|
+
* Cloudflare freezes the isolate once the response is returned, so a plain
|
|
65
|
+
* fire-and-forget promise would be killed mid-flight. The platform exposes a
|
|
66
|
+
* per-request `executionCtx.waitUntil(promise)` that keeps the isolate alive
|
|
67
|
+
* until `promise` settles; the request entry point (generated by the Cloudflare
|
|
68
|
+
* build) stashes it in the Alepha store under `cloudflare.waitUntil`.
|
|
69
|
+
*
|
|
70
|
+
* This is the ONE place that reads that key — call sites use
|
|
71
|
+
* {@link BackgroundTaskProvider.defer} and stay platform-agnostic.
|
|
72
|
+
*
|
|
73
|
+
* `waitUntil` is request-scoped, so `defer()` must be called within the
|
|
74
|
+
* request's async context (which is where background work is scheduled). Outside
|
|
75
|
+
* a request (e.g. a cron tick) the key is absent and we fall back to the base
|
|
76
|
+
* fire-and-track behaviour.
|
|
77
|
+
*/
|
|
78
|
+
var WorkerdBackgroundTaskProvider = class extends BackgroundTaskProvider {
|
|
79
|
+
keepAlive(promise) {
|
|
80
|
+
const waitUntil = this.alepha.store.get("cloudflare.waitUntil");
|
|
81
|
+
if (typeof waitUntil !== "function") return;
|
|
82
|
+
try {
|
|
83
|
+
waitUntil(promise);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
this.log.debug("waitUntil rejected — falling back to fire-and-track", error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region ../../src/background/index.ts
|
|
91
|
+
/**
|
|
92
|
+
* Fire-and-forget background work that should outlive the request that
|
|
93
|
+
* scheduled it, without blocking the response.
|
|
94
|
+
*
|
|
95
|
+
* Inject {@link BackgroundTaskProvider} and call `defer(() => …)`:
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* protected readonly background = $inject(BackgroundTaskProvider);
|
|
99
|
+
*
|
|
100
|
+
* createUser = $action({ handler: async ({ body }) => {
|
|
101
|
+
* const user = await this.users.create(body);
|
|
102
|
+
* this.background.defer(() => this.email.send(welcome(user))); // don't block
|
|
103
|
+
* return user;
|
|
104
|
+
* }});
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* On Node/Vercel the event loop keeps the task alive. On Cloudflare Workers the
|
|
108
|
+
* `workerd` build swaps in {@link WorkerdBackgroundTaskProvider}, which wraps
|
|
109
|
+
* the task in `executionCtx.waitUntil` so the isolate isn't frozen at response
|
|
110
|
+
* time — the call site is identical either way.
|
|
111
|
+
*
|
|
112
|
+
* @module alepha.background
|
|
113
|
+
*/
|
|
114
|
+
const AlephaBackground = $module({
|
|
115
|
+
name: "alepha.background",
|
|
116
|
+
services: [BackgroundTaskProvider]
|
|
117
|
+
});
|
|
118
|
+
//#endregion
|
|
119
|
+
export { AlephaBackground, BackgroundTaskProvider, WorkerdBackgroundTaskProvider };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/background/providers/BackgroundTaskProvider.ts","../../src/background/providers/WorkerdBackgroundTaskProvider.ts","../../src/background/index.ts"],"sourcesContent":["import { $hook, $inject, Alepha } from \"alepha\";\nimport { $logger } from \"alepha/logger\";\n\n/**\n * Runs fire-and-forget work that should outlive the request that scheduled it\n * (sending a welcome email, an audit write, a webhook) without blocking the\n * response.\n *\n * On a long-lived runtime (Node, Vercel) the event loop keeps the promise\n * alive, so the only job here is to detach the task from the caller and never\n * leak an unhandled rejection. On serverless/edge runtimes that freeze the\n * isolate once the response is returned (Cloudflare Workers) the\n * {@link WorkerdBackgroundTaskProvider} variant additionally wraps the task in\n * `executionCtx.waitUntil` — call sites stay platform-agnostic and only ever\n * call {@link defer}.\n *\n * In-flight tasks are tracked and awaited on shutdown (`flush`), so graceful\n * stop, `run({ once })`, and unit tests don't silently drop work.\n */\nexport class BackgroundTaskProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly log = $logger();\n\n /** In-flight deferred tasks, awaited on stop. */\n protected readonly pending = new Set<Promise<void>>();\n\n /**\n * Schedule `task` to run in the background. Returns immediately — the task is\n * detached onto a microtask, so the caller (e.g. an HTTP handler) is never\n * blocked and a synchronous throw inside `task` can't escape into it. Errors\n * are caught and logged.\n */\n public defer(task: () => unknown | Promise<unknown>): void {\n const promise = Promise.resolve()\n .then(task)\n .then(\n () => undefined,\n (error: unknown) => {\n this.log.warn(\"Background task failed\", error as Error);\n },\n );\n\n this.pending.add(promise);\n void promise.finally(() => {\n this.pending.delete(promise);\n });\n\n this.keepAlive(promise);\n }\n\n /**\n * Hook for platform variants to keep the runtime alive until `promise`\n * settles. No-op on long-lived runtimes (the event loop already does). The\n * Cloudflare variant overrides this with `executionCtx.waitUntil`.\n */\n protected keepAlive(_promise: Promise<void>): void {}\n\n /**\n * Await all in-flight tasks (best-effort). Called on `stop` so shutdown and\n * tests don't drop deferred work.\n */\n public async flush(): Promise<void> {\n await Promise.allSettled([...this.pending]);\n }\n\n protected readonly onStop = $hook({\n on: \"stop\",\n handler: () => this.flush(),\n });\n}\n","import { BackgroundTaskProvider } from \"./BackgroundTaskProvider.ts\";\n\n/**\n * Cloudflare Workers variant of {@link BackgroundTaskProvider}.\n *\n * Cloudflare freezes the isolate once the response is returned, so a plain\n * fire-and-forget promise would be killed mid-flight. The platform exposes a\n * per-request `executionCtx.waitUntil(promise)` that keeps the isolate alive\n * until `promise` settles; the request entry point (generated by the Cloudflare\n * build) stashes it in the Alepha store under `cloudflare.waitUntil`.\n *\n * This is the ONE place that reads that key — call sites use\n * {@link BackgroundTaskProvider.defer} and stay platform-agnostic.\n *\n * `waitUntil` is request-scoped, so `defer()` must be called within the\n * request's async context (which is where background work is scheduled). Outside\n * a request (e.g. a cron tick) the key is absent and we fall back to the base\n * fire-and-track behaviour.\n */\nexport class WorkerdBackgroundTaskProvider extends BackgroundTaskProvider {\n protected override keepAlive(promise: Promise<void>): void {\n const waitUntil = this.alepha.store.get(\"cloudflare.waitUntil\") as\n | ((p: Promise<unknown>) => void)\n | undefined;\n\n if (typeof waitUntil !== \"function\") {\n // No request-scoped execution context (cron / outside a request). The\n // base tracking + a long-lived isolate keep the promise alive.\n return;\n }\n\n try {\n waitUntil(promise);\n } catch (error) {\n // The runtime rejects waitUntil if called outside a request scope; the\n // promise still runs, just without the isolate-alive guarantee.\n this.log.debug(\n \"waitUntil rejected — falling back to fire-and-track\",\n error as Error,\n );\n }\n }\n}\n","import { $module } from \"alepha\";\nimport { BackgroundTaskProvider } from \"./providers/BackgroundTaskProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./providers/BackgroundTaskProvider.ts\";\nexport * from \"./providers/WorkerdBackgroundTaskProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Fire-and-forget background work that should outlive the request that\n * scheduled it, without blocking the response.\n *\n * Inject {@link BackgroundTaskProvider} and call `defer(() => …)`:\n *\n * ```ts\n * protected readonly background = $inject(BackgroundTaskProvider);\n *\n * createUser = $action({ handler: async ({ body }) => {\n * const user = await this.users.create(body);\n * this.background.defer(() => this.email.send(welcome(user))); // don't block\n * return user;\n * }});\n * ```\n *\n * On Node/Vercel the event loop keeps the task alive. On Cloudflare Workers the\n * `workerd` build swaps in {@link WorkerdBackgroundTaskProvider}, which wraps\n * the task in `executionCtx.waitUntil` so the isolate isn't frozen at response\n * time — the call site is identical either way.\n *\n * @module alepha.background\n */\nexport const AlephaBackground = $module({\n name: \"alepha.background\",\n services: [BackgroundTaskProvider],\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAa,yBAAb,MAAoC;CAClC,SAA4B,QAAQ,MAAM;CAC1C,MAAyB,QAAQ;;CAGjC,0BAA6B,IAAI,IAAmB;;;;;;;CAQpD,MAAa,MAA8C;EACzD,MAAM,UAAU,QAAQ,QAAQ,EAC7B,KAAK,IAAI,EACT,WACO,KAAA,IACL,UAAmB;GAClB,KAAK,IAAI,KAAK,0BAA0B,KAAc;EACxD,CACF;EAEF,KAAK,QAAQ,IAAI,OAAO;EACxB,QAAa,cAAc;GACzB,KAAK,QAAQ,OAAO,OAAO;EAC7B,CAAC;EAED,KAAK,UAAU,OAAO;CACxB;;;;;;CAOA,UAAoB,UAA+B,CAAC;;;;;CAMpD,MAAa,QAAuB;EAClC,MAAM,QAAQ,WAAW,CAAC,GAAG,KAAK,OAAO,CAAC;CAC5C;CAEA,SAA4B,MAAM;EAChC,IAAI;EACJ,eAAe,KAAK,MAAM;CAC5B,CAAC;AACH;;;;;;;;;;;;;;;;;;;;AClDA,IAAa,gCAAb,cAAmD,uBAAuB;CACxE,UAA6B,SAA8B;EACzD,MAAM,YAAY,KAAK,OAAO,MAAM,IAAI,sBAAsB;EAI9D,IAAI,OAAO,cAAc,YAGvB;EAGF,IAAI;GACF,UAAU,OAAO;EACnB,SAAS,OAAO;GAGd,KAAK,IAAI,MACP,uDACA,KACF;EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;ACTA,MAAa,mBAAmB,QAAQ;CACtC,MAAM;CACN,UAAU,CAAC,sBAAsB;AACnC,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { $hook, $inject, $module, Alepha } from "alepha";
|
|
2
|
+
import { $logger } from "alepha/logger";
|
|
3
|
+
//#region ../../src/background/providers/BackgroundTaskProvider.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runs fire-and-forget work that should outlive the request that scheduled it
|
|
6
|
+
* (sending a welcome email, an audit write, a webhook) without blocking the
|
|
7
|
+
* response.
|
|
8
|
+
*
|
|
9
|
+
* On a long-lived runtime (Node, Vercel) the event loop keeps the promise
|
|
10
|
+
* alive, so the only job here is to detach the task from the caller and never
|
|
11
|
+
* leak an unhandled rejection. On serverless/edge runtimes that freeze the
|
|
12
|
+
* isolate once the response is returned (Cloudflare Workers) the
|
|
13
|
+
* {@link WorkerdBackgroundTaskProvider} variant additionally wraps the task in
|
|
14
|
+
* `executionCtx.waitUntil` — call sites stay platform-agnostic and only ever
|
|
15
|
+
* call {@link defer}.
|
|
16
|
+
*
|
|
17
|
+
* In-flight tasks are tracked and awaited on shutdown (`flush`), so graceful
|
|
18
|
+
* stop, `run({ once })`, and unit tests don't silently drop work.
|
|
19
|
+
*/
|
|
20
|
+
var BackgroundTaskProvider = class {
|
|
21
|
+
alepha = $inject(Alepha);
|
|
22
|
+
log = $logger();
|
|
23
|
+
/** In-flight deferred tasks, awaited on stop. */
|
|
24
|
+
pending = /* @__PURE__ */ new Set();
|
|
25
|
+
/**
|
|
26
|
+
* Schedule `task` to run in the background. Returns immediately — the task is
|
|
27
|
+
* detached onto a microtask, so the caller (e.g. an HTTP handler) is never
|
|
28
|
+
* blocked and a synchronous throw inside `task` can't escape into it. Errors
|
|
29
|
+
* are caught and logged.
|
|
30
|
+
*/
|
|
31
|
+
defer(task) {
|
|
32
|
+
const promise = Promise.resolve().then(task).then(() => void 0, (error) => {
|
|
33
|
+
this.log.warn("Background task failed", error);
|
|
34
|
+
});
|
|
35
|
+
this.pending.add(promise);
|
|
36
|
+
promise.finally(() => {
|
|
37
|
+
this.pending.delete(promise);
|
|
38
|
+
});
|
|
39
|
+
this.keepAlive(promise);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Hook for platform variants to keep the runtime alive until `promise`
|
|
43
|
+
* settles. No-op on long-lived runtimes (the event loop already does). The
|
|
44
|
+
* Cloudflare variant overrides this with `executionCtx.waitUntil`.
|
|
45
|
+
*/
|
|
46
|
+
keepAlive(_promise) {}
|
|
47
|
+
/**
|
|
48
|
+
* Await all in-flight tasks (best-effort). Called on `stop` so shutdown and
|
|
49
|
+
* tests don't drop deferred work.
|
|
50
|
+
*/
|
|
51
|
+
async flush() {
|
|
52
|
+
await Promise.allSettled([...this.pending]);
|
|
53
|
+
}
|
|
54
|
+
onStop = $hook({
|
|
55
|
+
on: "stop",
|
|
56
|
+
handler: () => this.flush()
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region ../../src/background/providers/WorkerdBackgroundTaskProvider.ts
|
|
61
|
+
/**
|
|
62
|
+
* Cloudflare Workers variant of {@link BackgroundTaskProvider}.
|
|
63
|
+
*
|
|
64
|
+
* Cloudflare freezes the isolate once the response is returned, so a plain
|
|
65
|
+
* fire-and-forget promise would be killed mid-flight. The platform exposes a
|
|
66
|
+
* per-request `executionCtx.waitUntil(promise)` that keeps the isolate alive
|
|
67
|
+
* until `promise` settles; the request entry point (generated by the Cloudflare
|
|
68
|
+
* build) stashes it in the Alepha store under `cloudflare.waitUntil`.
|
|
69
|
+
*
|
|
70
|
+
* This is the ONE place that reads that key — call sites use
|
|
71
|
+
* {@link BackgroundTaskProvider.defer} and stay platform-agnostic.
|
|
72
|
+
*
|
|
73
|
+
* `waitUntil` is request-scoped, so `defer()` must be called within the
|
|
74
|
+
* request's async context (which is where background work is scheduled). Outside
|
|
75
|
+
* a request (e.g. a cron tick) the key is absent and we fall back to the base
|
|
76
|
+
* fire-and-track behaviour.
|
|
77
|
+
*/
|
|
78
|
+
var WorkerdBackgroundTaskProvider = class extends BackgroundTaskProvider {
|
|
79
|
+
keepAlive(promise) {
|
|
80
|
+
const waitUntil = this.alepha.store.get("cloudflare.waitUntil");
|
|
81
|
+
if (typeof waitUntil !== "function") return;
|
|
82
|
+
try {
|
|
83
|
+
waitUntil(promise);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
this.log.debug("waitUntil rejected — falling back to fire-and-track", error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region ../../src/background/index.workerd.ts
|
|
91
|
+
/**
|
|
92
|
+
* Cloudflare Workers build of {@link AlephaBackground}: swaps
|
|
93
|
+
* {@link BackgroundTaskProvider} for {@link WorkerdBackgroundTaskProvider},
|
|
94
|
+
* which keeps the isolate alive past the response via `executionCtx.waitUntil`.
|
|
95
|
+
*
|
|
96
|
+
* @module alepha.background
|
|
97
|
+
*/
|
|
98
|
+
const AlephaBackground = $module({
|
|
99
|
+
name: "alepha.background",
|
|
100
|
+
services: [BackgroundTaskProvider],
|
|
101
|
+
variants: [WorkerdBackgroundTaskProvider],
|
|
102
|
+
register: (alepha) => alepha.with({
|
|
103
|
+
provide: BackgroundTaskProvider,
|
|
104
|
+
use: WorkerdBackgroundTaskProvider
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
//#endregion
|
|
108
|
+
export { AlephaBackground, BackgroundTaskProvider, WorkerdBackgroundTaskProvider };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=index.workerd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.workerd.js","names":[],"sources":["../../src/background/providers/BackgroundTaskProvider.ts","../../src/background/providers/WorkerdBackgroundTaskProvider.ts","../../src/background/index.workerd.ts"],"sourcesContent":["import { $hook, $inject, Alepha } from \"alepha\";\nimport { $logger } from \"alepha/logger\";\n\n/**\n * Runs fire-and-forget work that should outlive the request that scheduled it\n * (sending a welcome email, an audit write, a webhook) without blocking the\n * response.\n *\n * On a long-lived runtime (Node, Vercel) the event loop keeps the promise\n * alive, so the only job here is to detach the task from the caller and never\n * leak an unhandled rejection. On serverless/edge runtimes that freeze the\n * isolate once the response is returned (Cloudflare Workers) the\n * {@link WorkerdBackgroundTaskProvider} variant additionally wraps the task in\n * `executionCtx.waitUntil` — call sites stay platform-agnostic and only ever\n * call {@link defer}.\n *\n * In-flight tasks are tracked and awaited on shutdown (`flush`), so graceful\n * stop, `run({ once })`, and unit tests don't silently drop work.\n */\nexport class BackgroundTaskProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly log = $logger();\n\n /** In-flight deferred tasks, awaited on stop. */\n protected readonly pending = new Set<Promise<void>>();\n\n /**\n * Schedule `task` to run in the background. Returns immediately — the task is\n * detached onto a microtask, so the caller (e.g. an HTTP handler) is never\n * blocked and a synchronous throw inside `task` can't escape into it. Errors\n * are caught and logged.\n */\n public defer(task: () => unknown | Promise<unknown>): void {\n const promise = Promise.resolve()\n .then(task)\n .then(\n () => undefined,\n (error: unknown) => {\n this.log.warn(\"Background task failed\", error as Error);\n },\n );\n\n this.pending.add(promise);\n void promise.finally(() => {\n this.pending.delete(promise);\n });\n\n this.keepAlive(promise);\n }\n\n /**\n * Hook for platform variants to keep the runtime alive until `promise`\n * settles. No-op on long-lived runtimes (the event loop already does). The\n * Cloudflare variant overrides this with `executionCtx.waitUntil`.\n */\n protected keepAlive(_promise: Promise<void>): void {}\n\n /**\n * Await all in-flight tasks (best-effort). Called on `stop` so shutdown and\n * tests don't drop deferred work.\n */\n public async flush(): Promise<void> {\n await Promise.allSettled([...this.pending]);\n }\n\n protected readonly onStop = $hook({\n on: \"stop\",\n handler: () => this.flush(),\n });\n}\n","import { BackgroundTaskProvider } from \"./BackgroundTaskProvider.ts\";\n\n/**\n * Cloudflare Workers variant of {@link BackgroundTaskProvider}.\n *\n * Cloudflare freezes the isolate once the response is returned, so a plain\n * fire-and-forget promise would be killed mid-flight. The platform exposes a\n * per-request `executionCtx.waitUntil(promise)` that keeps the isolate alive\n * until `promise` settles; the request entry point (generated by the Cloudflare\n * build) stashes it in the Alepha store under `cloudflare.waitUntil`.\n *\n * This is the ONE place that reads that key — call sites use\n * {@link BackgroundTaskProvider.defer} and stay platform-agnostic.\n *\n * `waitUntil` is request-scoped, so `defer()` must be called within the\n * request's async context (which is where background work is scheduled). Outside\n * a request (e.g. a cron tick) the key is absent and we fall back to the base\n * fire-and-track behaviour.\n */\nexport class WorkerdBackgroundTaskProvider extends BackgroundTaskProvider {\n protected override keepAlive(promise: Promise<void>): void {\n const waitUntil = this.alepha.store.get(\"cloudflare.waitUntil\") as\n | ((p: Promise<unknown>) => void)\n | undefined;\n\n if (typeof waitUntil !== \"function\") {\n // No request-scoped execution context (cron / outside a request). The\n // base tracking + a long-lived isolate keep the promise alive.\n return;\n }\n\n try {\n waitUntil(promise);\n } catch (error) {\n // The runtime rejects waitUntil if called outside a request scope; the\n // promise still runs, just without the isolate-alive guarantee.\n this.log.debug(\n \"waitUntil rejected — falling back to fire-and-track\",\n error as Error,\n );\n }\n }\n}\n","import { $module } from \"alepha\";\nimport { BackgroundTaskProvider } from \"./providers/BackgroundTaskProvider.ts\";\nimport { WorkerdBackgroundTaskProvider } from \"./providers/WorkerdBackgroundTaskProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./providers/BackgroundTaskProvider.ts\";\nexport * from \"./providers/WorkerdBackgroundTaskProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Cloudflare Workers build of {@link AlephaBackground}: swaps\n * {@link BackgroundTaskProvider} for {@link WorkerdBackgroundTaskProvider},\n * which keeps the isolate alive past the response via `executionCtx.waitUntil`.\n *\n * @module alepha.background\n */\nexport const AlephaBackground = $module({\n name: \"alepha.background\",\n services: [BackgroundTaskProvider],\n variants: [WorkerdBackgroundTaskProvider],\n register: (alepha) =>\n alepha.with({\n provide: BackgroundTaskProvider,\n use: WorkerdBackgroundTaskProvider,\n }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAa,yBAAb,MAAoC;CAClC,SAA4B,QAAQ,MAAM;CAC1C,MAAyB,QAAQ;;CAGjC,0BAA6B,IAAI,IAAmB;;;;;;;CAQpD,MAAa,MAA8C;EACzD,MAAM,UAAU,QAAQ,QAAQ,EAC7B,KAAK,IAAI,EACT,WACO,KAAA,IACL,UAAmB;GAClB,KAAK,IAAI,KAAK,0BAA0B,KAAc;EACxD,CACF;EAEF,KAAK,QAAQ,IAAI,OAAO;EACxB,QAAa,cAAc;GACzB,KAAK,QAAQ,OAAO,OAAO;EAC7B,CAAC;EAED,KAAK,UAAU,OAAO;CACxB;;;;;;CAOA,UAAoB,UAA+B,CAAC;;;;;CAMpD,MAAa,QAAuB;EAClC,MAAM,QAAQ,WAAW,CAAC,GAAG,KAAK,OAAO,CAAC;CAC5C;CAEA,SAA4B,MAAM;EAChC,IAAI;EACJ,eAAe,KAAK,MAAM;CAC5B,CAAC;AACH;;;;;;;;;;;;;;;;;;;;AClDA,IAAa,gCAAb,cAAmD,uBAAuB;CACxE,UAA6B,SAA8B;EACzD,MAAM,YAAY,KAAK,OAAO,MAAM,IAAI,sBAAsB;EAI9D,IAAI,OAAO,cAAc,YAGvB;EAGF,IAAI;GACF,UAAU,OAAO;EACnB,SAAS,OAAO;GAGd,KAAK,IAAI,MACP,uDACA,KACF;EACF;CACF;AACF;;;;;;;;;;ACxBA,MAAa,mBAAmB,QAAQ;CACtC,MAAM;CACN,UAAU,CAAC,sBAAsB;CACjC,UAAU,CAAC,6BAA6B;CACxC,WAAW,WACT,OAAO,KAAK;EACV,SAAS;EACT,KAAK;CACP,CAAC;AACL,CAAC"}
|
package/dist/batch/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import * as _$alepha from "alepha";
|
|
2
1
|
import { Alepha, KIND, Primitive, Static, TSchema } from "alepha";
|
|
3
2
|
import { CryptoProvider } from "alepha/crypto";
|
|
4
3
|
import { DateTimeProvider, DurationLike } from "alepha/datetime";
|
|
5
|
-
import * as _$alepha_logger0 from "alepha/logger";
|
|
6
4
|
import { RetryBackoffOptions, RetryPrimitiveOptions, RetryProvider } from "alepha/retry";
|
|
7
5
|
|
|
8
6
|
//#region ../../src/batch/providers/BatchProvider.d.ts
|
|
@@ -110,7 +108,7 @@ interface BatchContext<TItem, TResponse> {
|
|
|
110
108
|
* Provides methods to manage batches of items with automatic flushing based on size or time.
|
|
111
109
|
*/
|
|
112
110
|
declare class BatchProvider {
|
|
113
|
-
protected readonly log:
|
|
111
|
+
protected readonly log: import("alepha/logger").Logger;
|
|
114
112
|
protected readonly dateTime: DateTimeProvider;
|
|
115
113
|
protected readonly retryProvider: RetryProvider;
|
|
116
114
|
protected readonly crypto: CryptoProvider;
|
|
@@ -125,7 +123,7 @@ declare class BatchProvider {
|
|
|
125
123
|
/**
|
|
126
124
|
* Shutdown hook - flushes all batch contexts on application stop.
|
|
127
125
|
*/
|
|
128
|
-
protected readonly onStop:
|
|
126
|
+
protected readonly onStop: import("alepha").HookPrimitive<"stop">;
|
|
129
127
|
/**
|
|
130
128
|
* Get the effective maxSize for a context.
|
|
131
129
|
*/
|
|
@@ -287,7 +285,7 @@ declare class BatchPrimitive<TItem extends TSchema, TResponse = any> extends Pri
|
|
|
287
285
|
* @returns The number of items cleared
|
|
288
286
|
*/
|
|
289
287
|
clearCompleted(status?: "completed" | "failed"): number;
|
|
290
|
-
protected readonly onReady:
|
|
288
|
+
protected readonly onReady: import("alepha").HookPrimitive<"ready">;
|
|
291
289
|
}
|
|
292
290
|
//#endregion
|
|
293
291
|
//#region ../../src/batch/index.d.ts
|
|
@@ -302,7 +300,7 @@ declare class BatchPrimitive<TItem extends TSchema, TResponse = any> extends Pri
|
|
|
302
300
|
*
|
|
303
301
|
* @module alepha.batch
|
|
304
302
|
*/
|
|
305
|
-
declare const AlephaBatch:
|
|
303
|
+
declare const AlephaBatch: import("alepha").Service<import("alepha").Module>;
|
|
306
304
|
//#endregion
|
|
307
|
-
export { $batch, AlephaBatch, BatchContext,
|
|
305
|
+
export { $batch, AlephaBatch, BatchContext, BatchItemState, BatchItemStatus, BatchOptions, BatchPrimitive, BatchPrimitiveOptions, BatchProvider, PartitionState };
|
|
308
306
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/batch/providers/BatchProvider.ts","../../src/batch/primitives/$batch.ts","../../src/batch/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/batch/providers/BatchProvider.ts","../../src/batch/primitives/$batch.ts","../../src/batch/index.ts"],"mappings":";;;;;;UAQiB,YAAA;;AAAjB;;EAIE,OAAA,GAAU,KAAA,EAAO,KAAA,OAAY,SAAA;EAAZ;;;;;EAOjB,OAAA;EA0DiB;;;;EApDjB,YAAA;EAjBmC;;;;;EAwBnC,WAAA,GAAc,YAAA;EAPd;;;E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AA,mBAAO,aAAA;AAAA;;;;;;;ADnJ5B;;;;;;;cEca,WAAA,mBAAW,OAAA,kBAAA,MAAA"}
|
package/dist/batch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/batch/providers/BatchProvider.ts","../../src/batch/primitives/$batch.ts","../../src/batch/index.ts"],"sourcesContent":["import { $hook, $inject, type Alepha, AlephaError } from \"alepha\";\nimport { CryptoProvider } from \"alepha/crypto\";\nimport { DateTimeProvider, type DurationLike } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { type RetryBackoffOptions, RetryProvider } from \"alepha/retry\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface BatchOptions<TItem, TResponse = any> {\n /**\n * The batch processing handler function that processes arrays of validated items.\n */\n handler: (items: TItem[]) => TResponse;\n\n /**\n * Maximum number of items to collect before automatically flushing the batch.\n *\n * @default 10\n */\n maxSize?: number;\n\n /**\n * Maximum number of items that can be queued in a single partition.\n * If exceeded, push() will throw an error.\n */\n maxQueueSize?: number;\n\n /**\n * Maximum time to wait before flushing a batch, even if it hasn't reached maxSize.\n *\n * @default [1, \"second\"]\n */\n maxDuration?: DurationLike;\n\n /**\n * Function to determine partition keys for grouping items into separate batches.\n */\n partitionBy?: (item: TItem) => string;\n\n /**\n * Maximum number of batch handlers that can execute simultaneously.\n *\n * @default 1\n */\n concurrency?: number;\n\n /**\n * Retry configuration for failed batch processing operations.\n */\n retry?: {\n /**\n * The maximum number of attempts.\n *\n * @default 3\n */\n max?: number;\n\n /**\n * The backoff strategy for delays between retries.\n * Can be a fixed number (in ms) or a configuration object for exponential backoff.\n *\n * @default { initial: 200, factor: 2, jitter: true }\n */\n backoff?: number | RetryBackoffOptions;\n\n /**\n * An overall time limit for all retry attempts combined.\n *\n * e.g., `[5, 'seconds']`\n */\n maxDuration?: DurationLike;\n\n /**\n * A function that determines if a retry should be attempted based on the error.\n *\n * @default (error) => true (retries on any error)\n */\n when?: (error: Error) => boolean;\n\n /**\n * A custom callback for when a retry attempt fails.\n * This is called before the delay.\n */\n onError?: (error: Error, attempt: number) => void;\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type BatchItemStatus = \"pending\" | \"processing\" | \"completed\" | \"failed\";\n\nexport interface BatchItemState<TItem, TResponse> {\n id: string;\n item: TItem;\n partitionKey: string;\n status: BatchItemStatus;\n result?: TResponse;\n error?: Error;\n promise?: Promise<TResponse>;\n resolve?: (value: TResponse) => void;\n reject?: (error: Error) => void;\n}\n\nexport interface PartitionState {\n itemIds: string[];\n timeout?: { clear: () => void };\n flushing: boolean;\n}\n\n/**\n * Context object that holds all state for a batch processor instance.\n */\nexport interface BatchContext<TItem, TResponse> {\n options: BatchOptions<TItem, TResponse>;\n itemStates: Map<string, BatchItemState<TItem, TResponse>>;\n partitions: Map<string, PartitionState>;\n activeHandlers: PromiseWithResolvers<void>[];\n isShuttingDown: boolean;\n isReady: boolean;\n alepha: Alepha;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Service for batch processing operations.\n * Provides methods to manage batches of items with automatic flushing based on size or time.\n */\nexport class BatchProvider {\n protected readonly log = $logger();\n protected readonly dateTime = $inject(DateTimeProvider);\n protected readonly retryProvider = $inject(RetryProvider);\n protected readonly crypto = $inject(CryptoProvider);\n\n /**\n * All active batch contexts managed by this provider.\n */\n protected readonly contexts = new Set<BatchContext<any, any>>();\n\n /**\n * Creates a new batch context with the given options.\n */\n createContext<TItem, TResponse>(\n alepha: Alepha,\n options: BatchOptions<TItem, TResponse>,\n ): BatchContext<TItem, TResponse> {\n const context: BatchContext<TItem, TResponse> = {\n options,\n itemStates: new Map(),\n partitions: new Map(),\n activeHandlers: [],\n isShuttingDown: false,\n isReady: false,\n alepha,\n };\n this.contexts.add(context);\n return context;\n }\n\n /**\n * Shutdown hook - flushes all batch contexts on application stop.\n */\n protected readonly onStop = $hook({\n on: \"stop\",\n priority: \"first\",\n handler: async () => {\n if (this.contexts.size === 0) {\n return;\n }\n this.log.debug(`Shutting down ${this.contexts.size} batch context(s)...`);\n const promises: Promise<void>[] = [];\n for (const context of this.contexts) {\n promises.push(this.shutdown(context));\n }\n await Promise.all(promises);\n this.log.debug(\"All batch contexts shut down\");\n },\n });\n\n /**\n * Get the effective maxSize for a context.\n */\n protected getMaxSize<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): number {\n return context.options.maxSize ?? 10;\n }\n\n /**\n * Get the effective concurrency for a context.\n */\n protected getConcurrency<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): number {\n return context.options.concurrency ?? 1;\n }\n\n /**\n * Get the effective maxDuration for a context.\n */\n protected getMaxDuration<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): DurationLike {\n return context.options.maxDuration ?? [1, \"second\"];\n }\n\n /**\n * Pushes an item into the batch and returns immediately with a unique ID.\n * The item will be processed asynchronously with other items when the batch is flushed.\n * Use wait(id) to get the processing result.\n *\n * @throws Error if maxQueueSize is exceeded\n */\n push<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n item: TItem,\n ): string {\n // 1. Generate unique ID\n const id = this.crypto.randomUUID();\n\n // 2. Determine the partition key (with error handling)\n let partitionKey: string;\n try {\n partitionKey = context.options.partitionBy\n ? context.options.partitionBy(item)\n : \"default\";\n } catch (error) {\n this.log.warn(\n \"partitionBy function threw an error, using 'default' partition\",\n { error },\n );\n partitionKey = \"default\";\n }\n\n // 3. Create item state\n const itemState: BatchItemState<TItem, TResponse> = {\n id,\n item,\n partitionKey,\n status: \"pending\",\n };\n\n // CAUTION: Do not log.debug/info here as it may cause infinite loops if logging is batched\n\n context.itemStates.set(id, itemState);\n\n // 4. Get or create the partition state\n if (!context.partitions.has(partitionKey)) {\n context.partitions.set(partitionKey, {\n itemIds: [],\n flushing: false,\n });\n }\n const partition = context.partitions.get(partitionKey)!;\n\n // 5. Check maxQueueSize before adding\n if (\n context.options.maxQueueSize !== undefined &&\n partition.itemIds.length >= context.options.maxQueueSize\n ) {\n throw new AlephaError(\n `Batch queue size exceeded for partition '${partitionKey}' (max: ${context.options.maxQueueSize})`,\n );\n }\n\n // 6. Add item ID to partition\n partition.itemIds.push(id);\n\n const maxSize = this.getMaxSize(context);\n const maxDuration = this.getMaxDuration(context);\n\n // 7. Only start processing if the app is ready (after \"ready\" hook)\n // During startup, items are just buffered in memory\n if (context.isReady) {\n // Check if the batch is full\n if (partition.itemIds.length >= maxSize) {\n this.log.trace(\n `Batch partition '${partitionKey}' is full, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush batch partition '${partitionKey}' on max size`,\n error,\n ),\n );\n } else if (!partition.timeout && !partition.flushing) {\n // 8. Start the timeout if it's not already running for this partition and not currently flushing\n partition.timeout = this.dateTime.createTimeout(() => {\n this.log.trace(\n `Batch partition '${partitionKey}' timed out, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush batch partition '${partitionKey}' on timeout`,\n error,\n ),\n );\n }, maxDuration);\n }\n } else {\n // Not ready yet - just buffer items, no size checks or timeouts\n this.log.trace(\n `Buffering item in partition '${partitionKey}' (app not ready yet, ${partition.itemIds.length} items buffered)`,\n );\n }\n\n // 9. Return ID immediately\n return id;\n }\n\n /**\n * Wait for a specific item to be processed and get its result.\n * @param id The item ID returned from push()\n * @returns The processing result\n * @throws If the item doesn't exist or processing failed\n */\n async wait<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n id: string,\n ): Promise<TResponse> {\n const itemState = context.itemStates.get(id);\n if (!itemState) {\n throw new AlephaError(`Item with id '${id}' not found`);\n }\n\n // If already completed or failed, return immediately\n if (itemState.status === \"completed\") {\n return itemState.result!;\n }\n if (itemState.status === \"failed\") {\n throw itemState.error!;\n }\n\n // Create promise on-demand if not already created\n if (!itemState.promise) {\n itemState.promise = new Promise<TResponse>((resolve, reject) => {\n itemState.resolve = resolve;\n itemState.reject = reject;\n });\n }\n\n return itemState.promise;\n }\n\n /**\n * Get the current status of an item.\n * @param id The item ID returned from push()\n * @returns Status information or undefined if item doesn't exist\n */\n status<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n id: string,\n ):\n | { status: \"pending\" | \"processing\" }\n | { status: \"completed\"; result: TResponse }\n | { status: \"failed\"; error: Error }\n | undefined {\n const itemState = context.itemStates.get(id);\n if (!itemState) {\n return undefined;\n }\n\n if (itemState.status === \"completed\") {\n return { status: \"completed\", result: itemState.result! };\n }\n if (itemState.status === \"failed\") {\n return { status: \"failed\", error: itemState.error! };\n }\n return { status: itemState.status };\n }\n\n /**\n * Clears completed and failed items from the context to free memory.\n * Returns the number of items cleared.\n *\n * @param context The batch context\n * @param status Optional: only clear items with this specific status ('completed' or 'failed')\n * @returns The number of items cleared\n */\n clearCompleted<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n status?: \"completed\" | \"failed\",\n ): number {\n let count = 0;\n for (const [id, state] of context.itemStates) {\n if (status) {\n if (state.status === status) {\n context.itemStates.delete(id);\n count++;\n }\n } else if (state.status === \"completed\" || state.status === \"failed\") {\n context.itemStates.delete(id);\n count++;\n }\n }\n return count;\n }\n\n /**\n * Flush all partitions or a specific partition.\n */\n async flush<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n partitionKey?: string,\n ): Promise<void> {\n const promises: Promise<void>[] = [];\n if (partitionKey) {\n if (context.partitions.has(partitionKey)) {\n promises.push(this.flushPartition(context, partitionKey));\n }\n } else {\n for (const key of context.partitions.keys()) {\n promises.push(this.flushPartition(context, key));\n }\n }\n await Promise.all(promises);\n }\n\n /**\n * Flush a specific partition.\n */\n protected async flushPartition<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n partitionKey: string,\n limit?: number,\n ): Promise<void> {\n const partition = context.partitions.get(partitionKey);\n if (!partition || partition.itemIds.length === 0) {\n context.partitions.delete(partitionKey);\n return;\n }\n\n // Clear the timeout and grab the item IDs (up to limit if specified)\n partition.timeout?.clear();\n partition.timeout = undefined;\n const itemsToTake =\n limit !== undefined\n ? Math.min(limit, partition.itemIds.length)\n : partition.itemIds.length;\n const itemIdsToProcess = partition.itemIds.splice(0, itemsToTake);\n\n // Mark partition as flushing to prevent race conditions\n partition.flushing = true;\n\n // Get the items and mark them as processing\n const itemsToProcess: TItem[] = [];\n for (const id of itemIdsToProcess) {\n const itemState = context.itemStates.get(id);\n if (itemState) {\n itemState.status = \"processing\";\n itemsToProcess.push(itemState.item);\n }\n }\n\n const concurrency = this.getConcurrency(context);\n const maxDuration = this.getMaxDuration(context);\n\n // Wait until there's a free slot (if at concurrency limit)\n while (context.activeHandlers.length >= concurrency) {\n this.log.trace(\n `Batch handler is at concurrency limit, waiting for a slot...`,\n );\n // Wait for any single handler to complete, not all of them\n await Promise.race(context.activeHandlers.map((it) => it.promise));\n }\n\n const promise = Promise.withResolvers<void>();\n context.activeHandlers.push(promise);\n let result: any;\n try {\n result = await context.alepha.context.run(() =>\n // during shutdown, call handler directly to avoid retry cancellation\n context.isShuttingDown\n ? context.options.handler(itemsToProcess)\n : this.retryProvider.retry(\n {\n ...context.options.retry,\n handler: context.options.handler,\n },\n itemsToProcess,\n ),\n );\n\n // Mark all items as completed and resolve their promises\n for (const id of itemIdsToProcess) {\n const itemState = context.itemStates.get(id);\n if (itemState) {\n itemState.status = \"completed\";\n itemState.result = result;\n // Only resolve if someone is waiting\n itemState.resolve?.(result);\n }\n }\n } catch (error) {\n this.log.error(`Batch handler failed`, error);\n\n // Mark all items as failed and reject their promises\n for (const id of itemIdsToProcess) {\n const itemState = context.itemStates.get(id);\n if (itemState) {\n itemState.status = \"failed\";\n itemState.error = error as Error;\n // Only reject if someone is waiting (promise was created)\n itemState.reject?.(error as Error);\n }\n }\n } finally {\n promise.resolve();\n context.activeHandlers = context.activeHandlers.filter(\n (it) => it !== promise,\n );\n\n // Only delete partition if no new items arrived during processing\n const currentPartition = context.partitions.get(partitionKey);\n if (currentPartition?.flushing && currentPartition.itemIds.length === 0) {\n context.partitions.delete(partitionKey);\n } else if (currentPartition) {\n // Reset flushing flag if partition still exists with items\n currentPartition.flushing = false;\n\n // Restart timeout for items that arrived during flush\n if (currentPartition.itemIds.length > 0 && !currentPartition.timeout) {\n currentPartition.timeout = this.dateTime.createTimeout(() => {\n this.log.trace(\n `Batch partition '${partitionKey}' timed out, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush batch partition '${partitionKey}' on timeout`,\n error,\n ),\n );\n }, maxDuration);\n }\n }\n }\n }\n\n /**\n * Mark the context as ready and start processing buffered items.\n * Called after the \"ready\" hook.\n */\n async markReady<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): Promise<void> {\n this.log.debug(\n \"Batch processor is now ready, starting to process buffered items...\",\n );\n context.isReady = true;\n await this.startProcessing(context);\n }\n\n /**\n * Mark the context as shutting down and flush all remaining items.\n */\n async shutdown<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): Promise<void> {\n this.log.debug(\"Flushing all remaining batch partitions on shutdown...\");\n context.isShuttingDown = true;\n await this.flush(context);\n this.log.debug(\"All batch partitions flushed\");\n }\n\n /**\n * Called after the \"ready\" hook to start processing buffered items that were\n * pushed during startup. This checks all partitions and starts timeouts/flushes\n * for items that were accumulated before the app was ready.\n */\n protected async startProcessing<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): Promise<void> {\n const maxSize = this.getMaxSize(context);\n const maxDuration = this.getMaxDuration(context);\n\n for (const [partitionKey, partition] of context.partitions.entries()) {\n if (partition.itemIds.length === 0) {\n continue;\n }\n\n this.log.trace(\n `Starting processing for partition '${partitionKey}' with ${partition.itemIds.length} buffered items`,\n );\n\n // Flush batches of maxSize while we have items >= maxSize\n while (partition.itemIds.length >= maxSize) {\n this.log.trace(\n `Partition '${partitionKey}' has ${partition.itemIds.length} items, flushing batch of ${maxSize}...`,\n );\n await this.flushPartition(context, partitionKey, maxSize);\n }\n\n // After flushing full batches, start timeout for any remaining items\n if (\n partition.itemIds.length > 0 &&\n !partition.timeout &&\n !partition.flushing\n ) {\n this.log.trace(\n `Starting timeout for partition '${partitionKey}' with ${partition.itemIds.length} remaining items`,\n );\n partition.timeout = this.dateTime.createTimeout(() => {\n this.log.trace(\n `Batch partition '${partitionKey}' timed out, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush partition '${partitionKey}' on timeout after startup`,\n error,\n ),\n );\n }, maxDuration);\n }\n }\n }\n}\n","import {\n $hook,\n $inject,\n createPrimitive,\n KIND,\n Primitive,\n type Static,\n type TSchema,\n} from \"alepha\";\nimport type { DurationLike } from \"alepha/datetime\";\nimport type { RetryPrimitiveOptions } from \"alepha/retry\";\nimport {\n type BatchContext,\n type BatchItemState,\n type BatchItemStatus,\n BatchProvider,\n} from \"../providers/BatchProvider.ts\";\n\n/**\n * Creates a batch processing primitive for efficient grouping and processing of multiple operations.\n */\nexport const $batch = <TItem extends TSchema, TResponse>(\n options: BatchPrimitiveOptions<TItem, TResponse>,\n): BatchPrimitive<TItem, TResponse> =>\n createPrimitive(BatchPrimitive<TItem, TResponse>, options);\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface BatchPrimitiveOptions<TItem extends TSchema, TResponse = any> {\n /**\n * TypeBox schema for validating each item added to the batch.\n */\n schema: TItem;\n\n /**\n * The batch processing handler function that processes arrays of validated items.\n */\n handler: (items: Static<TItem>[]) => TResponse;\n\n /**\n * Maximum number of items to collect before automatically flushing the batch.\n */\n maxSize?: number;\n\n /**\n * Maximum number of items that can be queued in a single partition.\n * If exceeded, push() will throw an error.\n */\n maxQueueSize?: number;\n\n /**\n * Maximum time to wait before flushing a batch, even if it hasn't reached maxSize.\n */\n maxDuration?: DurationLike;\n\n /**\n * Function to determine partition keys for grouping items into separate batches.\n */\n partitionBy?: (item: Static<TItem>) => string;\n\n /**\n * Maximum number of batch handlers that can execute simultaneously.\n */\n concurrency?: number;\n\n /**\n * Retry configuration for failed batch processing operations.\n */\n retry?: Omit<RetryPrimitiveOptions<() => Array<Static<TItem>>>, \"handler\">;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type { BatchItemState, BatchItemStatus };\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class BatchPrimitive<\n TItem extends TSchema,\n TResponse = any,\n> extends Primitive<BatchPrimitiveOptions<TItem, TResponse>> {\n protected readonly batchProvider = $inject(BatchProvider);\n protected readonly context: BatchContext<Static<TItem>, TResponse>;\n\n constructor(\n ...args: ConstructorParameters<\n typeof Primitive<BatchPrimitiveOptions<TItem, TResponse>>\n >\n ) {\n super(...args);\n this.context = this.batchProvider.createContext(this.alepha, {\n handler: this.options.handler,\n maxSize: this.options.maxSize,\n maxQueueSize: this.options.maxQueueSize,\n maxDuration: this.options.maxDuration,\n partitionBy: this.options.partitionBy,\n concurrency: this.options.concurrency,\n retry: this.options.retry,\n });\n }\n\n /**\n * Pushes an item into the batch and returns immediately with a unique ID.\n * The item will be processed asynchronously with other items when the batch is flushed.\n * Use wait(id) to get the processing result.\n */\n public async push(item: Static<TItem>): Promise<string> {\n // Validate the item against the schema\n const validatedItem = this.alepha.codec.validate(this.options.schema, item);\n return this.batchProvider.push(this.context, validatedItem);\n }\n\n /**\n * Wait for a specific item to be processed and get its result.\n * @param id The item ID returned from push()\n * @returns The processing result\n * @throws If the item doesn't exist or processing failed\n */\n public async wait(id: string): Promise<TResponse> {\n return this.batchProvider.wait(this.context, id);\n }\n\n /**\n * Get the current status of an item.\n * @param id The item ID returned from push()\n * @returns Status information or undefined if item doesn't exist\n */\n public status(\n id: string,\n ):\n | { status: \"pending\" | \"processing\" }\n | { status: \"completed\"; result: TResponse }\n | { status: \"failed\"; error: Error }\n | undefined {\n return this.batchProvider.status(this.context, id);\n }\n\n /**\n * Flush all partitions or a specific partition.\n */\n public async flush(partitionKey?: string): Promise<void> {\n return this.batchProvider.flush(this.context, partitionKey);\n }\n\n /**\n * Clears completed and failed items from memory.\n * Call this periodically in long-running applications to prevent memory leaks.\n *\n * @param status Optional: only clear items with this specific status ('completed' or 'failed')\n * @returns The number of items cleared\n */\n public clearCompleted(status?: \"completed\" | \"failed\"): number {\n return this.batchProvider.clearCompleted(this.context, status);\n }\n\n protected readonly onReady = $hook({\n on: \"ready\",\n handler: async () => {\n await this.batchProvider.markReady(this.context);\n },\n });\n}\n\n$batch[KIND] = BatchPrimitive;\n","import { $module } from \"alepha\";\nimport { $batch } from \"./primitives/$batch.ts\";\nimport { BatchProvider } from \"./providers/BatchProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./primitives/$batch.ts\";\nexport * from \"./providers/BatchProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Batch accumulation and processing.\n *\n * **Features:**\n * - Batch accumulator with handler\n * - Configurable batch size\n * - Time-based triggers\n * - Status tracking\n *\n * @module alepha.batch\n */\nexport const AlephaBatch = $module({\n name: \"alepha.batch\",\n primitives: [$batch],\n services: [BatchProvider],\n});\n"],"mappings":";;;;;;;;;;AAgIA,IAAa,gBAAb,MAA2B;CACzB,MAAyB,SAAS;CAClC,WAA8B,QAAQ,iBAAiB;CACvD,gBAAmC,QAAQ,cAAc;CACzD,SAA4B,QAAQ,eAAe;;;;CAKnD,2BAA8B,IAAI,KAA6B;;;;CAK/D,cACE,QACA,SACgC;EAChC,MAAM,UAA0C;GAC9C;GACA,4BAAY,IAAI,KAAK;GACrB,4BAAY,IAAI,KAAK;GACrB,gBAAgB,EAAE;GAClB,gBAAgB;GAChB,SAAS;GACT;GACD;EACD,KAAK,SAAS,IAAI,QAAQ;EAC1B,OAAO;;;;;CAMT,SAA4B,MAAM;EAChC,IAAI;EACJ,UAAU;EACV,SAAS,YAAY;GACnB,IAAI,KAAK,SAAS,SAAS,GACzB;GAEF,KAAK,IAAI,MAAM,iBAAiB,KAAK,SAAS,KAAK,sBAAsB;GACzE,MAAM,WAA4B,EAAE;GACpC,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,gBAAgB,KAAK,OAAO,MAAM,SAAS,KAAK,QAAQ,QAAQ,KAAK;EAC3E,OAAO,KAAK,cAAc,KAAK,KAAK,SAAS,cAAc;;;;;;;;CAS7D,MAAa,KAAK,IAAgC;EAChD,OAAO,KAAK,cAAc,KAAK,KAAK,SAAS,GAAG;;;;;;;CAQlD,OACE,IAKY;EACZ,OAAO,KAAK,cAAc,OAAO,KAAK,SAAS,GAAG;;;;;CAMpD,MAAa,MAAM,cAAsC;EACvD,OAAO,KAAK,cAAc,MAAM,KAAK,SAAS,aAAa;;;;;;;;;CAU7D,eAAsB,QAAyC;EAC7D,OAAO,KAAK,cAAc,eAAe,KAAK,SAAS,OAAO;;CAGhE,UAA6B,MAAM;EACjC,IAAI;EACJ,SAAS,YAAY;GACnB,MAAM,KAAK,cAAc,UAAU,KAAK,QAAQ;;EAEnD,CAAC;;AAGJ,OAAO,QAAQ;;;;;;;;;;;;;;AC7If,MAAa,cAAc,QAAQ;CACjC,MAAM;CACN,YAAY,CAAC,OAAO;CACpB,UAAU,CAAC,cAAc;CAC1B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/batch/providers/BatchProvider.ts","../../src/batch/primitives/$batch.ts","../../src/batch/index.ts"],"sourcesContent":["import { $hook, $inject, type Alepha, AlephaError } from \"alepha\";\nimport { CryptoProvider } from \"alepha/crypto\";\nimport { DateTimeProvider, type DurationLike } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { type RetryBackoffOptions, RetryProvider } from \"alepha/retry\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface BatchOptions<TItem, TResponse = any> {\n /**\n * The batch processing handler function that processes arrays of validated items.\n */\n handler: (items: TItem[]) => TResponse;\n\n /**\n * Maximum number of items to collect before automatically flushing the batch.\n *\n * @default 10\n */\n maxSize?: number;\n\n /**\n * Maximum number of items that can be queued in a single partition.\n * If exceeded, push() will throw an error.\n */\n maxQueueSize?: number;\n\n /**\n * Maximum time to wait before flushing a batch, even if it hasn't reached maxSize.\n *\n * @default [1, \"second\"]\n */\n maxDuration?: DurationLike;\n\n /**\n * Function to determine partition keys for grouping items into separate batches.\n */\n partitionBy?: (item: TItem) => string;\n\n /**\n * Maximum number of batch handlers that can execute simultaneously.\n *\n * @default 1\n */\n concurrency?: number;\n\n /**\n * Retry configuration for failed batch processing operations.\n */\n retry?: {\n /**\n * The maximum number of attempts.\n *\n * @default 3\n */\n max?: number;\n\n /**\n * The backoff strategy for delays between retries.\n * Can be a fixed number (in ms) or a configuration object for exponential backoff.\n *\n * @default { initial: 200, factor: 2, jitter: true }\n */\n backoff?: number | RetryBackoffOptions;\n\n /**\n * An overall time limit for all retry attempts combined.\n *\n * e.g., `[5, 'seconds']`\n */\n maxDuration?: DurationLike;\n\n /**\n * A function that determines if a retry should be attempted based on the error.\n *\n * @default (error) => true (retries on any error)\n */\n when?: (error: Error) => boolean;\n\n /**\n * A custom callback for when a retry attempt fails.\n * This is called before the delay.\n */\n onError?: (error: Error, attempt: number) => void;\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type BatchItemStatus = \"pending\" | \"processing\" | \"completed\" | \"failed\";\n\nexport interface BatchItemState<TItem, TResponse> {\n id: string;\n item: TItem;\n partitionKey: string;\n status: BatchItemStatus;\n result?: TResponse;\n error?: Error;\n promise?: Promise<TResponse>;\n resolve?: (value: TResponse) => void;\n reject?: (error: Error) => void;\n}\n\nexport interface PartitionState {\n itemIds: string[];\n timeout?: { clear: () => void };\n flushing: boolean;\n}\n\n/**\n * Context object that holds all state for a batch processor instance.\n */\nexport interface BatchContext<TItem, TResponse> {\n options: BatchOptions<TItem, TResponse>;\n itemStates: Map<string, BatchItemState<TItem, TResponse>>;\n partitions: Map<string, PartitionState>;\n activeHandlers: PromiseWithResolvers<void>[];\n isShuttingDown: boolean;\n isReady: boolean;\n alepha: Alepha;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Service for batch processing operations.\n * Provides methods to manage batches of items with automatic flushing based on size or time.\n */\nexport class BatchProvider {\n protected readonly log = $logger();\n protected readonly dateTime = $inject(DateTimeProvider);\n protected readonly retryProvider = $inject(RetryProvider);\n protected readonly crypto = $inject(CryptoProvider);\n\n /**\n * All active batch contexts managed by this provider.\n */\n protected readonly contexts = new Set<BatchContext<any, any>>();\n\n /**\n * Creates a new batch context with the given options.\n */\n createContext<TItem, TResponse>(\n alepha: Alepha,\n options: BatchOptions<TItem, TResponse>,\n ): BatchContext<TItem, TResponse> {\n const context: BatchContext<TItem, TResponse> = {\n options,\n itemStates: new Map(),\n partitions: new Map(),\n activeHandlers: [],\n isShuttingDown: false,\n isReady: false,\n alepha,\n };\n this.contexts.add(context);\n return context;\n }\n\n /**\n * Shutdown hook - flushes all batch contexts on application stop.\n */\n protected readonly onStop = $hook({\n on: \"stop\",\n priority: \"first\",\n handler: async () => {\n if (this.contexts.size === 0) {\n return;\n }\n this.log.debug(`Shutting down ${this.contexts.size} batch context(s)...`);\n const promises: Promise<void>[] = [];\n for (const context of this.contexts) {\n promises.push(this.shutdown(context));\n }\n await Promise.all(promises);\n this.log.debug(\"All batch contexts shut down\");\n },\n });\n\n /**\n * Get the effective maxSize for a context.\n */\n protected getMaxSize<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): number {\n return context.options.maxSize ?? 10;\n }\n\n /**\n * Get the effective concurrency for a context.\n */\n protected getConcurrency<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): number {\n return context.options.concurrency ?? 1;\n }\n\n /**\n * Get the effective maxDuration for a context.\n */\n protected getMaxDuration<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): DurationLike {\n return context.options.maxDuration ?? [1, \"second\"];\n }\n\n /**\n * Pushes an item into the batch and returns immediately with a unique ID.\n * The item will be processed asynchronously with other items when the batch is flushed.\n * Use wait(id) to get the processing result.\n *\n * @throws Error if maxQueueSize is exceeded\n */\n push<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n item: TItem,\n ): string {\n // 1. Generate unique ID\n const id = this.crypto.randomUUID();\n\n // 2. Determine the partition key (with error handling)\n let partitionKey: string;\n try {\n partitionKey = context.options.partitionBy\n ? context.options.partitionBy(item)\n : \"default\";\n } catch (error) {\n this.log.warn(\n \"partitionBy function threw an error, using 'default' partition\",\n { error },\n );\n partitionKey = \"default\";\n }\n\n // 3. Create item state\n const itemState: BatchItemState<TItem, TResponse> = {\n id,\n item,\n partitionKey,\n status: \"pending\",\n };\n\n // CAUTION: Do not log.debug/info here as it may cause infinite loops if logging is batched\n\n context.itemStates.set(id, itemState);\n\n // 4. Get or create the partition state\n if (!context.partitions.has(partitionKey)) {\n context.partitions.set(partitionKey, {\n itemIds: [],\n flushing: false,\n });\n }\n const partition = context.partitions.get(partitionKey)!;\n\n // 5. Check maxQueueSize before adding\n if (\n context.options.maxQueueSize !== undefined &&\n partition.itemIds.length >= context.options.maxQueueSize\n ) {\n throw new AlephaError(\n `Batch queue size exceeded for partition '${partitionKey}' (max: ${context.options.maxQueueSize})`,\n );\n }\n\n // 6. Add item ID to partition\n partition.itemIds.push(id);\n\n const maxSize = this.getMaxSize(context);\n const maxDuration = this.getMaxDuration(context);\n\n // 7. Only start processing if the app is ready (after \"ready\" hook)\n // During startup, items are just buffered in memory\n if (context.isReady) {\n // Check if the batch is full\n if (partition.itemIds.length >= maxSize) {\n this.log.trace(\n `Batch partition '${partitionKey}' is full, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush batch partition '${partitionKey}' on max size`,\n error,\n ),\n );\n } else if (!partition.timeout && !partition.flushing) {\n // 8. Start the timeout if it's not already running for this partition and not currently flushing\n partition.timeout = this.dateTime.createTimeout(() => {\n this.log.trace(\n `Batch partition '${partitionKey}' timed out, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush batch partition '${partitionKey}' on timeout`,\n error,\n ),\n );\n }, maxDuration);\n }\n } else {\n // Not ready yet - just buffer items, no size checks or timeouts\n this.log.trace(\n `Buffering item in partition '${partitionKey}' (app not ready yet, ${partition.itemIds.length} items buffered)`,\n );\n }\n\n // 9. Return ID immediately\n return id;\n }\n\n /**\n * Wait for a specific item to be processed and get its result.\n * @param id The item ID returned from push()\n * @returns The processing result\n * @throws If the item doesn't exist or processing failed\n */\n async wait<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n id: string,\n ): Promise<TResponse> {\n const itemState = context.itemStates.get(id);\n if (!itemState) {\n throw new AlephaError(`Item with id '${id}' not found`);\n }\n\n // If already completed or failed, return immediately\n if (itemState.status === \"completed\") {\n return itemState.result!;\n }\n if (itemState.status === \"failed\") {\n throw itemState.error!;\n }\n\n // Create promise on-demand if not already created\n if (!itemState.promise) {\n itemState.promise = new Promise<TResponse>((resolve, reject) => {\n itemState.resolve = resolve;\n itemState.reject = reject;\n });\n }\n\n return itemState.promise;\n }\n\n /**\n * Get the current status of an item.\n * @param id The item ID returned from push()\n * @returns Status information or undefined if item doesn't exist\n */\n status<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n id: string,\n ):\n | { status: \"pending\" | \"processing\" }\n | { status: \"completed\"; result: TResponse }\n | { status: \"failed\"; error: Error }\n | undefined {\n const itemState = context.itemStates.get(id);\n if (!itemState) {\n return undefined;\n }\n\n if (itemState.status === \"completed\") {\n return { status: \"completed\", result: itemState.result! };\n }\n if (itemState.status === \"failed\") {\n return { status: \"failed\", error: itemState.error! };\n }\n return { status: itemState.status };\n }\n\n /**\n * Clears completed and failed items from the context to free memory.\n * Returns the number of items cleared.\n *\n * @param context The batch context\n * @param status Optional: only clear items with this specific status ('completed' or 'failed')\n * @returns The number of items cleared\n */\n clearCompleted<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n status?: \"completed\" | \"failed\",\n ): number {\n let count = 0;\n for (const [id, state] of context.itemStates) {\n if (status) {\n if (state.status === status) {\n context.itemStates.delete(id);\n count++;\n }\n } else if (state.status === \"completed\" || state.status === \"failed\") {\n context.itemStates.delete(id);\n count++;\n }\n }\n return count;\n }\n\n /**\n * Flush all partitions or a specific partition.\n */\n async flush<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n partitionKey?: string,\n ): Promise<void> {\n const promises: Promise<void>[] = [];\n if (partitionKey) {\n if (context.partitions.has(partitionKey)) {\n promises.push(this.flushPartition(context, partitionKey));\n }\n } else {\n for (const key of context.partitions.keys()) {\n promises.push(this.flushPartition(context, key));\n }\n }\n await Promise.all(promises);\n }\n\n /**\n * Flush a specific partition.\n */\n protected async flushPartition<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n partitionKey: string,\n limit?: number,\n ): Promise<void> {\n const partition = context.partitions.get(partitionKey);\n if (!partition || partition.itemIds.length === 0) {\n context.partitions.delete(partitionKey);\n return;\n }\n\n // Clear the timeout and grab the item IDs (up to limit if specified)\n partition.timeout?.clear();\n partition.timeout = undefined;\n const itemsToTake =\n limit !== undefined\n ? Math.min(limit, partition.itemIds.length)\n : partition.itemIds.length;\n const itemIdsToProcess = partition.itemIds.splice(0, itemsToTake);\n\n // Mark partition as flushing to prevent race conditions\n partition.flushing = true;\n\n // Get the items and mark them as processing\n const itemsToProcess: TItem[] = [];\n for (const id of itemIdsToProcess) {\n const itemState = context.itemStates.get(id);\n if (itemState) {\n itemState.status = \"processing\";\n itemsToProcess.push(itemState.item);\n }\n }\n\n const concurrency = this.getConcurrency(context);\n const maxDuration = this.getMaxDuration(context);\n\n // Wait until there's a free slot (if at concurrency limit)\n while (context.activeHandlers.length >= concurrency) {\n this.log.trace(\n `Batch handler is at concurrency limit, waiting for a slot...`,\n );\n // Wait for any single handler to complete, not all of them\n await Promise.race(context.activeHandlers.map((it) => it.promise));\n }\n\n const promise = Promise.withResolvers<void>();\n context.activeHandlers.push(promise);\n let result: any;\n try {\n result = await context.alepha.context.run(() =>\n // during shutdown, call handler directly to avoid retry cancellation\n context.isShuttingDown\n ? context.options.handler(itemsToProcess)\n : this.retryProvider.retry(\n {\n ...context.options.retry,\n handler: context.options.handler,\n },\n itemsToProcess,\n ),\n );\n\n // Mark all items as completed and resolve their promises\n for (const id of itemIdsToProcess) {\n const itemState = context.itemStates.get(id);\n if (itemState) {\n itemState.status = \"completed\";\n itemState.result = result;\n // Only resolve if someone is waiting\n itemState.resolve?.(result);\n }\n }\n } catch (error) {\n this.log.error(`Batch handler failed`, error);\n\n // Mark all items as failed and reject their promises\n for (const id of itemIdsToProcess) {\n const itemState = context.itemStates.get(id);\n if (itemState) {\n itemState.status = \"failed\";\n itemState.error = error as Error;\n // Only reject if someone is waiting (promise was created)\n itemState.reject?.(error as Error);\n }\n }\n } finally {\n promise.resolve();\n context.activeHandlers = context.activeHandlers.filter(\n (it) => it !== promise,\n );\n\n // Only delete partition if no new items arrived during processing\n const currentPartition = context.partitions.get(partitionKey);\n if (currentPartition?.flushing && currentPartition.itemIds.length === 0) {\n context.partitions.delete(partitionKey);\n } else if (currentPartition) {\n // Reset flushing flag if partition still exists with items\n currentPartition.flushing = false;\n\n // Restart timeout for items that arrived during flush\n if (currentPartition.itemIds.length > 0 && !currentPartition.timeout) {\n currentPartition.timeout = this.dateTime.createTimeout(() => {\n this.log.trace(\n `Batch partition '${partitionKey}' timed out, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush batch partition '${partitionKey}' on timeout`,\n error,\n ),\n );\n }, maxDuration);\n }\n }\n }\n }\n\n /**\n * Mark the context as ready and start processing buffered items.\n * Called after the \"ready\" hook.\n */\n async markReady<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): Promise<void> {\n this.log.debug(\n \"Batch processor is now ready, starting to process buffered items...\",\n );\n context.isReady = true;\n await this.startProcessing(context);\n }\n\n /**\n * Mark the context as shutting down and flush all remaining items.\n */\n async shutdown<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): Promise<void> {\n this.log.debug(\"Flushing all remaining batch partitions on shutdown...\");\n context.isShuttingDown = true;\n await this.flush(context);\n this.log.debug(\"All batch partitions flushed\");\n }\n\n /**\n * Called after the \"ready\" hook to start processing buffered items that were\n * pushed during startup. This checks all partitions and starts timeouts/flushes\n * for items that were accumulated before the app was ready.\n */\n protected async startProcessing<TItem, TResponse>(\n context: BatchContext<TItem, TResponse>,\n ): Promise<void> {\n const maxSize = this.getMaxSize(context);\n const maxDuration = this.getMaxDuration(context);\n\n for (const [partitionKey, partition] of context.partitions.entries()) {\n if (partition.itemIds.length === 0) {\n continue;\n }\n\n this.log.trace(\n `Starting processing for partition '${partitionKey}' with ${partition.itemIds.length} buffered items`,\n );\n\n // Flush batches of maxSize while we have items >= maxSize\n while (partition.itemIds.length >= maxSize) {\n this.log.trace(\n `Partition '${partitionKey}' has ${partition.itemIds.length} items, flushing batch of ${maxSize}...`,\n );\n await this.flushPartition(context, partitionKey, maxSize);\n }\n\n // After flushing full batches, start timeout for any remaining items\n if (\n partition.itemIds.length > 0 &&\n !partition.timeout &&\n !partition.flushing\n ) {\n this.log.trace(\n `Starting timeout for partition '${partitionKey}' with ${partition.itemIds.length} remaining items`,\n );\n partition.timeout = this.dateTime.createTimeout(() => {\n this.log.trace(\n `Batch partition '${partitionKey}' timed out, flushing...`,\n );\n this.flushPartition(context, partitionKey).catch((error) =>\n this.log.error(\n `Failed to flush partition '${partitionKey}' on timeout after startup`,\n error,\n ),\n );\n }, maxDuration);\n }\n }\n }\n}\n","import {\n $hook,\n $inject,\n createPrimitive,\n KIND,\n Primitive,\n type Static,\n type TSchema,\n} from \"alepha\";\nimport type { DurationLike } from \"alepha/datetime\";\nimport type { RetryPrimitiveOptions } from \"alepha/retry\";\nimport {\n type BatchContext,\n type BatchItemState,\n type BatchItemStatus,\n BatchProvider,\n} from \"../providers/BatchProvider.ts\";\n\n/**\n * Creates a batch processing primitive for efficient grouping and processing of multiple operations.\n */\nexport const $batch = <TItem extends TSchema, TResponse>(\n options: BatchPrimitiveOptions<TItem, TResponse>,\n): BatchPrimitive<TItem, TResponse> =>\n createPrimitive(BatchPrimitive<TItem, TResponse>, options);\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface BatchPrimitiveOptions<TItem extends TSchema, TResponse = any> {\n /**\n * TypeBox schema for validating each item added to the batch.\n */\n schema: TItem;\n\n /**\n * The batch processing handler function that processes arrays of validated items.\n */\n handler: (items: Static<TItem>[]) => TResponse;\n\n /**\n * Maximum number of items to collect before automatically flushing the batch.\n */\n maxSize?: number;\n\n /**\n * Maximum number of items that can be queued in a single partition.\n * If exceeded, push() will throw an error.\n */\n maxQueueSize?: number;\n\n /**\n * Maximum time to wait before flushing a batch, even if it hasn't reached maxSize.\n */\n maxDuration?: DurationLike;\n\n /**\n * Function to determine partition keys for grouping items into separate batches.\n */\n partitionBy?: (item: Static<TItem>) => string;\n\n /**\n * Maximum number of batch handlers that can execute simultaneously.\n */\n concurrency?: number;\n\n /**\n * Retry configuration for failed batch processing operations.\n */\n retry?: Omit<RetryPrimitiveOptions<() => Array<Static<TItem>>>, \"handler\">;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type { BatchItemState, BatchItemStatus };\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class BatchPrimitive<\n TItem extends TSchema,\n TResponse = any,\n> extends Primitive<BatchPrimitiveOptions<TItem, TResponse>> {\n protected readonly batchProvider = $inject(BatchProvider);\n protected readonly context: BatchContext<Static<TItem>, TResponse>;\n\n constructor(\n ...args: ConstructorParameters<\n typeof Primitive<BatchPrimitiveOptions<TItem, TResponse>>\n >\n ) {\n super(...args);\n this.context = this.batchProvider.createContext(this.alepha, {\n handler: this.options.handler,\n maxSize: this.options.maxSize,\n maxQueueSize: this.options.maxQueueSize,\n maxDuration: this.options.maxDuration,\n partitionBy: this.options.partitionBy,\n concurrency: this.options.concurrency,\n retry: this.options.retry,\n });\n }\n\n /**\n * Pushes an item into the batch and returns immediately with a unique ID.\n * The item will be processed asynchronously with other items when the batch is flushed.\n * Use wait(id) to get the processing result.\n */\n public async push(item: Static<TItem>): Promise<string> {\n // Validate the item against the schema\n const validatedItem = this.alepha.codec.validate(this.options.schema, item);\n return this.batchProvider.push(this.context, validatedItem);\n }\n\n /**\n * Wait for a specific item to be processed and get its result.\n * @param id The item ID returned from push()\n * @returns The processing result\n * @throws If the item doesn't exist or processing failed\n */\n public async wait(id: string): Promise<TResponse> {\n return this.batchProvider.wait(this.context, id);\n }\n\n /**\n * Get the current status of an item.\n * @param id The item ID returned from push()\n * @returns Status information or undefined if item doesn't exist\n */\n public status(\n id: string,\n ):\n | { status: \"pending\" | \"processing\" }\n | { status: \"completed\"; result: TResponse }\n | { status: \"failed\"; error: Error }\n | undefined {\n return this.batchProvider.status(this.context, id);\n }\n\n /**\n * Flush all partitions or a specific partition.\n */\n public async flush(partitionKey?: string): Promise<void> {\n return this.batchProvider.flush(this.context, partitionKey);\n }\n\n /**\n * Clears completed and failed items from memory.\n * Call this periodically in long-running applications to prevent memory leaks.\n *\n * @param status Optional: only clear items with this specific status ('completed' or 'failed')\n * @returns The number of items cleared\n */\n public clearCompleted(status?: \"completed\" | \"failed\"): number {\n return this.batchProvider.clearCompleted(this.context, status);\n }\n\n protected readonly onReady = $hook({\n on: \"ready\",\n handler: async () => {\n await this.batchProvider.markReady(this.context);\n },\n });\n}\n\n$batch[KIND] = BatchPrimitive;\n","import { $module } from \"alepha\";\nimport { $batch } from \"./primitives/$batch.ts\";\nimport { BatchProvider } from \"./providers/BatchProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./primitives/$batch.ts\";\nexport * from \"./providers/BatchProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Batch accumulation and processing.\n *\n * **Features:**\n * - Batch accumulator with handler\n * - Configurable batch size\n * - Time-based triggers\n * - Status tracking\n *\n * @module alepha.batch\n */\nexport const AlephaBatch = $module({\n name: \"alepha.batch\",\n primitives: [$batch],\n services: [BatchProvider],\n});\n"],"mappings":";;;;;;;;;;AAgIA,IAAa,gB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K,OAAO;EACjD;CACF,CAAC;AACH;AAEA,OAAO,QAAQ;;;;;;;;;;;;;;AC7If,MAAa,cAAc,QAAQ;CACjC,MAAM;CACN,YAAY,CAAC,MAAM;CACnB,UAAU,CAAC,aAAa;AAC1B,CAAC"}
|
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/bin/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Alepha, run } from \"alepha\";\nimport { AlephaCli, version } from \"alepha/cli\";\n\nconst alepha = Alepha.create({\n env: {\n APP_NAME: \"CLI\",\n CLI_NAME: \"alepha\",\n CLI_DESCRIPTION: `Alepha CLI v${version} - Create and manage Alepha projects.`,\n LOG_FORMAT: (process.env.LOG_FORMAT ?? \"raw\") as any,\n LOG_LEVEL: process.env.LOG_LEVEL ?? \"alepha.core:warn,info\",\n },\n});\n\nalepha.with(AlephaCli);\n\nrun(alepha);\n"],"mappings":";;;;AAIA,MAAM,SAAS,OAAO,OAAO,EAC3B,KAAK;CACH,UAAU;CACV,UAAU;CACV,iBAAiB,eAAe,QAAQ;CACxC,YAAa,QAAQ,IAAI,cAAc;CACvC,WAAW,QAAQ,IAAI,aAAa;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/bin/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Alepha, run } from \"alepha\";\nimport { AlephaCli, version } from \"alepha/cli\";\n\nconst alepha = Alepha.create({\n env: {\n APP_NAME: \"CLI\",\n CLI_NAME: \"alepha\",\n CLI_DESCRIPTION: `Alepha CLI v${version} - Create and manage Alepha projects.`,\n LOG_FORMAT: (process.env.LOG_FORMAT ?? \"raw\") as any,\n LOG_LEVEL: process.env.LOG_LEVEL ?? \"alepha.core:warn,info\",\n },\n});\n\nalepha.with(AlephaCli);\n\nrun(alepha);\n"],"mappings":";;;;AAIA,MAAM,SAAS,OAAO,OAAO,EAC3B,KAAK;CACH,UAAU;CACV,UAAU;CACV,iBAAiB,eAAe,QAAQ;CACxC,YAAa,QAAQ,IAAI,cAAc;CACvC,WAAW,QAAQ,IAAI,aAAa;AACtC,EACF,CAAC;AAED,OAAO,KAAK,SAAS;AAErB,IAAI,MAAM"}
|