@getstrata/core 2.2.59 → 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 +27 -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 -254
- package/dist/entries/queue/failedJobRepository.js +19 -8
- package/dist/entries/queue/failedJobService.js +1 -0
- package/dist/entries/queue/jobRunner.js +141 -66
- package/dist/entries/queue/publicQueue.js +411 -255
- package/dist/entries/queue/queueConfig.js +61 -0
- package/dist/entries/queue/queueHandoff.js +318 -0
- package/dist/entries/queue/queueMetrics.js +989 -1384
- 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 +10433 -11347
- 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,125 +1,17 @@
|
|
|
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/runtime/asyncContextStore.ts
|
|
15
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
16
|
-
function createAsyncContextStore(key) {
|
|
17
|
-
const symbol = Symbol.for(key);
|
|
18
|
-
const globalRecord = globalThis;
|
|
19
|
-
const existing = globalRecord[symbol];
|
|
20
|
-
if (existing) {
|
|
21
|
-
return existing;
|
|
22
|
-
}
|
|
23
|
-
const store = new AsyncLocalStorage;
|
|
24
|
-
globalRecord[symbol] = store;
|
|
25
|
-
return store;
|
|
26
|
-
}
|
|
27
|
-
var init_asyncContextStore = () => {};
|
|
28
|
-
|
|
29
|
-
// ../../src/core/database/connectionContext.ts
|
|
30
|
-
function runWithDatabaseConnection(connection, callback) {
|
|
31
|
-
return activeConnection.run(connection, callback);
|
|
32
|
-
}
|
|
33
|
-
function getActiveDatabaseConnection(fallback) {
|
|
34
|
-
return activeConnection.getStore() ?? fallback;
|
|
35
|
-
}
|
|
36
|
-
function hasActiveDatabaseConnection() {
|
|
37
|
-
return activeConnection.getStore() !== undefined;
|
|
38
|
-
}
|
|
39
|
-
var activeConnection;
|
|
40
|
-
var init_connectionContext = __esm(() => {
|
|
41
|
-
init_asyncContextStore();
|
|
42
|
-
activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// ../../src/core/database/transactionControl.ts
|
|
46
|
-
function unwrapTransactionRollback(error, depth = 0) {
|
|
47
|
-
if (error instanceof TransactionRollback) {
|
|
48
|
-
return error;
|
|
49
|
-
}
|
|
50
|
-
if (depth >= 5 || !(error instanceof Error) || error.cause === undefined) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return unwrapTransactionRollback(error.cause, depth + 1);
|
|
54
|
-
}
|
|
55
|
-
function hasActiveTransaction() {
|
|
56
|
-
return hasActiveDatabaseConnection() && (transactionScopes.getStore()?.rollback.length ?? 0) > 0;
|
|
57
|
-
}
|
|
58
|
-
function requestTransactionRollback() {
|
|
59
|
-
const state = transactionScopes.getStore();
|
|
60
|
-
const index = state ? state.rollback.length - 1 : -1;
|
|
61
|
-
if (!state || index < 0) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
state.rollback[index] = true;
|
|
65
|
-
}
|
|
66
|
-
function scopeRequestsRollback() {
|
|
67
|
-
const state = transactionScopes.getStore();
|
|
68
|
-
if (!state || state.rollback.length === 0) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
return state.rollback[state.rollback.length - 1] === true;
|
|
72
|
-
}
|
|
73
|
-
async function commitOrRollbackScope(result) {
|
|
74
|
-
if (scopeRequestsRollback()) {
|
|
75
|
-
throw new TransactionRollback(result);
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
async function settleTransaction(work) {
|
|
80
|
-
try {
|
|
81
|
-
return await work();
|
|
82
|
-
} catch (error) {
|
|
83
|
-
const rollback = unwrapTransactionRollback(error);
|
|
84
|
-
if (rollback) {
|
|
85
|
-
return rollback.result;
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async function runWithTransactionScope(callback) {
|
|
91
|
-
const existing = transactionScopes.getStore();
|
|
92
|
-
if (existing) {
|
|
93
|
-
existing.rollback.push(false);
|
|
94
|
-
try {
|
|
95
|
-
return await callback();
|
|
96
|
-
} finally {
|
|
97
|
-
existing.rollback.pop();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const state = { rollback: [false] };
|
|
101
|
-
return await transactionScopes.run(state, callback);
|
|
102
|
-
}
|
|
103
|
-
var TransactionRollback, transactionScopes;
|
|
104
|
-
var init_transactionControl = __esm(() => {
|
|
105
|
-
init_asyncContextStore();
|
|
106
|
-
init_connectionContext();
|
|
107
|
-
TransactionRollback = class TransactionRollback extends Error {
|
|
108
|
-
result;
|
|
109
|
-
constructor(result) {
|
|
110
|
-
super("Transaction rolled back");
|
|
111
|
-
this.name = "TransactionRollback";
|
|
112
|
-
this.result = result;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
transactionScopes = createAsyncContextStore("@getstrata/transactionScopes");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
2
|
// ../../src/core/http/response.ts
|
|
119
3
|
import { toHttpError as toHttpError2 } from "@getstrata/core/errors/http";
|
|
120
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
logServerError,
|
|
6
|
+
webErrorResponse
|
|
7
|
+
} from "@getstrata/core/http/webErrorResponse";
|
|
121
8
|
|
|
122
|
-
// ../../src/core/
|
|
9
|
+
// ../../src/core/http/databaseError.ts
|
|
10
|
+
import {
|
|
11
|
+
isPostgresError,
|
|
12
|
+
mapDatabaseError,
|
|
13
|
+
PersistenceError
|
|
14
|
+
} from "@getstrata/core/database/errors";
|
|
123
15
|
import {
|
|
124
16
|
BadRequestError,
|
|
125
17
|
ConflictError,
|
|
@@ -127,122 +19,60 @@ import {
|
|
|
127
19
|
toHttpError,
|
|
128
20
|
UnprocessableEntityError
|
|
129
21
|
} from "@getstrata/core/errors/http";
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
return error.errno;
|
|
136
|
-
}
|
|
137
|
-
if (typeof error.errno === "number") {
|
|
138
|
-
return String(error.errno).padStart(5, "0");
|
|
139
|
-
}
|
|
140
|
-
if (typeof error.code === "string" && /^\d{5}$/.test(error.code)) {
|
|
141
|
-
return error.code;
|
|
142
|
-
}
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
var MYSQL_ERRNO_MESSAGES = {
|
|
146
|
-
1062: () => new ConflictError("A record with these values already exists."),
|
|
147
|
-
1451: () => new UnprocessableEntityError("Record is still referenced by other records."),
|
|
148
|
-
1452: () => new UnprocessableEntityError("Referenced record does not exist."),
|
|
149
|
-
1048: () => new BadRequestError("Required field is missing."),
|
|
150
|
-
3819: () => new BadRequestError("Value violates a database constraint.")
|
|
151
|
-
};
|
|
152
|
-
function mapSqliteError(error) {
|
|
153
|
-
const code = typeof error.code === "string" ? error.code : "";
|
|
154
|
-
if (!code.startsWith("SQLITE_")) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
if (code === "SQLITE_CONSTRAINT_UNIQUE" || code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
158
|
-
return new ConflictError("A record with these values already exists.");
|
|
159
|
-
}
|
|
160
|
-
if (code === "SQLITE_CONSTRAINT_FOREIGNKEY") {
|
|
161
|
-
return new UnprocessableEntityError("Operation conflicts with related records.");
|
|
162
|
-
}
|
|
163
|
-
if (code === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
164
|
-
return new BadRequestError("Required field is missing.");
|
|
165
|
-
}
|
|
166
|
-
if (code.startsWith("SQLITE_CONSTRAINT")) {
|
|
167
|
-
return new BadRequestError("Value violates a database constraint.");
|
|
168
|
-
}
|
|
169
|
-
return new InternalServerError("Database operation failed.");
|
|
170
|
-
}
|
|
171
|
-
function mapMysqlError(error) {
|
|
172
|
-
const code = typeof error.code === "string" ? error.code : "";
|
|
173
|
-
if (!code.startsWith("ER_")) {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
const factory = typeof error.errno === "number" ? MYSQL_ERRNO_MESSAGES[error.errno] : undefined;
|
|
177
|
-
return factory ? factory() : new InternalServerError("Database operation failed.");
|
|
178
|
-
}
|
|
179
|
-
function mapDatabaseError(error) {
|
|
180
|
-
const httpError = toHttpError(error);
|
|
181
|
-
if (httpError) {
|
|
182
|
-
return httpError;
|
|
183
|
-
}
|
|
184
|
-
if (!isPostgresError(error)) {
|
|
22
|
+
function mapDatabaseHttpError(error) {
|
|
23
|
+
const existing = toHttpError(error);
|
|
24
|
+
if (existing)
|
|
25
|
+
return existing;
|
|
26
|
+
if (!(error instanceof PersistenceError) && !isPostgresError(error))
|
|
185
27
|
return new InternalServerError;
|
|
28
|
+
const outer = mapDatabaseError(error);
|
|
29
|
+
let failure = outer;
|
|
30
|
+
if ((outer.code === "DATABASE_TRANSACTION_UNKNOWN" || outer.code === "DATABASE_TRANSACTION_FAILED") && outer.data !== "committed") {
|
|
31
|
+
const cause = Object.getOwnPropertyDescriptor(outer, "cause")?.value;
|
|
32
|
+
if (!(cause instanceof AggregateError) && (cause instanceof PersistenceError || isPostgresError(cause))) {
|
|
33
|
+
const direct = mapDatabaseError(cause);
|
|
34
|
+
if ([
|
|
35
|
+
"DATABASE_UNIQUE_CONSTRAINT",
|
|
36
|
+
"DATABASE_FOREIGN_KEY_CONSTRAINT",
|
|
37
|
+
"DATABASE_REFERENCED_RECORD",
|
|
38
|
+
"DATABASE_RELATED_RECORD_CONSTRAINT",
|
|
39
|
+
"DATABASE_NOT_NULL_CONSTRAINT",
|
|
40
|
+
"DATABASE_CHECK_CONSTRAINT"
|
|
41
|
+
].includes(direct.code))
|
|
42
|
+
failure = direct;
|
|
43
|
+
}
|
|
186
44
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (error.detail) {
|
|
199
|
-
console.error("[database] unique violation", error.detail);
|
|
200
|
-
}
|
|
201
|
-
return new ConflictError("A record with these values already exists.");
|
|
202
|
-
case "23503":
|
|
203
|
-
if (error.detail) {
|
|
204
|
-
console.error("[database] foreign-key violation", error.detail);
|
|
205
|
-
}
|
|
206
|
-
return new UnprocessableEntityError("Operation conflicts with related records.");
|
|
207
|
-
case "23502":
|
|
208
|
-
if (error.detail) {
|
|
209
|
-
console.error("[database] not-null violation", error.detail);
|
|
210
|
-
}
|
|
211
|
-
return new BadRequestError("Required field is missing.");
|
|
212
|
-
case "23514":
|
|
213
|
-
if (error.detail) {
|
|
214
|
-
console.error("[database] check violation", error.detail);
|
|
215
|
-
}
|
|
216
|
-
return new BadRequestError("Value violates a database constraint.");
|
|
45
|
+
switch (failure.code) {
|
|
46
|
+
case "DATABASE_UNIQUE_CONSTRAINT":
|
|
47
|
+
case "DATABASE_TRANSACTION_ROLLBACK_ONLY":
|
|
48
|
+
return new ConflictError(failure.message);
|
|
49
|
+
case "DATABASE_FOREIGN_KEY_CONSTRAINT":
|
|
50
|
+
case "DATABASE_REFERENCED_RECORD":
|
|
51
|
+
case "DATABASE_RELATED_RECORD_CONSTRAINT":
|
|
52
|
+
return new UnprocessableEntityError(failure.message);
|
|
53
|
+
case "DATABASE_NOT_NULL_CONSTRAINT":
|
|
54
|
+
case "DATABASE_CHECK_CONSTRAINT":
|
|
55
|
+
return new BadRequestError(failure.message);
|
|
217
56
|
default:
|
|
218
|
-
return new InternalServerError(
|
|
57
|
+
return new InternalServerError(failure.message);
|
|
219
58
|
}
|
|
220
59
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
if (error.code === "SQLITE_CONSTRAINT_UNIQUE" || error.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
233
|
-
return true;
|
|
234
|
-
}
|
|
235
|
-
if (error.errno === 1062) {
|
|
236
|
-
return true;
|
|
60
|
+
|
|
61
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
62
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
63
|
+
function createAsyncContextStore(key) {
|
|
64
|
+
const symbol = Symbol.for(key);
|
|
65
|
+
const globalRecord = globalThis;
|
|
66
|
+
const existing = globalRecord[symbol];
|
|
67
|
+
if (existing) {
|
|
68
|
+
return existing;
|
|
237
69
|
}
|
|
238
|
-
|
|
70
|
+
const store = new AsyncLocalStorage;
|
|
71
|
+
globalRecord[symbol] = store;
|
|
72
|
+
return store;
|
|
239
73
|
}
|
|
240
74
|
|
|
241
|
-
// ../../src/core/http/response.ts
|
|
242
|
-
init_transactionControl();
|
|
243
|
-
|
|
244
75
|
// ../../src/core/http/requestMetaContext.ts
|
|
245
|
-
init_asyncContextStore();
|
|
246
76
|
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
247
77
|
function runWithRequestMeta(meta, callback) {
|
|
248
78
|
return requestMetaContext.run(meta, callback);
|
|
@@ -273,21 +103,21 @@ function noContentResponse() {
|
|
|
273
103
|
return new Response(null, { status: 204 });
|
|
274
104
|
}
|
|
275
105
|
function errorResponse(error) {
|
|
276
|
-
const mappedError = toHttpError2(error) ??
|
|
106
|
+
const mappedError = toHttpError2(error) ?? mapDatabaseHttpError(error);
|
|
277
107
|
logServerError(error, mappedError);
|
|
278
108
|
return Response.json({
|
|
279
109
|
error: mappedError.message,
|
|
280
110
|
...mappedError.details === undefined ? {} : { details: mappedError.details }
|
|
281
111
|
}, { status: mappedError.status, headers: { "Cache-Control": "no-store" } });
|
|
282
112
|
}
|
|
283
|
-
function withErrorHandling(handler) {
|
|
113
|
+
function withErrorHandling(handler, options = {}) {
|
|
114
|
+
const captured = { ...options };
|
|
284
115
|
return async (...args) => {
|
|
285
116
|
try {
|
|
286
117
|
return await handler(...args);
|
|
287
118
|
} catch (error) {
|
|
288
|
-
requestTransactionRollback();
|
|
289
119
|
const request = args.find((arg) => arg instanceof Request);
|
|
290
|
-
const webResponse = await webErrorResponse(error, request);
|
|
120
|
+
const webResponse = await webErrorResponse(error, request, captured);
|
|
291
121
|
if (webResponse) {
|
|
292
122
|
return webResponse;
|
|
293
123
|
}
|
|
@@ -300,7 +130,6 @@ function withJsonErrorHandling(handler) {
|
|
|
300
130
|
try {
|
|
301
131
|
return await handler(...args);
|
|
302
132
|
} catch (error) {
|
|
303
|
-
requestTransactionRollback();
|
|
304
133
|
return errorResponse(error);
|
|
305
134
|
}
|
|
306
135
|
};
|
|
@@ -310,13 +139,18 @@ function createJsonErrorMiddleware() {
|
|
|
310
139
|
try {
|
|
311
140
|
return await next();
|
|
312
141
|
} catch (error) {
|
|
313
|
-
requestTransactionRollback();
|
|
314
142
|
return errorResponse(error);
|
|
315
143
|
}
|
|
316
144
|
});
|
|
317
145
|
}
|
|
318
|
-
function createWebErrorMiddleware() {
|
|
319
|
-
|
|
146
|
+
function createWebErrorMiddleware(options = {}) {
|
|
147
|
+
const captured = { ...options };
|
|
148
|
+
return async (request, next) => await runWithRequestMeta({
|
|
149
|
+
...currentRequestMeta(),
|
|
150
|
+
webErrorView: captured.render,
|
|
151
|
+
viewsEnabled: captured.enabled ?? false,
|
|
152
|
+
webErrorsProduction: captured.production ?? true
|
|
153
|
+
}, () => withErrorHandling(async (_request) => next(), captured)(request));
|
|
320
154
|
}
|
|
321
155
|
export {
|
|
322
156
|
createJsonErrorMiddleware,
|
|
@@ -1,16 +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
2
|
// ../../src/core/runtime/asyncContextStore.ts
|
|
15
3
|
import { AsyncLocalStorage } from "async_hooks";
|
|
16
4
|
function createAsyncContextStore(key) {
|
|
@@ -24,10 +12,8 @@ function createAsyncContextStore(key) {
|
|
|
24
12
|
globalRecord[symbol] = store;
|
|
25
13
|
return store;
|
|
26
14
|
}
|
|
27
|
-
var init_asyncContextStore = () => {};
|
|
28
15
|
|
|
29
16
|
// ../../src/core/http/requestMetaContext.ts
|
|
30
|
-
init_asyncContextStore();
|
|
31
17
|
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
32
18
|
function runWithRequestMeta(meta, callback) {
|
|
33
19
|
return requestMetaContext.run(meta, callback);
|