alepha 0.22.0 → 0.24.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/assets/swagger-ui/swagger-ui-bundle.js +1 -1
- package/assets/swagger-ui/swagger-ui-standalone-preset.js +1 -1
- package/dist/api/audits/index.browser.js +49 -52
- package/dist/api/audits/index.browser.js.map +1 -1
- package/dist/api/audits/index.d.ts +629 -565
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +206 -98
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.browser.js +44 -44
- package/dist/api/files/index.browser.js.map +1 -1
- package/dist/api/files/index.d.ts +292 -293
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +61 -64
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.browser.js +61 -59
- package/dist/api/jobs/index.browser.js.map +1 -1
- package/dist/api/jobs/index.d.ts +546 -347
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +165 -86
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/keys/index.d.ts +242 -230
- package/dist/api/keys/index.d.ts.map +1 -1
- package/dist/api/keys/index.js +63 -66
- package/dist/api/keys/index.js.map +1 -1
- package/dist/api/notifications/index.browser.js +40 -38
- package/dist/api/notifications/index.browser.js.map +1 -1
- package/dist/api/notifications/index.d.ts +339 -209
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js +108 -60
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/oauth/index.d.ts +190 -78
- package/dist/api/oauth/index.d.ts.map +1 -1
- package/dist/api/oauth/index.js +290 -68
- package/dist/api/oauth/index.js.map +1 -1
- package/dist/api/organizations/index.browser.js +14 -14
- package/dist/api/organizations/index.browser.js.map +1 -1
- package/dist/api/organizations/index.d.ts +158 -134
- package/dist/api/organizations/index.d.ts.map +1 -1
- package/dist/api/organizations/index.js +18 -18
- package/dist/api/organizations/index.js.map +1 -1
- package/dist/api/parameters/index.browser.js +74 -53
- package/dist/api/parameters/index.browser.js.map +1 -1
- package/dist/api/parameters/index.d.ts +607 -513
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/parameters/index.js +205 -127
- package/dist/api/parameters/index.js.map +1 -1
- package/dist/api/payments/index.d.ts +652 -449
- package/dist/api/payments/index.d.ts.map +1 -1
- package/dist/api/payments/index.js +159 -93
- package/dist/api/payments/index.js.map +1 -1
- package/dist/api/subscriptions/index.d.ts +1032 -762
- package/dist/api/subscriptions/index.d.ts.map +1 -1
- package/dist/api/subscriptions/index.js +166 -185
- package/dist/api/subscriptions/index.js.map +1 -1
- package/dist/api/users/index.browser.js +48 -71
- package/dist/api/users/index.browser.js.map +1 -1
- package/dist/api/users/index.d.ts +1297 -1109
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +454 -369
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.browser.js +17 -17
- package/dist/api/verifications/index.browser.js.map +1 -1
- package/dist/api/verifications/index.d.ts +169 -157
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/api/verifications/index.js +47 -95
- package/dist/api/verifications/index.js.map +1 -1
- package/dist/background/index.d.ts +0 -1
- package/dist/background/index.d.ts.map +1 -1
- package/dist/background/index.js.map +1 -1
- package/dist/background/index.workerd.js.map +1 -1
- package/dist/batch/index.d.ts +0 -1
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js.map +1 -1
- package/dist/bin/index.js +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/bucket/index.d.ts +27 -32
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/bucket/index.js +56 -26
- package/dist/bucket/index.js.map +1 -1
- package/dist/bucket/index.workerd.js +52 -24
- package/dist/bucket/index.workerd.js.map +1 -1
- package/dist/cache/core/index.d.ts +4 -6
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/core/index.js +4 -10
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cache/core/index.workerd.js +4 -10
- package/dist/cache/core/index.workerd.js.map +1 -1
- package/dist/cache/database/index.d.ts +22 -23
- package/dist/cache/database/index.d.ts.map +1 -1
- package/dist/cache/database/index.js +11 -20
- package/dist/cache/database/index.js.map +1 -1
- package/dist/cache/redis/index.d.ts +3 -4
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cache/redis/index.js +2 -2
- package/dist/cache/redis/index.js.map +1 -1
- package/dist/captcha/index.d.ts.map +1 -1
- package/dist/captcha/index.js +4 -4
- package/dist/captcha/index.js.map +1 -1
- package/dist/cli/config/index.d.ts +0 -1
- package/dist/cli/config/index.d.ts.map +1 -1
- package/dist/cli/core/index.d.ts +244 -475
- package/dist/cli/core/index.d.ts.map +1 -1
- package/dist/cli/core/index.js +308 -383
- package/dist/cli/core/index.js.map +1 -1
- package/dist/cli/devtools/index.d.ts +3 -9
- package/dist/cli/devtools/index.d.ts.map +1 -1
- package/dist/cli/devtools/index.js +3 -3
- package/dist/cli/devtools/index.js.map +1 -1
- package/dist/cli/i18n/index.d.ts +20 -39
- package/dist/cli/i18n/index.d.ts.map +1 -1
- package/dist/cli/i18n/index.js +51 -17
- package/dist/cli/i18n/index.js.map +1 -1
- package/dist/cli/platform/index.d.ts +89 -82
- package/dist/cli/platform/index.d.ts.map +1 -1
- package/dist/cli/platform/index.js +27 -33
- package/dist/cli/platform/index.js.map +1 -1
- package/dist/cli/platform-lib/index.d.ts +383 -410
- package/dist/cli/platform-lib/index.d.ts.map +1 -1
- package/dist/cli/platform-lib/index.js +300 -258
- package/dist/cli/platform-lib/index.js.map +1 -1
- package/dist/cli/vendor/index.d.ts +17 -41
- package/dist/cli/vendor/index.d.ts.map +1 -1
- package/dist/cli/vendor/index.js +10 -13
- package/dist/cli/vendor/index.js.map +1 -1
- package/dist/command/index.d.ts +82 -194
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +160 -563
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +845 -859
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +787 -527
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +845 -859
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +845 -859
- package/dist/core/index.native.js.map +1 -1
- package/dist/core/index.workerd.js +845 -859
- package/dist/core/index.workerd.js.map +1 -1
- package/dist/crypto/index.browser.js +1 -1
- package/dist/crypto/index.browser.js.map +1 -1
- package/dist/crypto/index.d.ts +3 -4
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js +6 -3
- package/dist/crypto/index.js.map +1 -1
- package/dist/datetime/index.d.ts +12 -2
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js +6 -1
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/brevo/index.d.ts +0 -1
- package/dist/email/brevo/index.d.ts.map +1 -1
- package/dist/email/brevo/index.js +4 -4
- package/dist/email/brevo/index.js.map +1 -1
- package/dist/email/cloudflare/index.d.ts +0 -1
- package/dist/email/cloudflare/index.d.ts.map +1 -1
- package/dist/email/cloudflare/index.js +2 -2
- package/dist/email/cloudflare/index.js.map +1 -1
- package/dist/email/core/index.d.ts +15 -7
- package/dist/email/core/index.d.ts.map +1 -1
- package/dist/email/core/index.js +14 -5
- package/dist/email/core/index.js.map +1 -1
- package/dist/email/core/index.workerd.js +5 -1
- package/dist/email/core/index.workerd.js.map +1 -1
- package/dist/email/smtp/index.d.ts +8 -9
- package/dist/email/smtp/index.d.ts.map +1 -1
- package/dist/email/smtp/index.js +702 -479
- package/dist/email/smtp/index.js.map +1 -1
- package/dist/fake/index.d.ts +1580 -1238
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/fake/index.js +11728 -32131
- package/dist/fake/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +13 -9
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/core/index.js +5 -5
- package/dist/lock/core/index.js.map +1 -1
- package/dist/lock/redis/index.d.ts +0 -1
- 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 +81 -69
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +123 -56
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +36 -90
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +65 -70
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/core/index.browser.js +54 -40
- package/dist/orm/core/index.browser.js.map +1 -1
- package/dist/orm/core/index.bun.js +140 -106
- package/dist/orm/core/index.bun.js.map +1 -1
- package/dist/orm/core/index.d.ts +145 -150
- package/dist/orm/core/index.d.ts.map +1 -1
- package/dist/orm/core/index.js +144 -109
- package/dist/orm/core/index.js.map +1 -1
- package/dist/orm/postgres/index.bun.js +64 -54
- package/dist/orm/postgres/index.bun.js.map +1 -1
- package/dist/orm/postgres/index.d.ts +36 -76
- package/dist/orm/postgres/index.d.ts.map +1 -1
- package/dist/orm/postgres/index.js +67 -57
- package/dist/orm/postgres/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +62 -75
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/core/index.js +48 -71
- package/dist/queue/core/index.js.map +1 -1
- package/dist/queue/core/index.workerd.js +48 -71
- package/dist/queue/core/index.workerd.js.map +1 -1
- package/dist/queue/redis/index.d.ts +3 -4
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/queue/redis/index.js +2 -2
- package/dist/queue/redis/index.js.map +1 -1
- package/dist/react/auth/index.browser.js.map +1 -1
- package/dist/react/auth/index.d.ts +7 -4
- package/dist/react/auth/index.d.ts.map +1 -1
- package/dist/react/auth/index.js.map +1 -1
- package/dist/react/core/index.d.ts +87 -5
- package/dist/react/core/index.d.ts.map +1 -1
- package/dist/react/core/index.js +170 -23
- package/dist/react/core/index.js.map +1 -1
- package/dist/react/form/index.d.ts +4 -6
- package/dist/react/form/index.d.ts.map +1 -1
- package/dist/react/form/index.js +107 -71
- 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 +0 -1
- 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 +47 -5
- package/dist/react/i18n/index.d.ts.map +1 -1
- package/dist/react/i18n/index.js +116 -12
- package/dist/react/i18n/index.js.map +1 -1
- package/dist/react/intro/index.d.ts +1 -4
- package/dist/react/intro/index.d.ts.map +1 -1
- package/dist/react/intro/index.js.map +1 -1
- package/dist/react/router/index.browser.js +188 -29
- package/dist/react/router/index.browser.js.map +1 -1
- package/dist/react/router/index.d.ts +480 -372
- package/dist/react/router/index.d.ts.map +1 -1
- package/dist/react/router/index.js +261 -47
- 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 +91 -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 +4 -5
- package/dist/react/testing/index.d.ts.map +1 -1
- package/dist/react/testing/index.js +41 -15
- package/dist/react/testing/index.js.map +1 -1
- package/dist/react/testing/{chunk-BpyX8vjI.js → rolldown-runtime-Bl3dcgcQ.js} +1 -1
- package/dist/react/ui/index.d.ts +35 -34
- package/dist/react/ui/index.d.ts.map +1 -1
- package/dist/react/ui/index.js +12 -17
- package/dist/react/ui/index.js.map +1 -1
- package/dist/redis/index.bun.js +5 -5
- package/dist/redis/index.bun.js.map +1 -1
- package/dist/redis/index.d.ts +6 -7
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +6 -6
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.d.ts +0 -1
- 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 +4 -12
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js +9 -4
- package/dist/scheduler/index.js.map +1 -1
- package/dist/scheduler/index.workerd.js +9 -4
- package/dist/scheduler/index.workerd.js.map +1 -1
- package/dist/security/index.browser.js +30 -28
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +113 -44
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +452 -37
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.browser.js +19 -19
- package/dist/server/auth/index.browser.js.map +1 -1
- package/dist/server/auth/index.d.ts +215 -187
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +1145 -86
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cookies/index.browser.js +103 -5
- package/dist/server/cookies/index.browser.js.map +1 -1
- package/dist/server/cookies/index.d.ts +86 -4
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/cookies/index.js +121 -8
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.browser.js +22 -27
- package/dist/server/core/index.browser.js.map +1 -1
- package/dist/server/core/index.d.ts +134 -85
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +130 -118
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +9 -10
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/cors/index.js +14 -26
- package/dist/server/cors/index.js.map +1 -1
- package/dist/server/etag/index.d.ts +2 -3
- 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 -19
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/health/index.js +6 -6
- package/dist/server/health/index.js.map +1 -1
- package/dist/server/links/index.browser.js +15 -18
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +66 -67
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +29 -32
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts +0 -1
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/metrics/index.js +10 -3
- package/dist/server/metrics/index.js.map +1 -1
- package/dist/server/proxy/index.d.ts +0 -1
- 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 +8 -9
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.js +6 -12
- package/dist/server/rate-limit/index.js.map +1 -1
- package/dist/server/static/index.d.ts +0 -1
- 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 +4 -4
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js +37 -25
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.d.ts +0 -1
- 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 +0 -1
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js +2 -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 +19 -20
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/core/index.js +8 -8
- package/dist/topic/core/index.js.map +1 -1
- package/dist/topic/redis/index.d.ts +3 -4
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/topic/redis/index.js +2 -2
- package/dist/topic/redis/index.js.map +1 -1
- package/package.json +36 -36
- package/src/api/audits/__tests__/AuditJobs.spec.ts +83 -0
- package/src/api/audits/__tests__/AuditService.spec.ts +139 -1
- package/src/api/audits/controllers/AdminAuditController.ts +41 -41
- package/src/api/audits/entities/audits.ts +22 -22
- package/src/api/audits/index.ts +6 -1
- package/src/api/audits/jobs/AuditJobs.ts +29 -0
- package/src/api/audits/parameters/AuditParameters.ts +51 -0
- package/src/api/audits/primitives/$audit.ts +24 -0
- package/src/api/audits/schemas/auditQuerySchema.ts +13 -13
- package/src/api/audits/schemas/createAuditSchema.ts +18 -18
- package/src/api/audits/services/AuditService.ts +79 -7
- package/src/api/files/__tests__/FileController.spec.ts +5 -5
- package/src/api/files/__tests__/FileJobs.spec.ts +6 -0
- package/src/api/files/controllers/FileController.ts +25 -25
- package/src/api/files/entities/files.ts +15 -15
- package/src/api/files/schemas/fileCreatorSummarySchema.ts +7 -7
- package/src/api/files/schemas/fileQuerySchema.ts +9 -9
- package/src/api/files/schemas/fileResourceSchema.ts +7 -9
- package/src/api/files/schemas/storageStatsSchema.ts +13 -13
- package/src/api/jobs/__tests__/$job-hardening.spec.ts +289 -0
- package/src/api/jobs/__tests__/$job.spec.ts +18 -18
- package/src/api/jobs/controllers/AdminJobController.ts +8 -8
- package/src/api/jobs/entities/jobExecutionEntity.ts +29 -19
- package/src/api/jobs/providers/JobProvider.ts +128 -12
- package/src/api/jobs/providers/JobQueueProvider.ts +2 -2
- package/src/api/jobs/schemas/jobConfigAtom.ts +22 -22
- package/src/api/jobs/schemas/jobExecutionQuerySchema.ts +6 -6
- package/src/api/jobs/schemas/jobExecutionResourceSchema.ts +11 -15
- package/src/api/jobs/schemas/jobRegistrationSchema.ts +20 -19
- package/src/api/jobs/schemas/triggerJobSchema.ts +3 -3
- package/src/api/jobs/services/JobService.ts +6 -6
- package/src/api/keys/__tests__/ApiKeyService.spec.ts +2 -2
- package/src/api/keys/controllers/AdminApiKeyController.ts +10 -10
- package/src/api/keys/entities/apiKeyEntity.ts +15 -15
- package/src/api/keys/schemas/adminApiKeyQuerySchema.ts +4 -4
- package/src/api/keys/schemas/adminApiKeyResourceSchema.ts +15 -15
- package/src/api/keys/schemas/createApiKeyBodySchema.ts +5 -5
- package/src/api/keys/schemas/createApiKeyResponseSchema.ts +9 -9
- package/src/api/keys/schemas/listApiKeyResponseSchema.ts +13 -13
- package/src/api/keys/schemas/revokeApiKeyParamsSchema.ts +3 -3
- package/src/api/keys/schemas/revokeApiKeyResponseSchema.ts +3 -3
- package/src/api/notifications/__tests__/AlephaApiNotifications.spec.ts +2 -2
- package/src/api/notifications/controllers/AdminNotificationController.ts +38 -14
- package/src/api/notifications/jobs/NotificationJobs.ts +7 -6
- package/src/api/notifications/primitives/$notification.ts +43 -4
- package/src/api/notifications/schemas/notificationContactPreferencesSchema.ts +4 -4
- package/src/api/notifications/schemas/notificationContactSchema.ts +7 -7
- package/src/api/notifications/schemas/notificationDetailResourceSchema.ts +9 -11
- package/src/api/notifications/schemas/notificationPayloadSchema.ts +11 -9
- package/src/api/notifications/schemas/notificationQuerySchema.ts +6 -6
- package/src/api/notifications/schemas/notificationResourceSchema.ts +14 -14
- package/src/api/notifications/services/NotificationSenderService.ts +38 -2
- package/src/api/oauth/__tests__/OAuthClientService.spec.ts +42 -0
- package/src/api/oauth/__tests__/OAuthController.spec.ts +128 -0
- package/src/api/oauth/controllers/OAuthController.ts +132 -12
- package/src/api/oauth/entities/oauthClientEntity.ts +29 -12
- package/src/api/oauth/helpers/oauthMetadata.ts +1 -0
- package/src/api/oauth/helpers/oidcMetadata.ts +19 -0
- package/src/api/oauth/index.ts +1 -0
- package/src/api/oauth/schemas/authorizeDecisionBodySchema.ts +12 -11
- package/src/api/oauth/schemas/authorizeQuerySchema.ts +12 -10
- package/src/api/oauth/schemas/registerClientBodySchema.ts +10 -11
- package/src/api/oauth/schemas/tokenRequestBodySchema.ts +9 -8
- package/src/api/oauth/services/OAuthClientService.ts +228 -15
- package/src/api/organizations/controllers/AdminOrganizationController.ts +8 -8
- package/src/api/organizations/entities/organizations.ts +6 -6
- package/src/api/organizations/schemas/createOrganizationSchema.ts +5 -5
- package/src/api/organizations/schemas/organizationQuerySchema.ts +4 -4
- package/src/api/organizations/schemas/updateOrganizationSchema.ts +1 -2
- package/src/api/parameters/__tests__/$parameter.spec.ts +229 -50
- package/src/api/parameters/controllers/AdminParameterController.ts +9 -12
- package/src/api/parameters/entities/parameters.ts +29 -16
- package/src/api/parameters/primitives/$parameter.ts +3 -3
- package/src/api/parameters/schemas/activateParameterBodySchema.ts +4 -4
- package/src/api/parameters/schemas/createParameterVersionBodySchema.ts +15 -15
- package/src/api/parameters/schemas/parameterCreatorSummarySchema.ts +7 -7
- package/src/api/parameters/schemas/parameterCurrentResponseSchema.ts +7 -7
- package/src/api/parameters/schemas/parameterHistoryResponseSchema.ts +3 -3
- package/src/api/parameters/schemas/parameterNameParamSchema.ts +2 -3
- package/src/api/parameters/schemas/parameterNamesResponseSchema.ts +3 -3
- package/src/api/parameters/schemas/parameterResponseSchema.ts +3 -3
- package/src/api/parameters/schemas/parameterStatusSchema.ts +2 -2
- package/src/api/parameters/schemas/parameterTreeNodeSchema.ts +6 -6
- package/src/api/parameters/schemas/parameterVersionParamSchema.ts +5 -6
- package/src/api/parameters/schemas/parameterVersionResponseSchema.ts +3 -3
- package/src/api/parameters/schemas/rollbackParameterBodySchema.ts +6 -9
- package/src/api/parameters/services/ParameterProvider.ts +152 -65
- package/src/api/payments/controllers/AdminPaymentController.ts +7 -7
- package/src/api/payments/controllers/MockCheckoutController.ts +79 -28
- package/src/api/payments/controllers/PaymentController.ts +4 -4
- package/src/api/payments/entities/paymentIntents.ts +11 -11
- package/src/api/payments/entities/paymentMethods.ts +11 -11
- package/src/api/payments/entities/refunds.ts +9 -9
- package/src/api/payments/providers/PaymentProvider.ts +18 -0
- package/src/api/payments/schemas/intentSchemas.ts +25 -25
- package/src/api/payments/schemas/paymentMethodSchemas.ts +3 -3
- package/src/api/payments/services/PaymentService.ts +60 -3
- package/src/api/subscriptions/__tests__/SubscriptionService.spec.ts +14 -0
- package/src/api/subscriptions/controllers/AdminSubscriptionController.ts +11 -11
- package/src/api/subscriptions/controllers/SubscriptionController.ts +5 -4
- package/src/api/subscriptions/entities/subscriptionEvents.ts +15 -15
- package/src/api/subscriptions/entities/subscriptions.ts +22 -22
- package/src/api/subscriptions/notifications/SubscriptionNotifications.ts +22 -22
- package/src/api/subscriptions/schemas/cancelSubscriptionSchema.ts +4 -4
- package/src/api/subscriptions/schemas/changePlanSchema.ts +5 -5
- package/src/api/subscriptions/schemas/createSubscriptionSchema.ts +14 -7
- package/src/api/subscriptions/schemas/entitlementsSchema.ts +10 -10
- package/src/api/subscriptions/schemas/mrrSchema.ts +9 -9
- package/src/api/subscriptions/schemas/planDefinitionSchema.ts +21 -21
- package/src/api/subscriptions/schemas/planResourceSchema.ts +19 -19
- package/src/api/subscriptions/schemas/subscriptionQuerySchema.ts +8 -8
- package/src/api/subscriptions/schemas/subscriptionSettingsSchema.ts +7 -7
- package/src/api/subscriptions/schemas/subscriptionStatsSchema.ts +17 -17
- package/src/api/subscriptions/services/SubscriptionConfig.ts +2 -2
- package/src/api/users/__tests__/ApiKeys-integration.spec.ts +11 -11
- package/src/api/users/atoms/realmAuthSettingsAtom.ts +111 -119
- package/src/api/users/controllers/AdminIdentityController.ts +29 -19
- package/src/api/users/controllers/AdminSessionController.ts +37 -27
- package/src/api/users/controllers/AdminUserController.ts +75 -53
- package/src/api/users/controllers/MySessionController.ts +125 -0
- package/src/api/users/controllers/RealmController.ts +9 -9
- package/src/api/users/controllers/UserController.ts +55 -55
- package/src/api/users/entities/identities.ts +8 -8
- package/src/api/users/entities/sessions.ts +17 -17
- package/src/api/users/entities/users.ts +17 -17
- package/src/api/users/index.ts +3 -0
- package/src/api/users/notifications/UserNotifications.ts +76 -24
- package/src/api/users/primitives/$realm.ts +12 -0
- package/src/api/users/schemas/completePasswordResetRequestSchema.ts +8 -12
- package/src/api/users/schemas/completeRegistrationRequestSchema.ts +17 -20
- package/src/api/users/schemas/createUserSchema.ts +2 -2
- package/src/api/users/schemas/identityQuerySchema.ts +4 -4
- package/src/api/users/schemas/identityResourceSchema.ts +3 -2
- package/src/api/users/schemas/loginSchema.ts +4 -4
- package/src/api/users/schemas/passwordResetIntentResponseSchema.ts +6 -8
- package/src/api/users/schemas/realmConfigSchema.ts +10 -10
- package/src/api/users/schemas/registerQuerySchema.ts +6 -6
- package/src/api/users/schemas/registerRequestSchema.ts +21 -43
- package/src/api/users/schemas/registerResponseSchema.ts +2 -2
- package/src/api/users/schemas/registerSchema.ts +13 -31
- package/src/api/users/schemas/registrationIntentResponseSchema.ts +19 -23
- package/src/api/users/schemas/resetPasswordSchema.ts +10 -17
- package/src/api/users/schemas/sessionQuerySchema.ts +3 -3
- package/src/api/users/schemas/sessionResourceSchema.ts +25 -25
- package/src/api/users/schemas/updateUserSchema.ts +3 -4
- package/src/api/users/schemas/userQuerySchema.ts +7 -7
- package/src/api/users/services/RegistrationService.ts +25 -11
- package/src/api/users/services/UserService.ts +12 -6
- package/src/api/verifications/__tests__/CodeVerification.spec.ts +63 -101
- package/src/api/verifications/__tests__/LinkVerification.spec.ts +23 -92
- package/src/api/verifications/controllers/VerificationController.ts +13 -27
- package/src/api/verifications/entities/verifications.ts +13 -14
- package/src/api/verifications/schemas/requestVerificationCodeResponseSchema.ts +17 -14
- package/src/api/verifications/schemas/validateVerificationCodeResponseSchema.ts +9 -10
- package/src/api/verifications/schemas/verificationSettingsSchema.ts +65 -66
- package/src/api/verifications/schemas/verificationTypeEnumSchema.ts +2 -2
- package/src/api/verifications/services/VerificationService.ts +12 -0
- package/src/background/__tests__/BackgroundTaskProvider.spec.ts +36 -0
- package/src/batch/__tests__/$batch.spec.ts +22 -22
- package/src/batch/__tests__/startup-buffering.spec.ts +9 -9
- package/src/bin/index.ts +1 -1
- package/src/bucket/__tests__/TenantScopedBucket.spec.ts +60 -0
- package/src/bucket/providers/LocalFileStorageProvider.ts +14 -6
- package/src/bucket/providers/MemoryFileStorageProvider.ts +18 -7
- package/src/bucket/providers/R2FileStorageProvider.ts +14 -6
- package/src/bucket/providers/S3FileStorageProvider.ts +31 -15
- package/src/cache/core/primitives/$cache.ts +7 -10
- package/src/cache/database/entities/cacheEntries.ts +16 -27
- package/src/cache/database/providers/DatabaseCacheProvider.ts +15 -13
- package/src/cache/redis/providers/RedisCacheProvider.ts +6 -6
- package/src/captcha/providers/TurnstileCaptchaProvider.ts +4 -4
- package/src/cli/core/__tests__/BuildCloudflareTask.spec.ts +178 -0
- package/src/cli/core/__tests__/BuildDockerTask.spec.ts +0 -2
- package/src/cli/core/__tests__/DbCommand.spec.ts +108 -0
- package/src/cli/core/atoms/appEntryOptions.ts +5 -5
- package/src/cli/core/atoms/buildOptions.ts +76 -88
- package/src/cli/core/atoms/changelogOptions.ts +3 -3
- package/src/cli/core/atoms/devOptions.ts +3 -3
- package/src/cli/core/commands/build.ts +36 -49
- package/src/cli/core/commands/db.ts +171 -83
- package/src/cli/core/commands/dev.ts +8 -8
- package/src/cli/core/commands/gen/changelog.ts +12 -14
- package/src/cli/core/commands/gen/env.ts +6 -6
- package/src/cli/core/commands/gen/openapi.ts +6 -6
- package/src/cli/core/commands/init.ts +28 -33
- package/src/cli/core/commands/pack.ts +10 -10
- package/src/cli/core/commands/root.ts +7 -8
- package/src/cli/core/commands/test.ts +17 -20
- package/src/cli/core/index.ts +0 -3
- package/src/cli/core/tasks/BuildCloudflareTask.ts +138 -245
- package/src/cli/core/tasks/BuildPrerenderTask.ts +44 -7
- package/src/cli/core/templates/apiHelloResponseSchemaTs.ts +4 -4
- package/src/cli/devtools/atoms/devtoolsOptions.ts +6 -6
- package/src/cli/i18n/__tests__/I18nCheckService.spec.ts +48 -0
- package/src/cli/i18n/atoms/i18nOptions.ts +8 -8
- package/src/cli/i18n/services/I18nCheckService.ts +65 -11
- package/src/cli/platform/commands/SecretsCommand.ts +24 -25
- package/src/cli/platform/commands/platform.ts +40 -46
- package/src/cli/platform/index.ts +1 -1
- package/src/cli/platform-lib/__tests__/CloudflareAdapter.spec.ts +0 -4
- package/src/cli/platform-lib/__tests__/PlatformInspector.spec.ts +10 -3
- package/src/cli/platform-lib/__tests__/VercelAdapter.spec.ts +0 -2
- package/src/cli/platform-lib/adapters/CloudflareAdapter.ts +141 -50
- package/src/cli/platform-lib/adapters/VercelAdapter.ts +6 -11
- package/src/cli/platform-lib/atoms/platformOptions.ts +46 -25
- package/src/cli/platform-lib/schemas/cloudflare.ts +87 -87
- package/src/cli/platform-lib/schemas/platform.ts +51 -51
- package/src/cli/platform-lib/schemas/vercel.ts +28 -28
- package/src/cli/platform-lib/services/CloudflareApi.ts +5 -5
- package/src/cli/platform-lib/services/VercelApi.ts +4 -4
- package/src/cli/platform-lib/services/VercelCli.ts +6 -15
- package/src/cli/platform-lib/services/WranglerApi.ts +6 -15
- package/src/cli/vendor/atoms/vendorOptions.ts +9 -9
- package/src/cli/vendor/commands/VendorCommand.ts +11 -12
- package/src/command/__tests__/$command.spec.ts +82 -83
- package/src/command/__tests__/Asker.spec.ts +6 -13
- package/src/command/__tests__/CliProvider.spec.ts +136 -149
- package/src/command/__tests__/Runner.spec.ts +86 -110
- package/src/command/helpers/Asker.ts +23 -58
- package/src/command/helpers/Runner.ts +34 -110
- package/src/command/index.ts +4 -9
- package/src/command/primitives/$command.ts +10 -10
- package/src/command/providers/CliProvider.ts +183 -161
- package/src/core/Alepha.ts +62 -13
- package/src/core/__tests__/$atom.spec.ts +52 -3
- package/src/core/__tests__/$computed.spec.ts +129 -0
- package/src/core/__tests__/$env.spec.ts +13 -13
- package/src/core/__tests__/$inject.spec.ts +4 -4
- package/src/core/__tests__/$module.spec.ts +1 -1
- package/src/core/__tests__/Alepha-graph.spec.ts +1 -1
- package/src/core/__tests__/Alepha-parseEnv.spec.ts +32 -32
- package/src/core/__tests__/Alepha-start.spec.ts +3 -3
- package/src/core/__tests__/CodecManager.spec.ts +113 -94
- package/src/core/__tests__/KeylessJsonSchemaCodec.spec.ts +138 -138
- package/src/core/__tests__/SchemaValidator.spec.ts +43 -44
- package/src/core/__tests__/StateManager.persist.browser.spec.ts +87 -0
- package/src/core/__tests__/StateManager.spec.ts +423 -0
- package/src/core/__tests__/TypeBox-usecases.spec.ts +8 -8
- package/src/core/__tests__/TypeProvider.spec.ts +314 -309
- package/src/core/__tests__/dump.spec.ts +6 -6
- package/src/core/__tests__/pagination.spec.ts +4 -4
- package/src/core/__tests__/scoped-after-start.spec.ts +43 -0
- package/src/core/errors/TypeBoxError.ts +10 -4
- package/src/core/helpers/FileLike.ts +5 -5
- package/src/core/helpers/coerceStrings.ts +70 -0
- package/src/core/helpers/jsonSchemaToZod.ts +112 -0
- package/src/core/index.shared.ts +4 -1
- package/src/core/primitives/$atom.ts +95 -27
- package/src/core/primitives/$computed.ts +148 -0
- package/src/core/primitives/$env.ts +5 -5
- package/src/core/primitives/$state.ts +1 -1
- package/src/core/providers/AlsProvider.ts +26 -0
- package/src/core/providers/CodecManager.ts +1 -2
- package/src/core/providers/JsonSchemaCodec.ts +1 -2
- package/src/core/providers/KeylessJsonSchemaCodec.ts +82 -57
- package/src/core/providers/SchemaValidator.ts +48 -158
- package/src/core/providers/StateManager.ts +383 -9
- package/src/core/providers/TypeProvider.ts +80 -734
- package/src/core/providers/ZodProvider.ts +380 -0
- package/src/core/providers/zodAugment.ts +69 -0
- package/src/core/schemas/pageQuerySchema.ts +19 -21
- package/src/core/schemas/pageSchema.ts +47 -57
- package/src/crypto/__tests__/SecretProvider.spec.ts +31 -0
- package/src/crypto/providers/SecretProvider.ts +16 -10
- package/src/datetime/primitives/$throttle.ts +6 -1
- package/src/email/brevo/providers/BrevoEmailProvider.ts +4 -4
- package/src/email/cloudflare/providers/CloudflareEmailProvider.ts +6 -6
- package/src/email/core/index.ts +7 -2
- package/src/email/core/primitives/$email.ts +5 -1
- package/src/email/core/providers/LocalEmailProvider.ts +5 -5
- package/src/email/smtp/providers/NodemailerEmailProvider.ts +41 -52
- package/src/fake/__tests__/FakeProvider.spec.ts +110 -110
- package/src/fake/__tests__/keyName.example.ts +21 -21
- package/src/fake/__tests__/keyName.spec.ts +41 -41
- package/src/fake/__tests__/module.example.ts +8 -8
- package/src/fake/providers/FakeProvider.ts +122 -121
- package/src/lock/core/__tests__/lock-mutual-exclusion.spec.ts +44 -0
- package/src/lock/core/index.ts +1 -0
- package/src/lock/core/primitives/$lock.ts +13 -6
- package/src/logger/__tests__/CliFormatterProvider.spec.ts +76 -0
- package/src/logger/__tests__/Logger.spec.ts +49 -0
- package/src/logger/index.ts +25 -18
- package/src/logger/providers/CliFormatterProvider.ts +75 -0
- package/src/logger/schemas/logEntrySchema.ts +10 -10
- package/src/logger/services/Logger.ts +18 -0
- package/src/mcp/__tests__/$prompt.spec.ts +21 -23
- package/src/mcp/__tests__/$tool.spec.ts +22 -22
- package/src/mcp/__tests__/McpServerProvider.spec.ts +82 -11
- package/src/mcp/__tests__/StreamableHttpMcpTransport.spec.ts +2 -2
- package/src/mcp/__tests__/integration.spec.ts +33 -33
- package/src/mcp/primitives/$prompt.ts +11 -9
- package/src/mcp/primitives/$tool.ts +27 -86
- package/src/mcp/providers/McpServerProvider.ts +55 -0
- package/src/mcp/transports/StreamableHttpMcpTransport.ts +7 -7
- package/src/orm/__tests__/$repository-tests.ts +133 -27
- package/src/orm/__tests__/$repository.spec.ts +23 -0
- package/src/orm/__tests__/$transactional-tests.ts +4 -4
- package/src/orm/__tests__/ModelBuilder-tests.ts +28 -28
- package/src/orm/__tests__/ModelBuilder.spec.ts +124 -106
- package/src/orm/__tests__/QueryManager.spec.ts +5 -5
- package/src/orm/__tests__/delete-returning-tests.ts +11 -11
- package/src/orm/__tests__/deletedAt-tests.ts +3 -3
- package/src/orm/__tests__/enums.spec.ts +29 -25
- package/src/orm/__tests__/execute-tests.ts +8 -8
- package/src/orm/__tests__/fixtures/bigEntitySchema.ts +48 -48
- package/src/orm/__tests__/fixtures/userEntitySchema.ts +6 -6
- package/src/orm/__tests__/joins-tests.ts +30 -30
- package/src/orm/__tests__/organization-tests.ts +105 -3
- package/src/orm/__tests__/organization.spec.ts +46 -0
- package/src/orm/__tests__/orm-errors.spec.ts +10 -10
- package/src/orm/__tests__/orm-next-tests.ts +29 -29
- package/src/orm/__tests__/orm-showcase-tests.ts +9 -9
- package/src/orm/__tests__/primaryKey.spec.ts +4 -4
- package/src/orm/__tests__/query-date-encoding-tests.ts +17 -17
- package/src/orm/__tests__/ref-auto-onDelete.spec.ts +14 -14
- package/src/orm/__tests__/references.spec.ts +7 -7
- package/src/orm/__tests__/security.spec.ts +17 -17
- package/src/orm/__tests__/string-operators-tests.ts +5 -5
- package/src/orm/__tests__/timestamps-tests.ts +14 -14
- package/src/orm/__tests__/validation-tests.ts +5 -5
- package/src/orm/core/__tests__/BunSqliteProvider.bun.spec.ts +8 -8
- package/src/orm/core/constants/PG_SYMBOLS.ts +13 -1
- package/src/orm/core/entities/alephaSequences.ts +8 -8
- package/src/orm/core/helpers/pgAttr.ts +4 -4
- package/src/orm/core/primitives/$entity.ts +10 -6
- package/src/orm/core/providers/DatabaseTypeProvider.ts +46 -53
- package/src/orm/core/providers/drivers/BunSqliteProvider.ts +8 -8
- package/src/orm/core/providers/drivers/CloudflareD1Provider.ts +3 -5
- package/src/orm/core/providers/drivers/NodeSqliteProvider.ts +8 -8
- package/src/orm/core/schemas/databaseEnvSchema.ts +4 -4
- package/src/orm/core/schemas/insertSchema.ts +14 -18
- package/src/orm/core/schemas/legacyIdSchema.ts +2 -2
- package/src/orm/core/schemas/updateSchema.ts +10 -16
- package/src/orm/core/services/PgRelationManager.ts +2 -2
- package/src/orm/core/services/QueryManager.ts +13 -2
- package/src/orm/core/services/Repository.ts +88 -33
- package/src/orm/core/services/SqliteModelBuilder.ts +38 -45
- package/src/orm/postgres/__tests__/BunPostgresProvider.bun.spec.ts +4 -4
- package/src/orm/postgres/providers/CloudflareHyperdriveProvider.ts +4 -6
- package/src/orm/postgres/schemas/postgresEnvSchema.ts +6 -6
- package/src/orm/postgres/services/PostgresModelBuilder.ts +127 -114
- package/src/queue/core/__tests__/$consumer.spec.ts +4 -4
- package/src/queue/core/__tests__/WorkerProvider.spec.ts +4 -4
- package/src/queue/core/__tests__/shared.ts +6 -6
- package/src/queue/core/primitives/$consumer.ts +5 -5
- package/src/queue/core/primitives/$queue.ts +44 -61
- package/src/queue/core/providers/CloudflareQueueProvider.ts +6 -0
- package/src/queue/core/providers/WorkerProvider.ts +17 -14
- package/src/queue/redis/providers/RedisQueueProvider.ts +3 -3
- package/src/react/core/__tests__/ErrorBoundary.browser.spec.tsx +92 -0
- package/src/react/core/__tests__/Router.spec.tsx +4 -4
- package/src/react/core/__tests__/useComputed.browser.spec.tsx +192 -0
- package/src/react/core/__tests__/useQuery.browser.spec.tsx +48 -0
- package/src/react/core/__tests__/useSelector.browser.spec.tsx +105 -0
- package/src/react/core/__tests__/useStore.browser.spec.tsx +113 -0
- package/src/react/core/components/ErrorBoundary.tsx +42 -0
- package/src/react/core/hooks/useAction.ts +56 -19
- package/src/react/core/hooks/useComputed.ts +91 -0
- package/src/react/core/hooks/useSelector.ts +67 -0
- package/src/react/core/hooks/useStore.ts +36 -17
- package/src/react/core/index.ts +3 -0
- package/src/react/core/utils/shallowEqual.ts +36 -0
- 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/__tests__/useForm.browser.spec.tsx +54 -54
- package/src/react/form/errors/FormValidationError.ts +0 -2
- package/src/react/form/hooks/useForm.ts +19 -4
- package/src/react/form/hooks/useFormQuerySync.ts +0 -0
- package/src/react/form/services/FormModel.ts +124 -86
- package/src/react/form/services/parseField.ts +66 -27
- package/src/react/i18n/__tests__/I18nProvider.spec.ts +89 -0
- package/src/react/i18n/__tests__/Localize.spec.tsx +1 -1
- package/src/react/i18n/__tests__/locale-routing.spec.ts +107 -0
- package/src/react/i18n/providers/I18nProvider.ts +173 -14
- package/src/react/router/__tests__/$page.browser.spec.tsx +19 -19
- package/src/react/router/__tests__/$page.spec.tsx +21 -21
- package/src/react/router/__tests__/ReactBrowserProvider.browser.spec.ts +87 -1
- package/src/react/router/__tests__/RouterLocaleProvider.spec.ts +127 -0
- package/src/react/router/atoms/ssrManifestAtom.ts +16 -16
- package/src/react/router/components/NestedView.tsx +11 -3
- package/src/react/router/hooks/useQueryParams.ts +1 -1
- 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 +2 -2
- package/src/react/router/providers/ReactBrowserProvider.ts +64 -13
- package/src/react/router/providers/ReactBrowserRouterProvider.ts +15 -1
- package/src/react/router/providers/ReactPageProvider.ts +38 -13
- package/src/react/router/providers/ReactServerProvider.ts +105 -16
- 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/atoms/uiAtom.ts +6 -6
- package/src/react/ui/atoms/uiThemeListAtom.ts +7 -7
- package/src/react/ui/hooks/useColorMode.ts +11 -4
- package/src/react/ui/services/SchemaControl.ts +4 -4
- package/src/redis/providers/BunRedisProvider.ts +19 -11
- package/src/redis/providers/NodeRedisProvider.ts +3 -3
- package/src/scheduler/primitives/$scheduler.ts +21 -8
- package/src/security/__tests__/assertRealmScope.spec.ts +29 -0
- package/src/security/atoms/currentTenantAtom.ts +6 -6
- package/src/security/atoms/currentUserAtom.ts +2 -2
- package/src/security/primitives/$issuer.ts +24 -2
- package/src/security/providers/JwtProvider.ts +100 -0
- package/src/security/providers/SecurityProvider.ts +43 -2
- package/src/security/schemas/permissionSchema.ts +19 -19
- package/src/security/schemas/roleSchema.ts +22 -28
- package/src/security/schemas/userAccountInfoSchema.ts +47 -37
- package/src/server/auth/__tests__/appleClientSecret.spec.ts +34 -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/jtiReplayGuard.ts +41 -0
- package/src/server/auth/helpers/safeRedirectPath.ts +19 -0
- package/src/server/auth/index.ts +1 -0
- package/src/server/auth/primitives/$auth.ts +6 -6
- package/src/server/auth/primitives/$authApple.ts +10 -10
- package/src/server/auth/primitives/$authFacebook.ts +10 -10
- package/src/server/auth/primitives/$authFranceConnect.ts +10 -10
- package/src/server/auth/primitives/$authGithub.ts +10 -10
- package/src/server/auth/primitives/$authGoogle.ts +10 -10
- package/src/server/auth/primitives/$authMicrosoft.ts +14 -14
- package/src/server/auth/providers/ServerAuthProvider.ts +67 -52
- package/src/server/auth/schemas/authenticationProviderSchema.ts +9 -12
- package/src/server/auth/schemas/tokenResponseSchema.ts +2 -2
- package/src/server/auth/schemas/tokensSchema.ts +16 -16
- package/src/server/auth/schemas/userinfoResponseSchema.ts +3 -3
- package/src/server/cookies/__tests__/AtomCookieBinding.spec.ts +80 -0
- package/src/server/cookies/__tests__/AtomCookiePersistence.browser.spec.ts +169 -0
- package/src/server/cookies/__tests__/AtomCookiePersistence.spec.ts +294 -0
- package/src/server/cookies/__tests__/ServerCookiesProvider.spec.ts +82 -12
- package/src/server/cookies/index.browser.ts +4 -1
- package/src/server/cookies/index.ts +8 -1
- package/src/server/cookies/primitives/$cookie.browser.ts +1 -1
- package/src/server/cookies/primitives/$cookie.ts +16 -0
- package/src/server/cookies/providers/AtomCookiePersistence.browser.ts +133 -0
- package/src/server/cookies/providers/AtomCookiePersistence.ts +148 -0
- package/src/server/cookies/providers/ServerCookiesProvider.ts +32 -4
- package/src/server/cookies/services/CookieParser.ts +6 -1
- package/src/server/core/__tests__/$action.spec.ts +13 -13
- package/src/server/core/__tests__/$middleware.spec.ts +10 -10
- package/src/server/core/__tests__/$route.spec.ts +9 -9
- package/src/server/core/__tests__/$sse.spec.ts +26 -26
- package/src/server/core/__tests__/BunHttpServerProvider.bun.spec.ts +6 -6
- package/src/server/core/__tests__/HttpClient.spec.ts +2 -2
- package/src/server/core/__tests__/NodeHttpServerProvider.spec.ts +15 -3
- package/src/server/core/__tests__/ServerBodyParserProvider.spec.ts +14 -14
- package/src/server/core/__tests__/ServerMultipartProvider.spec.ts +33 -33
- package/src/server/core/__tests__/ServerRouterProvider-errorHandler.spec.ts +5 -1
- package/src/server/core/__tests__/ServerRouterProvider-getRoutes.spec.ts +25 -25
- package/src/server/core/__tests__/ServerRouterProvider-serializationError.spec.ts +9 -5
- package/src/server/core/__tests__/ServerRouterProvider-validationError.spec.ts +56 -24
- package/src/server/core/errors/ValidationError.ts +6 -3
- package/src/server/core/helpers/isMultipart.ts +2 -1
- package/src/server/core/index.ts +5 -2
- package/src/server/core/interfaces/ServerRequest.ts +14 -14
- package/src/server/core/primitives/$action.ts +26 -36
- package/src/server/core/primitives/$route.ts +27 -0
- package/src/server/core/primitives/$sse.ts +3 -3
- package/src/server/core/providers/BunHttpServerProvider.ts +8 -9
- package/src/server/core/providers/NodeHttpServerProvider.ts +8 -9
- package/src/server/core/providers/ServerBodyParserProvider.ts +20 -12
- package/src/server/core/providers/ServerCompressProvider.ts +9 -10
- package/src/server/core/providers/ServerHelmetProvider.ts +26 -27
- package/src/server/core/providers/ServerMultipartProvider.ts +19 -19
- package/src/server/core/providers/ServerRouterProvider.ts +44 -15
- package/src/server/core/schemas/errorSchema.ts +20 -25
- package/src/server/core/schemas/okSchema.ts +9 -14
- package/src/server/core/services/HttpClient.ts +13 -1
- package/src/server/core/services/ServerRequestParser.ts +6 -6
- package/src/server/cors/providers/ServerCorsProvider.ts +26 -28
- package/src/server/health/schemas/healthSchema.ts +6 -6
- package/src/server/links/__tests__/$remote.spec.ts +3 -3
- package/src/server/links/__tests__/BatchEndpoint.spec.ts +9 -9
- package/src/server/links/__tests__/LinkProvider.spec.ts +9 -9
- package/src/server/links/__tests__/ServerLinksProvider.spec.ts +23 -23
- package/src/server/links/__tests__/fixtures/CrudApp.ts +21 -21
- package/src/server/links/atoms/apiLinksAtom.ts +2 -2
- package/src/server/links/atoms/linkOptionsAtom.ts +6 -6
- package/src/server/links/primitives/$remote.ts +3 -3
- package/src/server/links/providers/LinkProvider.ts +3 -3
- package/src/server/links/providers/ServerLinksProvider.ts +20 -20
- package/src/server/links/schemas/apiLinksResponseSchema.ts +23 -23
- package/src/server/proxy/__tests__/$proxy.spec.ts +9 -9
- package/src/server/proxy/providers/ServerProxyProvider.ts +5 -0
- package/src/server/rate-limit/providers/ServerRateLimitProvider.ts +18 -20
- package/src/server/swagger/__tests__/$swagger.spec.ts +91 -94
- package/src/server/swagger/__tests__/ui.spec.ts +3 -3
- package/src/server/swagger/providers/ServerSwaggerProvider.ts +66 -43
- package/src/system/__tests__/NodeShellProvider.spec.ts +46 -0
- package/src/system/providers/NodeShellProvider.ts +4 -1
- package/src/topic/core/__tests__/$subscriber.spec.ts +4 -4
- package/src/topic/core/__tests__/shared.ts +8 -8
- package/src/topic/core/primitives/$subscriber.ts +5 -5
- package/src/topic/core/primitives/$topic.ts +14 -14
- package/src/topic/redis/providers/RedisTopicProvider.ts +3 -3
- package/dist/container/core/index.d.ts +0 -236
- package/dist/container/core/index.d.ts.map +0 -1
- package/dist/container/core/index.js +0 -231
- package/dist/container/core/index.js.map +0 -1
- package/dist/container/core/index.workerd.js +0 -192
- package/dist/container/core/index.workerd.js.map +0 -1
- package/src/cli/core/tasks/BuildSitemapTask.ts +0 -130
- package/src/command/helpers/PrettyAsker.ts +0 -256
- package/src/command/helpers/PrettyPrint.ts +0 -332
- package/src/container/core/__tests__/$container.spec.ts +0 -83
- package/src/container/core/index.ts +0 -50
- package/src/container/core/index.workerd.ts +0 -53
- package/src/container/core/interfaces/ContainerOptions.ts +0 -69
- package/src/container/core/primitives/$container.ts +0 -100
- package/src/container/core/providers/CloudflareContainerProvider.ts +0 -70
- package/src/container/core/providers/ContainerProvider.ts +0 -92
- package/src/container/core/providers/MockContainerProvider.ts +0 -62
- package/src/container/core/providers/NodeContainerProvider.ts +0 -53
- package/src/core/__tests__/jsonSchemaToTypeBox.spec.ts +0 -771
- package/src/core/helpers/jsonSchemaToTypeBox.ts +0 -359
- /package/dist/orm/core/{chunk-B4FMCO8f.js → rolldown-runtime-B4FMCO8f.js} +0 -0
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { Settings } from "typebox/system";
|
|
4
|
-
import { Compile } from "typebox/compile";
|
|
5
|
-
import * as Value from "typebox/value";
|
|
1
|
+
import { z as z$1 } from "zod";
|
|
2
|
+
import enLocale from "zod/v4/locales/en.js";
|
|
6
3
|
import { createMiddleware as createMiddleware$1 } from "alepha";
|
|
7
4
|
//#region ../../src/core/constants/KIND.ts
|
|
8
5
|
/**
|
|
@@ -60,6 +57,316 @@ var TooLateSubstitutionError = class extends AlephaError {
|
|
|
60
57
|
}
|
|
61
58
|
};
|
|
62
59
|
//#endregion
|
|
60
|
+
//#region ../../src/core/providers/zodAugment.ts
|
|
61
|
+
const alias = (ctor, name, target) => {
|
|
62
|
+
const proto = ctor?.prototype;
|
|
63
|
+
if (!proto || Object.getOwnPropertyDescriptor(proto, name)) return;
|
|
64
|
+
Object.defineProperty(proto, name, {
|
|
65
|
+
configurable: true,
|
|
66
|
+
get() {
|
|
67
|
+
return this[target];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
alias(z$1.ZodObject, "properties", "shape");
|
|
72
|
+
alias(z$1.ZodArray, "items", "element");
|
|
73
|
+
alias(z$1.ZodUnion, "anyOf", "options");
|
|
74
|
+
{
|
|
75
|
+
const proto = z$1.ZodTuple?.prototype;
|
|
76
|
+
if (proto && !Object.getOwnPropertyDescriptor(proto, "items")) Object.defineProperty(proto, "items", {
|
|
77
|
+
configurable: true,
|
|
78
|
+
get() {
|
|
79
|
+
return this?._zod?.def?.items ?? [];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region ../../src/core/providers/ZodProvider.ts
|
|
85
|
+
z$1.config(enLocale());
|
|
86
|
+
/** Defaults mirroring TypeProvider's static length caps. */
|
|
87
|
+
const Z_LIMITS = {
|
|
88
|
+
short: 64,
|
|
89
|
+
regular: 255,
|
|
90
|
+
long: 1024,
|
|
91
|
+
rich: 65535,
|
|
92
|
+
arrayMaxItems: 1e3
|
|
93
|
+
};
|
|
94
|
+
/** Attach metadata + default without changing the schema's inferred type. */
|
|
95
|
+
const meta = (schema, options) => {
|
|
96
|
+
if (!options) return schema;
|
|
97
|
+
const { default: def, ...rest } = options;
|
|
98
|
+
let s = schema;
|
|
99
|
+
if (def !== void 0) s = s.default(def);
|
|
100
|
+
if (Object.keys(rest).length > 0) s = s.meta(rest);
|
|
101
|
+
return s;
|
|
102
|
+
};
|
|
103
|
+
const applyString = (base, o) => {
|
|
104
|
+
let s = base;
|
|
105
|
+
if (o?.minLength != null) s = s.min(o.minLength);
|
|
106
|
+
if (o?.maxLength != null) s = s.max(o.maxLength);
|
|
107
|
+
if (o?.pattern) s = s.regex(typeof o.pattern === "string" ? new RegExp(o.pattern) : o.pattern);
|
|
108
|
+
return s;
|
|
109
|
+
};
|
|
110
|
+
/** zod's native `.format` getter (uuid/email/safeint/…), guarded. */
|
|
111
|
+
const nativeFmt = (s) => {
|
|
112
|
+
try {
|
|
113
|
+
return s?.format ?? void 0;
|
|
114
|
+
} catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Read the JSON-Schema-style format tag off a schema (drives ORM columns).
|
|
120
|
+
* Prefers our normalized `.meta({ format })` (typebox vocab: `date-time`,
|
|
121
|
+
* `int64`, `binary`, …) and falls back to zod's native `.format`.
|
|
122
|
+
*/
|
|
123
|
+
const fmt = (s) => {
|
|
124
|
+
try {
|
|
125
|
+
return s?.meta?.()?.format ?? nativeFmt(s);
|
|
126
|
+
} catch {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/** zod's internal type discriminator (`string` | `number` | …), wrapping-safe. */
|
|
131
|
+
const defType = (s) => s?._zod?.def?.type;
|
|
132
|
+
/** Tag a string-format schema with its JSON-Schema `format` (stays a real `ZodString`). */
|
|
133
|
+
const strFmt = (base, format) => meta(base, { format });
|
|
134
|
+
const z = {
|
|
135
|
+
/**
|
|
136
|
+
* Native zod coercion namespace (`z.coerce.number()`, `z.coerce.boolean()`…).
|
|
137
|
+
* Used at the HTTP/string boundary (query, headers, env) where everything
|
|
138
|
+
* arrives as a string; request bodies and the ORM stay strict (no coercion).
|
|
139
|
+
*/
|
|
140
|
+
coerce: z$1.coerce,
|
|
141
|
+
object: z$1.object,
|
|
142
|
+
array: z$1.array,
|
|
143
|
+
record: z$1.record,
|
|
144
|
+
tuple: z$1.tuple,
|
|
145
|
+
union: z$1.union,
|
|
146
|
+
string: z$1.string,
|
|
147
|
+
number: z$1.number,
|
|
148
|
+
boolean: z$1.boolean,
|
|
149
|
+
null: z$1.null,
|
|
150
|
+
any: z$1.any,
|
|
151
|
+
void: z$1.void,
|
|
152
|
+
undefined: z$1.undefined,
|
|
153
|
+
literal: z$1.literal,
|
|
154
|
+
/** Alias for `zod.literal` (legacy `t.const`). */
|
|
155
|
+
const: z$1.literal,
|
|
156
|
+
enum: z$1.enum,
|
|
157
|
+
/** Integer — native `z.int()` (format `safeint`, drives PG INT column). */
|
|
158
|
+
integer: z$1.int,
|
|
159
|
+
/** Free-form JSON object (`Record<string, any>`). */
|
|
160
|
+
json: () => z$1.record(z$1.string(), z$1.any()),
|
|
161
|
+
text: (options = {}) => {
|
|
162
|
+
const { size = "regular", trim = true, lowercase = false, maxLength, ...rest } = options;
|
|
163
|
+
const max = maxLength ?? Z_LIMITS[size] ?? Z_LIMITS.regular;
|
|
164
|
+
let s = z$1.string().max(max);
|
|
165
|
+
if (trim) s = s.trim();
|
|
166
|
+
if (lowercase) s = s.toLowerCase();
|
|
167
|
+
return meta(applyString(s, rest), {
|
|
168
|
+
...rest,
|
|
169
|
+
maxLength: max,
|
|
170
|
+
"~options": {
|
|
171
|
+
trim,
|
|
172
|
+
lowercase
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
shortText: (options = {}) => z.text({
|
|
177
|
+
...options,
|
|
178
|
+
size: "short"
|
|
179
|
+
}),
|
|
180
|
+
longText: (options = {}) => z.text({
|
|
181
|
+
...options,
|
|
182
|
+
size: "long"
|
|
183
|
+
}),
|
|
184
|
+
richText: (options = {}) => z.text({
|
|
185
|
+
...options,
|
|
186
|
+
size: "rich"
|
|
187
|
+
}),
|
|
188
|
+
email: () => strFmt(z$1.email(), "email"),
|
|
189
|
+
uuid: () => strFmt(z$1.guid(), "uuid"),
|
|
190
|
+
url: () => strFmt(z$1.url(), "url"),
|
|
191
|
+
datetime: () => strFmt(z$1.iso.datetime(), "date-time"),
|
|
192
|
+
date: () => strFmt(z$1.iso.date(), "date"),
|
|
193
|
+
time: () => strFmt(z$1.iso.time(), "time"),
|
|
194
|
+
/** bigint as a validated string (no codec). */
|
|
195
|
+
bigint: () => strFmt(z$1.string().regex(/^-?\d+$/), "bigint"),
|
|
196
|
+
binary: () => strFmt(z$1.string(), "binary"),
|
|
197
|
+
duration: () => strFmt(z$1.string(), "duration"),
|
|
198
|
+
e164: () => z.text({ pattern: "^\\+[1-9]\\d{1,14}$" }),
|
|
199
|
+
bcp47: () => z.text({ pattern: "^[a-z]{2,3}(?:-[A-Z]{2})?$" }),
|
|
200
|
+
constantCase: () => z.text({ pattern: "^[A-Z_-]+$" }),
|
|
201
|
+
int32: () => z$1.int().min(-2147483648).max(2147483647),
|
|
202
|
+
int64: () => z$1.int().min(-9007199254740991).max(9007199254740991).meta({ format: "int64" }),
|
|
203
|
+
file: (options) => z$1.any().meta({
|
|
204
|
+
format: "binary",
|
|
205
|
+
...options
|
|
206
|
+
}),
|
|
207
|
+
stream: () => z$1.any().meta({ format: "stream" }),
|
|
208
|
+
valueLabel: () => z$1.object({
|
|
209
|
+
value: z.constantCase(),
|
|
210
|
+
label: z.text(),
|
|
211
|
+
description: z.longText().optional()
|
|
212
|
+
}),
|
|
213
|
+
/** Pagination wrapper, mirrors `pageSchema(item)`. */
|
|
214
|
+
page: (item) => z$1.object({
|
|
215
|
+
content: z$1.array(item),
|
|
216
|
+
page: z$1.object({
|
|
217
|
+
number: z$1.int(),
|
|
218
|
+
size: z$1.int(),
|
|
219
|
+
offset: z$1.int(),
|
|
220
|
+
numberOfElements: z$1.int(),
|
|
221
|
+
totalElements: z$1.int().optional(),
|
|
222
|
+
totalPages: z$1.int().optional(),
|
|
223
|
+
isEmpty: z$1.boolean(),
|
|
224
|
+
isFirst: z$1.boolean(),
|
|
225
|
+
isLast: z$1.boolean()
|
|
226
|
+
})
|
|
227
|
+
}),
|
|
228
|
+
/** Export a schema to JSON Schema (OpenAPI / form generation). */
|
|
229
|
+
toJSONSchema: z$1.toJSONSchema,
|
|
230
|
+
/** Runtime type guards (`z.schema.*`) — schema introspection for ORM + forms. */
|
|
231
|
+
schema: {
|
|
232
|
+
isOptional: (s) => s instanceof z$1.ZodOptional,
|
|
233
|
+
isDefault: (s) => s instanceof z$1.ZodDefault,
|
|
234
|
+
isObject: (s) => s instanceof z$1.ZodObject,
|
|
235
|
+
isString: (s) => defType(s) === "string",
|
|
236
|
+
isNumber: (s) => defType(s) === "number",
|
|
237
|
+
isBoolean: (s) => s instanceof z$1.ZodBoolean,
|
|
238
|
+
isArray: (s) => s instanceof z$1.ZodArray,
|
|
239
|
+
isUnion: (s) => s instanceof z$1.ZodUnion,
|
|
240
|
+
isNull: (s) => s instanceof z$1.ZodNull,
|
|
241
|
+
isRecord: (s) => s instanceof z$1.ZodRecord,
|
|
242
|
+
isEnum: (s) => s instanceof z$1.ZodEnum,
|
|
243
|
+
isLiteral: (s) => s instanceof z$1.ZodLiteral,
|
|
244
|
+
isAny: (s) => s instanceof z$1.ZodAny,
|
|
245
|
+
isNullable: (s) => s instanceof z$1.ZodNullable,
|
|
246
|
+
isInteger: (s) => defType(s) === "number" && nativeFmt(s) === "safeint",
|
|
247
|
+
isText: (s) => defType(s) === "string" && !fmt(s),
|
|
248
|
+
isDateTime: (s) => fmt(s) === "date-time",
|
|
249
|
+
isDate: (s) => fmt(s) === "date",
|
|
250
|
+
isTime: (s) => fmt(s) === "time",
|
|
251
|
+
isBigInt: (s) => fmt(s) === "bigint",
|
|
252
|
+
isUuid: (s) => fmt(s) === "uuid",
|
|
253
|
+
isEmail: (s) => fmt(s) === "email",
|
|
254
|
+
isUrl: (s) => fmt(s) === "url",
|
|
255
|
+
isBinary: (s) => fmt(s) === "binary",
|
|
256
|
+
isUUID: (s) => fmt(s) === "uuid",
|
|
257
|
+
isScalar: (s) => s instanceof z$1.ZodString || s instanceof z$1.ZodNumber || s instanceof z$1.ZodBoolean || s instanceof z$1.ZodNull || s instanceof z$1.ZodLiteral || s instanceof z$1.ZodEnum || s instanceof z$1.ZodDate,
|
|
258
|
+
isSchema: (s) => s instanceof z$1.ZodType,
|
|
259
|
+
isTuple: (s) => s instanceof z$1.ZodTuple,
|
|
260
|
+
isUndefined: (s) => s instanceof z$1.ZodUndefined,
|
|
261
|
+
isUnsafe: (s) => s instanceof z$1.ZodAny || s instanceof z$1.ZodUnknown,
|
|
262
|
+
isVoid: (s) => s instanceof z$1.ZodVoid,
|
|
263
|
+
format: (s) => fmt(s),
|
|
264
|
+
/** The string values of a `ZodEnum` (typebox-compat for `value.enum`). */
|
|
265
|
+
enumValues: (s) => {
|
|
266
|
+
const opts = s?.options;
|
|
267
|
+
if (Array.isArray(opts)) return opts;
|
|
268
|
+
const entries = s?._zod?.def?.entries;
|
|
269
|
+
return entries ? Object.values(entries) : [];
|
|
270
|
+
},
|
|
271
|
+
/** Peel optional / nullable / default wrappers to the inner schema. */
|
|
272
|
+
unwrap: (s) => {
|
|
273
|
+
let cur = s;
|
|
274
|
+
while (cur instanceof z$1.ZodOptional || cur instanceof z$1.ZodNullable || cur instanceof z$1.ZodDefault) cur = typeof cur.unwrap === "function" ? cur.unwrap() : cur?._zod?.def?.innerType;
|
|
275
|
+
return cur;
|
|
276
|
+
},
|
|
277
|
+
/**
|
|
278
|
+
* Read a schema's default value (peeling optional/nullable wrappers), or
|
|
279
|
+
* `undefined` if there is none. In zod, defaults are a `ZodDefault` wrapper
|
|
280
|
+
* (not a `default` data property as in typebox), so `"default" in schema`
|
|
281
|
+
* is NOT a valid test — every schema has a `.default()` method.
|
|
282
|
+
*/
|
|
283
|
+
getDefault: (s) => {
|
|
284
|
+
if (s && Object.hasOwn(s, "default")) return s.default;
|
|
285
|
+
let cur = s;
|
|
286
|
+
while (cur) {
|
|
287
|
+
if (cur instanceof z$1.ZodDefault) {
|
|
288
|
+
const dv = cur?._zod?.def?.defaultValue;
|
|
289
|
+
return typeof dv === "function" ? dv() : dv;
|
|
290
|
+
}
|
|
291
|
+
if (cur instanceof z$1.ZodOptional || cur instanceof z$1.ZodNullable) {
|
|
292
|
+
cur = cur.unwrap();
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
/** typebox-compat: the object's required (non-optional) field names. */
|
|
299
|
+
requiredKeys: (s) => {
|
|
300
|
+
const shape = s?.shape;
|
|
301
|
+
return shape ? Object.keys(shape).filter((k) => !(shape[k] instanceof z$1.ZodOptional)) : [];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region ../../src/core/providers/TypeProvider.ts
|
|
307
|
+
/**
|
|
308
|
+
* TypeProvider — now a thin compatibility shim over `z` (zod 4).
|
|
309
|
+
*
|
|
310
|
+
* typebox is gone. `t` is just `z`, and the legacy `T*` type names are
|
|
311
|
+
* re-aliased to their zod equivalents so existing call-sites keep compiling
|
|
312
|
+
* while they are migrated to `z` / `Infer`.
|
|
313
|
+
*/
|
|
314
|
+
/** Raw zod namespace (legacy `Type` escape hatch). */
|
|
315
|
+
const Type = z$1;
|
|
316
|
+
/** Legacy `TypeProvider` — kept for its static config knobs. */
|
|
317
|
+
var TypeProvider = class {
|
|
318
|
+
static DEFAULT_STRING_MAX_LENGTH = 255;
|
|
319
|
+
static DEFAULT_SHORT_STRING_MAX_LENGTH = 64;
|
|
320
|
+
static DEFAULT_LONG_STRING_MAX_LENGTH = 1024;
|
|
321
|
+
static DEFAULT_RICH_STRING_MAX_LENGTH = 65535;
|
|
322
|
+
static DEFAULT_ARRAY_MAX_ITEMS = 1e3;
|
|
323
|
+
static translateError = (error, _locale) => error.message ?? "";
|
|
324
|
+
static setLocale = (_locale) => {};
|
|
325
|
+
static isValidBigInt = (value) => typeof value === "number" ? Number.isInteger(value) : /^-?\d+$/.test(value.trim());
|
|
326
|
+
};
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region ../../src/core/helpers/coerceStrings.ts
|
|
329
|
+
/**
|
|
330
|
+
* Coerce a single string value coming from a string-only boundary (HTTP query,
|
|
331
|
+
* HTTP headers, environment variables) to the JS type its schema declares.
|
|
332
|
+
*
|
|
333
|
+
* This is the zod-standard `z.coerce` behavior applied only at the edges where
|
|
334
|
+
* inputs are inherently strings — request bodies and the ORM stay strict. A
|
|
335
|
+
* value that cannot be coerced is returned unchanged so the subsequent
|
|
336
|
+
* validation produces a proper rejection. Arrays coerce element-wise.
|
|
337
|
+
*/
|
|
338
|
+
const coerceScalar = (schema, value) => {
|
|
339
|
+
const base = z.schema.unwrap(schema);
|
|
340
|
+
if (z.schema.isArray(base) && Array.isArray(value)) {
|
|
341
|
+
const element = base.element;
|
|
342
|
+
return value.map((v) => coerceScalar(element, v));
|
|
343
|
+
}
|
|
344
|
+
if (z.schema.isString(base) && (typeof value === "number" || typeof value === "boolean")) return String(value);
|
|
345
|
+
if (typeof value !== "string") return value;
|
|
346
|
+
if (z.schema.isInteger(base) || z.schema.isNumber(base)) {
|
|
347
|
+
const n = Number(value);
|
|
348
|
+
return value.trim() !== "" && !Number.isNaN(n) ? n : value;
|
|
349
|
+
}
|
|
350
|
+
if (z.schema.isBoolean(base)) {
|
|
351
|
+
if (value === "true") return true;
|
|
352
|
+
if (value === "false") return false;
|
|
353
|
+
return value;
|
|
354
|
+
}
|
|
355
|
+
return value;
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* Coerce each declared field of an object against its object schema. Used to
|
|
359
|
+
* normalize string-only boundary maps (env vars, query objects) before strict
|
|
360
|
+
* validation. Undeclared keys are passed through untouched.
|
|
361
|
+
*/
|
|
362
|
+
const coerceObject = (schema, value) => {
|
|
363
|
+
const shape = schema?.shape;
|
|
364
|
+
if (!shape) return value;
|
|
365
|
+
const out = { ...value };
|
|
366
|
+
for (const key of Object.keys(shape)) if (out[key] != null) out[key] = coerceScalar(shape[key], out[key]);
|
|
367
|
+
return out;
|
|
368
|
+
};
|
|
369
|
+
//#endregion
|
|
63
370
|
//#region ../../src/core/errors/MissingContextError.ts
|
|
64
371
|
var MissingContextError = class extends AlephaError {
|
|
65
372
|
name = "MissingContextError";
|
|
@@ -374,6 +681,24 @@ var AlsProvider = class AlsProvider {
|
|
|
374
681
|
current = current[ALS_PARENT];
|
|
375
682
|
}
|
|
376
683
|
}
|
|
684
|
+
/**
|
|
685
|
+
* Return the raw ALS layer object that owns `key`, walking from the
|
|
686
|
+
* current layer up through parent forks — the same resolution order as
|
|
687
|
+
* the default-scope branch of {@link get}. Returns `undefined` when no
|
|
688
|
+
* active ALS layer (current or any ancestor) has the key.
|
|
689
|
+
*
|
|
690
|
+
* Used by `StateManager.register()` to decode a value in place, in
|
|
691
|
+
* whichever fork layer it physically lives, instead of flattening
|
|
692
|
+
* fork-scoped state into the app-level store.
|
|
693
|
+
*/
|
|
694
|
+
getLayer(key) {
|
|
695
|
+
if (!this.als) return;
|
|
696
|
+
let current = this.als.getStore();
|
|
697
|
+
while (current) {
|
|
698
|
+
if (key in current) return current;
|
|
699
|
+
current = current[ALS_PARENT];
|
|
700
|
+
}
|
|
701
|
+
}
|
|
377
702
|
has(key) {
|
|
378
703
|
if (!this.als) return false;
|
|
379
704
|
const store = this.als.getStore();
|
|
@@ -516,458 +841,6 @@ var HookPrimitive = class extends Primitive {
|
|
|
516
841
|
};
|
|
517
842
|
$hook[KIND] = HookPrimitive;
|
|
518
843
|
//#endregion
|
|
519
|
-
//#region ../../src/core/helpers/FileLike.ts
|
|
520
|
-
const isTypeFile = (value) => {
|
|
521
|
-
return value && typeof value === "object" && "format" in value && value.format === "binary";
|
|
522
|
-
};
|
|
523
|
-
const isFileLike = (value) => {
|
|
524
|
-
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.name === "string" && typeof value.type === "string" && typeof value.size === "number" && typeof value.stream.bind(value) === "function";
|
|
525
|
-
};
|
|
526
|
-
//#endregion
|
|
527
|
-
//#region ../../src/core/providers/TypeProvider.ts
|
|
528
|
-
Settings.Set({ correctiveParse: true });
|
|
529
|
-
var TypeGuard = class {
|
|
530
|
-
isBigInt = (value) => Type.IsString(value) && "format" in value && value.format === "bigint";
|
|
531
|
-
isUUID = (value) => Type.IsString(value) && "format" in value && value.format === "uuid";
|
|
532
|
-
isObject = Type.IsObject;
|
|
533
|
-
isNumber = Type.IsNumber;
|
|
534
|
-
isString = Type.IsString;
|
|
535
|
-
isBoolean = Type.IsBoolean;
|
|
536
|
-
isAny = Type.IsAny;
|
|
537
|
-
isArray = Type.IsArray;
|
|
538
|
-
isOptional = Type.IsOptional;
|
|
539
|
-
isUnion = Type.IsUnion;
|
|
540
|
-
isInteger = Type.IsInteger;
|
|
541
|
-
isNull = Type.IsNull;
|
|
542
|
-
isUndefined = Type.IsUndefined;
|
|
543
|
-
isUnsafe = Type.IsUnsafe;
|
|
544
|
-
isRecord = Type.IsRecord;
|
|
545
|
-
isTuple = Type.IsTuple;
|
|
546
|
-
isVoid = Type.IsVoid;
|
|
547
|
-
isLiteral = Type.IsLiteral;
|
|
548
|
-
isSchema = Type.IsSchema;
|
|
549
|
-
isScalar = (schema) => this.isString(schema) || this.isNumber(schema) || this.isInteger(schema) || this.isBoolean(schema);
|
|
550
|
-
isFile = isTypeFile;
|
|
551
|
-
isDateTime = (schema) => {
|
|
552
|
-
return t.schema.isString(schema) && schema.format === "date-time";
|
|
553
|
-
};
|
|
554
|
-
isDate = (schema) => {
|
|
555
|
-
return t.schema.isString(schema) && schema.format === "date";
|
|
556
|
-
};
|
|
557
|
-
isTime = (schema) => {
|
|
558
|
-
return t.schema.isString(schema) && schema.format === "time";
|
|
559
|
-
};
|
|
560
|
-
isDuration = (schema) => {
|
|
561
|
-
return t.schema.isString(schema) && schema.format === "duration";
|
|
562
|
-
};
|
|
563
|
-
};
|
|
564
|
-
var TypeProvider = class TypeProvider {
|
|
565
|
-
static format = Format;
|
|
566
|
-
static {
|
|
567
|
-
Format.Set("bigint", (value) => TypeProvider.isValidBigInt(value));
|
|
568
|
-
}
|
|
569
|
-
static translateError(error, _locale) {
|
|
570
|
-
return error.cause.message;
|
|
571
|
-
}
|
|
572
|
-
static setLocale(_locale) {}
|
|
573
|
-
static isValidBigInt(value) {
|
|
574
|
-
if (typeof value === "number") return Number.isInteger(value);
|
|
575
|
-
if (!value.trim()) return false;
|
|
576
|
-
if (!/^-?\d+$/.test(value)) return false;
|
|
577
|
-
try {
|
|
578
|
-
BigInt(value);
|
|
579
|
-
return true;
|
|
580
|
-
} catch {
|
|
581
|
-
return false;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Default maximum length for strings.
|
|
586
|
-
*
|
|
587
|
-
* It can be set to a larger value:
|
|
588
|
-
* ```ts
|
|
589
|
-
* TypeProvider.DEFAULT_STRING_MAX_LENGTH = 1000000;
|
|
590
|
-
* TypeProvider.DEFAULT_STRING_MAX_LENGTH = undefined; // no limit (not recommended)
|
|
591
|
-
* ```
|
|
592
|
-
*/
|
|
593
|
-
static DEFAULT_STRING_MAX_LENGTH = 255;
|
|
594
|
-
/**
|
|
595
|
-
* Maximum length for short strings, such as names or titles.
|
|
596
|
-
*/
|
|
597
|
-
static DEFAULT_SHORT_STRING_MAX_LENGTH = 64;
|
|
598
|
-
/**
|
|
599
|
-
* Maximum length for long strings, such as descriptions or comments.
|
|
600
|
-
* It can be overridden in the string options.
|
|
601
|
-
*
|
|
602
|
-
* It can be set to a larger value:
|
|
603
|
-
* ```ts
|
|
604
|
-
* TypeProvider.DEFAULT_LONG_STRING_MAX_LENGTH = 2048;
|
|
605
|
-
* ```
|
|
606
|
-
*/
|
|
607
|
-
static DEFAULT_LONG_STRING_MAX_LENGTH = 1024;
|
|
608
|
-
/**
|
|
609
|
-
* Maximum length for rich strings, such as HTML or Markdown.
|
|
610
|
-
* This is a large value to accommodate rich text content.
|
|
611
|
-
* > It's also the maximum length of PG's TEXT type.
|
|
612
|
-
*
|
|
613
|
-
* It can be overridden in the string options.
|
|
614
|
-
*
|
|
615
|
-
* It can be set to a larger value:
|
|
616
|
-
* ```ts
|
|
617
|
-
* TypeProvider.DEFAULT_RICH_STRING_MAX_LENGTH = 1000000;
|
|
618
|
-
* ```
|
|
619
|
-
*/
|
|
620
|
-
static DEFAULT_RICH_STRING_MAX_LENGTH = 65535;
|
|
621
|
-
/**
|
|
622
|
-
* Maximum number of items in an array.
|
|
623
|
-
* This is a default value to prevent excessive memory usage.
|
|
624
|
-
* It can be overridden in the array options.
|
|
625
|
-
*/
|
|
626
|
-
static DEFAULT_ARRAY_MAX_ITEMS = 1e3;
|
|
627
|
-
raw = Type;
|
|
628
|
-
any = Type.Any;
|
|
629
|
-
void = Type.Void;
|
|
630
|
-
undefined = Type.Undefined;
|
|
631
|
-
record = Type.Record;
|
|
632
|
-
union = Type.Union;
|
|
633
|
-
tuple = Type.Tuple;
|
|
634
|
-
null = Type.Null;
|
|
635
|
-
const = Type.Literal;
|
|
636
|
-
options = Type.Options;
|
|
637
|
-
/**
|
|
638
|
-
* Type guards to check the type of schema.
|
|
639
|
-
* This is not a runtime type check, but a compile-time type guard.
|
|
640
|
-
*
|
|
641
|
-
* @example
|
|
642
|
-
* ```ts
|
|
643
|
-
* if (t.schema.isString(schema)) {
|
|
644
|
-
* // schema is TString
|
|
645
|
-
* }
|
|
646
|
-
* ```
|
|
647
|
-
*/
|
|
648
|
-
schema = new TypeGuard();
|
|
649
|
-
extend(schema, properties, options) {
|
|
650
|
-
return Type.Interface(Array.isArray(schema) ? schema : [schema], properties, {
|
|
651
|
-
additionalProperties: false,
|
|
652
|
-
...options
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
pick(schema, keys, options) {
|
|
656
|
-
return Type.Pick(schema, keys, {
|
|
657
|
-
additionalProperties: false,
|
|
658
|
-
...options
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
omit(schema, keys, options) {
|
|
662
|
-
return Type.Omit(schema, keys, {
|
|
663
|
-
additionalProperties: false,
|
|
664
|
-
...options
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
partial(schema, options) {
|
|
668
|
-
return Type.Partial(schema, {
|
|
669
|
-
additionalProperties: false,
|
|
670
|
-
...options
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Create a schema for an object.
|
|
675
|
-
* By default, additional properties are not allowed.
|
|
676
|
-
*
|
|
677
|
-
* @example
|
|
678
|
-
* ```ts
|
|
679
|
-
* const userSchema = t.object({
|
|
680
|
-
* id: t.integer(),
|
|
681
|
-
* name: t.string(),
|
|
682
|
-
* });
|
|
683
|
-
* ```
|
|
684
|
-
*/
|
|
685
|
-
object(properties, options) {
|
|
686
|
-
return Type.Object(properties, {
|
|
687
|
-
additionalProperties: false,
|
|
688
|
-
...options
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Create a schema for an array.
|
|
693
|
-
* By default, the maximum number of items is limited to prevent excessive memory usage.
|
|
694
|
-
*
|
|
695
|
-
* @see TypeProvider.DEFAULT_ARRAY_MAX_ITEMS
|
|
696
|
-
*/
|
|
697
|
-
array(schema, options) {
|
|
698
|
-
return Type.Array(schema, {
|
|
699
|
-
maxItems: TypeProvider.DEFAULT_ARRAY_MAX_ITEMS,
|
|
700
|
-
...options
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Create a schema for a string.
|
|
705
|
-
* For db or input fields, consider using `t.text()` instead, which has length limits.
|
|
706
|
-
*
|
|
707
|
-
* If you need a string with specific format (e.g. email, uuid), consider using the corresponding method (e.g. `t.email()`, `t.uuid()`).
|
|
708
|
-
*/
|
|
709
|
-
string(options = {}) {
|
|
710
|
-
return Type.String({ ...options });
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Create a schema for a string with length limits.
|
|
714
|
-
* For internal strings without length limits, consider using `t.string()` instead.
|
|
715
|
-
*
|
|
716
|
-
* Default size is "regular", which has a max length of 255 characters.
|
|
717
|
-
*/
|
|
718
|
-
text(options = {}) {
|
|
719
|
-
const { size, ...rest } = options;
|
|
720
|
-
const maxLength = size === "short" ? TypeProvider.DEFAULT_SHORT_STRING_MAX_LENGTH : size === "long" ? TypeProvider.DEFAULT_LONG_STRING_MAX_LENGTH : size === "rich" ? TypeProvider.DEFAULT_RICH_STRING_MAX_LENGTH : TypeProvider.DEFAULT_STRING_MAX_LENGTH;
|
|
721
|
-
return Type.String({
|
|
722
|
-
maxLength,
|
|
723
|
-
"~options": {
|
|
724
|
-
trim: options.trim ?? true,
|
|
725
|
-
lowercase: options.lowercase ?? false
|
|
726
|
-
},
|
|
727
|
-
...rest
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Create a schema for a JSON object.
|
|
732
|
-
* This is a record with string keys and any values.
|
|
733
|
-
*/
|
|
734
|
-
json(options) {
|
|
735
|
-
return t.record(t.text(), t.any(), options);
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Create a schema for a boolean.
|
|
739
|
-
*/
|
|
740
|
-
boolean(options) {
|
|
741
|
-
return Type.Boolean({ ...options });
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Create a schema for a number.
|
|
745
|
-
*/
|
|
746
|
-
number(options) {
|
|
747
|
-
return Type.Number({ ...options });
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Create a schema for an integer.
|
|
751
|
-
*/
|
|
752
|
-
integer(options) {
|
|
753
|
-
return Type.Integer({ ...options });
|
|
754
|
-
}
|
|
755
|
-
int32(options) {
|
|
756
|
-
return Type.Integer({
|
|
757
|
-
minimum: -2147483648,
|
|
758
|
-
maximum: 2147483647,
|
|
759
|
-
...options
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
/**
|
|
763
|
-
* Mimic a signed 64-bit integer.
|
|
764
|
-
*
|
|
765
|
-
* This is NOT a true int64, as JavaScript cannot represent all int64 values.
|
|
766
|
-
* It is a number that is an integer and between -9007199254740991 and 9007199254740991.
|
|
767
|
-
* Use `t.bigint()` for true int64 values represented as strings.
|
|
768
|
-
*/
|
|
769
|
-
int64(options) {
|
|
770
|
-
return Type.Number({
|
|
771
|
-
format: "int64",
|
|
772
|
-
multipleOf: 1,
|
|
773
|
-
minimum: -9007199254740991,
|
|
774
|
-
maximum: 9007199254740991,
|
|
775
|
-
...options
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Make a schema optional.
|
|
780
|
-
*/
|
|
781
|
-
optional(schema) {
|
|
782
|
-
return Type.Optional(schema);
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Make a schema nullable.
|
|
786
|
-
*/
|
|
787
|
-
nullable(schema, options) {
|
|
788
|
-
return Type.Union([Type.Null(), schema], options);
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* Create a schema that maps all properties of an object schema to nullable.
|
|
792
|
-
*/
|
|
793
|
-
nullify = (schema, options) => Type.Mapped(Type.Identifier("K"), Type.KeyOf(schema), Type.Ref("K"), Type.Union([Type.Index(schema, Type.Ref("K")), Type.Null()]), options);
|
|
794
|
-
/**
|
|
795
|
-
* Create a schema for a string enum.
|
|
796
|
-
*
|
|
797
|
-
* By default, this creates a real PostgreSQL ENUM type in the database.
|
|
798
|
-
* Use `{ mode: "text" }` to store as a TEXT column instead.
|
|
799
|
-
*
|
|
800
|
-
* @example
|
|
801
|
-
* ```ts
|
|
802
|
-
* // PostgreSQL ENUM type (default)
|
|
803
|
-
* status: t.enum(["pending", "active", "archived"])
|
|
804
|
-
*
|
|
805
|
-
* // TEXT column
|
|
806
|
-
* status: t.enum(["pending", "active", "archived"], { mode: "text" })
|
|
807
|
-
*
|
|
808
|
-
* // Shared enum name across tables
|
|
809
|
-
* status: t.enum(["enabled", "disabled"], { name: "shared_status_enum" })
|
|
810
|
-
* ```
|
|
811
|
-
*/
|
|
812
|
-
enum(values, options) {
|
|
813
|
-
const { mode, name, ...textOptions } = options ?? {};
|
|
814
|
-
const schema = Type.Unsafe(t.text({
|
|
815
|
-
enum: values,
|
|
816
|
-
pattern: values.map((v) => `^${v}$`).join("|"),
|
|
817
|
-
...textOptions
|
|
818
|
-
}));
|
|
819
|
-
if (mode === "text") Object.assign(schema, { mode: "text" });
|
|
820
|
-
else Object.assign(schema, { enumName: name });
|
|
821
|
-
return schema;
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* Create a schema for a bigint represented as a string.
|
|
825
|
-
* This is a string that validates bigint format (e.g. "123456789").
|
|
826
|
-
*/
|
|
827
|
-
bigint(options) {
|
|
828
|
-
return t.string({
|
|
829
|
-
...options,
|
|
830
|
-
format: "bigint"
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* Create a schema for a URL represented as a string.
|
|
835
|
-
*/
|
|
836
|
-
url(options) {
|
|
837
|
-
return this.string({
|
|
838
|
-
...options,
|
|
839
|
-
format: "url"
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
|
-
* Create a schema for binary data represented as a base64 string.
|
|
844
|
-
*/
|
|
845
|
-
binary(options = {}) {
|
|
846
|
-
return this.string({
|
|
847
|
-
...options,
|
|
848
|
-
format: "binary"
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
/**
|
|
852
|
-
* Create a schema for uuid.
|
|
853
|
-
*/
|
|
854
|
-
uuid(options) {
|
|
855
|
-
return this.string({
|
|
856
|
-
...options,
|
|
857
|
-
format: "uuid"
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* Create a schema for a file-like object.
|
|
862
|
-
*
|
|
863
|
-
* File like mimics the File API in browsers, but is adapted to work in Node.js as well.
|
|
864
|
-
*
|
|
865
|
-
* Implementation of file-like objects is handled by "alepha/file" package.
|
|
866
|
-
*/
|
|
867
|
-
file(options) {
|
|
868
|
-
return Type.Unsafe(Type.Any({
|
|
869
|
-
[OPTIONS]: options,
|
|
870
|
-
format: "binary"
|
|
871
|
-
}));
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* @experimental
|
|
875
|
-
*/
|
|
876
|
-
stream() {
|
|
877
|
-
return Type.Unsafe(Type.Any({
|
|
878
|
-
format: "stream",
|
|
879
|
-
type: "string"
|
|
880
|
-
}));
|
|
881
|
-
}
|
|
882
|
-
email(options) {
|
|
883
|
-
return this.text({
|
|
884
|
-
...options,
|
|
885
|
-
format: "email",
|
|
886
|
-
trim: true,
|
|
887
|
-
lowercase: true
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
e164(options) {
|
|
891
|
-
return this.text({
|
|
892
|
-
...options,
|
|
893
|
-
description: "Phone number in E.164 format, e.g. +1234567890.",
|
|
894
|
-
pattern: "^\\+[1-9]\\d{1,14}$"
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
bcp47(options) {
|
|
898
|
-
return this.text({
|
|
899
|
-
...options,
|
|
900
|
-
description: "BCP 47 language tag, e.g. en, en-US, fr, fr-CA.",
|
|
901
|
-
pattern: "^[a-z]{2,3}(?:-[A-Z]{2})?$"
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
|
-
* Create a schema for short text, such as names or titles.
|
|
906
|
-
* Default max length is 64 characters.
|
|
907
|
-
*/
|
|
908
|
-
shortText(options) {
|
|
909
|
-
return this.text({
|
|
910
|
-
size: "short",
|
|
911
|
-
...options
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* Create a schema for long text, such as descriptions or comments.
|
|
916
|
-
* Default max length is 1024 characters.
|
|
917
|
-
*/
|
|
918
|
-
longText(options) {
|
|
919
|
-
return this.text({
|
|
920
|
-
size: "long",
|
|
921
|
-
...options
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Create a schema for rich text, such as HTML or Markdown.
|
|
926
|
-
* Default max length is 65535 characters.
|
|
927
|
-
*/
|
|
928
|
-
richText(options) {
|
|
929
|
-
return this.text({
|
|
930
|
-
size: "rich",
|
|
931
|
-
...options
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
/**
|
|
935
|
-
* Create a schema for a constant case string e.g. LIKE_THIS.
|
|
936
|
-
*/
|
|
937
|
-
constantCase = (options) => this.text({
|
|
938
|
-
pattern: "^[A-Z_-]+$",
|
|
939
|
-
...options
|
|
940
|
-
});
|
|
941
|
-
/**
|
|
942
|
-
* Create a schema for an object with a value and label.
|
|
943
|
-
*/
|
|
944
|
-
valueLabel = (options) => this.object({
|
|
945
|
-
value: this.constantCase({ description: "Machine-readable value." }),
|
|
946
|
-
label: this.text({ description: "Human-readable label." }),
|
|
947
|
-
description: this.optional(this.text({
|
|
948
|
-
description: "Description of the value.",
|
|
949
|
-
size: "long"
|
|
950
|
-
}))
|
|
951
|
-
}, options);
|
|
952
|
-
datetime = (options) => t.text({
|
|
953
|
-
...options,
|
|
954
|
-
format: "date-time"
|
|
955
|
-
});
|
|
956
|
-
date = (options) => t.text({
|
|
957
|
-
...options,
|
|
958
|
-
format: "date"
|
|
959
|
-
});
|
|
960
|
-
time = (options) => t.text({
|
|
961
|
-
...options,
|
|
962
|
-
format: "time"
|
|
963
|
-
});
|
|
964
|
-
duration = (options) => t.text({
|
|
965
|
-
...options,
|
|
966
|
-
format: "duration"
|
|
967
|
-
});
|
|
968
|
-
};
|
|
969
|
-
const t = new TypeProvider();
|
|
970
|
-
//#endregion
|
|
971
844
|
//#region ../../src/core/providers/KeylessJsonSchemaCodec.ts
|
|
972
845
|
/**
|
|
973
846
|
* KeylessJsonSchemaCodec provides schema-driven JSON encoding without keys.
|
|
@@ -1085,14 +958,14 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1085
958
|
}
|
|
1086
959
|
interpretEncode(schema, value) {
|
|
1087
960
|
if (this.isLeaf(schema)) return value;
|
|
1088
|
-
if (
|
|
1089
|
-
if (
|
|
961
|
+
if (z.schema.isBigInt(schema)) return `${value}n`;
|
|
962
|
+
if (z.schema.isArray(schema)) {
|
|
1090
963
|
const arrSchema = schema;
|
|
1091
964
|
if (!Array.isArray(value)) return value;
|
|
1092
|
-
if (
|
|
965
|
+
if (z.schema.isScalar(arrSchema.items)) return value;
|
|
1093
966
|
return value.map((e) => this.interpretEncode(arrSchema.items, e));
|
|
1094
967
|
}
|
|
1095
|
-
if (
|
|
968
|
+
if (z.schema.isObject(schema)) {
|
|
1096
969
|
const result = [];
|
|
1097
970
|
for (const { key, isOpt, isNullable, inner } of this.getObjectFields(schema)) {
|
|
1098
971
|
const v = value[key];
|
|
@@ -1102,7 +975,7 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1102
975
|
}
|
|
1103
976
|
return result;
|
|
1104
977
|
}
|
|
1105
|
-
if (
|
|
978
|
+
if (z.schema.isOptional(schema) || z.schema.isUnion(schema)) {
|
|
1106
979
|
const inner = this.unwrap(schema);
|
|
1107
980
|
if (this.isNullable(schema)) return value !== null ? this.interpretEncode(inner, value) : null;
|
|
1108
981
|
return value !== void 0 ? this.interpretEncode(inner, value) : null;
|
|
@@ -1111,15 +984,15 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1111
984
|
}
|
|
1112
985
|
interpretDecode(schema, ctx) {
|
|
1113
986
|
if (this.isLeaf(schema)) return ctx.arr[ctx.i++];
|
|
1114
|
-
if (
|
|
1115
|
-
if (
|
|
987
|
+
if (z.schema.isBigInt(schema)) return BigInt(ctx.arr[ctx.i++].slice(0, -1));
|
|
988
|
+
if (z.schema.isArray(schema)) {
|
|
1116
989
|
const arrSchema = schema;
|
|
1117
990
|
const arr = ctx.arr[ctx.i++];
|
|
1118
991
|
if (!Array.isArray(arr)) return arr;
|
|
1119
|
-
if (
|
|
992
|
+
if (z.schema.isObject(arrSchema.items)) return arr.map((e) => this.interpretDecodeFromValue(arrSchema.items, e));
|
|
1120
993
|
return arr;
|
|
1121
994
|
}
|
|
1122
|
-
if (
|
|
995
|
+
if (z.schema.isObject(schema)) {
|
|
1123
996
|
const result = {};
|
|
1124
997
|
for (const { key, isOpt, isNullable, inner } of this.getObjectFields(schema)) {
|
|
1125
998
|
const val = ctx.arr[ctx.i++];
|
|
@@ -1130,37 +1003,37 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1130
1003
|
}
|
|
1131
1004
|
return result;
|
|
1132
1005
|
}
|
|
1133
|
-
if (
|
|
1006
|
+
if (z.schema.isOptional(schema) || z.schema.isUnion(schema)) {
|
|
1134
1007
|
const inner = this.unwrap(schema);
|
|
1135
1008
|
const val = ctx.arr[ctx.i++];
|
|
1136
1009
|
if (val === null) return this.isNullable(schema) ? null : void 0;
|
|
1137
|
-
if (
|
|
1010
|
+
if (z.schema.isObject(inner) || z.schema.isArray(inner)) return this.interpretDecodeFromValue(inner, val);
|
|
1138
1011
|
return val;
|
|
1139
1012
|
}
|
|
1140
1013
|
return ctx.arr[ctx.i++];
|
|
1141
1014
|
}
|
|
1142
1015
|
interpretDecodeFromValue(schema, value) {
|
|
1143
1016
|
if (this.isLeaf(schema)) return value;
|
|
1144
|
-
if (
|
|
1145
|
-
if (
|
|
1017
|
+
if (z.schema.isBigInt(schema)) return BigInt(value.slice(0, -1));
|
|
1018
|
+
if (z.schema.isArray(schema)) {
|
|
1146
1019
|
if (!Array.isArray(value)) return value;
|
|
1147
1020
|
const arrSchema = schema;
|
|
1148
|
-
if (
|
|
1021
|
+
if (z.schema.isObject(arrSchema.items)) return value.map((e) => this.interpretDecodeFromValue(arrSchema.items, e));
|
|
1149
1022
|
return value;
|
|
1150
1023
|
}
|
|
1151
|
-
if (
|
|
1024
|
+
if (z.schema.isObject(schema)) {
|
|
1152
1025
|
const props = schema.properties;
|
|
1153
1026
|
const keys = Object.keys(props);
|
|
1154
1027
|
const result = {};
|
|
1155
1028
|
for (let idx = 0; idx < keys.length; idx++) {
|
|
1156
1029
|
const k = keys[idx];
|
|
1157
1030
|
const prop = props[k];
|
|
1158
|
-
const isOpt =
|
|
1031
|
+
const isOpt = z.schema.isOptional(prop);
|
|
1159
1032
|
const inner = this.unwrap(prop);
|
|
1160
1033
|
const v = value[idx];
|
|
1161
1034
|
if (isOpt && v === null) continue;
|
|
1162
|
-
if (
|
|
1163
|
-
else if (
|
|
1035
|
+
if (z.schema.isObject(inner)) result[k] = this.interpretDecodeFromValue(inner, v);
|
|
1036
|
+
else if (z.schema.isBigInt(inner)) result[k] = BigInt(v.slice(0, -1));
|
|
1164
1037
|
else result[k] = v;
|
|
1165
1038
|
}
|
|
1166
1039
|
return result;
|
|
@@ -1169,14 +1042,14 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1169
1042
|
}
|
|
1170
1043
|
genEnc(schema, ve) {
|
|
1171
1044
|
if (this.isLeaf(schema)) return ve;
|
|
1172
|
-
if (
|
|
1173
|
-
if (
|
|
1045
|
+
if (z.schema.isBigInt(schema)) return `${ve}+'n'`;
|
|
1046
|
+
if (z.schema.isArray(schema)) {
|
|
1174
1047
|
const arrSchema = schema;
|
|
1175
1048
|
const itemEnc = this.genEnc(arrSchema.items, "e");
|
|
1176
|
-
if (
|
|
1049
|
+
if (z.schema.isScalar(arrSchema.items)) return ve;
|
|
1177
1050
|
return `${ve}.map(e=>${itemEnc})`;
|
|
1178
1051
|
}
|
|
1179
|
-
if (
|
|
1052
|
+
if (z.schema.isObject(schema)) {
|
|
1180
1053
|
const parts = [];
|
|
1181
1054
|
for (const { key, isOpt, isNullable, inner } of this.getObjectFields(schema)) {
|
|
1182
1055
|
const access = `${ve}[${JSON.stringify(key)}]`;
|
|
@@ -1187,7 +1060,7 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1187
1060
|
}
|
|
1188
1061
|
return `[${parts.join(",")}]`;
|
|
1189
1062
|
}
|
|
1190
|
-
if (
|
|
1063
|
+
if (z.schema.isOptional(schema) || z.schema.isUnion(schema)) {
|
|
1191
1064
|
const inner = this.unwrap(schema);
|
|
1192
1065
|
const innerEnc = this.genEnc(inner, ve);
|
|
1193
1066
|
if (this.isNullable(schema)) return `${ve}!==null?${innerEnc}:null`;
|
|
@@ -1201,13 +1074,13 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1201
1074
|
code: "",
|
|
1202
1075
|
result: "a[i++]"
|
|
1203
1076
|
};
|
|
1204
|
-
if (
|
|
1077
|
+
if (z.schema.isBigInt(schema)) return {
|
|
1205
1078
|
code: "",
|
|
1206
1079
|
result: "BigInt(a[i++].slice(0,-1))"
|
|
1207
1080
|
};
|
|
1208
|
-
if (
|
|
1081
|
+
if (z.schema.isArray(schema)) {
|
|
1209
1082
|
const arrSchema = schema;
|
|
1210
|
-
if (
|
|
1083
|
+
if (z.schema.isObject(arrSchema.items)) return {
|
|
1211
1084
|
code: "",
|
|
1212
1085
|
result: `a[i++].map(e=>${this.genDecFromValue(arrSchema.items, "e")})`
|
|
1213
1086
|
};
|
|
@@ -1216,9 +1089,9 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1216
1089
|
result: "a[i++]"
|
|
1217
1090
|
};
|
|
1218
1091
|
}
|
|
1219
|
-
if (
|
|
1092
|
+
if (z.schema.isObject(schema)) {
|
|
1220
1093
|
const fields = this.getObjectFields(schema);
|
|
1221
|
-
if (fields.every(({ isOpt, isNullable, inner }) => !isOpt && !isNullable && !
|
|
1094
|
+
if (fields.every(({ isOpt, isNullable, inner }) => !isOpt && !isNullable && !z.schema.isObject(inner) && !z.schema.isArray(inner))) return {
|
|
1222
1095
|
code: "",
|
|
1223
1096
|
result: `{${fields.map(({ key }) => `${JSON.stringify(key)}:a[i++]`).join(",")}}`
|
|
1224
1097
|
};
|
|
@@ -1231,12 +1104,12 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1231
1104
|
} else if (isNullable) {
|
|
1232
1105
|
const nested = this.genDecFromValue(inner, "t");
|
|
1233
1106
|
code += `{const t=a[i++];if(t===null){${v}[${sk}]=null;}else{${v}[${sk}]=${nested};}}`;
|
|
1234
|
-
} else if (
|
|
1107
|
+
} else if (z.schema.isObject(inner)) {
|
|
1235
1108
|
const nested = this.genDecFromValue(inner, "a[i++]");
|
|
1236
1109
|
code += `${v}[${sk}]=${nested};`;
|
|
1237
|
-
} else if (
|
|
1110
|
+
} else if (z.schema.isArray(inner)) {
|
|
1238
1111
|
const arrSchema = inner;
|
|
1239
|
-
if (
|
|
1112
|
+
if (z.schema.isObject(arrSchema.items)) {
|
|
1240
1113
|
const itemTransform = this.genDecFromValue(arrSchema.items, "e");
|
|
1241
1114
|
code += `${v}[${sk}]=a[i++].map(e=>${itemTransform});`;
|
|
1242
1115
|
} else code += `${v}[${sk}]=a[i++];`;
|
|
@@ -1247,7 +1120,7 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1247
1120
|
result: v
|
|
1248
1121
|
};
|
|
1249
1122
|
}
|
|
1250
|
-
if (
|
|
1123
|
+
if (z.schema.isOptional(schema) || z.schema.isUnion(schema)) {
|
|
1251
1124
|
const inner = this.unwrap(schema);
|
|
1252
1125
|
const innerDec = this.genDec(inner);
|
|
1253
1126
|
return {
|
|
@@ -1262,16 +1135,16 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1262
1135
|
}
|
|
1263
1136
|
genDecFromValue(schema, expr) {
|
|
1264
1137
|
if (this.isLeaf(schema)) return expr;
|
|
1265
|
-
if (
|
|
1266
|
-
if (
|
|
1138
|
+
if (z.schema.isBigInt(schema)) return `BigInt(${expr}.slice(0,-1))`;
|
|
1139
|
+
if (z.schema.isArray(schema)) {
|
|
1267
1140
|
const items = schema.items;
|
|
1268
|
-
if (
|
|
1141
|
+
if (z.schema.isObject(items) || z.schema.isBigInt(items)) {
|
|
1269
1142
|
const v = this.nextVar();
|
|
1270
1143
|
return `${expr}.map(${v}=>${this.genDecFromValue(items, v)})`;
|
|
1271
1144
|
}
|
|
1272
1145
|
return expr;
|
|
1273
1146
|
}
|
|
1274
|
-
if (
|
|
1147
|
+
if (z.schema.isObject(schema)) {
|
|
1275
1148
|
const props = schema.properties;
|
|
1276
1149
|
const keys = Object.keys(props);
|
|
1277
1150
|
const v = this.nextVar();
|
|
@@ -1279,24 +1152,24 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1279
1152
|
const inner = this.unwrap(props[k]);
|
|
1280
1153
|
const innerExpr = `${v}[${idx}]`;
|
|
1281
1154
|
const sk = JSON.stringify(k);
|
|
1282
|
-
if (
|
|
1283
|
-
if (
|
|
1155
|
+
if (z.schema.isObject(inner)) return `${sk}:${this.genDecFromValue(inner, innerExpr)}`;
|
|
1156
|
+
if (z.schema.isBigInt(inner)) return `${sk}:BigInt(${innerExpr}.slice(0,-1))`;
|
|
1284
1157
|
return `${sk}:${innerExpr}`;
|
|
1285
1158
|
}).join(",")}}))()`;
|
|
1286
1159
|
}
|
|
1287
1160
|
return expr;
|
|
1288
1161
|
}
|
|
1289
1162
|
isLeaf(schema) {
|
|
1290
|
-
return
|
|
1163
|
+
return z.schema.isScalar(schema) || this.isEnum(schema);
|
|
1291
1164
|
}
|
|
1292
1165
|
getObjectFields(schema) {
|
|
1293
1166
|
const props = schema.properties;
|
|
1294
|
-
const req = new Set(schema.
|
|
1167
|
+
const req = new Set(z.schema.requiredKeys(schema));
|
|
1295
1168
|
return Object.keys(props).map((key) => {
|
|
1296
1169
|
const ps = props[key];
|
|
1297
1170
|
return {
|
|
1298
1171
|
key,
|
|
1299
|
-
isOpt: !req.has(key) ||
|
|
1172
|
+
isOpt: !req.has(key) || z.schema.isOptional(ps),
|
|
1300
1173
|
isNullable: this.isNullable(ps),
|
|
1301
1174
|
inner: this.unwrap(ps)
|
|
1302
1175
|
};
|
|
@@ -1306,26 +1179,39 @@ var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
|
1306
1179
|
return "enum" in schema && Array.isArray(schema.enum) && (schema.enum?.length ?? 0) > 0;
|
|
1307
1180
|
}
|
|
1308
1181
|
isNullable(schema) {
|
|
1309
|
-
|
|
1310
|
-
|
|
1182
|
+
let cur = schema;
|
|
1183
|
+
while (cur) {
|
|
1184
|
+
if (z.schema.isNullable(cur)) return true;
|
|
1185
|
+
if (z.schema.isOptional(cur) && typeof cur.unwrap === "function") {
|
|
1186
|
+
cur = cur.unwrap();
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
break;
|
|
1190
|
+
}
|
|
1191
|
+
if (z.schema.isUnion(schema)) return schema.anyOf?.some((s) => z.schema.isNull(s)) ?? false;
|
|
1192
|
+
return false;
|
|
1311
1193
|
}
|
|
1312
1194
|
unwrap(schema) {
|
|
1313
|
-
|
|
1314
|
-
|
|
1195
|
+
const peeled = z.schema.unwrap(schema);
|
|
1196
|
+
if (z.schema.isUnion(peeled)) {
|
|
1197
|
+
const unionSchema = peeled;
|
|
1198
|
+
if (Array.isArray(unionSchema.anyOf)) return unionSchema.anyOf.find((s) => !z.schema.isNull(s)) || peeled;
|
|
1199
|
+
}
|
|
1200
|
+
return peeled;
|
|
1315
1201
|
}
|
|
1316
1202
|
/**
|
|
1317
1203
|
* Reconstruct an object from a parsed array (for when input is already parsed).
|
|
1318
1204
|
*/
|
|
1319
1205
|
reconstructObject(schema, arr) {
|
|
1320
|
-
if (!
|
|
1206
|
+
if (!z.schema.isObject(schema)) return arr;
|
|
1321
1207
|
const result = {};
|
|
1322
1208
|
let i = 0;
|
|
1323
1209
|
for (const { key, isOpt, isNullable, inner } of this.getObjectFields(schema)) {
|
|
1324
1210
|
const val = arr[i++];
|
|
1325
1211
|
if (isOpt) {
|
|
1326
|
-
if (val !== null) result[key] =
|
|
1327
|
-
} else if (isNullable) result[key] = val === null ? null :
|
|
1328
|
-
else result[key] =
|
|
1212
|
+
if (val !== null) result[key] = z.schema.isObject(inner) ? this.reconstructObject(inner, val) : val;
|
|
1213
|
+
} else if (isNullable) result[key] = val === null ? null : z.schema.isObject(inner) ? this.reconstructObject(inner, val) : val;
|
|
1214
|
+
else result[key] = z.schema.isObject(inner) ? this.reconstructObject(inner, val) : val;
|
|
1329
1215
|
}
|
|
1330
1216
|
return result;
|
|
1331
1217
|
}
|
|
@@ -1344,7 +1230,7 @@ var TypeBoxError = class extends AlephaError {
|
|
|
1344
1230
|
message: "must be defined"
|
|
1345
1231
|
};
|
|
1346
1232
|
else this.value = {
|
|
1347
|
-
path: error.instancePath,
|
|
1233
|
+
path: error.instancePath ?? "",
|
|
1348
1234
|
message: error.message
|
|
1349
1235
|
};
|
|
1350
1236
|
this.cause = error;
|
|
@@ -1352,93 +1238,42 @@ var TypeBoxError = class extends AlephaError {
|
|
|
1352
1238
|
};
|
|
1353
1239
|
//#endregion
|
|
1354
1240
|
//#region ../../src/core/providers/SchemaValidator.ts
|
|
1241
|
+
/**
|
|
1242
|
+
* Validates + coerces a value against a zod schema.
|
|
1243
|
+
*
|
|
1244
|
+
* Trimming / lowercasing / defaults / unknown-key stripping all live in the
|
|
1245
|
+
* schema itself now (zod), so this is a thin wrapper over `schema.parse`.
|
|
1246
|
+
* No typebox `Compile`, no `eval` — safe inside Cloudflare Workers.
|
|
1247
|
+
*/
|
|
1355
1248
|
var SchemaValidator = class {
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
});
|
|
1369
|
-
try {
|
|
1370
|
-
if (!this.useEval) return Value.Parse(schema, newValue);
|
|
1371
|
-
return this.getValidator(schema).Parse(newValue);
|
|
1372
|
-
} catch (error) {
|
|
1373
|
-
if (error.cause?.errors?.[0]) throw new TypeBoxError(error.cause.errors[0]);
|
|
1374
|
-
throw error;
|
|
1249
|
+
validate(schema, value, _options = {}) {
|
|
1250
|
+
const result = schema.safeParse(value);
|
|
1251
|
+
if (!result.success) {
|
|
1252
|
+
const issue = result.error.issues[0];
|
|
1253
|
+
const path = issue?.path?.length ? issue.path.join("/") : "";
|
|
1254
|
+
let message = issue?.message ?? "Validation failed";
|
|
1255
|
+
if (issue?.code === "invalid_type" && /received undefined/i.test(message) && path) message = `'${path}' is required`;
|
|
1256
|
+
throw new TypeBoxError({
|
|
1257
|
+
message,
|
|
1258
|
+
instancePath: path ? `/${path}` : "",
|
|
1259
|
+
params: issue
|
|
1260
|
+
});
|
|
1375
1261
|
}
|
|
1262
|
+
return result.data;
|
|
1376
1263
|
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
*/
|
|
1380
|
-
clone(schema) {
|
|
1381
|
-
return Value.Clone(schema);
|
|
1382
|
-
}
|
|
1383
|
-
getValidator(schema) {
|
|
1384
|
-
if (this.cache.has(schema)) return this.cache.get(schema);
|
|
1385
|
-
const validator = Compile(schema);
|
|
1386
|
-
this.cache.set(schema, validator);
|
|
1387
|
-
return validator;
|
|
1264
|
+
safeValidate(schema, value) {
|
|
1265
|
+
return schema.safeParse(value);
|
|
1388
1266
|
}
|
|
1389
|
-
/**
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
* - If the value is `null` and the schema does not allow `null`, it converts it to `undefined`.
|
|
1393
|
-
* - If the value is a string and the schema has a `~options.trim` flag, it trims whitespace from the string.
|
|
1394
|
-
*/
|
|
1395
|
-
beforeParse(schema, value, options) {
|
|
1396
|
-
if (!schema) return value;
|
|
1397
|
-
if (value === null && !this.isSchemaNullable(schema) && options.nullToUndefined) return;
|
|
1398
|
-
if (!schema.type && schema.anyOf) schema = schema.anyOf.find((s) => s.type !== "null" && s.type !== "undefined") || schema;
|
|
1399
|
-
if (Array.isArray(value)) return value.map((it) => this.beforeParse(schema.items, it, options));
|
|
1400
|
-
if (typeof value === "string" && schema.type === "string") {
|
|
1401
|
-
let str = value;
|
|
1402
|
-
if (options.trim && schema["~options"]?.trim) str = str.trim();
|
|
1403
|
-
if (schema["~options"]?.lowercase) str = str.toLowerCase();
|
|
1404
|
-
return str;
|
|
1405
|
-
}
|
|
1406
|
-
if (typeof value === "object" && value !== null && schema.type === "object") {
|
|
1407
|
-
const obj = {};
|
|
1408
|
-
for (const key in value) {
|
|
1409
|
-
const newValue = this.beforeParse(schema.properties?.[key], value[key], options);
|
|
1410
|
-
if (newValue === void 0 && options.deleteUndefined) continue;
|
|
1411
|
-
obj[key] = newValue;
|
|
1412
|
-
}
|
|
1413
|
-
return obj;
|
|
1414
|
-
}
|
|
1415
|
-
return value;
|
|
1267
|
+
/** Zod schemas are immutable — clone is a pass-through. */
|
|
1268
|
+
clone(schema) {
|
|
1269
|
+
return schema;
|
|
1416
1270
|
}
|
|
1417
1271
|
/**
|
|
1418
|
-
*
|
|
1272
|
+
* Legacy pre-processing entry point. Coercion now happens inside `parse`,
|
|
1273
|
+
* so this is a no-op kept for call-site compatibility.
|
|
1419
1274
|
*/
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
if (schema.type === "null") return true;
|
|
1423
|
-
if (Array.isArray(schema.type) && schema.type.includes("null")) return true;
|
|
1424
|
-
if (schema.anyOf) return schema.anyOf.some((it) => this.isSchemaNullable(it));
|
|
1425
|
-
if (schema.oneOf) return schema.oneOf.some((it) => this.isSchemaNullable(it));
|
|
1426
|
-
if (schema.allOf) return schema.allOf.some((it) => this.isSchemaNullable(it));
|
|
1427
|
-
return false;
|
|
1428
|
-
};
|
|
1429
|
-
onConfigure = $hook({
|
|
1430
|
-
on: "configure",
|
|
1431
|
-
handler: () => {
|
|
1432
|
-
this.useEval = this.canEval();
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
canEval() {
|
|
1436
|
-
try {
|
|
1437
|
-
Compile(t.object({ test: t.string() })).Parse({ test: "value" });
|
|
1438
|
-
return true;
|
|
1439
|
-
} catch {
|
|
1440
|
-
return false;
|
|
1441
|
-
}
|
|
1275
|
+
beforeParse(_schema, value, _options) {
|
|
1276
|
+
return value;
|
|
1442
1277
|
}
|
|
1443
1278
|
};
|
|
1444
1279
|
//#endregion
|
|
@@ -1742,16 +1577,16 @@ var EventManager = class {
|
|
|
1742
1577
|
* You control how state is structured and validated.
|
|
1743
1578
|
*
|
|
1744
1579
|
* Features:
|
|
1745
|
-
* -
|
|
1746
|
-
* -
|
|
1747
|
-
* -
|
|
1748
|
-
* - Automatic getter access in services with {@link $use}
|
|
1580
|
+
* - Schema validation on every write (invalid writes throw)
|
|
1581
|
+
* - Default value for initial state
|
|
1582
|
+
* - Automatic getter access in services with {@link $state}
|
|
1749
1583
|
* - SSR support (server state automatically serialized and hydrated on client)
|
|
1750
|
-
* - React integration (
|
|
1751
|
-
* -
|
|
1752
|
-
* - Persistence adapters (
|
|
1753
|
-
* -
|
|
1754
|
-
* -
|
|
1584
|
+
* - React integration (useStore / useSelector hooks for automatic re-renders)
|
|
1585
|
+
* - Derived values with {@link $computed} (useComputed hook)
|
|
1586
|
+
* - Persistence adapters: cookie (SSR-safe), localStorage, sessionStorage
|
|
1587
|
+
* - `serverOnly` flag to keep an atom out of the hydration payload
|
|
1588
|
+
* - reset / watch helpers on the state manager
|
|
1589
|
+
* - Documentation generation & devtools integration (mutation log)
|
|
1755
1590
|
*
|
|
1756
1591
|
* Common use cases:
|
|
1757
1592
|
* - user preferences
|
|
@@ -1764,6 +1599,7 @@ var EventManager = class {
|
|
|
1764
1599
|
* If you need to store complex data, consider using identifiers or references instead.
|
|
1765
1600
|
*/
|
|
1766
1601
|
const $atom = (options) => {
|
|
1602
|
+
if (options.serverOnly && options.persist) throw new AlephaError(`Atom "${options.name}" declares both serverOnly and persist: "${options.persist}", which is a contradiction: serverOnly only guarantees exclusion from the SSR hydration payload, while every persist adapter (cookie, localStorage, sessionStorage) targets the browser by definition — cookie persistence ships the value in a Set-Cookie response header, and web-storage persistence IS the browser. Combining them silently leaks the value through the persistence channel instead of the hydration payload. Remove \`serverOnly\` or \`persist\` from atom "${options.name}".`);
|
|
1767
1603
|
return new Atom(options);
|
|
1768
1604
|
};
|
|
1769
1605
|
var Atom = class {
|
|
@@ -1780,11 +1616,108 @@ var Atom = class {
|
|
|
1780
1616
|
};
|
|
1781
1617
|
$atom[KIND] = "atom";
|
|
1782
1618
|
//#endregion
|
|
1619
|
+
//#region ../../src/core/primitives/$computed.ts
|
|
1620
|
+
/**
|
|
1621
|
+
* Define a derived, read-only value computed from one or more atoms
|
|
1622
|
+
* (or other computed values).
|
|
1623
|
+
*
|
|
1624
|
+
* Dependencies are declared statically, which keeps the data flow explicit
|
|
1625
|
+
* and lets subscribers know exactly which mutations invalidate the value.
|
|
1626
|
+
*
|
|
1627
|
+
* Computed values are never stored, serialized, hydrated, or persisted —
|
|
1628
|
+
* they are recomputed from their dependencies on every read, so they are
|
|
1629
|
+
* always correct inside request-scoped (fork) state on the server.
|
|
1630
|
+
*
|
|
1631
|
+
* ```ts
|
|
1632
|
+
* const cartTotal = $computed({
|
|
1633
|
+
* name: "cartTotal",
|
|
1634
|
+
* deps: [cartAtom],
|
|
1635
|
+
* get: (cart) => cart.items.reduce((sum, it) => sum + it.price, 0),
|
|
1636
|
+
* });
|
|
1637
|
+
*
|
|
1638
|
+
* alepha.store.get(cartTotal); // number
|
|
1639
|
+
* ```
|
|
1640
|
+
*
|
|
1641
|
+
* ### Footgun: a `serverOnly` dependency breaks hydration
|
|
1642
|
+
*
|
|
1643
|
+
* A computed whose deps include a `serverOnly` atom will NOT agree across the
|
|
1644
|
+
* SSR boundary. `serverOnly` keeps the atom out of the hydration payload, so
|
|
1645
|
+
* the server derives the value from the atom's real value while the browser
|
|
1646
|
+
* re-derives it from the atom's *default* — React then hydrates a DOM that
|
|
1647
|
+
* does not match the markup it received (a hydration mismatch, and a
|
|
1648
|
+
* silently wrong value afterwards).
|
|
1649
|
+
*
|
|
1650
|
+
* Either keep the computed server-side only (read it via `alepha.store.get`,
|
|
1651
|
+
* never through `useComputed`), or derive it from atoms that ship to the
|
|
1652
|
+
* browser. Note this cuts the other way too: if the value is safe to send to
|
|
1653
|
+
* the browser, the dependency should not have been `serverOnly` to begin
|
|
1654
|
+
* with.
|
|
1655
|
+
*/
|
|
1656
|
+
const $computed = (options) => {
|
|
1657
|
+
return new Computed(options);
|
|
1658
|
+
};
|
|
1659
|
+
var Computed = class Computed {
|
|
1660
|
+
options;
|
|
1661
|
+
constructor(options) {
|
|
1662
|
+
this.options = options;
|
|
1663
|
+
}
|
|
1664
|
+
get key() {
|
|
1665
|
+
return this.options.name;
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Reentrancy guard for {@link keys}. Deps are declared as a `readonly`
|
|
1669
|
+
* array at construction time, so a cycle can't be built through the
|
|
1670
|
+
* public API — but the array itself isn't frozen, so nothing stops a
|
|
1671
|
+
* caller from reaching in and creating one anyway. Without this guard,
|
|
1672
|
+
* a cycle would recurse until the JS engine throws a native
|
|
1673
|
+
* `RangeError`, which violates the repo's "never throw a bare `Error`"
|
|
1674
|
+
* convention.
|
|
1675
|
+
*/
|
|
1676
|
+
resolvingKeys = false;
|
|
1677
|
+
/**
|
|
1678
|
+
* Reentrancy guard for {@link compute}, same rationale as
|
|
1679
|
+
* {@link resolvingKeys}.
|
|
1680
|
+
*/
|
|
1681
|
+
computing = false;
|
|
1682
|
+
/**
|
|
1683
|
+
* Transitive atom keys this computed value depends on. Subscribers
|
|
1684
|
+
* (useComputed, StateManager.watch) use this to know which `state:mutate`
|
|
1685
|
+
* events invalidate the value.
|
|
1686
|
+
*/
|
|
1687
|
+
keys() {
|
|
1688
|
+
if (this.resolvingKeys) throw new AlephaError(`Circular $computed dependency detected at "${this.key}". A computed cannot depend on itself, even transitively.`);
|
|
1689
|
+
this.resolvingKeys = true;
|
|
1690
|
+
try {
|
|
1691
|
+
const out = [];
|
|
1692
|
+
for (const dep of this.options.deps) if (dep instanceof Computed) out.push(...dep.keys());
|
|
1693
|
+
else out.push(dep.key);
|
|
1694
|
+
return [...new Set(out)];
|
|
1695
|
+
} finally {
|
|
1696
|
+
this.resolvingKeys = false;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
/**
|
|
1700
|
+
* Resolve the value using the given dependency resolver.
|
|
1701
|
+
*/
|
|
1702
|
+
compute(resolve) {
|
|
1703
|
+
if (this.computing) throw new AlephaError(`Circular $computed dependency detected at "${this.key}". A computed cannot depend on itself, even transitively.`);
|
|
1704
|
+
this.computing = true;
|
|
1705
|
+
try {
|
|
1706
|
+
const values = this.options.deps.map(resolve);
|
|
1707
|
+
return this.options.get(...values);
|
|
1708
|
+
} finally {
|
|
1709
|
+
this.computing = false;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
$computed[KIND] = "computed";
|
|
1714
|
+
//#endregion
|
|
1783
1715
|
//#region ../../src/core/providers/StateManager.ts
|
|
1784
1716
|
var StateManager = class {
|
|
1785
1717
|
als = $inject(AlsProvider);
|
|
1786
1718
|
events = $inject(EventManager);
|
|
1787
1719
|
codec = $inject(JsonSchemaCodec);
|
|
1720
|
+
validator = $inject(SchemaValidator);
|
|
1788
1721
|
atoms = /* @__PURE__ */ new Map();
|
|
1789
1722
|
store = {};
|
|
1790
1723
|
constructor(store = {}) {
|
|
@@ -1804,12 +1737,14 @@ var StateManager = class {
|
|
|
1804
1737
|
const exported = {};
|
|
1805
1738
|
if (scope === "current") {
|
|
1806
1739
|
if (this.als?.exists()) for (const atom of this.atoms.values()) {
|
|
1740
|
+
if (atom.options.serverOnly) continue;
|
|
1807
1741
|
const value = this.als.get(atom.key, "current");
|
|
1808
1742
|
if (value !== void 0) exported[atom.key] = value;
|
|
1809
1743
|
}
|
|
1810
1744
|
return exported;
|
|
1811
1745
|
}
|
|
1812
1746
|
for (const [key, atom] of this.atoms.entries()) {
|
|
1747
|
+
if (atom.options.serverOnly) continue;
|
|
1813
1748
|
const value = this.get(atom, scope);
|
|
1814
1749
|
if (value !== void 0) exported[key] = value;
|
|
1815
1750
|
}
|
|
@@ -1830,15 +1765,172 @@ var StateManager = class {
|
|
|
1830
1765
|
});
|
|
1831
1766
|
return atoms;
|
|
1832
1767
|
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Return the registered atom for a state key, if any.
|
|
1770
|
+
*/
|
|
1771
|
+
getAtom(key) {
|
|
1772
|
+
return this.atoms.get(key);
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Every atom registered so far, whatever store layer (if any) currently
|
|
1776
|
+
* holds its value.
|
|
1777
|
+
*
|
|
1778
|
+
* This is the order-independent way to discover atoms. The
|
|
1779
|
+
* `"state:register"` event fires exactly once per key and `EventManager`
|
|
1780
|
+
* has no replay buffer, so a service instantiated after an atom registered
|
|
1781
|
+
* never hears about it — a real hazard, since `$module.register()`
|
|
1782
|
+
* registers `atoms[]` BEFORE it wires `imports[]` and injects `services[]`.
|
|
1783
|
+
* Services that act on atoms (e.g. the cookie persistence adapter) must
|
|
1784
|
+
* read this registry on demand rather than build their own map from the
|
|
1785
|
+
* event.
|
|
1786
|
+
*/
|
|
1787
|
+
listAtoms() {
|
|
1788
|
+
return [...this.atoms.values()];
|
|
1789
|
+
}
|
|
1833
1790
|
register(atom) {
|
|
1791
|
+
if (atom instanceof Computed) throw new AlephaError(`Cannot register computed value "${atom.key}" as an atom. Computed values are derived from their dependencies on every read — they are never stored, serialized, hydrated, or persisted. Register its dependency atoms instead.`);
|
|
1834
1792
|
const key = atom.key;
|
|
1835
|
-
if (
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1793
|
+
if (this.atoms.has(key)) return this;
|
|
1794
|
+
this.atoms.set(key, atom);
|
|
1795
|
+
const layer = this.als?.getLayer(key);
|
|
1796
|
+
if (layer) this.decodeExisting(atom, key, layer);
|
|
1797
|
+
if (key in this.store) this.decodeExisting(atom, key, this.store);
|
|
1798
|
+
else this.seedDefault(atom, key);
|
|
1799
|
+
this.bindWebStorage(atom);
|
|
1800
|
+
this.events?.emit("state:register", { atom }, { catch: true }).catch(() => null);
|
|
1839
1801
|
return this;
|
|
1840
1802
|
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Install the atom's declared default into the app-level store.
|
|
1805
|
+
*
|
|
1806
|
+
* Deliberately bypasses {@link set}, for two reasons:
|
|
1807
|
+
*
|
|
1808
|
+
* 1. `set()` short-circuits when the new value equals the currently
|
|
1809
|
+
* *resolved* value (`prevValue === value` for non-objects) — inside a
|
|
1810
|
+
* fork that already holds the same primitive value, the app-store write
|
|
1811
|
+
* would simply never happen.
|
|
1812
|
+
* 2. A registration seed is initialisation, NOT a mutation, so it must not
|
|
1813
|
+
* emit `state:mutate`. Persistence adapters listen on that event: an
|
|
1814
|
+
* atom registering lazily mid-request would otherwise emit a mutation
|
|
1815
|
+
* carrying its *default*, and the cookie adapter would dutifully write
|
|
1816
|
+
* it back as a `Set-Cookie` — overwriting the very cookie the request
|
|
1817
|
+
* arrived with.
|
|
1818
|
+
*
|
|
1819
|
+
* A `undefined` default (only reachable for an optional schema) is not
|
|
1820
|
+
* written at all, so the key stays absent from the store — matching the
|
|
1821
|
+
* previous behaviour of `set(key, undefined)`.
|
|
1822
|
+
*/
|
|
1823
|
+
seedDefault(atom, key) {
|
|
1824
|
+
const value = this.cloneDefault(atom);
|
|
1825
|
+
if (value === void 0) return;
|
|
1826
|
+
this.store[key] = value;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* A fresh, schema-validated copy of the atom's declared default.
|
|
1830
|
+
*
|
|
1831
|
+
* `atom.options.default` is a module-level object shared by every
|
|
1832
|
+
* container and every request in the process. Handing that exact reference
|
|
1833
|
+
* to the store would let an ordinary `store.mut(atom, s => ...)` mutate the
|
|
1834
|
+
* declaration itself, permanently and process-wide. Every other write path
|
|
1835
|
+
* round-trips through the validator (zod always returns a new object), so
|
|
1836
|
+
* these must too.
|
|
1837
|
+
*/
|
|
1838
|
+
cloneDefault(atom) {
|
|
1839
|
+
if (atom.options.default === void 0) return;
|
|
1840
|
+
return this.validator.validate(atom.schema, atom.options.default);
|
|
1841
|
+
}
|
|
1842
|
+
/**
|
|
1843
|
+
* Decode a value that already exists under an atom's key at registration
|
|
1844
|
+
* time, in place, in whichever layer it physically lives (an ALS fork
|
|
1845
|
+
* layer or the app store) — never flattening a fork-scoped value into the
|
|
1846
|
+
* app-level store.
|
|
1847
|
+
*
|
|
1848
|
+
* On schema mismatch, falls back to the atom's default (written into that
|
|
1849
|
+
* same layer) and emits a warning: a bad seed silently reverting a whole
|
|
1850
|
+
* atom to its defaults should be visible, not indistinguishable from
|
|
1851
|
+
* "nothing was ever set".
|
|
1852
|
+
*/
|
|
1853
|
+
decodeExisting(atom, key, layer) {
|
|
1854
|
+
const current = layer[key];
|
|
1855
|
+
if (current === void 0) return;
|
|
1856
|
+
const result = this.validator.safeValidate(atom.schema, current);
|
|
1857
|
+
if (result.success) {
|
|
1858
|
+
layer[key] = result.data;
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
this.logger?.warn(`Atom "${String(key)}" received an invalid seed value at registration, falling back to its default.`, { issues: result.error.issues });
|
|
1862
|
+
layer[key] = this.cloneDefault(atom);
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Web-storage persistence (localStorage / sessionStorage) for atoms
|
|
1866
|
+
* declared with `persist`. Best-effort: quota errors and privacy modes
|
|
1867
|
+
* are swallowed. Cookie persistence is NOT handled here — it needs the
|
|
1868
|
+
* HTTP request cycle and lives in `alepha/server/cookies`
|
|
1869
|
+
* (AtomCookiePersistence), which discovers its atoms through
|
|
1870
|
+
* {@link listAtoms}. Both adapters are therefore registration-order
|
|
1871
|
+
* independent: one `persist` option, one reliability contract.
|
|
1872
|
+
*/
|
|
1873
|
+
bindWebStorage(atom) {
|
|
1874
|
+
const persist = atom.options.persist;
|
|
1875
|
+
if (persist !== "localStorage" && persist !== "sessionStorage") return;
|
|
1876
|
+
const storage = this.getWebStorage(persist);
|
|
1877
|
+
if (!storage) {
|
|
1878
|
+
this.logger?.warn(`Atom "${atom.key}" uses ${persist} persistence, which is unavailable in this environment. Use persist: "cookie" for SSR apps.`);
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
const key = atom.key;
|
|
1882
|
+
try {
|
|
1883
|
+
const raw = storage.getItem(atom.key);
|
|
1884
|
+
if (raw != null) {
|
|
1885
|
+
const result = this.validator.safeValidate(atom.schema, JSON.parse(raw));
|
|
1886
|
+
if (result.success) this.store[key] = result.data;
|
|
1887
|
+
else this.safeRemoveItem(storage, atom.key);
|
|
1888
|
+
}
|
|
1889
|
+
} catch {
|
|
1890
|
+
this.safeRemoveItem(storage, atom.key);
|
|
1891
|
+
}
|
|
1892
|
+
this.events.on("state:mutate", ({ key: mutatedKey, value }) => {
|
|
1893
|
+
if (mutatedKey !== atom.key) return;
|
|
1894
|
+
try {
|
|
1895
|
+
if (value === void 0) storage.removeItem(atom.key);
|
|
1896
|
+
else storage.setItem(atom.key, JSON.stringify(value));
|
|
1897
|
+
} catch {}
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Best-effort `Storage#removeItem`. Some privacy modes throw on every
|
|
1902
|
+
* Storage method, including `removeItem` — this must never escape a
|
|
1903
|
+
* recovery `catch`, or persistence stops being best-effort.
|
|
1904
|
+
*/
|
|
1905
|
+
safeRemoveItem(storage, key) {
|
|
1906
|
+
try {
|
|
1907
|
+
storage.removeItem(key);
|
|
1908
|
+
} catch {}
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Resolve a Web Storage area, or undefined when unavailable (server,
|
|
1912
|
+
* privacy mode that throws on access).
|
|
1913
|
+
*/
|
|
1914
|
+
getWebStorage(kind) {
|
|
1915
|
+
try {
|
|
1916
|
+
if (typeof window === "undefined") return;
|
|
1917
|
+
return kind === "localStorage" ? window.localStorage : window.sessionStorage;
|
|
1918
|
+
} catch {
|
|
1919
|
+
return;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Best-effort logger lookup. `StateManager` lives in `core`, which cannot
|
|
1924
|
+
* depend on the logger module, so this reads the `"alepha.logger"` state
|
|
1925
|
+
* key directly (set by `Alepha.create()`, see `Alepha.ts`) instead of
|
|
1926
|
+
* injecting a logger service. May be `undefined` during early boot, before
|
|
1927
|
+
* the logger is wired up — callers must stay null-safe.
|
|
1928
|
+
*/
|
|
1929
|
+
get logger() {
|
|
1930
|
+
return this.get("alepha.logger");
|
|
1931
|
+
}
|
|
1841
1932
|
get(target, scope) {
|
|
1933
|
+
if (target instanceof Computed) return target.compute((dep) => this.get(dep, scope));
|
|
1842
1934
|
if (target instanceof Atom) this.register(target);
|
|
1843
1935
|
const key = target instanceof Atom ? target.key : target;
|
|
1844
1936
|
const store = this.store;
|
|
@@ -1846,9 +1938,12 @@ var StateManager = class {
|
|
|
1846
1938
|
return this.als?.exists() ? this.als.get(key, scope) ?? (scope ? void 0 : store[key]) : store[key];
|
|
1847
1939
|
}
|
|
1848
1940
|
set(target, value, options) {
|
|
1941
|
+
if (target instanceof Computed) throw new AlephaError(`Cannot set computed value "${target.key}". Mutate its dependencies instead.`);
|
|
1849
1942
|
if (target instanceof Atom) this.register(target);
|
|
1850
1943
|
const key = target instanceof Atom ? target.key : target;
|
|
1851
1944
|
const store = this.store;
|
|
1945
|
+
const atom = target instanceof Atom ? target : this.atoms.get(key);
|
|
1946
|
+
if (atom && value !== void 0 && options?.skipValidation !== true) value = this.validator.validate(atom.schema, value);
|
|
1852
1947
|
const prevValue = this.get(key);
|
|
1853
1948
|
if (prevValue === value && typeof value !== "object") return this;
|
|
1854
1949
|
if (options?.skipContext !== true && this.als?.exists()) this.als.set(key, value);
|
|
@@ -1860,6 +1955,31 @@ var StateManager = class {
|
|
|
1860
1955
|
}, { catch: true }).catch(() => null);
|
|
1861
1956
|
return this;
|
|
1862
1957
|
}
|
|
1958
|
+
/**
|
|
1959
|
+
* Reset an atom back to its declared default value.
|
|
1960
|
+
*/
|
|
1961
|
+
reset(atom) {
|
|
1962
|
+
this.register(atom);
|
|
1963
|
+
return this.set(atom, atom.options.default);
|
|
1964
|
+
}
|
|
1965
|
+
watch(target, callback) {
|
|
1966
|
+
if (target instanceof Computed) {
|
|
1967
|
+
const keys = new Set(target.keys());
|
|
1968
|
+
let prev = this.get(target);
|
|
1969
|
+
return this.events.on("state:mutate", (ev) => {
|
|
1970
|
+
if (!keys.has(ev.key)) return;
|
|
1971
|
+
const next = this.get(target);
|
|
1972
|
+
const last = prev;
|
|
1973
|
+
prev = next;
|
|
1974
|
+
callback(next, last);
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
if (target instanceof Atom) this.register(target);
|
|
1978
|
+
const key = target instanceof Atom ? target.key : target;
|
|
1979
|
+
return this.events.on("state:mutate", (ev) => {
|
|
1980
|
+
if (ev.key === key) callback(ev.value, ev.prevValue);
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1863
1983
|
mut(target, mutator) {
|
|
1864
1984
|
const updated = mutator(this.get(target));
|
|
1865
1985
|
return this.set(target, updated);
|
|
@@ -1962,8 +2082,8 @@ var StateManager = class {
|
|
|
1962
2082
|
* // But you should use $env() primitive to get typed values from the environment.
|
|
1963
2083
|
* class App {
|
|
1964
2084
|
* env = $env(
|
|
1965
|
-
*
|
|
1966
|
-
* MY_VAR:
|
|
2085
|
+
* z.object({
|
|
2086
|
+
* MY_VAR: z.text(),
|
|
1967
2087
|
* })
|
|
1968
2088
|
* );
|
|
1969
2089
|
* }
|
|
@@ -2182,6 +2302,13 @@ var Alepha = class Alepha {
|
|
|
2182
2302
|
return this;
|
|
2183
2303
|
}
|
|
2184
2304
|
/**
|
|
2305
|
+
* Reset an atom back to its declared default value.
|
|
2306
|
+
*/
|
|
2307
|
+
reset(target) {
|
|
2308
|
+
this.store.reset(target);
|
|
2309
|
+
return this;
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2185
2312
|
* True when start() is called.
|
|
2186
2313
|
*
|
|
2187
2314
|
* -> No more services can be added, it's over, bye!
|
|
@@ -2505,7 +2632,7 @@ var Alepha = class Alepha {
|
|
|
2505
2632
|
if (!match.parents.includes(parent) && parent !== service) match.parents.push(parent);
|
|
2506
2633
|
return match.instance;
|
|
2507
2634
|
}
|
|
2508
|
-
if (this.started) {
|
|
2635
|
+
if (this.started && registry === this.registry) {
|
|
2509
2636
|
const mod = service[MODULE]?.name;
|
|
2510
2637
|
throw new ContainerLockedError(`Container is locked. No more services can be added. Attempted to inject '${service.name}' from '${parent?.name}'. ${mod ? `Module '${mod}' is not registered ?` : ""}`);
|
|
2511
2638
|
}
|
|
@@ -2566,7 +2693,7 @@ var Alepha = class Alepha {
|
|
|
2566
2693
|
*/
|
|
2567
2694
|
parseEnv(schema) {
|
|
2568
2695
|
if (this.cacheEnv.has(schema)) return this.cacheEnv.get(schema);
|
|
2569
|
-
const config = this.codec.validate(schema, this.env);
|
|
2696
|
+
const config = this.codec.validate(schema, coerceObject(schema, this.env));
|
|
2570
2697
|
const sortedKeys = Object.keys(config).sort((a, b) => b.length - a.length);
|
|
2571
2698
|
let changed = true;
|
|
2572
2699
|
for (let pass = 0; changed && pass < 10; pass++) {
|
|
@@ -2620,13 +2747,17 @@ var Alepha = class Alepha {
|
|
|
2620
2747
|
const env = {};
|
|
2621
2748
|
for (const [schema] of this.cacheEnv.entries()) {
|
|
2622
2749
|
const ref = schema;
|
|
2623
|
-
|
|
2750
|
+
const shape = ref.properties ?? {};
|
|
2751
|
+
const required = new Set(z.schema.requiredKeys(ref));
|
|
2752
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
2624
2753
|
const prop = value;
|
|
2754
|
+
const inner = z.schema.unwrap(prop);
|
|
2755
|
+
const enumValues = z.schema.isEnum(inner) ? z.schema.enumValues(inner) : void 0;
|
|
2625
2756
|
env[key] = {
|
|
2626
|
-
description: prop
|
|
2627
|
-
default: prop
|
|
2628
|
-
required:
|
|
2629
|
-
enum:
|
|
2757
|
+
description: inner?.description ?? prop?.description,
|
|
2758
|
+
default: z.schema.getDefault(prop),
|
|
2759
|
+
required: required.has(key) ? true : void 0,
|
|
2760
|
+
enum: enumValues?.length ? [...enumValues] : void 0
|
|
2630
2761
|
};
|
|
2631
2762
|
}
|
|
2632
2763
|
}
|
|
@@ -2761,222 +2892,86 @@ function createPagination(entities, limit = 10, offset = 0, sort) {
|
|
|
2761
2892
|
};
|
|
2762
2893
|
}
|
|
2763
2894
|
//#endregion
|
|
2764
|
-
//#region ../../src/core/helpers/
|
|
2895
|
+
//#region ../../src/core/helpers/FileLike.ts
|
|
2896
|
+
const isTypeFile = (value) => {
|
|
2897
|
+
return !!value && typeof value === "object" && z.schema.format(value) === "binary";
|
|
2898
|
+
};
|
|
2899
|
+
const isFileLike = (value) => {
|
|
2900
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.name === "string" && typeof value.type === "string" && typeof value.size === "number" && typeof value.stream.bind(value) === "function";
|
|
2901
|
+
};
|
|
2902
|
+
//#endregion
|
|
2903
|
+
//#region ../../src/core/helpers/jsonSchemaToZod.ts
|
|
2765
2904
|
/**
|
|
2766
|
-
*
|
|
2767
|
-
*
|
|
2768
|
-
*
|
|
2769
|
-
*
|
|
2770
|
-
*
|
|
2771
|
-
*
|
|
2772
|
-
*
|
|
2773
|
-
*
|
|
2774
|
-
*
|
|
2775
|
-
* - Nested objects with required/optional properties
|
|
2776
|
-
* - Arrays with item schemas
|
|
2777
|
-
* - Common validation options: minLength, maxLength, minimum, maximum, pattern
|
|
2778
|
-
* - anyOf/oneOf/allOf with nullable patterns (e.g., `anyOf: [type, null]` → `t.nullable(type)`)
|
|
2779
|
-
* - Alepha ~options (trim, lowercase) pass-through
|
|
2780
|
-
*
|
|
2781
|
-
* **Not supported:**
|
|
2782
|
-
* - $ref (references)
|
|
2783
|
-
* - additionalProperties, patternProperties
|
|
2784
|
-
* - Complex composition schemas (multiple non-null types in anyOf/oneOf/allOf)
|
|
2785
|
-
*
|
|
2786
|
-
* @param schema - JSON Schema object to convert
|
|
2787
|
-
* @returns TypeBox TSchema
|
|
2788
|
-
*
|
|
2789
|
-
* @example
|
|
2790
|
-
* ```ts
|
|
2791
|
-
* const jsonSchema = {
|
|
2792
|
-
* type: "object",
|
|
2793
|
-
* properties: {
|
|
2794
|
-
* email: { type: "string", format: "email" },
|
|
2795
|
-
* age: { type: "integer", minimum: 0 },
|
|
2796
|
-
* active: { type: "boolean" },
|
|
2797
|
-
* },
|
|
2798
|
-
* required: ["email"]
|
|
2799
|
-
* };
|
|
2800
|
-
*
|
|
2801
|
-
* const typeBoxSchema = jsonSchemaToTypeBox(jsonSchema);
|
|
2802
|
-
* // Equivalent to:
|
|
2803
|
-
* // t.object({
|
|
2804
|
-
* // email: t.email(),
|
|
2805
|
-
* // age: t.optional(t.integer({ minimum: 0 })),
|
|
2806
|
-
* // active: t.optional(t.boolean()),
|
|
2807
|
-
* // })
|
|
2808
|
-
* ```
|
|
2905
|
+
* Convert a JSON Schema object into a zod schema (the inverse of
|
|
2906
|
+
* `z.toJSONSchema`). zod 4 has no native `fromJSONSchema`, so this provides the
|
|
2907
|
+
* round-trip needed by dynamic, schema-driven UIs (e.g. devtools forms built
|
|
2908
|
+
* from an entity's or action's published JSON Schema).
|
|
2909
|
+
*
|
|
2910
|
+
* Covers the JSON Schema subset Alepha emits: object/array/string (+formats),
|
|
2911
|
+
* number/integer, boolean, null, enum, and `anyOf`/`oneOf` (including the
|
|
2912
|
+
* nullable `anyOf: [..., { type: "null" }]` shape). Anything unrecognized falls
|
|
2913
|
+
* back to `z.any()`.
|
|
2809
2914
|
*/
|
|
2810
|
-
|
|
2811
|
-
if (schema
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
2821
|
-
const nullSchema = schema.anyOf.find((s) => s.type === "null");
|
|
2822
|
-
const nonNullSchemas = schema.anyOf.filter((s) => s.type !== "null");
|
|
2823
|
-
if (nullSchema && nonNullSchemas.length === 1) {
|
|
2824
|
-
const converted = jsonSchemaToTypeBox(nonNullSchemas[0]);
|
|
2825
|
-
return t.nullable(converted);
|
|
2826
|
-
}
|
|
2827
|
-
return t.union(schema.anyOf.map((s) => jsonSchemaToTypeBox(s)));
|
|
2828
|
-
}
|
|
2829
|
-
if (schema.allOf && Array.isArray(schema.allOf)) {
|
|
2830
|
-
const nullSchema = schema.allOf.find((s) => s.type === "null");
|
|
2831
|
-
const nonNullSchemas = schema.allOf.filter((s) => s.type !== "null");
|
|
2832
|
-
if (nullSchema && nonNullSchemas.length === 1) {
|
|
2833
|
-
const converted = jsonSchemaToTypeBox(nonNullSchemas[0]);
|
|
2834
|
-
return t.nullable(converted);
|
|
2835
|
-
}
|
|
2836
|
-
if (nonNullSchemas.length > 0) return jsonSchemaToTypeBox(nonNullSchemas[0]);
|
|
2837
|
-
}
|
|
2838
|
-
if (schema.oneOf && Array.isArray(schema.oneOf)) {
|
|
2839
|
-
const nullSchema = schema.oneOf.find((s) => s.type === "null");
|
|
2840
|
-
const nonNullSchemas = schema.oneOf.filter((s) => s.type !== "null");
|
|
2841
|
-
if (nullSchema && nonNullSchemas.length === 1) {
|
|
2842
|
-
const converted = jsonSchemaToTypeBox(nonNullSchemas[0]);
|
|
2843
|
-
return t.nullable(converted);
|
|
2844
|
-
}
|
|
2845
|
-
return t.union(schema.oneOf.map((s) => jsonSchemaToTypeBox(s)));
|
|
2846
|
-
}
|
|
2847
|
-
switch (Array.isArray(schema.type) ? schema.type[0] : schema.type) {
|
|
2848
|
-
case "string": return convertString(schema);
|
|
2849
|
-
case "number": return convertNumber(schema);
|
|
2850
|
-
case "integer": return convertInteger(schema);
|
|
2851
|
-
case "boolean": return convertBoolean(schema);
|
|
2852
|
-
case "null": return t.null();
|
|
2853
|
-
case "object": return convertObject(schema);
|
|
2854
|
-
case "array": return convertArray(schema);
|
|
2855
|
-
default:
|
|
2856
|
-
if (schema.properties) return convertObject(schema);
|
|
2857
|
-
return t.any();
|
|
2915
|
+
const jsonSchemaToZod = (schema) => {
|
|
2916
|
+
if (!schema || typeof schema !== "object") return z.any();
|
|
2917
|
+
const variants = schema.anyOf ?? schema.oneOf;
|
|
2918
|
+
if (Array.isArray(variants) && variants.length > 0) {
|
|
2919
|
+
const nonNull = variants.filter((v) => v?.type !== "null" && v !== null);
|
|
2920
|
+
const nullable = nonNull.length !== variants.length;
|
|
2921
|
+
const mapped = nonNull.map(jsonSchemaToZod);
|
|
2922
|
+
let result = mapped.length === 1 ? mapped[0] : z.union(mapped);
|
|
2923
|
+
if (nullable) result = result.nullable();
|
|
2924
|
+
return result;
|
|
2858
2925
|
}
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
case "
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
}
|
|
2897
|
-
case "
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
if (schema.
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2926
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
2927
|
+
const values = schema.enum.filter((v) => typeof v === "string");
|
|
2928
|
+
if (values.length === schema.enum.length) return z.enum(values);
|
|
2929
|
+
}
|
|
2930
|
+
switch (schema.type) {
|
|
2931
|
+
case "object": {
|
|
2932
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
2933
|
+
const shape = {};
|
|
2934
|
+
for (const [key, value] of Object.entries(schema.properties ?? {})) {
|
|
2935
|
+
const child = jsonSchemaToZod(value);
|
|
2936
|
+
shape[key] = required.includes(key) ? child : child.optional();
|
|
2937
|
+
}
|
|
2938
|
+
return z.object(shape);
|
|
2939
|
+
}
|
|
2940
|
+
case "array": return z.array(jsonSchemaToZod(schema.items ?? {}));
|
|
2941
|
+
case "string": {
|
|
2942
|
+
switch (schema.format) {
|
|
2943
|
+
case "uuid": return z.uuid();
|
|
2944
|
+
case "email": return z.email();
|
|
2945
|
+
case "url":
|
|
2946
|
+
case "uri": return z.url();
|
|
2947
|
+
case "date-time": return z.datetime();
|
|
2948
|
+
case "date": return z.date();
|
|
2949
|
+
case "time": return z.time();
|
|
2950
|
+
case "binary": return z.binary();
|
|
2951
|
+
}
|
|
2952
|
+
let str = z.string();
|
|
2953
|
+
if (typeof schema.minLength === "number") str = str.min(schema.minLength);
|
|
2954
|
+
if (typeof schema.maxLength === "number") str = str.max(schema.maxLength);
|
|
2955
|
+
if (typeof schema.pattern === "string") str = str.regex(new RegExp(schema.pattern));
|
|
2956
|
+
return str;
|
|
2957
|
+
}
|
|
2958
|
+
case "integer": {
|
|
2959
|
+
let int = z.integer();
|
|
2960
|
+
if (typeof schema.minimum === "number") int = int.min(schema.minimum);
|
|
2961
|
+
if (typeof schema.maximum === "number") int = int.max(schema.maximum);
|
|
2962
|
+
return int;
|
|
2963
|
+
}
|
|
2964
|
+
case "number": {
|
|
2965
|
+
let num = z.number();
|
|
2966
|
+
if (typeof schema.minimum === "number") num = num.min(schema.minimum);
|
|
2967
|
+
if (typeof schema.maximum === "number") num = num.max(schema.maximum);
|
|
2968
|
+
return num;
|
|
2969
|
+
}
|
|
2970
|
+
case "boolean": return z.boolean();
|
|
2971
|
+
case "null": return z.null();
|
|
2972
|
+
default: return z.any();
|
|
2905
2973
|
}
|
|
2906
|
-
}
|
|
2907
|
-
/**
|
|
2908
|
-
* Convert JSON Schema number type to TypeBox.
|
|
2909
|
-
*/
|
|
2910
|
-
function convertNumber(schema) {
|
|
2911
|
-
return t.number(filterUndefined({
|
|
2912
|
-
title: schema.title,
|
|
2913
|
-
description: schema.description,
|
|
2914
|
-
default: schema.default,
|
|
2915
|
-
minimum: schema.minimum,
|
|
2916
|
-
maximum: schema.maximum,
|
|
2917
|
-
exclusiveMinimum: schema.exclusiveMinimum,
|
|
2918
|
-
exclusiveMaximum: schema.exclusiveMaximum,
|
|
2919
|
-
multipleOf: schema.multipleOf
|
|
2920
|
-
}));
|
|
2921
|
-
}
|
|
2922
|
-
/**
|
|
2923
|
-
* Convert JSON Schema integer type to TypeBox.
|
|
2924
|
-
*/
|
|
2925
|
-
function convertInteger(schema) {
|
|
2926
|
-
return t.integer(filterUndefined({
|
|
2927
|
-
title: schema.title,
|
|
2928
|
-
description: schema.description,
|
|
2929
|
-
default: schema.default,
|
|
2930
|
-
minimum: schema.minimum,
|
|
2931
|
-
maximum: schema.maximum,
|
|
2932
|
-
exclusiveMinimum: schema.exclusiveMinimum,
|
|
2933
|
-
exclusiveMaximum: schema.exclusiveMaximum,
|
|
2934
|
-
multipleOf: schema.multipleOf
|
|
2935
|
-
}));
|
|
2936
|
-
}
|
|
2937
|
-
/**
|
|
2938
|
-
* Convert JSON Schema boolean type to TypeBox.
|
|
2939
|
-
*/
|
|
2940
|
-
function convertBoolean(schema) {
|
|
2941
|
-
return t.boolean(filterUndefined({
|
|
2942
|
-
title: schema.title,
|
|
2943
|
-
description: schema.description,
|
|
2944
|
-
default: schema.default
|
|
2945
|
-
}));
|
|
2946
|
-
}
|
|
2947
|
-
/**
|
|
2948
|
-
* Convert JSON Schema object type to TypeBox.
|
|
2949
|
-
*/
|
|
2950
|
-
function convertObject(schema) {
|
|
2951
|
-
if (!schema.properties) return t.json(filterUndefined({
|
|
2952
|
-
title: schema.title,
|
|
2953
|
-
description: schema.description
|
|
2954
|
-
}));
|
|
2955
|
-
const required = new Set(schema.required ?? []);
|
|
2956
|
-
const properties = {};
|
|
2957
|
-
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
2958
|
-
let converted = jsonSchemaToTypeBox(propSchema);
|
|
2959
|
-
if (!required.has(key)) converted = t.optional(converted);
|
|
2960
|
-
properties[key] = converted;
|
|
2961
|
-
}
|
|
2962
|
-
return t.object(properties, filterUndefined({
|
|
2963
|
-
title: schema.title,
|
|
2964
|
-
description: schema.description
|
|
2965
|
-
}));
|
|
2966
|
-
}
|
|
2967
|
-
/**
|
|
2968
|
-
* Convert JSON Schema array type to TypeBox.
|
|
2969
|
-
*/
|
|
2970
|
-
function convertArray(schema) {
|
|
2971
|
-
const itemSchema = schema.items ? jsonSchemaToTypeBox(schema.items) : t.any();
|
|
2972
|
-
return t.array(itemSchema, filterUndefined({
|
|
2973
|
-
title: schema.title,
|
|
2974
|
-
description: schema.description,
|
|
2975
|
-
minItems: schema.minItems,
|
|
2976
|
-
maxItems: schema.maxItems,
|
|
2977
|
-
uniqueItems: schema.uniqueItems
|
|
2978
|
-
}));
|
|
2979
|
-
}
|
|
2974
|
+
};
|
|
2980
2975
|
//#endregion
|
|
2981
2976
|
//#region ../../src/core/primitives/$env.ts
|
|
2982
2977
|
/**
|
|
@@ -2995,8 +2990,8 @@ function convertArray(schema) {
|
|
|
2995
2990
|
* log = $logger();
|
|
2996
2991
|
*
|
|
2997
2992
|
* // program expect a var env "HELLO" as string to works
|
|
2998
|
-
* env = $env(
|
|
2999
|
-
* HELLO:
|
|
2993
|
+
* env = $env(z.object({
|
|
2994
|
+
* HELLO: z.text()
|
|
3000
2995
|
* }));
|
|
3001
2996
|
*
|
|
3002
2997
|
* sayHello = () => this.log.info("Hello ${this.env.HELLO}")
|
|
@@ -3007,7 +3002,7 @@ function convertArray(schema) {
|
|
|
3007
3002
|
*/
|
|
3008
3003
|
const $env = (type) => {
|
|
3009
3004
|
const { alepha } = $context();
|
|
3010
|
-
if (!
|
|
3005
|
+
if (!z.schema.isObject(type)) throw new AlephaError("Type must be an TObject");
|
|
3011
3006
|
return alepha.parseEnv(type);
|
|
3012
3007
|
};
|
|
3013
3008
|
//#endregion
|
|
@@ -3253,7 +3248,7 @@ const $scope = () => {
|
|
|
3253
3248
|
*
|
|
3254
3249
|
* @example
|
|
3255
3250
|
* ```ts
|
|
3256
|
-
* const userState = $atom({ schema:
|
|
3251
|
+
* const userState = $atom({ schema: z.object({ name: z.text(), role: z.text() }) });
|
|
3257
3252
|
*
|
|
3258
3253
|
* class UserComponent {
|
|
3259
3254
|
* user = $state(userState); // Reactive reference to atom state
|
|
@@ -3275,39 +3270,30 @@ const $state = (atom) => {
|
|
|
3275
3270
|
};
|
|
3276
3271
|
//#endregion
|
|
3277
3272
|
//#region ../../src/core/schemas/pageQuerySchema.ts
|
|
3278
|
-
const pageQuerySchema =
|
|
3279
|
-
page:
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
default: 0
|
|
3283
|
-
})),
|
|
3284
|
-
size: t.optional(t.integer({
|
|
3285
|
-
description: "The number of items per page.",
|
|
3286
|
-
minimum: 1,
|
|
3287
|
-
maximum: 100,
|
|
3288
|
-
default: 10
|
|
3289
|
-
})),
|
|
3290
|
-
sort: t.optional(t.text({ description: "Sort by field(s). Multiple columns separated by comma. Prefix with '-' for DESC. Examples: 'name' (ASC), '-createdAt' (DESC), 'role,-name' (role ASC, name DESC)" }))
|
|
3273
|
+
const pageQuerySchema = z.object({
|
|
3274
|
+
page: z.integer().min(0).describe("The page number to retrieve.").default(0).optional(),
|
|
3275
|
+
size: z.integer().min(1).max(100).describe("The number of items per page.").default(10).optional(),
|
|
3276
|
+
sort: z.text({ description: "Sort by field(s). Multiple columns separated by comma. Prefix with '-' for DESC. Examples: 'name' (ASC), '-createdAt' (DESC), 'role,-name' (role ASC, name DESC)" }).optional()
|
|
3291
3277
|
});
|
|
3292
3278
|
//#endregion
|
|
3293
3279
|
//#region ../../src/core/schemas/pageSchema.ts
|
|
3294
|
-
const pageMetadataSchema =
|
|
3295
|
-
number:
|
|
3296
|
-
size:
|
|
3297
|
-
offset:
|
|
3298
|
-
numberOfElements:
|
|
3299
|
-
totalElements:
|
|
3300
|
-
totalPages:
|
|
3301
|
-
isEmpty:
|
|
3302
|
-
isFirst:
|
|
3303
|
-
isLast:
|
|
3304
|
-
sort:
|
|
3305
|
-
sorted:
|
|
3306
|
-
fields:
|
|
3307
|
-
field:
|
|
3308
|
-
direction:
|
|
3280
|
+
const pageMetadataSchema = z.object({
|
|
3281
|
+
number: z.integer().describe("Page number, starting from 0"),
|
|
3282
|
+
size: z.integer().describe("Number of items per page (requested page size)"),
|
|
3283
|
+
offset: z.integer().describe("Offset in the dataset (page × size)"),
|
|
3284
|
+
numberOfElements: z.integer().describe("Number of elements in THIS page (content.length). Different from totalElements which is the total across all pages."),
|
|
3285
|
+
totalElements: z.integer().describe("Total number of elements across all pages. Only available when counting is enabled.").optional(),
|
|
3286
|
+
totalPages: z.integer().describe("Total number of pages. Only available when `totalElements` is present.").optional(),
|
|
3287
|
+
isEmpty: z.boolean().describe("Indicates if the current page has no items (numberOfElements === 0)"),
|
|
3288
|
+
isFirst: z.boolean().describe("Indicates if this is the first page (number === 0)"),
|
|
3289
|
+
isLast: z.boolean().describe("Indicates if this is the last page (no more pages after this)"),
|
|
3290
|
+
sort: z.object({
|
|
3291
|
+
sorted: z.boolean().describe("Whether the results are sorted"),
|
|
3292
|
+
fields: z.array(z.object({
|
|
3293
|
+
field: z.text({ description: "The field used for sorting" }),
|
|
3294
|
+
direction: z.enum(["asc", "desc"]).describe("The direction of the sort. Either 'asc' or 'desc'")
|
|
3309
3295
|
}))
|
|
3310
|
-
}))
|
|
3296
|
+
}).optional()
|
|
3311
3297
|
});
|
|
3312
3298
|
/**
|
|
3313
3299
|
* Create a pagination schema for the given object schema.
|
|
@@ -3317,7 +3303,7 @@ const pageMetadataSchema = t.object({
|
|
|
3317
3303
|
*
|
|
3318
3304
|
* @example
|
|
3319
3305
|
* ```ts
|
|
3320
|
-
* const userSchema =
|
|
3306
|
+
* const userSchema = z.object({ id: z.integer(), name: z.text() });
|
|
3321
3307
|
* const userPageSchema = pageSchema(userSchema);
|
|
3322
3308
|
* ```
|
|
3323
3309
|
*
|
|
@@ -3331,10 +3317,10 @@ const pageMetadataSchema = t.object({
|
|
|
3331
3317
|
* })
|
|
3332
3318
|
* ```
|
|
3333
3319
|
*/
|
|
3334
|
-
const pageSchema = (objectSchema
|
|
3335
|
-
content:
|
|
3320
|
+
const pageSchema = (objectSchema) => z.object({
|
|
3321
|
+
content: z.array(objectSchema),
|
|
3336
3322
|
page: pageMetadataSchema
|
|
3337
|
-
}
|
|
3323
|
+
});
|
|
3338
3324
|
TypeProvider.prototype.page = (itemSchema) => pageSchema(itemSchema);
|
|
3339
3325
|
//#endregion
|
|
3340
3326
|
//#region ../../src/core/index.browser.ts
|
|
@@ -3357,6 +3343,6 @@ const run = (entry, opts) => {
|
|
|
3357
3343
|
return alepha;
|
|
3358
3344
|
};
|
|
3359
3345
|
//#endregion
|
|
3360
|
-
export { $atom, $context, $env, $hook, $inject, $memoize, $mode, $module, $pipeline, $scope, $state, ALS_PARENT, Alepha, AlephaError, AlsProvider, AppNotStartedError, Atom, CircularDependencyError, CodecManager, ContainerLockedError, EventManager,
|
|
3346
|
+
export { $atom, $computed, $context, $env, $hook, $inject, $memoize, $mode, $module, $pipeline, $scope, $state, ALS_PARENT, Alepha, AlephaError, AlsProvider, AppNotStartedError, Atom, CircularDependencyError, CodecManager, Computed, ContainerLockedError, EventManager, HookPrimitive, InjectPrimitive, Json, JsonSchemaCodec, KIND, KeylessJsonSchemaCodec, Module, OPTIONS, PipelineHandler, PipelinePrimitive, Primitive, SchemaCodec, SchemaValidator, StateManager, TooLateSubstitutionError, Type, TypeBoxError, TypeProvider, Z_LIMITS, __alephaRef, coerceObject, coerceScalar, createMiddleware, createPagination, createPrimitive, isClass, isFileLike, isTypeFile, jsonSchemaToZod, pageMetadataSchema, pageQuerySchema, pageSchema, run, z };
|
|
3361
3347
|
|
|
3362
3348
|
//# sourceMappingURL=index.browser.js.map
|