@getstrata/core 2.2.60 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/core/audit/exportAuditLogs.d.ts +12 -3
- package/dist/core/audit/exportStore.d.ts +6 -2
- package/dist/core/audit/siemFormatter.d.ts +2 -2
- package/dist/core/auth/abilityCatalog.d.ts +1 -9
- package/dist/core/auth/authContext.d.ts +2 -0
- package/dist/core/auth/authOutcome.d.ts +32 -0
- package/dist/core/auth/authReader.d.ts +22 -0
- package/dist/core/auth/basicAuthGuard.d.ts +19 -3
- package/dist/core/auth/emailVerification.d.ts +1 -1
- package/dist/core/auth/guard.d.ts +27 -6
- package/dist/core/auth/intendedUrlCookie.d.ts +13 -7
- package/dist/core/auth/jwt.d.ts +5 -4
- package/dist/core/auth/jwtGuard.d.ts +7 -6
- package/dist/core/auth/membershipContext.d.ts +10 -7
- package/dist/core/auth/membershipContextMiddleware.d.ts +3 -3
- package/dist/core/auth/membershipMiddleware.d.ts +1 -2
- package/dist/core/auth/membershipServiceImplementation.d.ts +1 -1
- package/dist/core/auth/oauth/oidcIdToken.d.ts +25 -16
- package/dist/core/auth/oauth/oidcProvider.d.ts +6 -4
- package/dist/core/auth/oauth/providers.d.ts +3 -1
- package/dist/core/auth/oneTimeToken.d.ts +2 -3
- package/dist/core/auth/passwordConfirmCookie.d.ts +15 -6
- package/dist/core/auth/passwordLogin.d.ts +5 -5
- package/dist/core/auth/pendingMfaCookie.d.ts +2 -2
- package/dist/core/auth/policy.d.ts +23 -10
- package/dist/core/auth/requireAuthCapability.d.ts +3 -0
- package/dist/core/auth/resolveMembershipService.d.ts +3 -2
- package/dist/core/auth/saml/samlAssertionReplay.d.ts +4 -4
- package/dist/core/auth/saml/samlServiceProvider.d.ts +11 -7
- package/dist/core/auth/scimAuthMiddleware.d.ts +10 -3
- package/dist/core/auth/sessionCookie.d.ts +20 -9
- package/dist/core/auth/sessionGuard.d.ts +14 -3
- package/dist/core/cache/createCacheStore.d.ts +6 -3
- package/dist/core/cache/redisCacheStore.d.ts +5 -1
- package/dist/core/cache/repository.d.ts +5 -1
- package/dist/core/cache/simpleCache.d.ts +2 -1
- package/dist/core/cache/tokens.d.ts +8 -0
- package/dist/core/config/applicationConfig.d.ts +21 -0
- package/dist/core/config/configSnapshot.d.ts +3 -0
- package/dist/core/config/envSchema.d.ts +3 -2
- package/dist/core/contracts/application.d.ts +153 -0
- package/dist/core/contracts/authUserDirectory.d.ts +24 -7
- package/dist/core/contracts/container.d.ts +20 -23
- package/dist/core/contracts/di.d.ts +4 -2
- package/dist/core/contracts/executionContext.d.ts +5 -0
- package/dist/core/contracts/executionOperations.d.ts +10 -0
- package/dist/core/contracts/executionOwnership.d.ts +38 -0
- package/dist/core/contracts/persistence.d.ts +20 -0
- package/dist/core/contracts/serviceTokens.d.ts +32 -18
- package/dist/core/contracts/services.d.ts +63 -0
- package/dist/core/contracts/token.d.ts +19 -0
- package/dist/core/crypto/fieldEncryption.d.ts +19 -7
- package/dist/core/crypto/fieldEncryptionRotation.d.ts +21 -5
- package/dist/core/crypto/mfaSecret.d.ts +10 -3
- package/dist/core/database/baseRepository.d.ts +14 -10
- package/dist/core/database/bindings.d.ts +6 -0
- package/dist/core/database/bunSql.d.ts +3 -12
- package/dist/core/database/definitions.d.ts +209 -0
- package/dist/core/database/dialect.d.ts +5 -24
- package/dist/core/database/driverPorts.d.ts +116 -0
- package/dist/core/database/errors.d.ts +47 -7
- package/dist/core/database/factory.d.ts +51 -31
- package/dist/core/database/index.d.ts +9 -10
- package/dist/core/database/keyset.d.ts +2 -1
- package/dist/core/database/legacyNativeTransaction.d.ts +5 -0
- package/dist/core/database/manager.d.ts +12 -0
- package/dist/core/database/model.d.ts +91 -97
- package/dist/core/database/modelQuery.d.ts +9 -5
- package/dist/core/database/modelRegistry.d.ts +52 -33
- package/dist/core/database/mysqlConnection.d.ts +1 -19
- package/dist/core/database/mysqlNative.d.ts +38 -0
- package/dist/core/database/nativeTransactions.d.ts +16 -0
- package/dist/core/database/ormInternal.d.ts +85 -0
- package/dist/core/database/ormRuntime.d.ts +4 -0
- package/dist/core/database/ownedReadOnlyObservation.d.ts +16 -0
- package/dist/core/database/postgresNative.d.ts +11 -0
- package/dist/core/database/query.d.ts +24 -23
- package/dist/core/database/queryPlanSnapshot.d.ts +7 -0
- package/dist/core/database/rawMysql.d.ts +7 -0
- package/dist/core/database/rawPostgres.d.ts +23 -0
- package/dist/core/database/rawSqlite.d.ts +6 -0
- package/dist/core/database/relationQueries.d.ts +3 -2
- package/dist/core/database/relationQuery.d.ts +24 -6
- package/dist/core/database/repositoryQuery.d.ts +6 -1
- package/dist/core/database/schema/driver.d.ts +1 -1
- package/dist/core/database/seeders/types.d.ts +1 -1
- package/dist/core/database/session.d.ts +13 -0
- package/dist/core/database/sessionFactory.d.ts +9 -0
- package/dist/core/database/sqlDialects.d.ts +22 -0
- package/dist/core/database/tokens.d.ts +7 -0
- package/dist/core/database/transactionSession.d.ts +43 -0
- package/dist/core/errors/http.d.ts +4 -1
- package/dist/core/events/{eventBus.d.ts → eventBusClass.d.ts} +1 -3
- package/dist/core/events/index.d.ts +2 -3
- package/dist/core/events/outbox/index.d.ts +44 -13
- package/dist/core/events/outbox/metrics.d.ts +4 -4
- package/dist/core/events/outbox/workerTransport.d.ts +17 -0
- package/dist/core/http/authMiddleware.d.ts +2 -2
- package/dist/core/http/authorizeMiddleware.d.ts +2 -2
- package/dist/core/http/bodySizeLimitMiddleware.d.ts +1 -1
- package/dist/core/http/conditionalResponse.d.ts +7 -2
- package/dist/core/http/contentSecurityPolicy.d.ts +4 -3
- package/dist/core/http/corsMiddleware.d.ts +2 -1
- package/dist/core/http/csrfMiddleware.d.ts +6 -1
- package/dist/core/http/csrfToken.d.ts +17 -7
- package/dist/core/http/databaseError.d.ts +4 -0
- package/dist/core/http/etag.d.ts +5 -2
- package/dist/core/http/flashMiddleware.d.ts +1 -1
- package/dist/core/http/flashSession.d.ts +13 -7
- package/dist/core/http/index.d.ts +1 -1
- package/dist/core/http/loginThrottleMiddleware.d.ts +3 -3
- package/dist/core/http/memoryThrottleMiddleware.d.ts +2 -2
- package/dist/core/http/parseMultipartUpload.d.ts +3 -2
- package/dist/core/http/requestMetaContext.d.ts +5 -0
- package/dist/core/http/requireAbilityMiddleware.d.ts +1 -1
- package/dist/core/http/requireAuthMiddleware.d.ts +2 -2
- package/dist/core/http/requirePasswordConfirmMiddleware.d.ts +2 -1
- package/dist/core/http/requireVerifiedMiddleware.d.ts +2 -2
- package/dist/core/http/requireWebAuthMiddleware.d.ts +2 -2
- package/dist/core/http/response.d.ts +4 -3
- package/dist/core/http/scimThrottleMiddleware.d.ts +4 -3
- package/dist/core/http/securedRouteModelBinding.d.ts +10 -3
- package/dist/core/http/securityHeadersMiddleware.d.ts +1 -2
- package/dist/core/http/signedUrl.d.ts +8 -6
- package/dist/core/http/throttleMiddleware.d.ts +9 -5
- package/dist/core/http/uploads.d.ts +9 -3
- package/dist/core/http/webErrorResponse.d.ts +8 -2
- package/dist/core/jobs/exportAuditLogsJob.d.ts +5 -2
- package/dist/core/jobs/invalidateCacheTagsJob.d.ts +5 -4
- package/dist/core/lifecycle/gracefulShutdown.d.ts +2 -5
- package/dist/core/logging/requestLoggingMiddleware.d.ts +1 -1
- package/dist/core/mail/mailer.d.ts +7 -5
- package/dist/core/openapi/generator.d.ts +12 -4
- package/dist/core/openapi/registeredRoute.d.ts +4 -4
- package/dist/core/queue/createAppQueue.d.ts +9 -4
- package/dist/core/queue/failedJobMetrics.d.ts +11 -2
- package/dist/core/queue/failedJobRepository.d.ts +6 -3
- package/dist/core/queue/failedJobService.d.ts +1 -0
- package/dist/core/queue/index.d.ts +16 -6
- package/dist/core/queue/jobRegistry.d.ts +3 -2
- package/dist/core/queue/jobRunner.d.ts +10 -4
- package/dist/core/queue/publicQueue.d.ts +18 -9
- package/dist/core/queue/queueConfig.d.ts +20 -10
- package/dist/core/queue/queueHandoff.d.ts +31 -0
- package/dist/core/queue/queueMetrics.d.ts +10 -3
- package/dist/core/queue/queueServices.d.ts +28 -0
- package/dist/core/queue/queueWorkerTransport.d.ts +28 -0
- package/dist/core/queue/redisQueue.d.ts +19 -10
- package/dist/core/queue/redisQueueKeys.d.ts +5 -5
- package/dist/core/queue/redisStreams.d.ts +17 -10
- package/dist/core/queue/resilientQueue.d.ts +10 -4
- package/dist/core/queue/types.d.ts +1 -0
- package/dist/core/runtime/appKeyPrefix.d.ts +5 -5
- package/dist/core/runtime/application.d.ts +7 -0
- package/dist/core/runtime/executionContext.d.ts +9 -0
- package/dist/core/runtime/executionTasks.d.ts +49 -0
- package/dist/core/runtime/resourceJournal.d.ts +67 -0
- package/dist/core/runtime/serviceGraph.d.ts +14 -0
- package/dist/core/security/oauthState.d.ts +13 -9
- package/dist/core/security/publicReads.d.ts +2 -2
- package/dist/core/security/safeFetch.d.ts +1 -0
- package/dist/core/security/safeUrl.d.ts +3 -0
- package/dist/core/security/scimTenantTokens.d.ts +1 -1
- package/dist/core/security/tokenExpiry.d.ts +1 -1
- package/dist/core/security/webhookSignature.d.ts +1 -1
- package/dist/core/storage/storage.d.ts +24 -16
- package/dist/core/tenant/databaseTenantContext.d.ts +5 -7
- package/dist/core/tenant/resolveTenant.d.ts +2 -2
- package/dist/core/tenant/scopedDatabasePolicy.d.ts +8 -0
- package/dist/core/tenant/tenantDatabaseScope.d.ts +3 -7
- package/dist/core/tenant/tenantMiddleware.d.ts +15 -4
- package/dist/core/tracing/otel.d.ts +4 -6
- package/dist/core/tracing/tracingMiddleware.d.ts +3 -3
- package/dist/core/view/etaViewEngine.d.ts +1 -1
- package/dist/core/view/index.d.ts +5 -4
- package/dist/core/view/tokens.d.ts +8 -0
- package/dist/core/view/viewRenderer.d.ts +2 -2
- package/dist/core/view/webErrorView.d.ts +8 -7
- package/dist/core/view/webLayoutData.d.ts +6 -4
- package/dist/entries/audit/exportAuditLogs.js +87 -1024
- package/dist/entries/audit/siemFormatter.js +4 -90
- package/dist/entries/auth/abilityCatalog.js +28 -0
- package/dist/entries/auth/accessControl.js +5 -16
- package/dist/entries/auth/accountStateMigration.js +216 -236
- package/dist/entries/auth/authOutcome.js +80 -0
- package/dist/entries/auth/authReader.js +68 -0
- package/dist/entries/auth/basicAuthGuard.js +144 -1249
- package/dist/entries/auth/emailVerification.js +2 -2
- package/dist/entries/auth/intendedUrlCookie.js +35 -59
- package/dist/entries/auth/jwt.js +22 -47
- package/dist/entries/auth/jwtGuard.js +99 -231
- package/dist/entries/auth/membershipMiddleware.js +71 -10
- package/dist/entries/auth/membershipScope.js +16 -22
- package/dist/entries/auth/membershipService.js +11 -28
- package/dist/entries/auth/oauth/oidcProvider.js +59 -64
- package/dist/entries/auth/oauth/providers.js +12 -95
- package/dist/entries/auth/oauth/samlProvider.js +53 -1080
- package/dist/entries/auth/oneTimeToken.js +27 -289
- package/dist/entries/auth/passwordConfirmCookie.js +40 -63
- package/dist/entries/auth/passwordLogin.js +94 -399
- package/dist/entries/auth/pendingMfaCookie.js +6 -6
- package/dist/entries/auth/policy.js +22 -56
- package/dist/entries/auth/saml/samlServiceProvider.js +55 -1084
- package/dist/entries/auth/scimAuthMiddleware.js +16 -3358
- package/dist/entries/auth/sessionCookie.js +58 -73
- package/dist/entries/auth/sessionGuard.js +95 -248
- package/dist/entries/auth/tokenHash.js +11 -43
- package/dist/entries/cache/createCacheStore.js +126 -117
- package/dist/entries/cache/repository.js +25 -0
- package/dist/entries/cache/simpleCache.js +12 -7
- package/dist/entries/cache/tokens.js +9 -0
- package/dist/entries/config/applicationConfig.js +163 -0
- package/dist/entries/config/envSchema.js +21 -4
- package/dist/entries/contracts/application.js +1 -0
- package/dist/entries/contracts/authUserDirectory.js +10 -0
- package/dist/entries/contracts/container.js +99 -26
- package/dist/entries/contracts/di.js +3 -0
- package/dist/entries/contracts/executionContext.js +7 -0
- package/dist/entries/contracts/executionOperations.js +7 -0
- package/dist/entries/contracts/executionOwnership.js +7 -0
- package/dist/entries/contracts/membership.js +1 -0
- package/dist/entries/contracts/persistence.js +1 -0
- package/dist/entries/contracts/serviceTokens.js +26 -116
- package/dist/entries/contracts/services.js +98 -0
- package/dist/entries/contracts/token.js +41 -0
- package/dist/entries/crypto/fieldEncryption.js +49 -50
- package/dist/entries/crypto/mfaSecret.js +86 -82
- package/dist/entries/database/acquisitionMetrics.js +107 -0
- package/dist/entries/database/baseRepository.d.ts +2 -0
- package/dist/entries/database/bindings.js +2082 -0
- package/dist/entries/database/definitions.js +175 -0
- package/dist/entries/database/errors.js +114 -89
- package/dist/entries/database/factory.js +67 -28
- package/dist/entries/database/migrations.js +172 -224
- package/dist/entries/database/model.d.ts +1 -0
- package/dist/entries/database/ownedReadOnlyObservation.js +1282 -0
- package/dist/entries/database/query.js +159 -161
- package/dist/entries/database/repositoryQuery.d.ts +1 -0
- package/dist/entries/database/repositoryQuery.js +1 -1373
- package/dist/entries/database/schema.js +216 -236
- package/dist/entries/database/session.js +1 -0
- package/dist/entries/database/sqliteConnection.js +525 -83
- package/dist/entries/database/tokens.js +9 -0
- package/dist/entries/errors/http.js +118 -1
- package/dist/entries/http/authMiddleware.js +8 -5
- package/dist/entries/http/authorizeMiddleware.js +1 -1
- package/dist/entries/http/bodySizeLimitMiddleware.js +2 -2
- package/dist/entries/http/clientIp.js +2 -2
- package/dist/entries/http/conditionalResponse.js +19 -7
- package/dist/entries/http/corsMiddleware.js +6 -101
- package/dist/entries/http/csrfMiddleware.js +92 -106
- package/dist/entries/http/csrfToken.js +58 -94
- package/dist/entries/http/etag.js +7 -4
- package/dist/entries/http/flashMiddleware.js +57 -99
- package/dist/entries/http/flashSession.js +41 -68
- package/dist/entries/http/memoryThrottleMiddleware.js +43 -186
- package/dist/entries/http/metricsMiddleware.js +2 -16
- package/dist/entries/http/parseMultipartUpload.js +15 -29
- package/dist/entries/http/requireAbilityMiddleware.js +2 -2
- package/dist/entries/http/requirePasswordConfirmMiddleware.js +19 -31
- package/dist/entries/http/requireVerifiedMiddleware.js +4 -7
- package/dist/entries/http/requireWebAuthMiddleware.js +2 -2
- package/dist/entries/http/response.js +67 -233
- package/dist/entries/http/routeMiddleware.js +0 -14
- package/dist/entries/http/scimThrottleMiddleware.js +43 -237
- package/dist/entries/http/securedRouteModelBinding.js +37 -25
- package/dist/entries/http/securityHeadersMiddleware.js +8 -25
- package/dist/entries/http/signedUrl.js +20 -110
- package/dist/entries/http/throttleMiddleware.js +41 -185
- package/dist/entries/http/uploads.js +9 -24
- package/dist/entries/jobs/exportAuditLogsJob.js +17 -1498
- package/dist/entries/jobs/invalidateCacheTagsJob.js +12 -47
- package/dist/entries/logging/requestLoggingMiddleware.js +4 -4
- package/dist/entries/mail/mailer.js +68 -78
- package/dist/entries/openapi/generator.js +33 -100
- package/dist/entries/queue/createAppQueue.js +416 -256
- package/dist/entries/queue/failedJobRepository.js +17 -8
- package/dist/entries/queue/failedJobService.js +1 -0
- package/dist/entries/queue/jobRunner.js +141 -66
- package/dist/entries/queue/publicQueue.js +411 -257
- package/dist/entries/queue/queueConfig.js +61 -0
- package/dist/entries/queue/queueHandoff.js +318 -0
- package/dist/entries/queue/queueMetrics.js +989 -1386
- package/dist/entries/queue/queueServices.js +133 -0
- package/dist/entries/queue/queueWorkerTransport.js +1703 -0
- package/dist/entries/queue/redisQueue.js +282 -180
- package/dist/entries/queue.js +6 -45
- package/dist/entries/runtime/application.js +1585 -0
- package/dist/entries/runtime/asyncContextStore.js +0 -16
- package/dist/entries/security/oauthState.js +35 -67
- package/dist/entries/security/publicReads.js +4 -4
- package/dist/entries/security/safeFetch.js +1 -0
- package/dist/entries/security/scimTenantTokens.js +3 -3
- package/dist/entries/security/tokenExpiry.js +2 -2
- package/dist/entries/security/totp.js +1 -87
- package/dist/entries/security/webhookSignature.js +2 -90
- package/dist/entries/storage/storage.js +120 -45
- package/dist/entries/tenant/databaseTenantContext.js +6 -907
- package/dist/entries/tenant/publicTenantHost.js +78 -0
- package/dist/entries/tenant/resolveTenant.js +14 -0
- package/dist/entries/tenant/scopedDatabasePolicy.js +75 -0
- package/dist/entries/tenant/tenancyConfig.js +1 -19
- package/dist/entries/tenant/tenantDatabaseScope.js +3 -892
- package/dist/entries/tracing/tracingMiddleware.js +104 -173
- package/dist/entries/view/tokens.js +11 -0
- package/dist/framework/public-api.d.ts +62 -44
- package/dist/index.js +10435 -11351
- package/dist/internal/ormInternal.js +117 -0
- package/dist/internal/ormRuntime.js +5000 -0
- package/package.json +158 -46
- package/dist/core/database/bindConnection.d.ts +0 -1
- package/dist/core/database/boundConnection.d.ts +0 -5
- package/dist/core/database/defaultConnection.d.ts +0 -7
- package/dist/core/database/namedConnections.d.ts +0 -15
- package/dist/core/database/readOnlyCollector.d.ts +0 -7
- package/dist/core/database/repositoryConnection.d.ts +0 -4
- package/dist/core/database/transaction.d.ts +0 -23
- package/dist/core/database/transactionControl.d.ts +0 -6
- package/dist/core/events/deferredModelEvents.d.ts +0 -7
- package/dist/core/facades/index.d.ts +0 -10
- package/dist/core/runtime/applicationRegistry.d.ts +0 -18
- package/dist/entries/database/bindConnection.js +0 -1
- package/dist/entries/database/boundConnection.js +0 -1
- package/dist/entries/database/defaultConnection.js +0 -1
- package/dist/entries/database/namedConnections.js +0 -1
- package/dist/entries/database/repositoryConnection.js +0 -1
- package/dist/entries/database/transaction.js +0 -1
- package/dist/entries/facades.js +0 -711
- package/dist/entries/runtime/applicationRegistry.js +0 -1
|
@@ -1,93 +1,59 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// ../../src/core/runtime/appKeyPrefix.ts
|
|
26
|
-
function appKeyPrefix() {
|
|
27
|
-
return process.env.APP_KEY_PREFIX?.trim() || "strata";
|
|
28
|
-
}
|
|
29
|
-
function appCookieName(kind) {
|
|
30
|
-
return `${appKeyPrefix()}_${kind}`;
|
|
31
|
-
}
|
|
32
|
-
function appDevSecret(kind) {
|
|
33
|
-
return `${appKeyPrefix()}-dev-${kind}`;
|
|
34
|
-
}
|
|
35
|
-
function requireConfiguredSecret(names, devKind, env = process.env) {
|
|
36
|
-
for (const name of names) {
|
|
37
|
-
const value = env[name]?.trim();
|
|
38
|
-
if (value) {
|
|
39
|
-
return value;
|
|
2
|
+
// ../../src/core/config/configSnapshot.ts
|
|
3
|
+
function copyApplicationConfig(value, ancestors = new Set) {
|
|
4
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
5
|
+
return value;
|
|
6
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
7
|
+
return value;
|
|
8
|
+
if (typeof value !== "object" || ancestors.has(value)) {
|
|
9
|
+
throw new TypeError("Application config must contain acyclic plain data.");
|
|
10
|
+
}
|
|
11
|
+
const array = Array.isArray(value);
|
|
12
|
+
const prototype = Object.getPrototypeOf(value);
|
|
13
|
+
if (prototype !== (array ? Array.prototype : Object.prototype) && !(prototype === null && !array)) {
|
|
14
|
+
throw new TypeError("Application config must contain only plain objects and arrays.");
|
|
15
|
+
}
|
|
16
|
+
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
17
|
+
throw new TypeError("Application config cannot contain symbol keys.");
|
|
18
|
+
}
|
|
19
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
20
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
21
|
+
if (!(array && key === "length") && (!descriptor.enumerable || !("value" in descriptor))) {
|
|
22
|
+
throw new TypeError("Application config cannot contain accessors or hidden properties.");
|
|
40
23
|
}
|
|
41
24
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return process.env.APP_NAME?.trim() || "Strata";
|
|
69
|
-
}
|
|
70
|
-
function appEnv() {
|
|
71
|
-
return process.env.APP_ENV?.trim() || "local";
|
|
72
|
-
}
|
|
73
|
-
function appUrl() {
|
|
74
|
-
return (process.env.APP_URL?.trim() || "http://localhost:3000").replace(/\/$/, "");
|
|
75
|
-
}
|
|
76
|
-
function apiPrefix() {
|
|
77
|
-
const raw = process.env.API_PREFIX?.trim() || "/api/v1";
|
|
78
|
-
const withSlash = raw.startsWith("/") ? raw : `/${raw}`;
|
|
79
|
-
const trimmed = withSlash.replace(/\/+$/, "");
|
|
80
|
-
return trimmed || "/api/v1";
|
|
81
|
-
}
|
|
82
|
-
function sdkClientClassName() {
|
|
83
|
-
const override = process.env.APP_SDK_CLASS?.trim();
|
|
84
|
-
if (override && /^[A-Za-z_][A-Za-z0-9_]*$/.test(override)) {
|
|
85
|
-
return override;
|
|
25
|
+
ancestors.add(value);
|
|
26
|
+
try {
|
|
27
|
+
if (array) {
|
|
28
|
+
const length = descriptors.length.value;
|
|
29
|
+
if (Object.keys(descriptors).length !== length + 1) {
|
|
30
|
+
throw new TypeError("Application config arrays must be dense and have no extra properties.");
|
|
31
|
+
}
|
|
32
|
+
const result = [];
|
|
33
|
+
for (let index = 0;index < length; index++) {
|
|
34
|
+
const descriptor = descriptors[String(index)];
|
|
35
|
+
if (!descriptor)
|
|
36
|
+
throw new TypeError("Application config arrays must be dense.");
|
|
37
|
+
result.push(copyApplicationConfig(descriptor.value, ancestors));
|
|
38
|
+
}
|
|
39
|
+
return Object.freeze(result);
|
|
40
|
+
}
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
43
|
+
Object.defineProperty(result, key, {
|
|
44
|
+
value: copyApplicationConfig(descriptor.value, ancestors),
|
|
45
|
+
enumerable: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return Object.freeze(result);
|
|
49
|
+
} finally {
|
|
50
|
+
ancestors.delete(value);
|
|
86
51
|
}
|
|
87
|
-
const fromName = appDisplayName().replace(/[^A-Za-z0-9]/g, "");
|
|
88
|
-
return fromName ? `${fromName}Client` : "AppClient";
|
|
89
52
|
}
|
|
90
53
|
|
|
54
|
+
// ../../src/core/cache/redisCacheStore.ts
|
|
55
|
+
var {RedisClient } = globalThis.Bun;
|
|
56
|
+
|
|
91
57
|
// ../../src/core/cache/redisCacheScript.ts
|
|
92
58
|
var CACHE_SCRIPT = `
|
|
93
59
|
local expected = {'hash', 'zset', 'zset', 'hash', 'zset'}
|
|
@@ -289,6 +255,35 @@ return redis.error_reply('Unknown cache operation')
|
|
|
289
255
|
`;
|
|
290
256
|
|
|
291
257
|
// ../../src/core/cache/redisCacheStore.ts
|
|
258
|
+
var DEFAULT_CACHE_NAMESPACE = "strata:cache:v3:";
|
|
259
|
+
function validateCacheNamespace(namespace) {
|
|
260
|
+
if (typeof namespace !== "string" || namespace.length === 0)
|
|
261
|
+
throw new TypeError("Cache namespace must be a nonempty string.");
|
|
262
|
+
}
|
|
263
|
+
function normalizeRedisCacheOptions(ttlMs, maxEntries, options = {}) {
|
|
264
|
+
if (!Number.isSafeInteger(ttlMs) || ttlMs < 0)
|
|
265
|
+
throw new RangeError("ttlMs must be a non-negative safe integer.");
|
|
266
|
+
if (!Number.isInteger(maxEntries) || maxEntries < 1 || maxEntries > 1e4)
|
|
267
|
+
throw new RangeError("maxEntries must be between 1 and 10000.");
|
|
268
|
+
const copied = copyApplicationConfig(options);
|
|
269
|
+
const resolved = {
|
|
270
|
+
commandTimeoutMs: 5000,
|
|
271
|
+
leaseMs: 1e4,
|
|
272
|
+
fillTimeoutMs: 30000,
|
|
273
|
+
waitTimeoutMs: 35000,
|
|
274
|
+
pollMs: 25,
|
|
275
|
+
metadataTtlMs: 60000,
|
|
276
|
+
metadataLimit: 4096,
|
|
277
|
+
...copied
|
|
278
|
+
};
|
|
279
|
+
for (const [key, value] of Object.entries(resolved))
|
|
280
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
281
|
+
throw new RangeError(`${key} must be a positive safe integer.`);
|
|
282
|
+
if (resolved.leaseMs < 30 || resolved.fillTimeoutMs < resolved.leaseMs || resolved.metadataTtlMs < resolved.fillTimeoutMs + resolved.leaseMs || resolved.metadataLimit < 66 || resolved.metadataLimit > 1e5)
|
|
283
|
+
throw new RangeError("Invalid Redis cache lease, deadline or metadata bounds.");
|
|
284
|
+
return Object.freeze(resolved);
|
|
285
|
+
}
|
|
286
|
+
|
|
292
287
|
class RedisCacheStore {
|
|
293
288
|
redisUrl;
|
|
294
289
|
ttlMs;
|
|
@@ -298,30 +293,14 @@ class RedisCacheStore {
|
|
|
298
293
|
options;
|
|
299
294
|
fills = new Set;
|
|
300
295
|
closed = false;
|
|
301
|
-
constructor(redisUrl, ttlMs, maxEntries, options = {}) {
|
|
296
|
+
constructor(redisUrl, ttlMs, maxEntries, options = {}, namespace = DEFAULT_CACHE_NAMESPACE) {
|
|
302
297
|
this.redisUrl = redisUrl;
|
|
303
298
|
this.ttlMs = ttlMs;
|
|
304
299
|
this.maxEntries = maxEntries;
|
|
305
|
-
if (
|
|
306
|
-
throw new
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.options = {
|
|
310
|
-
commandTimeoutMs: 5000,
|
|
311
|
-
leaseMs: 1e4,
|
|
312
|
-
fillTimeoutMs: 30000,
|
|
313
|
-
waitTimeoutMs: 35000,
|
|
314
|
-
pollMs: 25,
|
|
315
|
-
metadataTtlMs: 60000,
|
|
316
|
-
metadataLimit: 4096,
|
|
317
|
-
...options
|
|
318
|
-
};
|
|
319
|
-
for (const [key, value] of Object.entries(this.options))
|
|
320
|
-
if (!Number.isSafeInteger(value) || value < 1)
|
|
321
|
-
throw new RangeError(`${key} must be a positive safe integer.`);
|
|
322
|
-
if (this.options.leaseMs < 30 || this.options.fillTimeoutMs < this.options.leaseMs || this.options.metadataTtlMs < this.options.fillTimeoutMs + this.options.leaseMs || this.options.metadataLimit < 66 || this.options.metadataLimit > 1e5)
|
|
323
|
-
throw new RangeError("Invalid Redis cache lease, deadline or metadata bounds.");
|
|
324
|
-
const namespace = namespacedRedisKey("cache:v3:");
|
|
300
|
+
if (typeof redisUrl !== "string" || !redisUrl)
|
|
301
|
+
throw new TypeError("Redis cache requires an explicit URL.");
|
|
302
|
+
this.options = normalizeRedisCacheOptions(ttlMs, maxEntries, options);
|
|
303
|
+
validateCacheNamespace(namespace);
|
|
325
304
|
const slot = new Bun.CryptoHasher("sha256").update(namespace).digest("hex");
|
|
326
305
|
this.keys = ["entries", "expiry", "order", "metadata", "metadata-expiry"].map((name) => `${namespace}{${slot}}:${name}`);
|
|
327
306
|
this.client = this.createClient();
|
|
@@ -512,6 +491,15 @@ class RedisCacheStore {
|
|
|
512
491
|
var redisCacheStore_default = RedisCacheStore;
|
|
513
492
|
|
|
514
493
|
// ../../src/core/cache/simpleCache.ts
|
|
494
|
+
function validateSimpleCacheOptions(ttlMs, maxEntries) {
|
|
495
|
+
if (!Number.isFinite(ttlMs) || ttlMs < 0) {
|
|
496
|
+
throw new RangeError("ttlMs must be a non-negative number.");
|
|
497
|
+
}
|
|
498
|
+
if (!Number.isInteger(maxEntries) || maxEntries < 1) {
|
|
499
|
+
throw new RangeError("maxEntries must be a positive integer.");
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
515
503
|
class SimpleCache {
|
|
516
504
|
ttlMs;
|
|
517
505
|
maxEntries;
|
|
@@ -522,12 +510,7 @@ class SimpleCache {
|
|
|
522
510
|
constructor(ttlMs = 3600000, maxEntries = 100) {
|
|
523
511
|
this.ttlMs = ttlMs;
|
|
524
512
|
this.maxEntries = maxEntries;
|
|
525
|
-
|
|
526
|
-
throw new RangeError("ttlMs must be a non-negative number.");
|
|
527
|
-
}
|
|
528
|
-
if (!Number.isInteger(maxEntries) || maxEntries < 1) {
|
|
529
|
-
throw new RangeError("maxEntries must be a positive integer.");
|
|
530
|
-
}
|
|
513
|
+
validateSimpleCacheOptions(ttlMs, maxEntries);
|
|
531
514
|
}
|
|
532
515
|
get(key) {
|
|
533
516
|
return this.getFreshEntry(key)?.value;
|
|
@@ -739,15 +722,41 @@ class SimpleCacheStore {
|
|
|
739
722
|
var simpleCacheStore_default = SimpleCacheStore;
|
|
740
723
|
|
|
741
724
|
// ../../src/core/cache/createCacheStore.ts
|
|
742
|
-
function
|
|
743
|
-
if (options
|
|
744
|
-
|
|
725
|
+
function snapshotCacheStoreOptions(options, requireExplicitNamespace = false) {
|
|
726
|
+
if (options === null || typeof options !== "object" || Array.isArray(options))
|
|
727
|
+
throw new TypeError("Cache options must be a plain data record.");
|
|
728
|
+
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
729
|
+
for (const key of ["redisUrl", "redis", "namespace"]) {
|
|
730
|
+
const descriptor = descriptors[key];
|
|
731
|
+
if (descriptor && "value" in descriptor && descriptor.value === undefined)
|
|
732
|
+
delete descriptors[key];
|
|
733
|
+
}
|
|
734
|
+
const data = Object.create(Object.getPrototypeOf(options), descriptors);
|
|
735
|
+
const copied = copyApplicationConfig(data);
|
|
736
|
+
if (requireExplicitNamespace)
|
|
737
|
+
validateCacheNamespace(copied.namespace);
|
|
738
|
+
const namespace = copied.namespace === undefined ? DEFAULT_CACHE_NAMESPACE : copied.namespace;
|
|
739
|
+
validateCacheNamespace(namespace);
|
|
740
|
+
if (copied.driver === "redis") {
|
|
741
|
+
if (typeof copied.redisUrl !== "string" || !copied.redisUrl) {
|
|
745
742
|
throw new Error('CACHE_DRIVER="redis" requires REDIS_URL to be set.');
|
|
746
743
|
}
|
|
747
|
-
|
|
744
|
+
const redis = normalizeRedisCacheOptions(copied.ttlMs, copied.maxEntries, copied.redis);
|
|
745
|
+
return Object.freeze({ ...copied, namespace, redis });
|
|
746
|
+
}
|
|
747
|
+
if (copied.driver !== "array")
|
|
748
|
+
throw new TypeError("Unknown cache driver.");
|
|
749
|
+
validateSimpleCacheOptions(copied.ttlMs, copied.maxEntries);
|
|
750
|
+
return Object.freeze({ ...copied, namespace });
|
|
751
|
+
}
|
|
752
|
+
function createCacheStore(options) {
|
|
753
|
+
const copied = snapshotCacheStoreOptions(options);
|
|
754
|
+
if (copied.driver === "redis") {
|
|
755
|
+
return new redisCacheStore_default(copied.redisUrl, copied.ttlMs, copied.maxEntries, copied.redis, copied.namespace);
|
|
748
756
|
}
|
|
749
|
-
return new simpleCacheStore_default(new simpleCache_default(
|
|
757
|
+
return new simpleCacheStore_default(new simpleCache_default(copied.ttlMs, copied.maxEntries));
|
|
750
758
|
}
|
|
751
759
|
export {
|
|
752
|
-
createCacheStore
|
|
760
|
+
createCacheStore,
|
|
761
|
+
snapshotCacheStoreOptions
|
|
753
762
|
};
|
|
@@ -60,8 +60,33 @@ class CacheRepository {
|
|
|
60
60
|
return this.store.size();
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
function createGuardedCache(backend, operations) {
|
|
64
|
+
const remember = (key, loader, ttlMs) => operations.operation(() => backend.remember(key, (signal) => operations.operation(() => loader(signal)), ttlMs));
|
|
65
|
+
const forget = (key) => operations.operation(() => backend.forget(key));
|
|
66
|
+
const flush = () => operations.operation(() => backend.flush());
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
get: (key) => operations.operation(() => backend.get(key)),
|
|
69
|
+
remember,
|
|
70
|
+
forget,
|
|
71
|
+
flush,
|
|
72
|
+
tags: (...names) => {
|
|
73
|
+
operations.assertActive();
|
|
74
|
+
const tags = [...names];
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
remember: (key, loader, ttlMs) => operations.operation(() => backend.tags(...tags).remember(key, (signal) => operations.operation(() => loader(signal)), ttlMs)),
|
|
77
|
+
flush: () => operations.operation(() => backend.tags(...tags).flush())
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
getOrSet: remember,
|
|
81
|
+
invalidate: forget,
|
|
82
|
+
invalidateByPrefix: (prefix) => operations.operation(() => backend.invalidateByPrefix(prefix)),
|
|
83
|
+
clear: flush,
|
|
84
|
+
size: () => operations.operation(() => backend.size())
|
|
85
|
+
});
|
|
86
|
+
}
|
|
63
87
|
var repository_default = CacheRepository;
|
|
64
88
|
export {
|
|
65
89
|
CacheRepository,
|
|
90
|
+
createGuardedCache,
|
|
66
91
|
repository_default as default
|
|
67
92
|
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/core/cache/simpleCache.ts
|
|
3
|
+
function validateSimpleCacheOptions(ttlMs, maxEntries) {
|
|
4
|
+
if (!Number.isFinite(ttlMs) || ttlMs < 0) {
|
|
5
|
+
throw new RangeError("ttlMs must be a non-negative number.");
|
|
6
|
+
}
|
|
7
|
+
if (!Number.isInteger(maxEntries) || maxEntries < 1) {
|
|
8
|
+
throw new RangeError("maxEntries must be a positive integer.");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
class SimpleCache {
|
|
4
13
|
ttlMs;
|
|
5
14
|
maxEntries;
|
|
@@ -10,12 +19,7 @@ class SimpleCache {
|
|
|
10
19
|
constructor(ttlMs = 3600000, maxEntries = 100) {
|
|
11
20
|
this.ttlMs = ttlMs;
|
|
12
21
|
this.maxEntries = maxEntries;
|
|
13
|
-
|
|
14
|
-
throw new RangeError("ttlMs must be a non-negative number.");
|
|
15
|
-
}
|
|
16
|
-
if (!Number.isInteger(maxEntries) || maxEntries < 1) {
|
|
17
|
-
throw new RangeError("maxEntries must be a positive integer.");
|
|
18
|
-
}
|
|
22
|
+
validateSimpleCacheOptions(ttlMs, maxEntries);
|
|
19
23
|
}
|
|
20
24
|
get(key) {
|
|
21
25
|
return this.getFreshEntry(key)?.value;
|
|
@@ -185,5 +189,6 @@ class SimpleCache {
|
|
|
185
189
|
var simpleCache_default = SimpleCache;
|
|
186
190
|
export {
|
|
187
191
|
SimpleCache,
|
|
188
|
-
simpleCache_default as default
|
|
192
|
+
simpleCache_default as default,
|
|
193
|
+
validateSimpleCacheOptions
|
|
189
194
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/cache/tokens.ts
|
|
3
|
+
import { createServiceToken } from "@getstrata/core/contracts/token";
|
|
4
|
+
var CORE_CACHE_TOKEN = createServiceToken("core.cache");
|
|
5
|
+
var CORE_CACHE_BACKEND_TOKEN = createServiceToken("core.cache.backend");
|
|
6
|
+
export {
|
|
7
|
+
CORE_CACHE_BACKEND_TOKEN,
|
|
8
|
+
CORE_CACHE_TOKEN
|
|
9
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/config/applicationConfig.ts
|
|
3
|
+
import { validateEnv } from "@getstrata/core/config/envSchema";
|
|
4
|
+
|
|
5
|
+
// ../../src/core/config/configSnapshot.ts
|
|
6
|
+
function copyApplicationConfig(value, ancestors = new Set) {
|
|
7
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
8
|
+
return value;
|
|
9
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
10
|
+
return value;
|
|
11
|
+
if (typeof value !== "object" || ancestors.has(value)) {
|
|
12
|
+
throw new TypeError("Application config must contain acyclic plain data.");
|
|
13
|
+
}
|
|
14
|
+
const array = Array.isArray(value);
|
|
15
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16
|
+
if (prototype !== (array ? Array.prototype : Object.prototype) && !(prototype === null && !array)) {
|
|
17
|
+
throw new TypeError("Application config must contain only plain objects and arrays.");
|
|
18
|
+
}
|
|
19
|
+
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
20
|
+
throw new TypeError("Application config cannot contain symbol keys.");
|
|
21
|
+
}
|
|
22
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
23
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
24
|
+
if (!(array && key === "length") && (!descriptor.enumerable || !("value" in descriptor))) {
|
|
25
|
+
throw new TypeError("Application config cannot contain accessors or hidden properties.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
ancestors.add(value);
|
|
29
|
+
try {
|
|
30
|
+
if (array) {
|
|
31
|
+
const length = descriptors.length.value;
|
|
32
|
+
if (Object.keys(descriptors).length !== length + 1) {
|
|
33
|
+
throw new TypeError("Application config arrays must be dense and have no extra properties.");
|
|
34
|
+
}
|
|
35
|
+
const result = [];
|
|
36
|
+
for (let index = 0;index < length; index++) {
|
|
37
|
+
const descriptor = descriptors[String(index)];
|
|
38
|
+
if (!descriptor)
|
|
39
|
+
throw new TypeError("Application config arrays must be dense.");
|
|
40
|
+
result.push(copyApplicationConfig(descriptor.value, ancestors));
|
|
41
|
+
}
|
|
42
|
+
return Object.freeze(result);
|
|
43
|
+
}
|
|
44
|
+
const result = {};
|
|
45
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
46
|
+
Object.defineProperty(result, key, {
|
|
47
|
+
value: copyApplicationConfig(descriptor.value, ancestors),
|
|
48
|
+
enumerable: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return Object.freeze(result);
|
|
52
|
+
} finally {
|
|
53
|
+
ancestors.delete(value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ../../src/core/config/applicationConfig.ts
|
|
58
|
+
function invalidRule(field) {
|
|
59
|
+
throw new TypeError(`Configuration rule for "${field}" must contain valid own data fields.`);
|
|
60
|
+
}
|
|
61
|
+
function plainRecord(value) {
|
|
62
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
63
|
+
return false;
|
|
64
|
+
const prototype = Object.getPrototypeOf(value);
|
|
65
|
+
return prototype === Object.prototype || prototype === null;
|
|
66
|
+
}
|
|
67
|
+
function schemaSnapshot(schema) {
|
|
68
|
+
if (!plainRecord(schema) || Object.getOwnPropertySymbols(schema).length) {
|
|
69
|
+
throw new TypeError("Application configuration schema must be a plain rule map.");
|
|
70
|
+
}
|
|
71
|
+
const snapshot = Object.create(null);
|
|
72
|
+
for (const [field, declaration] of Object.entries(Object.getOwnPropertyDescriptors(schema))) {
|
|
73
|
+
if (!declaration.enumerable || !("value" in declaration) || !plainRecord(declaration.value)) {
|
|
74
|
+
invalidRule(field);
|
|
75
|
+
}
|
|
76
|
+
const rule = declaration.value;
|
|
77
|
+
if (Object.getOwnPropertySymbols(rule).length)
|
|
78
|
+
invalidRule(field);
|
|
79
|
+
const copied = {};
|
|
80
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(rule))) {
|
|
81
|
+
if (!descriptor.enumerable || !("value" in descriptor))
|
|
82
|
+
invalidRule(field);
|
|
83
|
+
const value = descriptor.value;
|
|
84
|
+
if (!["required", "integer", "minimum", "maximum", "default", "pattern"].includes(key)) {
|
|
85
|
+
invalidRule(field);
|
|
86
|
+
}
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
if (key === "required" || key === "integer") {
|
|
90
|
+
if (typeof value !== "boolean")
|
|
91
|
+
invalidRule(field);
|
|
92
|
+
} else if (key === "minimum" || key === "maximum") {
|
|
93
|
+
if (typeof value !== "number")
|
|
94
|
+
invalidRule(field);
|
|
95
|
+
} else if (key === "default") {
|
|
96
|
+
if (typeof value !== "string")
|
|
97
|
+
invalidRule(field);
|
|
98
|
+
} else if (!(value instanceof RegExp) || Object.getPrototypeOf(value) !== RegExp.prototype || Object.getOwnPropertySymbols(value).length || Object.getOwnPropertyNames(value).some((name) => name !== "lastIndex")) {
|
|
99
|
+
invalidRule(field);
|
|
100
|
+
}
|
|
101
|
+
Object.defineProperty(copied, key, { value, enumerable: true });
|
|
102
|
+
}
|
|
103
|
+
if ((copied.minimum !== undefined || copied.maximum !== undefined) && !copied.integer) {
|
|
104
|
+
invalidRule(field);
|
|
105
|
+
}
|
|
106
|
+
Object.defineProperty(snapshot, field, { value: copied, enumerable: true });
|
|
107
|
+
}
|
|
108
|
+
return snapshot;
|
|
109
|
+
}
|
|
110
|
+
function inputSnapshot(schema, input) {
|
|
111
|
+
const snapshot = Object.create(null);
|
|
112
|
+
for (const field of Object.keys(schema)) {
|
|
113
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, field);
|
|
114
|
+
if (!descriptor)
|
|
115
|
+
continue;
|
|
116
|
+
if (!("value" in descriptor)) {
|
|
117
|
+
throw new TypeError(`Configuration field "${field}" must be an own data property.`);
|
|
118
|
+
}
|
|
119
|
+
if (descriptor.value !== undefined && typeof descriptor.value !== "string") {
|
|
120
|
+
throw new TypeError(`Configuration field "${field}" must be a string.`);
|
|
121
|
+
}
|
|
122
|
+
Object.defineProperty(snapshot, field, { value: descriptor.value, enumerable: true });
|
|
123
|
+
}
|
|
124
|
+
return snapshot;
|
|
125
|
+
}
|
|
126
|
+
function parseApplicationConfig(schema, input, convert) {
|
|
127
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
128
|
+
throw new TypeError("Application configuration input must be an explicit string map.");
|
|
129
|
+
}
|
|
130
|
+
const copiedSchema = schemaSnapshot(schema);
|
|
131
|
+
const resolved = validateEnv(copiedSchema, inputSnapshot(copiedSchema, input));
|
|
132
|
+
for (const [field, rule] of Object.entries(copiedSchema)) {
|
|
133
|
+
if ((rule.required || rule.default !== undefined) && !Object.hasOwn(resolved, field)) {
|
|
134
|
+
throw new TypeError(`Configuration field "${field}" must resolve to a nonempty string.`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const values = Object.freeze(Object.assign(Object.create(null), resolved));
|
|
138
|
+
const copied = copyApplicationConfig(convert(values));
|
|
139
|
+
if (copied === null || typeof copied !== "object" || Array.isArray(copied)) {
|
|
140
|
+
throw new TypeError("Application configuration conversion must return a plain settings object.");
|
|
141
|
+
}
|
|
142
|
+
return copied;
|
|
143
|
+
}
|
|
144
|
+
function configInteger(field, value, bounds = {}) {
|
|
145
|
+
const resolved = validateEnv({
|
|
146
|
+
[field]: { required: true, integer: true, minimum: bounds.minimum, maximum: bounds.maximum }
|
|
147
|
+
}, { [field]: value });
|
|
148
|
+
return Number(resolved[field]);
|
|
149
|
+
}
|
|
150
|
+
function configEnum(field, value, choices) {
|
|
151
|
+
if (!Array.isArray(choices) || !choices.length || choices.some((choice) => typeof choice !== "string")) {
|
|
152
|
+
throw new TypeError(`Configuration field "${field}" has an invalid enum rule.`);
|
|
153
|
+
}
|
|
154
|
+
if (typeof value !== "string" || !choices.includes(value)) {
|
|
155
|
+
throw new TypeError(`Configuration field "${field}" must match an allowed enum value.`);
|
|
156
|
+
}
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
configEnum,
|
|
161
|
+
configInteger,
|
|
162
|
+
parseApplicationConfig
|
|
163
|
+
};
|
|
@@ -6,8 +6,19 @@ function defineEnvSchema(schema) {
|
|
|
6
6
|
function validateEnv(schema, env = process.env) {
|
|
7
7
|
const resolved = {};
|
|
8
8
|
for (const [name, rule] of Object.entries(schema)) {
|
|
9
|
+
if (rule.integer) {
|
|
10
|
+
if (rule.minimum !== undefined && !Number.isSafeInteger(rule.minimum) || rule.maximum !== undefined && !Number.isSafeInteger(rule.maximum) || rule.minimum !== undefined && rule.maximum !== undefined && rule.minimum > rule.maximum) {
|
|
11
|
+
throw new TypeError(`Environment integer rule for "${name}" has invalid bounds.`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
9
14
|
const rawValue = env[name];
|
|
15
|
+
if (rawValue !== undefined && typeof rawValue !== "string") {
|
|
16
|
+
throw new TypeError(`Environment variable "${name}" must be a string.`);
|
|
17
|
+
}
|
|
10
18
|
const value = rawValue === undefined || rawValue.trim() === "" ? rule.default : rawValue;
|
|
19
|
+
if (value !== undefined && typeof value !== "string") {
|
|
20
|
+
throw new TypeError(`Environment variable "${name}" must resolve to a string.`);
|
|
21
|
+
}
|
|
11
22
|
if (value === undefined || value.trim() === "") {
|
|
12
23
|
if (rule.required) {
|
|
13
24
|
throw new Error(`Missing required environment variable "${name}".`);
|
|
@@ -18,15 +29,21 @@ function validateEnv(schema, env = process.env) {
|
|
|
18
29
|
const completeInteger = /^[+-]?\d+$/.test(value.trim());
|
|
19
30
|
const parsed = Number.parseInt(value, 10);
|
|
20
31
|
const minimum = rule.minimum ?? Number.NEGATIVE_INFINITY;
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
const maximum = rule.maximum ?? Number.POSITIVE_INFINITY;
|
|
33
|
+
if (!completeInteger || !Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) {
|
|
34
|
+
const comparison = minimum !== Number.NEGATIVE_INFINITY && maximum !== Number.POSITIVE_INFINITY ? `an integer between ${minimum} and ${maximum}` : maximum !== Number.POSITIVE_INFINITY ? `an integer <= ${maximum}` : minimum === Number.NEGATIVE_INFINITY ? "an integer" : `an integer >= ${minimum}`;
|
|
23
35
|
throw new Error(`Environment variable "${name}" must be ${comparison}.`);
|
|
24
36
|
}
|
|
25
37
|
}
|
|
26
|
-
if (rule.pattern && !rule.pattern.test(value)) {
|
|
38
|
+
if (rule.pattern && !new RegExp(rule.pattern.source, rule.pattern.flags).test(value)) {
|
|
27
39
|
throw new Error(`Environment variable "${name}" has an invalid format.`);
|
|
28
40
|
}
|
|
29
|
-
resolved
|
|
41
|
+
Object.defineProperty(resolved, name, {
|
|
42
|
+
value,
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true
|
|
46
|
+
});
|
|
30
47
|
}
|
|
31
48
|
return resolved;
|
|
32
49
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -1 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// ../../src/core/contracts/authUserDirectory.ts
|
|
3
|
+
class AuthAccountNotFoundError extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super("Authentication account not found.");
|
|
6
|
+
this.name = "AuthAccountNotFoundError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
AuthAccountNotFoundError
|
|
11
|
+
};
|