@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,95 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/runtime/appEnv.ts
|
|
3
|
-
var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
|
|
4
|
-
function normalizeEnvValue(value) {
|
|
5
|
-
return (value ?? "").trim().toLowerCase();
|
|
6
|
-
}
|
|
7
|
-
function isProductionEnv(env = process.env) {
|
|
8
|
-
const appEnv = normalizeEnvValue(env.APP_ENV);
|
|
9
|
-
const nodeEnv = normalizeEnvValue(env.NODE_ENV);
|
|
10
|
-
if (appEnv === "production" || nodeEnv === "production") {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
if (appEnv === "") {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return !NON_PRODUCTION_APP_ENVS.has(appEnv);
|
|
17
|
-
}
|
|
18
|
-
function envFlagEnabled(value) {
|
|
19
|
-
return value === "true";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// ../../src/core/runtime/appKeyPrefix.ts
|
|
23
|
-
function appKeyPrefix() {
|
|
24
|
-
return process.env.APP_KEY_PREFIX?.trim() || "strata";
|
|
25
|
-
}
|
|
26
|
-
function appCookieName(kind) {
|
|
27
|
-
return `${appKeyPrefix()}_${kind}`;
|
|
28
|
-
}
|
|
29
|
-
function appDevSecret(kind) {
|
|
30
|
-
return `${appKeyPrefix()}-dev-${kind}`;
|
|
31
|
-
}
|
|
32
|
-
function requireConfiguredSecret(names, devKind, env = process.env) {
|
|
33
|
-
for (const name of names) {
|
|
34
|
-
const value = env[name]?.trim();
|
|
35
|
-
if (value) {
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (isProductionEnv(env)) {
|
|
40
|
-
throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
|
|
41
|
-
}
|
|
42
|
-
return appDevSecret(devKind);
|
|
43
|
-
}
|
|
44
|
-
function namespacedRedisKey(kind) {
|
|
45
|
-
return `${appKeyPrefix()}:${kind}`;
|
|
46
|
-
}
|
|
47
|
-
function smtpEhloHost() {
|
|
48
|
-
const raw = process.env.MAIL_EHLO?.trim() || `${appKeyPrefix()}.local`;
|
|
49
|
-
const safe = raw.replace(/[^a-zA-Z0-9.-]/g, "");
|
|
50
|
-
return safe || "strata.local";
|
|
51
|
-
}
|
|
52
|
-
function siemEventType() {
|
|
53
|
-
return process.env.SIEM_EVENT_TYPE?.trim() || `${appKeyPrefix()}.audit`;
|
|
54
|
-
}
|
|
55
|
-
function appUserAgent() {
|
|
56
|
-
return process.env.APP_USER_AGENT?.trim() || appKeyPrefix();
|
|
57
|
-
}
|
|
58
|
-
function otelServiceName() {
|
|
59
|
-
return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
|
|
60
|
-
}
|
|
61
|
-
function webhookSignatureHeader() {
|
|
62
|
-
return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
|
|
63
|
-
}
|
|
64
|
-
function appDisplayName() {
|
|
65
|
-
return process.env.APP_NAME?.trim() || "Strata";
|
|
66
|
-
}
|
|
67
|
-
function appEnv() {
|
|
68
|
-
return process.env.APP_ENV?.trim() || "local";
|
|
69
|
-
}
|
|
70
|
-
function appUrl() {
|
|
71
|
-
return (process.env.APP_URL?.trim() || "http://localhost:3000").replace(/\/$/, "");
|
|
72
|
-
}
|
|
73
|
-
function apiPrefix() {
|
|
74
|
-
const raw = process.env.API_PREFIX?.trim() || "/api/v1";
|
|
75
|
-
const withSlash = raw.startsWith("/") ? raw : `/${raw}`;
|
|
76
|
-
const trimmed = withSlash.replace(/\/+$/, "");
|
|
77
|
-
return trimmed || "/api/v1";
|
|
78
|
-
}
|
|
79
|
-
function sdkClientClassName() {
|
|
80
|
-
const override = process.env.APP_SDK_CLASS?.trim();
|
|
81
|
-
if (override && /^[A-Za-z_][A-Za-z0-9_]*$/.test(override)) {
|
|
82
|
-
return override;
|
|
83
|
-
}
|
|
84
|
-
const fromName = appDisplayName().replace(/[^A-Za-z0-9]/g, "");
|
|
85
|
-
return fromName ? `${fromName}Client` : "AppClient";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
2
|
// ../../src/core/audit/siemFormatter.ts
|
|
89
|
-
function formatSiemAuditEvent(input) {
|
|
3
|
+
function formatSiemAuditEvent(input, eventType = "strata.audit") {
|
|
90
4
|
return {
|
|
91
5
|
timestamp: input.created_at.toISOString(),
|
|
92
|
-
event_type:
|
|
6
|
+
event_type: eventType,
|
|
93
7
|
actor_user_id: input.user_id,
|
|
94
8
|
tenant_id: input.tenant_id ?? null,
|
|
95
9
|
trace_id: input.trace_id ?? null,
|
|
@@ -102,7 +16,7 @@ function formatSiemAuditEvent(input) {
|
|
|
102
16
|
payload: input.payload ?? {}
|
|
103
17
|
};
|
|
104
18
|
}
|
|
105
|
-
function formatCefLine(event) {
|
|
19
|
+
function formatCefLine(event, displayName = "Strata") {
|
|
106
20
|
const extension = [
|
|
107
21
|
`rt=${event.timestamp}`,
|
|
108
22
|
`suid=${event.actor_user_id ?? "unknown"}`,
|
|
@@ -115,7 +29,7 @@ function formatCefLine(event) {
|
|
|
115
29
|
`src=${event.ip_address ?? ""}`,
|
|
116
30
|
`request=${event.trace_id ?? ""}`
|
|
117
31
|
].join(" ");
|
|
118
|
-
return `CEF:0|${
|
|
32
|
+
return `CEF:0|${displayName}|API|1.0|${event.action}|${event.subject_type}|5|${extension}`;
|
|
119
33
|
}
|
|
120
34
|
export {
|
|
121
35
|
formatCefLine,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/auth/abilityCatalog.ts
|
|
3
|
+
var MEMBER_ABILITIES = Object.freeze([
|
|
4
|
+
"profile:read",
|
|
5
|
+
"auth:tokens:read",
|
|
6
|
+
"auth:tokens:write",
|
|
7
|
+
"auth:tokens:delete"
|
|
8
|
+
]);
|
|
9
|
+
var ADMIN_ABILITIES = Object.freeze([
|
|
10
|
+
...MEMBER_ABILITIES,
|
|
11
|
+
"webhooks:read",
|
|
12
|
+
"webhooks:write",
|
|
13
|
+
"audit:read",
|
|
14
|
+
"audit:export"
|
|
15
|
+
]);
|
|
16
|
+
var PLATFORM_ADMIN_ABILITIES = Object.freeze(["*"]);
|
|
17
|
+
function resolveAbilitiesForRole(role) {
|
|
18
|
+
if (role === "admin") {
|
|
19
|
+
return [...PLATFORM_ADMIN_ABILITIES];
|
|
20
|
+
}
|
|
21
|
+
return [...MEMBER_ABILITIES];
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
ADMIN_ABILITIES,
|
|
25
|
+
MEMBER_ABILITIES,
|
|
26
|
+
PLATFORM_ADMIN_ABILITIES,
|
|
27
|
+
resolveAbilitiesForRole
|
|
28
|
+
};
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
res = fn(fn = 0);
|
|
6
|
-
} catch (e) {
|
|
7
|
-
err = [e];
|
|
8
|
-
}
|
|
9
|
-
if (err)
|
|
10
|
-
throw err[0];
|
|
11
|
-
return res;
|
|
12
|
-
};
|
|
2
|
+
// ../../src/core/auth/accessControl.ts
|
|
3
|
+
import { ForbiddenError } from "@getstrata/core/errors/http";
|
|
13
4
|
|
|
14
5
|
// ../../src/core/runtime/asyncContextStore.ts
|
|
15
6
|
import { AsyncLocalStorage } from "async_hooks";
|
|
@@ -24,15 +15,13 @@ function createAsyncContextStore(key) {
|
|
|
24
15
|
globalRecord[symbol] = store;
|
|
25
16
|
return store;
|
|
26
17
|
}
|
|
27
|
-
var init_asyncContextStore = () => {};
|
|
28
|
-
|
|
29
|
-
// ../../src/core/auth/accessControl.ts
|
|
30
|
-
import { ForbiddenError } from "@getstrata/core/errors/http";
|
|
31
18
|
|
|
32
19
|
// ../../src/core/auth/authContext.ts
|
|
33
|
-
init_asyncContextStore();
|
|
34
20
|
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
35
21
|
var credentialSourceContext = createAsyncContextStore("@getstrata/credentialSource");
|
|
22
|
+
function runWithAuthContext(user, credentialSource, callback) {
|
|
23
|
+
return authContext.run(user, () => credentialSourceContext.run(credentialSource, callback));
|
|
24
|
+
}
|
|
36
25
|
function currentAuthUser() {
|
|
37
26
|
return authContext.getStore() ?? null;
|
|
38
27
|
}
|
|
@@ -1,232 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var __esm = (fn, res, err) => () => {
|
|
3
|
-
if (fn)
|
|
4
|
-
try {
|
|
5
|
-
res = fn(fn = 0);
|
|
6
|
-
} catch (e) {
|
|
7
|
-
err = [e];
|
|
8
|
-
}
|
|
9
|
-
if (err)
|
|
10
|
-
throw err[0];
|
|
11
|
-
return res;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
// ../../src/core/database/schema/driver.ts
|
|
15
|
-
function normalizeConnectionName(connection) {
|
|
16
|
-
const normalized = connection.trim().toLowerCase();
|
|
17
|
-
if (normalized === "pgsql" || normalized === "postgres" || normalized === "postgresql") {
|
|
18
|
-
return "pgsql";
|
|
19
|
-
}
|
|
20
|
-
if (normalized === "mysql" || normalized === "mariadb") {
|
|
21
|
-
return "mysql";
|
|
22
|
-
}
|
|
23
|
-
if (normalized === "sqlite") {
|
|
24
|
-
return "sqlite";
|
|
25
|
-
}
|
|
26
|
-
throw new Error(`Unsupported DB_CONNECTION: ${connection}`);
|
|
27
|
-
}
|
|
28
|
-
function resolveDriverFromUrl(url) {
|
|
29
|
-
const normalized = url.trim().toLowerCase();
|
|
30
|
-
if (normalized.startsWith("postgres://") || normalized.startsWith("postgresql://") || normalized.startsWith("postgres:")) {
|
|
31
|
-
return "pgsql";
|
|
32
|
-
}
|
|
33
|
-
if (normalized.startsWith("mysql://") || normalized.startsWith("mysql:")) {
|
|
34
|
-
return "mysql";
|
|
35
|
-
}
|
|
36
|
-
if (normalized.startsWith("sqlite:")) {
|
|
37
|
-
return "sqlite";
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
function resolveDatabaseDriver(options = {}) {
|
|
42
|
-
const connection = options.connection ?? process.env.DB_CONNECTION;
|
|
43
|
-
if (connection) {
|
|
44
|
-
return normalizeConnectionName(connection);
|
|
45
|
-
}
|
|
46
|
-
const url = options.url ?? process.env.DATABASE_URL ?? "";
|
|
47
|
-
const fromUrl = resolveDriverFromUrl(url);
|
|
48
|
-
if (fromUrl) {
|
|
49
|
-
return fromUrl;
|
|
50
|
-
}
|
|
51
|
-
return "pgsql";
|
|
52
|
-
}
|
|
53
|
-
var init_driver = () => {};
|
|
54
|
-
|
|
55
|
-
// ../../src/core/runtime/asyncContextStore.ts
|
|
56
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
57
|
-
function createAsyncContextStore(key) {
|
|
58
|
-
const symbol = Symbol.for(key);
|
|
59
|
-
const globalRecord = globalThis;
|
|
60
|
-
const existing = globalRecord[symbol];
|
|
61
|
-
if (existing) {
|
|
62
|
-
return existing;
|
|
63
|
-
}
|
|
64
|
-
const store = new AsyncLocalStorage;
|
|
65
|
-
globalRecord[symbol] = store;
|
|
66
|
-
return store;
|
|
67
|
-
}
|
|
68
|
-
var init_asyncContextStore = () => {};
|
|
69
|
-
|
|
70
|
-
// ../../src/core/database/dialect.ts
|
|
71
|
-
function assertSafeIdentifier(identifier) {
|
|
72
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(identifier)) {
|
|
73
|
-
throw new Error(`Invalid SQL identifier: ${identifier}`);
|
|
74
|
-
}
|
|
75
|
-
return identifier;
|
|
76
|
-
}
|
|
77
|
-
function quoteIdentifierFor(dialect, column) {
|
|
78
|
-
return dialect.quoteIdentifier(column);
|
|
79
|
-
}
|
|
80
|
-
function dialectFor(driver) {
|
|
81
|
-
return dialects[driver];
|
|
82
|
-
}
|
|
83
|
-
function currentSqlDialect() {
|
|
84
|
-
return dialectContext.getStore() ?? dialectOverride ?? dialectFor(resolveDatabaseDriver());
|
|
85
|
-
}
|
|
86
|
-
var postgresDialect, mysqlDialect, sqliteDialect, dialects, dialectContext, dialectOverride = null;
|
|
87
|
-
var init_dialect = __esm(() => {
|
|
88
|
-
init_asyncContextStore();
|
|
89
|
-
init_driver();
|
|
90
|
-
postgresDialect = {
|
|
91
|
-
driver: "pgsql",
|
|
92
|
-
placeholder(index) {
|
|
93
|
-
return `$${index}`;
|
|
94
|
-
},
|
|
95
|
-
quoteIdentifier(identifier) {
|
|
96
|
-
return `"${assertSafeIdentifier(identifier)}"`;
|
|
97
|
-
},
|
|
98
|
-
nowExpression() {
|
|
99
|
-
return "NOW()";
|
|
100
|
-
},
|
|
101
|
-
epochMillisecondsExpression() {
|
|
102
|
-
return "CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT)";
|
|
103
|
-
},
|
|
104
|
-
rowLockClause(skipLocked = false) {
|
|
105
|
-
return ` FOR UPDATE${skipLocked ? " SKIP LOCKED" : ""}`;
|
|
106
|
-
},
|
|
107
|
-
timestampValue(value) {
|
|
108
|
-
return value.toISOString();
|
|
109
|
-
},
|
|
110
|
-
returningClause(columns) {
|
|
111
|
-
return ` RETURNING ${columns}`;
|
|
112
|
-
},
|
|
113
|
-
ilikeOperator() {
|
|
114
|
-
return "ILIKE";
|
|
115
|
-
},
|
|
116
|
-
nullsLastSuffix() {
|
|
117
|
-
return " NULLS LAST";
|
|
118
|
-
},
|
|
119
|
-
castToText(expression) {
|
|
120
|
-
return `${expression}::text`;
|
|
121
|
-
},
|
|
122
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
123
|
-
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
124
|
-
if (updateColumns.length === 0) {
|
|
125
|
-
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
126
|
-
}
|
|
127
|
-
const assignments = updateColumns.map((column) => {
|
|
128
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
129
|
-
return `${quoted} = excluded.${quoted}`;
|
|
130
|
-
}).join(", ");
|
|
131
|
-
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
mysqlDialect = {
|
|
135
|
-
driver: "mysql",
|
|
136
|
-
placeholder() {
|
|
137
|
-
return "?";
|
|
138
|
-
},
|
|
139
|
-
quoteIdentifier(identifier) {
|
|
140
|
-
return `\`${assertSafeIdentifier(identifier)}\``;
|
|
141
|
-
},
|
|
142
|
-
nowExpression() {
|
|
143
|
-
return "CURRENT_TIMESTAMP";
|
|
144
|
-
},
|
|
145
|
-
epochMillisecondsExpression() {
|
|
146
|
-
return "CAST(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000 AS UNSIGNED)";
|
|
147
|
-
},
|
|
148
|
-
rowLockClause(skipLocked = false) {
|
|
149
|
-
return ` FOR UPDATE${skipLocked ? " SKIP LOCKED" : ""}`;
|
|
150
|
-
},
|
|
151
|
-
timestampValue(value) {
|
|
152
|
-
return value.toISOString().slice(0, 19).replace("T", " ");
|
|
153
|
-
},
|
|
154
|
-
returningClause() {
|
|
155
|
-
return "";
|
|
156
|
-
},
|
|
157
|
-
ilikeOperator() {
|
|
158
|
-
return "LIKE";
|
|
159
|
-
},
|
|
160
|
-
nullsLastSuffix() {
|
|
161
|
-
return "";
|
|
162
|
-
},
|
|
163
|
-
castToText(expression) {
|
|
164
|
-
return `CAST(${expression} AS CHAR)`;
|
|
165
|
-
},
|
|
166
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
167
|
-
if (updateColumns.length === 0) {
|
|
168
|
-
const anchor = quoteIdentifierFor(this, conflictColumns[0] ?? "");
|
|
169
|
-
return ` ON DUPLICATE KEY UPDATE ${anchor} = ${anchor}`;
|
|
170
|
-
}
|
|
171
|
-
const assignments = updateColumns.map((column) => {
|
|
172
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
173
|
-
return `${quoted} = VALUES(${quoted})`;
|
|
174
|
-
}).join(", ");
|
|
175
|
-
return ` ON DUPLICATE KEY UPDATE ${assignments}`;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
sqliteDialect = {
|
|
179
|
-
driver: "sqlite",
|
|
180
|
-
placeholder() {
|
|
181
|
-
return "?";
|
|
182
|
-
},
|
|
183
|
-
quoteIdentifier(identifier) {
|
|
184
|
-
return `"${assertSafeIdentifier(identifier)}"`;
|
|
185
|
-
},
|
|
186
|
-
nowExpression() {
|
|
187
|
-
return "strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
188
|
-
},
|
|
189
|
-
epochMillisecondsExpression() {
|
|
190
|
-
return "CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER)";
|
|
191
|
-
},
|
|
192
|
-
rowLockClause() {
|
|
193
|
-
return "";
|
|
194
|
-
},
|
|
195
|
-
timestampValue(value) {
|
|
196
|
-
return value.toISOString();
|
|
197
|
-
},
|
|
198
|
-
returningClause(columns) {
|
|
199
|
-
return ` RETURNING ${columns}`;
|
|
200
|
-
},
|
|
201
|
-
ilikeOperator() {
|
|
202
|
-
return "LIKE";
|
|
203
|
-
},
|
|
204
|
-
nullsLastSuffix() {
|
|
205
|
-
return "";
|
|
206
|
-
},
|
|
207
|
-
castToText(expression) {
|
|
208
|
-
return `CAST(${expression} AS TEXT)`;
|
|
209
|
-
},
|
|
210
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
211
|
-
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
212
|
-
if (updateColumns.length === 0) {
|
|
213
|
-
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
214
|
-
}
|
|
215
|
-
const assignments = updateColumns.map((column) => {
|
|
216
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
217
|
-
return `${quoted} = excluded.${quoted}`;
|
|
218
|
-
}).join(", ");
|
|
219
|
-
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
dialects = {
|
|
223
|
-
pgsql: postgresDialect,
|
|
224
|
-
mysql: mysqlDialect,
|
|
225
|
-
sqlite: sqliteDialect
|
|
226
|
-
};
|
|
227
|
-
dialectContext = createAsyncContextStore("@getstrata/sqlDialect");
|
|
228
|
-
});
|
|
229
|
-
|
|
230
2
|
// ../../src/core/database/migrations/rollbackGuard.ts
|
|
231
3
|
async function guardMigrationRollback(context, guard) {
|
|
232
4
|
if (context?.operation === "fresh")
|
|
@@ -490,10 +262,45 @@ class Blueprint {
|
|
|
490
262
|
});
|
|
491
263
|
}
|
|
492
264
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
265
|
+
// ../../src/core/database/schema/driver.ts
|
|
266
|
+
function normalizeConnectionName(connection) {
|
|
267
|
+
const normalized = connection.trim().toLowerCase();
|
|
268
|
+
if (normalized === "pgsql" || normalized === "postgres" || normalized === "postgresql") {
|
|
269
|
+
return "pgsql";
|
|
270
|
+
}
|
|
271
|
+
if (normalized === "mysql" || normalized === "mariadb") {
|
|
272
|
+
return "mysql";
|
|
273
|
+
}
|
|
274
|
+
if (normalized === "sqlite") {
|
|
275
|
+
return "sqlite";
|
|
276
|
+
}
|
|
277
|
+
throw new Error(`Unsupported DB_CONNECTION: ${connection}`);
|
|
278
|
+
}
|
|
279
|
+
function resolveDriverFromUrl(url) {
|
|
280
|
+
const normalized = url.trim().toLowerCase();
|
|
281
|
+
if (normalized.startsWith("postgres://") || normalized.startsWith("postgresql://") || normalized.startsWith("postgres:")) {
|
|
282
|
+
return "pgsql";
|
|
283
|
+
}
|
|
284
|
+
if (normalized.startsWith("mysql://") || normalized.startsWith("mysql:")) {
|
|
285
|
+
return "mysql";
|
|
286
|
+
}
|
|
287
|
+
if (normalized.startsWith("sqlite:")) {
|
|
288
|
+
return "sqlite";
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
function resolveDatabaseDriver(options) {
|
|
293
|
+
const connection = options.connection;
|
|
294
|
+
if (connection) {
|
|
295
|
+
return normalizeConnectionName(connection);
|
|
296
|
+
}
|
|
297
|
+
const url = options.url ?? "";
|
|
298
|
+
const fromUrl = resolveDriverFromUrl(url);
|
|
299
|
+
if (fromUrl) {
|
|
300
|
+
return fromUrl;
|
|
301
|
+
}
|
|
302
|
+
throw new Error("An explicit database connection or supported database URL is required.");
|
|
303
|
+
}
|
|
497
304
|
// ../../src/core/database/schema/errors.ts
|
|
498
305
|
class UnsupportedSchemaFeatureError extends Error {
|
|
499
306
|
constructor(feature, driver) {
|
|
@@ -501,8 +308,182 @@ class UnsupportedSchemaFeatureError extends Error {
|
|
|
501
308
|
this.name = "UnsupportedSchemaFeatureError";
|
|
502
309
|
}
|
|
503
310
|
}
|
|
504
|
-
// ../../src/core/
|
|
505
|
-
|
|
311
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
312
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
313
|
+
function createAsyncContextStore(key) {
|
|
314
|
+
const symbol = Symbol.for(key);
|
|
315
|
+
const globalRecord = globalThis;
|
|
316
|
+
const existing = globalRecord[symbol];
|
|
317
|
+
if (existing) {
|
|
318
|
+
return existing;
|
|
319
|
+
}
|
|
320
|
+
const store = new AsyncLocalStorage;
|
|
321
|
+
globalRecord[symbol] = store;
|
|
322
|
+
return store;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// ../../src/core/database/sqlDialects.ts
|
|
326
|
+
function assertSafeIdentifier(identifier) {
|
|
327
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(identifier)) {
|
|
328
|
+
throw new Error(`Invalid SQL identifier: ${identifier}`);
|
|
329
|
+
}
|
|
330
|
+
return identifier;
|
|
331
|
+
}
|
|
332
|
+
function quoteIdentifierFor(dialect, column) {
|
|
333
|
+
return dialect.quoteIdentifier(column);
|
|
334
|
+
}
|
|
335
|
+
var postgresDialect = Object.freeze({
|
|
336
|
+
driver: "pgsql",
|
|
337
|
+
placeholder(index) {
|
|
338
|
+
return `$${index}`;
|
|
339
|
+
},
|
|
340
|
+
quoteIdentifier(identifier) {
|
|
341
|
+
return `"${assertSafeIdentifier(identifier)}"`;
|
|
342
|
+
},
|
|
343
|
+
nowExpression() {
|
|
344
|
+
return "NOW()";
|
|
345
|
+
},
|
|
346
|
+
epochMillisecondsExpression() {
|
|
347
|
+
return "CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT)";
|
|
348
|
+
},
|
|
349
|
+
rowLockClause(skipLocked = false) {
|
|
350
|
+
return ` FOR UPDATE${skipLocked ? " SKIP LOCKED" : ""}`;
|
|
351
|
+
},
|
|
352
|
+
timestampValue(value) {
|
|
353
|
+
return value.toISOString();
|
|
354
|
+
},
|
|
355
|
+
returningClause(columns) {
|
|
356
|
+
return ` RETURNING ${columns}`;
|
|
357
|
+
},
|
|
358
|
+
ilikeOperator() {
|
|
359
|
+
return "ILIKE";
|
|
360
|
+
},
|
|
361
|
+
nullsLastSuffix() {
|
|
362
|
+
return " NULLS LAST";
|
|
363
|
+
},
|
|
364
|
+
castToText(expression) {
|
|
365
|
+
return `${expression}::text`;
|
|
366
|
+
},
|
|
367
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
368
|
+
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
369
|
+
if (updateColumns.length === 0) {
|
|
370
|
+
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
371
|
+
}
|
|
372
|
+
const assignments = updateColumns.map((column) => {
|
|
373
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
374
|
+
return `${quoted} = excluded.${quoted}`;
|
|
375
|
+
}).join(", ");
|
|
376
|
+
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
var mysqlDialect = Object.freeze({
|
|
380
|
+
driver: "mysql",
|
|
381
|
+
placeholder() {
|
|
382
|
+
return "?";
|
|
383
|
+
},
|
|
384
|
+
quoteIdentifier(identifier) {
|
|
385
|
+
return `\`${assertSafeIdentifier(identifier)}\``;
|
|
386
|
+
},
|
|
387
|
+
nowExpression() {
|
|
388
|
+
return "CURRENT_TIMESTAMP";
|
|
389
|
+
},
|
|
390
|
+
epochMillisecondsExpression() {
|
|
391
|
+
return "CAST(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000 AS UNSIGNED)";
|
|
392
|
+
},
|
|
393
|
+
rowLockClause(skipLocked = false) {
|
|
394
|
+
return ` FOR UPDATE${skipLocked ? " SKIP LOCKED" : ""}`;
|
|
395
|
+
},
|
|
396
|
+
timestampValue(value) {
|
|
397
|
+
return value.toISOString().slice(0, 19).replace("T", " ");
|
|
398
|
+
},
|
|
399
|
+
returningClause() {
|
|
400
|
+
return "";
|
|
401
|
+
},
|
|
402
|
+
ilikeOperator() {
|
|
403
|
+
return "LIKE";
|
|
404
|
+
},
|
|
405
|
+
nullsLastSuffix() {
|
|
406
|
+
return "";
|
|
407
|
+
},
|
|
408
|
+
castToText(expression) {
|
|
409
|
+
return `CAST(${expression} AS CHAR)`;
|
|
410
|
+
},
|
|
411
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
412
|
+
if (updateColumns.length === 0) {
|
|
413
|
+
const anchor = quoteIdentifierFor(this, conflictColumns[0] ?? "");
|
|
414
|
+
return ` ON DUPLICATE KEY UPDATE ${anchor} = ${anchor}`;
|
|
415
|
+
}
|
|
416
|
+
const assignments = updateColumns.map((column) => {
|
|
417
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
418
|
+
return `${quoted} = VALUES(${quoted})`;
|
|
419
|
+
}).join(", ");
|
|
420
|
+
return ` ON DUPLICATE KEY UPDATE ${assignments}`;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
var sqliteDialect = Object.freeze({
|
|
424
|
+
driver: "sqlite",
|
|
425
|
+
placeholder() {
|
|
426
|
+
return "?";
|
|
427
|
+
},
|
|
428
|
+
quoteIdentifier(identifier) {
|
|
429
|
+
return `"${assertSafeIdentifier(identifier)}"`;
|
|
430
|
+
},
|
|
431
|
+
nowExpression() {
|
|
432
|
+
return "strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
433
|
+
},
|
|
434
|
+
epochMillisecondsExpression() {
|
|
435
|
+
return "CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER)";
|
|
436
|
+
},
|
|
437
|
+
rowLockClause() {
|
|
438
|
+
return "";
|
|
439
|
+
},
|
|
440
|
+
timestampValue(value) {
|
|
441
|
+
return value.toISOString();
|
|
442
|
+
},
|
|
443
|
+
returningClause(columns) {
|
|
444
|
+
return ` RETURNING ${columns}`;
|
|
445
|
+
},
|
|
446
|
+
ilikeOperator() {
|
|
447
|
+
return "LIKE";
|
|
448
|
+
},
|
|
449
|
+
nullsLastSuffix() {
|
|
450
|
+
return "";
|
|
451
|
+
},
|
|
452
|
+
castToText(expression) {
|
|
453
|
+
return `CAST(${expression} AS TEXT)`;
|
|
454
|
+
},
|
|
455
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
456
|
+
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
457
|
+
if (updateColumns.length === 0) {
|
|
458
|
+
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
459
|
+
}
|
|
460
|
+
const assignments = updateColumns.map((column) => {
|
|
461
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
462
|
+
return `${quoted} = excluded.${quoted}`;
|
|
463
|
+
}).join(", ");
|
|
464
|
+
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
var dialects = Object.freeze({
|
|
468
|
+
pgsql: postgresDialect,
|
|
469
|
+
mysql: mysqlDialect,
|
|
470
|
+
sqlite: sqliteDialect
|
|
471
|
+
});
|
|
472
|
+
function dialectFor(driver) {
|
|
473
|
+
if (!Object.hasOwn(dialects, driver))
|
|
474
|
+
throw new TypeError("Unsupported SQL driver.");
|
|
475
|
+
return dialects[driver];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// ../../src/core/database/dialect.ts
|
|
479
|
+
var dialectContext = createAsyncContextStore("@getstrata/sqlDialect");
|
|
480
|
+
function currentSqlDialect() {
|
|
481
|
+
const dialect = dialectContext.getStore();
|
|
482
|
+
if (!dialect) {
|
|
483
|
+
throw new Error("SQL dialect context is required. Use runWithSqlDialect(driver, callback).");
|
|
484
|
+
}
|
|
485
|
+
return dialect;
|
|
486
|
+
}
|
|
506
487
|
|
|
507
488
|
// ../../src/core/database/schema/grammars/grammar.ts
|
|
508
489
|
function compileColumnType(driver, column) {
|
|
@@ -847,7 +828,6 @@ function grammarForDriver(driver) {
|
|
|
847
828
|
}
|
|
848
829
|
}
|
|
849
830
|
// ../../src/core/database/schema/schema.ts
|
|
850
|
-
init_driver();
|
|
851
831
|
class SchemaBuilder {
|
|
852
832
|
#driver;
|
|
853
833
|
#statements = [];
|
|
@@ -883,7 +863,7 @@ class SchemaBuilder {
|
|
|
883
863
|
|
|
884
864
|
class Schema {
|
|
885
865
|
static builder(driver) {
|
|
886
|
-
return new SchemaBuilder(driver ??
|
|
866
|
+
return new SchemaBuilder(driver ?? currentSqlDialect().driver);
|
|
887
867
|
}
|
|
888
868
|
static async run(db, driver, callback) {
|
|
889
869
|
const schema = Schema.builder(driver);
|