@contember/engine-http 2.2.0-alpha.1 → 2.2.0-alpha.10
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/CLAUDE.md +3 -1
- package/dist/development/index.cjs +28 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +27 -2
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/MasterContainer.cjs +44 -19
- package/dist/development/src/MasterContainer.cjs.map +1 -1
- package/dist/development/src/MasterContainer.js +44 -19
- package/dist/development/src/MasterContainer.js.map +1 -1
- package/dist/development/src/application/PanelApiMount.cjs +8 -0
- package/dist/development/src/application/PanelApiMount.cjs.map +1 -0
- package/dist/development/src/application/PanelApiMount.js +8 -0
- package/dist/development/src/application/PanelApiMount.js.map +1 -0
- package/dist/development/src/application/application.cjs +296 -69
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +298 -71
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/development/src/application/forceHttpOk.cjs +2 -9
- package/dist/development/src/application/forceHttpOk.cjs.map +1 -1
- package/dist/development/src/application/forceHttpOk.js +2 -9
- package/dist/development/src/application/forceHttpOk.js.map +1 -1
- package/dist/development/src/common/Authorizator.cjs +22 -19
- package/dist/development/src/common/Authorizator.cjs.map +1 -1
- package/dist/development/src/common/Authorizator.js +22 -19
- package/dist/development/src/common/Authorizator.js.map +1 -1
- package/dist/development/src/common/HttpResponse.cjs +5 -3
- package/dist/development/src/common/HttpResponse.cjs.map +1 -1
- package/dist/development/src/common/HttpResponse.js +5 -3
- package/dist/development/src/common/HttpResponse.js.map +1 -1
- package/dist/development/src/config/config.cjs +2 -1
- package/dist/development/src/config/config.cjs.map +1 -1
- package/dist/development/src/config/config.js +2 -1
- package/dist/development/src/config/config.js.map +1 -1
- package/dist/development/src/config/configSchema.cjs +71 -0
- package/dist/development/src/config/configSchema.cjs.map +1 -1
- package/dist/development/src/config/configSchema.js +71 -0
- package/dist/development/src/config/configSchema.js.map +1 -1
- package/dist/development/src/config/configTemplate.cjs +35 -1
- package/dist/development/src/config/configTemplate.cjs.map +1 -1
- package/dist/development/src/config/configTemplate.js +35 -1
- package/dist/development/src/config/configTemplate.js.map +1 -1
- package/dist/development/src/config/projectConfigResolver.cjs +1 -0
- package/dist/development/src/config/projectConfigResolver.cjs.map +1 -1
- package/dist/development/src/config/projectConfigResolver.js +2 -1
- package/dist/development/src/config/projectConfigResolver.js.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs +30 -4
- package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.js +30 -4
- package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/development/src/content/ContentApiSpecificCache.cjs +44 -16
- package/dist/development/src/content/ContentApiSpecificCache.cjs.map +1 -1
- package/dist/development/src/content/ContentApiSpecificCache.js +44 -16
- package/dist/development/src/content/ContentApiSpecificCache.js.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs +2 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.js +2 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.cjs +26 -3
- package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.js +26 -3
- package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/development/src/graphql/execution.cjs +19 -4
- package/dist/development/src/graphql/execution.cjs.map +1 -1
- package/dist/development/src/graphql/execution.js +19 -4
- package/dist/development/src/graphql/execution.js.map +1 -1
- package/dist/development/src/misc/HomepageMiddlewareFactory.cjs +1 -0
- package/dist/development/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/misc/HomepageMiddlewareFactory.js +1 -0
- package/dist/development/src/misc/HomepageMiddlewareFactory.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +1 -0
- package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainer.js +1 -0
- package/dist/development/src/project/ProjectContainer.js.map +1 -1
- package/dist/development/src/project-common/ProjectContextResolver.cjs +1 -0
- package/dist/development/src/project-common/ProjectContextResolver.cjs.map +1 -1
- package/dist/development/src/project-common/ProjectContextResolver.js +1 -0
- package/dist/development/src/project-common/ProjectContextResolver.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +27 -22
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +27 -22
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupResolver.cjs +1 -0
- package/dist/development/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupResolver.js +1 -0
- package/dist/development/src/projectGroup/ProjectGroupResolver.js.map +1 -1
- package/dist/development/src/prometheus/dbMetrics.cjs +4 -1
- package/dist/development/src/prometheus/dbMetrics.cjs.map +1 -1
- package/dist/development/src/prometheus/dbMetrics.js +5 -2
- package/dist/development/src/prometheus/dbMetrics.js.map +1 -1
- package/dist/development/src/system/SystemApiMiddlewareFactory.cjs +1 -0
- package/dist/development/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/system/SystemApiMiddlewareFactory.js +1 -0
- package/dist/development/src/system/SystemApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/telemetry/FilteringSpanProcessor.cjs +15 -0
- package/dist/development/src/telemetry/FilteringSpanProcessor.cjs.map +1 -0
- package/dist/development/src/telemetry/FilteringSpanProcessor.js +15 -0
- package/dist/development/src/telemetry/FilteringSpanProcessor.js.map +1 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.cjs +59 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.cjs.map +1 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.js +59 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.js.map +1 -0
- package/dist/development/src/telemetry/TelemetryFactory.cjs +87 -0
- package/dist/development/src/telemetry/TelemetryFactory.cjs.map +1 -0
- package/dist/development/src/telemetry/TelemetryFactory.js +87 -0
- package/dist/development/src/telemetry/TelemetryFactory.js.map +1 -0
- package/dist/development/src/telemetry/incomingTrace.cjs +32 -0
- package/dist/development/src/telemetry/incomingTrace.cjs.map +1 -0
- package/dist/development/src/telemetry/incomingTrace.js +32 -0
- package/dist/development/src/telemetry/incomingTrace.js.map +1 -0
- package/dist/development/src/telemetry/sqlSpans.cjs +59 -0
- package/dist/development/src/telemetry/sqlSpans.cjs.map +1 -0
- package/dist/development/src/telemetry/sqlSpans.js +59 -0
- package/dist/development/src/telemetry/sqlSpans.js.map +1 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +1 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +1 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -1
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs +13 -14
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.js +13 -14
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/testing/TestTransactions.cjs +21 -11
- package/dist/development/src/testing/TestTransactions.cjs.map +1 -1
- package/dist/development/src/testing/TestTransactions.js +21 -11
- package/dist/development/src/testing/TestTransactions.js.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs +1 -0
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.js +1 -0
- package/dist/development/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs +1 -0
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js +1 -0
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.cjs +1 -0
- package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.js +1 -0
- package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/development/src/utils/remoteAddress.cjs +9 -1
- package/dist/development/src/utils/remoteAddress.cjs.map +1 -1
- package/dist/development/src/utils/remoteAddress.js +10 -2
- package/dist/development/src/utils/remoteAddress.js.map +1 -1
- package/dist/development/src/utils/sentry.cjs +4 -1
- package/dist/development/src/utils/sentry.cjs.map +1 -1
- package/dist/development/src/utils/sentry.js +4 -1
- package/dist/development/src/utils/sentry.js.map +1 -1
- package/dist/development/src/utils/serverTermination.cjs +21 -3
- package/dist/development/src/utils/serverTermination.cjs.map +1 -1
- package/dist/development/src/utils/serverTermination.js +21 -3
- package/dist/development/src/utils/serverTermination.js.map +1 -1
- package/dist/development/src/utils/truthyHeader.cjs +13 -0
- package/dist/development/src/utils/truthyHeader.cjs.map +1 -0
- package/dist/development/src/utils/truthyHeader.js +13 -0
- package/dist/development/src/utils/truthyHeader.js.map +1 -0
- package/dist/production/index.cjs +28 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +27 -2
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/MasterContainer.cjs +44 -19
- package/dist/production/src/MasterContainer.cjs.map +1 -1
- package/dist/production/src/MasterContainer.js +44 -19
- package/dist/production/src/MasterContainer.js.map +1 -1
- package/dist/production/src/application/PanelApiMount.cjs +8 -0
- package/dist/production/src/application/PanelApiMount.cjs.map +1 -0
- package/dist/production/src/application/PanelApiMount.js +8 -0
- package/dist/production/src/application/PanelApiMount.js.map +1 -0
- package/dist/production/src/application/application.cjs +296 -69
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +298 -71
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/production/src/application/forceHttpOk.cjs +2 -9
- package/dist/production/src/application/forceHttpOk.cjs.map +1 -1
- package/dist/production/src/application/forceHttpOk.js +2 -9
- package/dist/production/src/application/forceHttpOk.js.map +1 -1
- package/dist/production/src/common/Authorizator.cjs +22 -19
- package/dist/production/src/common/Authorizator.cjs.map +1 -1
- package/dist/production/src/common/Authorizator.js +22 -19
- package/dist/production/src/common/Authorizator.js.map +1 -1
- package/dist/production/src/common/HttpResponse.cjs +5 -3
- package/dist/production/src/common/HttpResponse.cjs.map +1 -1
- package/dist/production/src/common/HttpResponse.js +5 -3
- package/dist/production/src/common/HttpResponse.js.map +1 -1
- package/dist/production/src/config/config.cjs +2 -1
- package/dist/production/src/config/config.cjs.map +1 -1
- package/dist/production/src/config/config.js +2 -1
- package/dist/production/src/config/config.js.map +1 -1
- package/dist/production/src/config/configSchema.cjs +71 -0
- package/dist/production/src/config/configSchema.cjs.map +1 -1
- package/dist/production/src/config/configSchema.js +71 -0
- package/dist/production/src/config/configSchema.js.map +1 -1
- package/dist/production/src/config/configTemplate.cjs +35 -1
- package/dist/production/src/config/configTemplate.cjs.map +1 -1
- package/dist/production/src/config/configTemplate.js +35 -1
- package/dist/production/src/config/configTemplate.js.map +1 -1
- package/dist/production/src/config/projectConfigResolver.cjs +1 -0
- package/dist/production/src/config/projectConfigResolver.cjs.map +1 -1
- package/dist/production/src/config/projectConfigResolver.js +2 -1
- package/dist/production/src/config/projectConfigResolver.js.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs +30 -4
- package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.js +30 -4
- package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/production/src/content/ContentApiSpecificCache.cjs +44 -16
- package/dist/production/src/content/ContentApiSpecificCache.cjs.map +1 -1
- package/dist/production/src/content/ContentApiSpecificCache.js +44 -16
- package/dist/production/src/content/ContentApiSpecificCache.js.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs +2 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.js +2 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.cjs +26 -3
- package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.js +26 -3
- package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/production/src/graphql/execution.cjs +19 -4
- package/dist/production/src/graphql/execution.cjs.map +1 -1
- package/dist/production/src/graphql/execution.js +19 -4
- package/dist/production/src/graphql/execution.js.map +1 -1
- package/dist/production/src/misc/HomepageMiddlewareFactory.cjs +1 -0
- package/dist/production/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/misc/HomepageMiddlewareFactory.js +1 -0
- package/dist/production/src/misc/HomepageMiddlewareFactory.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +1 -0
- package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainer.js +1 -0
- package/dist/production/src/project/ProjectContainer.js.map +1 -1
- package/dist/production/src/project-common/ProjectContextResolver.cjs +1 -0
- package/dist/production/src/project-common/ProjectContextResolver.cjs.map +1 -1
- package/dist/production/src/project-common/ProjectContextResolver.js +1 -0
- package/dist/production/src/project-common/ProjectContextResolver.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +27 -22
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +27 -22
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupResolver.cjs +1 -0
- package/dist/production/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupResolver.js +1 -0
- package/dist/production/src/projectGroup/ProjectGroupResolver.js.map +1 -1
- package/dist/production/src/prometheus/dbMetrics.cjs +4 -1
- package/dist/production/src/prometheus/dbMetrics.cjs.map +1 -1
- package/dist/production/src/prometheus/dbMetrics.js +5 -2
- package/dist/production/src/prometheus/dbMetrics.js.map +1 -1
- package/dist/production/src/system/SystemApiMiddlewareFactory.cjs +1 -0
- package/dist/production/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/system/SystemApiMiddlewareFactory.js +1 -0
- package/dist/production/src/system/SystemApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/telemetry/FilteringSpanProcessor.cjs +15 -0
- package/dist/production/src/telemetry/FilteringSpanProcessor.cjs.map +1 -0
- package/dist/production/src/telemetry/FilteringSpanProcessor.js +15 -0
- package/dist/production/src/telemetry/FilteringSpanProcessor.js.map +1 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.cjs +59 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.cjs.map +1 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.js +59 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.js.map +1 -0
- package/dist/production/src/telemetry/TelemetryFactory.cjs +87 -0
- package/dist/production/src/telemetry/TelemetryFactory.cjs.map +1 -0
- package/dist/production/src/telemetry/TelemetryFactory.js +87 -0
- package/dist/production/src/telemetry/TelemetryFactory.js.map +1 -0
- package/dist/production/src/telemetry/incomingTrace.cjs +32 -0
- package/dist/production/src/telemetry/incomingTrace.cjs.map +1 -0
- package/dist/production/src/telemetry/incomingTrace.js +32 -0
- package/dist/production/src/telemetry/incomingTrace.js.map +1 -0
- package/dist/production/src/telemetry/sqlSpans.cjs +59 -0
- package/dist/production/src/telemetry/sqlSpans.cjs.map +1 -0
- package/dist/production/src/telemetry/sqlSpans.js +59 -0
- package/dist/production/src/telemetry/sqlSpans.js.map +1 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +1 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +1 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -1
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs +13 -14
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.js +13 -14
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/testing/TestTransactions.cjs +21 -11
- package/dist/production/src/testing/TestTransactions.cjs.map +1 -1
- package/dist/production/src/testing/TestTransactions.js +21 -11
- package/dist/production/src/testing/TestTransactions.js.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs +1 -0
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.js +1 -0
- package/dist/production/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs +1 -0
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js +1 -0
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.cjs +1 -0
- package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.js +1 -0
- package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/production/src/utils/remoteAddress.cjs +9 -1
- package/dist/production/src/utils/remoteAddress.cjs.map +1 -1
- package/dist/production/src/utils/remoteAddress.js +10 -2
- package/dist/production/src/utils/remoteAddress.js.map +1 -1
- package/dist/production/src/utils/sentry.cjs +4 -1
- package/dist/production/src/utils/sentry.cjs.map +1 -1
- package/dist/production/src/utils/sentry.js +4 -1
- package/dist/production/src/utils/sentry.js.map +1 -1
- package/dist/production/src/utils/serverTermination.cjs +21 -3
- package/dist/production/src/utils/serverTermination.cjs.map +1 -1
- package/dist/production/src/utils/serverTermination.js +21 -3
- package/dist/production/src/utils/serverTermination.js.map +1 -1
- package/dist/production/src/utils/truthyHeader.cjs +13 -0
- package/dist/production/src/utils/truthyHeader.cjs.map +1 -0
- package/dist/production/src/utils/truthyHeader.js +13 -0
- package/dist/production/src/utils/truthyHeader.js.map +1 -0
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/applicationShutdown.test.d.ts +2 -0
- package/dist/tests/cases/unit/applicationShutdown.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/contentApiSpecificCacheLimit.test.d.ts +2 -0
- package/dist/tests/cases/unit/contentApiSpecificCacheLimit.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/forcePrimary.test.d.ts +2 -0
- package/dist/tests/cases/unit/forcePrimary.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/graphQlSchemaFactory.test.d.ts +2 -0
- package/dist/tests/cases/unit/graphQlSchemaFactory.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/incomingTrace.test.d.ts +2 -0
- package/dist/tests/cases/unit/incomingTrace.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestTracing.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestTracing.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/serverTermination.fixture.d.ts +2 -0
- package/dist/tests/cases/unit/serverTermination.fixture.d.ts.map +1 -0
- package/dist/tests/cases/unit/serverTermination.test.d.ts +2 -0
- package/dist/tests/cases/unit/serverTermination.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/spanFiltering.test.d.ts +2 -0
- package/dist/tests/cases/unit/spanFiltering.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/sqlSpans.test.d.ts +2 -0
- package/dist/tests/cases/unit/sqlSpans.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/telemetryConfig.test.d.ts +2 -0
- package/dist/tests/cases/unit/telemetryConfig.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/timerFacade.test.d.ts +2 -0
- package/dist/tests/cases/unit/timerFacade.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MasterContainer.d.ts +66 -6
- package/dist/types/MasterContainer.d.ts.map +1 -1
- package/dist/types/application/PanelApiMount.d.ts +29 -0
- package/dist/types/application/PanelApiMount.d.ts.map +1 -0
- package/dist/types/application/application.d.ts +19 -1
- package/dist/types/application/application.d.ts.map +1 -1
- package/dist/types/application/forceHttpOk.d.ts.map +1 -1
- package/dist/types/application/index.d.ts +1 -0
- package/dist/types/application/index.d.ts.map +1 -1
- package/dist/types/bootstrap/Initializer.d.ts.map +1 -1
- package/dist/types/common/Authorizator.d.ts +9 -1
- package/dist/types/common/Authorizator.d.ts.map +1 -1
- package/dist/types/common/HttpResponse.d.ts +6 -2
- package/dist/types/common/HttpResponse.d.ts.map +1 -1
- package/dist/types/common/ModuleInfoMiddleware.d.ts.map +1 -1
- package/dist/types/common/index.d.ts +2 -0
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/config/config.d.ts +3 -1
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/config/configSchema.d.ts +358 -11
- package/dist/types/config/configSchema.d.ts.map +1 -1
- package/dist/types/config/configTemplate.d.ts.map +1 -1
- package/dist/types/config/projectConfigResolver.d.ts +1 -0
- package/dist/types/config/projectConfigResolver.d.ts.map +1 -1
- package/dist/types/config/tenantConfigResolver.d.ts.map +1 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts +4 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentApiSpecificCache.d.ts +5 -0
- package/dist/types/content/ContentApiSpecificCache.d.ts.map +1 -1
- package/dist/types/content/ContentGraphqlContext.d.ts +2 -0
- package/dist/types/content/ContentGraphqlContext.d.ts.map +1 -1
- package/dist/types/content/ContentQueryHandlerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentSchemaResolver.d.ts.map +1 -1
- package/dist/types/content/GraphQLSchemaContributor.d.ts +4 -0
- package/dist/types/content/GraphQLSchemaContributor.d.ts.map +1 -1
- package/dist/types/content/GraphQlSchemaFactory.d.ts +2 -0
- package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/types/content/NotModifiedChecker.d.ts.map +1 -1
- package/dist/types/content/ProjectMembershipFetcher.d.ts.map +1 -1
- package/dist/types/content/ProjectMembershipResolver.d.ts.map +1 -1
- package/dist/types/graphql/dbQueriesListener.d.ts.map +1 -1
- package/dist/types/graphql/execution.d.ts +4 -1
- package/dist/types/graphql/execution.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/project/ProjectContainer.d.ts.map +1 -1
- package/dist/types/project/ProjectContainerResolver.d.ts.map +1 -1
- package/dist/types/project/ProjectContainerStore.d.ts.map +1 -1
- package/dist/types/project/ProjectDatabaseMetadataResolver.d.ts.map +1 -1
- package/dist/types/project/ProjectInitializer.d.ts.map +1 -1
- package/dist/types/project/ProjectSchemaResolver.d.ts.map +1 -1
- package/dist/types/project-common/ProjectContextResolver.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainerResolver.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupResolver.d.ts.map +1 -1
- package/dist/types/prometheus/CollectHttpMetricsMiddelware.d.ts.map +1 -1
- package/dist/types/prometheus/CustomMetric.d.ts.map +1 -1
- package/dist/types/prometheus/ProjectGroupContainerMetricsHook.d.ts.map +1 -1
- package/dist/types/prometheus/PrometheusRegistryFactory.d.ts.map +1 -1
- package/dist/types/prometheus/ShowMetricsMiddleware.d.ts.map +1 -1
- package/dist/types/prometheus/contemberEngineInfoMetric.d.ts.map +1 -1
- package/dist/types/prometheus/dbMetrics.d.ts.map +1 -1
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/system/ContentQueryExecutor.d.ts.map +1 -1
- package/dist/types/system/SystemApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/system/SystemGraphQLContextFactory.d.ts.map +1 -1
- package/dist/types/system/SystemGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/types/telemetry/FilteringSpanProcessor.d.ts +8 -0
- package/dist/types/telemetry/FilteringSpanProcessor.d.ts.map +1 -0
- package/dist/types/telemetry/ProjectGroupContainerTelemetryHook.d.ts +18 -0
- package/dist/types/telemetry/ProjectGroupContainerTelemetryHook.d.ts.map +1 -0
- package/dist/types/telemetry/TelemetryFactory.d.ts +19 -0
- package/dist/types/telemetry/TelemetryFactory.d.ts.map +1 -0
- package/dist/types/telemetry/incomingTrace.d.ts +18 -0
- package/dist/types/telemetry/incomingTrace.d.ts.map +1 -0
- package/dist/types/telemetry/index.d.ts +6 -0
- package/dist/types/telemetry/index.d.ts.map +1 -0
- package/dist/types/telemetry/sqlSpans.d.ts +16 -0
- package/dist/types/telemetry/sqlSpans.d.ts.map +1 -0
- package/dist/types/tenant/OidcBackchannelLogoutMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/tenant/TenantApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/tenant/TenantGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/types/testing/TestTransactions.d.ts.map +1 -1
- package/dist/types/transfer/Command.d.ts +5 -5
- package/dist/types/transfer/Command.d.ts.map +1 -1
- package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportApiControllerFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/SystemSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/CryptoWrapper.d.ts +1 -1
- package/dist/types/utils/CryptoWrapper.d.ts.map +1 -1
- package/dist/types/utils/memoizeObject.d.ts.map +1 -1
- package/dist/types/utils/remoteAddress.d.ts +1 -0
- package/dist/types/utils/remoteAddress.d.ts.map +1 -1
- package/dist/types/utils/sentry.d.ts.map +1 -1
- package/dist/types/utils/serverStartup.d.ts +1 -0
- package/dist/types/utils/serverStartup.d.ts.map +1 -1
- package/dist/types/utils/serverTermination.d.ts +13 -1
- package/dist/types/utils/serverTermination.d.ts.map +1 -1
- package/dist/types/utils/strings.d.ts.map +1 -1
- package/dist/types/utils/truthyHeader.d.ts +3 -0
- package/dist/types/utils/truthyHeader.d.ts.map +1 -0
- package/dist/types/workers/ApplicationWorkerManager.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/MasterContainer.ts +50 -16
- package/src/application/PanelApiMount.ts +33 -0
- package/src/application/application.ts +315 -76
- package/src/application/forceHttpOk.ts +2 -10
- package/src/application/index.ts +1 -0
- package/src/common/Authorizator.ts +41 -21
- package/src/common/HttpResponse.ts +4 -0
- package/src/common/index.ts +2 -0
- package/src/config/config.ts +4 -1
- package/src/config/configSchema.ts +72 -0
- package/src/config/configTemplate.ts +34 -0
- package/src/config/projectConfigResolver.ts +1 -1
- package/src/content/ContentApiControllerFactory.ts +32 -4
- package/src/content/ContentApiSpecificCache.ts +56 -17
- package/src/content/ContentGraphqlContext.ts +2 -0
- package/src/content/ContentQueryHandlerFactory.ts +1 -0
- package/src/content/GraphQLSchemaContributor.ts +4 -0
- package/src/content/GraphQlSchemaFactory.ts +29 -3
- package/src/graphql/execution.ts +27 -4
- package/src/index.ts +2 -0
- package/src/projectGroup/ProjectGroupContainer.ts +28 -24
- package/src/prometheus/dbMetrics.ts +5 -2
- package/src/telemetry/FilteringSpanProcessor.ts +22 -0
- package/src/telemetry/ProjectGroupContainerTelemetryHook.ts +67 -0
- package/src/telemetry/TelemetryFactory.ts +118 -0
- package/src/telemetry/incomingTrace.ts +47 -0
- package/src/telemetry/index.ts +5 -0
- package/src/telemetry/sqlSpans.ts +76 -0
- package/src/tenant/TenantApiMiddlewareFactory.ts +14 -14
- package/src/testing/TestTransactions.ts +21 -11
- package/src/tsconfig.json +1 -0
- package/src/utils/remoteAddress.ts +9 -2
- package/src/utils/sentry.ts +5 -0
- package/src/utils/serverTermination.ts +41 -3
- package/src/utils/truthyHeader.ts +12 -0
- package/tests/cases/integration/requestMemoryBudget.test.ts +88 -0
- package/tests/cases/unit/applicationShutdown.test.ts +149 -0
- package/tests/cases/unit/contentApiSpecificCache.tst.js +22 -0
- package/tests/cases/unit/contentApiSpecificCacheLimit.test.ts +63 -0
- package/tests/cases/unit/forcePrimary.test.ts +295 -0
- package/tests/cases/unit/graphQlSchemaFactory.test.ts +87 -0
- package/tests/cases/unit/incomingTrace.test.ts +100 -0
- package/tests/cases/unit/remoteAddress.test.ts +13 -1
- package/tests/cases/unit/requestMemoryBudget.test.ts +172 -0
- package/tests/cases/unit/requestTracing.test.ts +224 -0
- package/tests/cases/unit/serverConfig.test.ts +35 -0
- package/tests/cases/unit/serverTermination.fixture.ts +13 -0
- package/tests/cases/unit/serverTermination.test.ts +97 -0
- package/tests/cases/unit/spanFiltering.test.ts +71 -0
- package/tests/cases/unit/sqlSpans.test.ts +198 -0
- package/tests/cases/unit/telemetryConfig.test.ts +186 -0
- package/tests/cases/unit/timerFacade.test.ts +78 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configTemplate.js","sources":["../../../../../packages/engine-http/src/config/configTemplate.ts"],"sourcesContent":["const createDbConfigTemplate = (prefix: string) => {\n\treturn {\n\t\tssl: `%?${prefix}_SSL::bool%`,\n\t\tqueryTimeoutMs: `%?${prefix}_QUERY_TIMEOUT_MS::number%`,\n\t\tstatementTimeoutMs: `%?${prefix}_STATEMENT_TIMEOUT_MS::number%`,\n\t\tlockTimeoutMs: `%?${prefix}_LOCK_TIMEOUT_MS::number%`,\n\t\tconnectionTimeoutMs: `%?${prefix}_CONNECTION_TIMEOUT_MS::number%`,\n\t\tmaxConnectionsPerRequest: `%?${prefix}_MAX_CONNECTIONS_PER_REQUEST::number%`,\n\t\tpool: {\n\t\t\tmaxConnections: `%?${prefix}_POOL_MAX_CONNECTIONS::number%`,\n\t\t\tmaxConnecting: `%?${prefix}_POOL_MAX_CONNECTING::number%`,\n\t\t\tmaxIdle: `%?${prefix}_POOL_MAX_IDLE::number%`,\n\t\t\treconnectIntervalMs: `%?${prefix}_POOL_RECONNECT_INTERVAL_MS::number%`,\n\t\t\tidleTimeoutMs: `%?${prefix}_POOL_IDLE_TIMEOUT_MS::number%`,\n\t\t\tacquireTimeoutMs: `%?${prefix}_POOL_ACQUIRE_TIMEOUT_MS::number%`,\n\t\t\tmaxUses: `%?${prefix}_POOL_MAX_USES::number%`,\n\t\t\tmaxAgeMs: `%?${prefix}_POOL_MAX_AGE_MS::number%`,\n\t\t\trateLimitCount: `%?${prefix}_POOL_RATE_LIMIT_COUNT::number%`,\n\t\t\trateLimitPeriodMs: `%?${prefix}_POOL_RATE_LIMIT_PERIOD_MS::number%`,\n\t\t},\n\t}\n}\nexport const configTemplate: any = {\n\ttenant: {\n\t\tdb: {\n\t\t\thost: `%tenant.env.DB_HOST%`,\n\t\t\tport: `%tenant.env.DB_PORT::number%`,\n\t\t\tuser: `%tenant.env.DB_USER%`,\n\t\t\tpassword: `%tenant.env.DB_PASSWORD%`,\n\t\t\tdatabase: `%tenant.env.DB_NAME%`,\n\t\t\t...createDbConfigTemplate('tenant.env.DB'),\n\t\t\tread: {\n\t\t\t\thost: `%?tenant.env.DB_READ_HOST%`,\n\t\t\t\tport: `%?tenant.env.DB_READ_PORT::number%`,\n\t\t\t\tuser: `%?tenant.env.DB_READ_USER%`,\n\t\t\t\tpassword: `%?tenant.env.DB_READ_PASSWORD%`,\n\t\t\t\tdatabase: `%?tenant.env.DB_READ_NAME%`,\n\t\t\t\t...createDbConfigTemplate('tenant.env.DB_READ'),\n\t\t\t},\n\t\t},\n\t\tmailer: {\n\t\t\tfrom: '%?tenant.env.MAILER_FROM%',\n\t\t\thost: '%?tenant.env.MAILER_HOST::string%',\n\t\t\tport: '%?tenant.env.MAILER_PORT::number%',\n\t\t\tsecure: '%?tenant.env.MAILER_SECURE::bool%',\n\t\t\trequireTLS: '%?tenant.env.MAILER_REQUIRE_TLS::bool%',\n\t\t\tuser: '%?tenant.env.MAILER_USER%',\n\t\t\tpassword: '%?tenant.env.MAILER_PASSWORD%',\n\t\t\twebhook: '%?tenant.env.MAILER_WEBHOOK%',\n\t\t},\n\t\tcredentials: {\n\t\t\trootEmail: '%?env.CONTEMBER_ROOT_EMAIL%',\n\t\t\trootToken: '%?env.CONTEMBER_ROOT_TOKEN%',\n\t\t\trootTokenHash: '%?env.CONTEMBER_ROOT_TOKEN_HASH%',\n\t\t\trootPassword: '%?env.CONTEMBER_ROOT_PASSWORD%',\n\t\t\tloginToken: '%?env.CONTEMBER_LOGIN_TOKEN%',\n\t\t\trootTokens: '%?env.CONTEMBER_ROOT_TOKENS%',\n\t\t\trootTokenHashes: '%?env.CONTEMBER_ROOT_TOKEN_HASHES%',\n\t\t},\n\t\tsecrets: {\n\t\t\tencryptionKey: '%?env.CONTEMBER_ENCRYPTION_KEY%',\n\t\t},\n\t},\n\tprojectDefaults: {\n\t\tstageSlug: '%?project.env.STAGE_SLUG%',\n\t\tdb: {\n\t\t\thost: `%?project.env.DB_HOST%`,\n\t\t\tport: `%?project.env.DB_PORT::number%`,\n\t\t\tuser: `%?project.env.DB_USER%`,\n\t\t\tpassword: `%?project.secret.db.password||project.env.DB_PASSWORD%`,\n\t\t\tdatabase: `%?project.env.DB_NAME||project.slug%`,\n\t\t\t...createDbConfigTemplate('project.env.DB'),\n\t\t\tread: {\n\t\t\t\thost: `%?project.env.DB_READ_HOST%`,\n\t\t\t\tport: `%?project.env.DB_READ_PORT::number%`,\n\t\t\t\tuser: `%?project.env.DB_READ_USER%`,\n\t\t\t\tpassword: `%?project.secret.db.read.password||project.env.DB_READ_PASSWORD%`,\n\t\t\t\tdatabase: `%?project.env.DB_READ_NAME%`,\n\t\t\t\t...createDbConfigTemplate('project.env.DB_READ'),\n\t\t\t},\n\t\t},\n\t},\n\tserver: {\n\t\tport: '%?env.CONTEMBER_PORT::number%',\n\t\tmonitoringPort: '%?env.CONTEMBER_MONITORING_PORT::number%',\n\t\tworkerCount: '%?env.CONTEMBER_WORKER_COUNT::string%',\n\t\tapplicationWorker: '%?env.CONTEMBER_APPLICATION_WORKER::string%',\n\t\thttp: {\n\t\t\trequestBodySize: '%?env.CONTEMBER_HTTP_REQUEST_BODY_SIZE::string%',\n\t\t\tsuppressAccessLog: '%?env.CONTEMBER_HTTP_SUPPRESS_ACCESS_LOG::string%',\n\t\t\ttrustedProxies: '%?env.CONTEMBER_HTTP_TRUSTED_PROXIES::string%',\n\t\t\tresponseStatusHeader: '%?env.CONTEMBER_HTTP_RESPONSE_STATUS_HEADER::string%',\n\t\t\tgeoCountryHeader: '%?env.CONTEMBER_HTTP_GEO_COUNTRY_HEADER::string%',\n\t\t},\n\t\tcontentApi: {\n\t\t\tschemaCacheTtlSeconds: '%?env.CONTEMBER_CONTENT_API_SCHEMA_CACHE_TTL_SECONDS::number%',\n\t\t\twhereOptimizer: {\n\t\t\t\tdisable: '%?env.CONTEMBER_CONTENT_API_WHERE_OPTIMIZER_DISABLE::bool%',\n\t\t\t\tmaxCrossOptimizationInput: '%?env.CONTEMBER_CONTENT_API_MAX_CROSS_OPTIMIZATION_INPUT::number%',\n\t\t\t},\n\t\t},\n\t\tprojectGroup: {\n\t\t\tdomainMapping: '%?env.CONTEMBER_PROJECT_GROUP_DOMAIN_MAPPING%',\n\t\t\tconfigHeader: '%?env.CONTEMBER_PROJECT_GROUP_CONFIG_HEADER%',\n\t\t\tconfigEncryptionKey: '%?env.CONTEMBER_PROJECT_GROUP_CONFIG_ENCRYPTION_KEY%',\n\t\t},\n\t\tlogging: {\n\t\t\tsentry: {\n\t\t\t\tdsn: '%?env.SENTRY_DSN%',\n\t\t\t},\n\t\t},\n\t\ttest: {\n\t\t\ttransactions: '%?env.CONTEMBER_TEST_TRANSACTIONS::bool%',\n\t\t\ttransactionTtlSeconds: '%?env.CONTEMBER_TEST_TRANSACTION_TTL_SECONDS::number%',\n\t\t},\n\t},\n}\n"],"names":[],"mappings":"AAAA,MAAM,yBAAyB,CAAC,WAAmB;AAClD,SAAO;AAAA,IACN,KAAK,KAAK,MAAM;AAAA,IAChB,gBAAgB,KAAK,MAAM;AAAA,IAC3B,oBAAoB,KAAK,MAAM;AAAA,IAC/B,eAAe,KAAK,MAAM;AAAA,IAC1B,qBAAqB,KAAK,MAAM;AAAA,IAChC,0BAA0B,KAAK,MAAM;AAAA,IACrC,MAAM;AAAA,MACL,gBAAgB,KAAK,MAAM;AAAA,MAC3B,eAAe,KAAK,MAAM;AAAA,MAC1B,SAAS,KAAK,MAAM;AAAA,MACpB,qBAAqB,KAAK,MAAM;AAAA,MAChC,eAAe,KAAK,MAAM;AAAA,MAC1B,kBAAkB,KAAK,MAAM;AAAA,MAC7B,SAAS,KAAK,MAAM;AAAA,MACpB,UAAU,KAAK,MAAM;AAAA,MACrB,gBAAgB,KAAK,MAAM;AAAA,MAC3B,mBAAmB,KAAK,MAAM;AAAA,IAAA;AAAA,EAC/B;AAEF;AACO,MAAM,iBAAsB;AAAA,EAClC,QAAQ;AAAA,IACP,IAAI;AAAA,MACH,MAAM;AAAA,MACN,M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.js","sources":["../../../../../packages/engine-http/src/config/configTemplate.ts"],"sourcesContent":["const createDbConfigTemplate = (prefix: string) => {\n\treturn {\n\t\tssl: `%?${prefix}_SSL::bool%`,\n\t\tqueryTimeoutMs: `%?${prefix}_QUERY_TIMEOUT_MS::number%`,\n\t\tstatementTimeoutMs: `%?${prefix}_STATEMENT_TIMEOUT_MS::number%`,\n\t\tlockTimeoutMs: `%?${prefix}_LOCK_TIMEOUT_MS::number%`,\n\t\tconnectionTimeoutMs: `%?${prefix}_CONNECTION_TIMEOUT_MS::number%`,\n\t\tkeepAlive: `%?${prefix}_KEEP_ALIVE::bool%`,\n\t\tkeepAliveInitialDelayMs: `%?${prefix}_KEEP_ALIVE_INITIAL_DELAY_MS::number%`,\n\t\tmaxConnectionsPerRequest: `%?${prefix}_MAX_CONNECTIONS_PER_REQUEST::number%`,\n\t\tpool: {\n\t\t\tmaxConnections: `%?${prefix}_POOL_MAX_CONNECTIONS::number%`,\n\t\t\tmaxConnecting: `%?${prefix}_POOL_MAX_CONNECTING::number%`,\n\t\t\tmaxIdle: `%?${prefix}_POOL_MAX_IDLE::number%`,\n\t\t\treconnectIntervalMs: `%?${prefix}_POOL_RECONNECT_INTERVAL_MS::number%`,\n\t\t\tidleTimeoutMs: `%?${prefix}_POOL_IDLE_TIMEOUT_MS::number%`,\n\t\t\tacquireTimeoutMs: `%?${prefix}_POOL_ACQUIRE_TIMEOUT_MS::number%`,\n\t\t\tmaxUses: `%?${prefix}_POOL_MAX_USES::number%`,\n\t\t\tmaxAgeMs: `%?${prefix}_POOL_MAX_AGE_MS::number%`,\n\t\t\trateLimitCount: `%?${prefix}_POOL_RATE_LIMIT_COUNT::number%`,\n\t\t\trateLimitPeriodMs: `%?${prefix}_POOL_RATE_LIMIT_PERIOD_MS::number%`,\n\t\t},\n\t}\n}\nexport const configTemplate: any = {\n\ttenant: {\n\t\tdb: {\n\t\t\thost: `%tenant.env.DB_HOST%`,\n\t\t\tport: `%tenant.env.DB_PORT::number%`,\n\t\t\tuser: `%tenant.env.DB_USER%`,\n\t\t\tpassword: `%tenant.env.DB_PASSWORD%`,\n\t\t\tdatabase: `%tenant.env.DB_NAME%`,\n\t\t\t...createDbConfigTemplate('tenant.env.DB'),\n\t\t\tread: {\n\t\t\t\thost: `%?tenant.env.DB_READ_HOST%`,\n\t\t\t\tport: `%?tenant.env.DB_READ_PORT::number%`,\n\t\t\t\tuser: `%?tenant.env.DB_READ_USER%`,\n\t\t\t\tpassword: `%?tenant.env.DB_READ_PASSWORD%`,\n\t\t\t\tdatabase: `%?tenant.env.DB_READ_NAME%`,\n\t\t\t\t...createDbConfigTemplate('tenant.env.DB_READ'),\n\t\t\t},\n\t\t},\n\t\tmailer: {\n\t\t\tfrom: '%?tenant.env.MAILER_FROM%',\n\t\t\thost: '%?tenant.env.MAILER_HOST::string%',\n\t\t\tport: '%?tenant.env.MAILER_PORT::number%',\n\t\t\tsecure: '%?tenant.env.MAILER_SECURE::bool%',\n\t\t\trequireTLS: '%?tenant.env.MAILER_REQUIRE_TLS::bool%',\n\t\t\tuser: '%?tenant.env.MAILER_USER%',\n\t\t\tpassword: '%?tenant.env.MAILER_PASSWORD%',\n\t\t\twebhook: '%?tenant.env.MAILER_WEBHOOK%',\n\t\t},\n\t\tcredentials: {\n\t\t\trootEmail: '%?env.CONTEMBER_ROOT_EMAIL%',\n\t\t\trootToken: '%?env.CONTEMBER_ROOT_TOKEN%',\n\t\t\trootTokenHash: '%?env.CONTEMBER_ROOT_TOKEN_HASH%',\n\t\t\trootPassword: '%?env.CONTEMBER_ROOT_PASSWORD%',\n\t\t\tloginToken: '%?env.CONTEMBER_LOGIN_TOKEN%',\n\t\t\trootTokens: '%?env.CONTEMBER_ROOT_TOKENS%',\n\t\t\trootTokenHashes: '%?env.CONTEMBER_ROOT_TOKEN_HASHES%',\n\t\t},\n\t\tsecrets: {\n\t\t\tencryptionKey: '%?env.CONTEMBER_ENCRYPTION_KEY%',\n\t\t},\n\t},\n\tprojectDefaults: {\n\t\tstageSlug: '%?project.env.STAGE_SLUG%',\n\t\tdb: {\n\t\t\thost: `%?project.env.DB_HOST%`,\n\t\t\tport: `%?project.env.DB_PORT::number%`,\n\t\t\tuser: `%?project.env.DB_USER%`,\n\t\t\tpassword: `%?project.secret.db.password||project.env.DB_PASSWORD%`,\n\t\t\tdatabase: `%?project.env.DB_NAME||project.slug%`,\n\t\t\t...createDbConfigTemplate('project.env.DB'),\n\t\t\tread: {\n\t\t\t\thost: `%?project.env.DB_READ_HOST%`,\n\t\t\t\tport: `%?project.env.DB_READ_PORT::number%`,\n\t\t\t\tuser: `%?project.env.DB_READ_USER%`,\n\t\t\t\tpassword: `%?project.secret.db.read.password||project.env.DB_READ_PASSWORD%`,\n\t\t\t\tdatabase: `%?project.env.DB_READ_NAME%`,\n\t\t\t\t...createDbConfigTemplate('project.env.DB_READ'),\n\t\t\t},\n\t\t},\n\t},\n\tserver: {\n\t\tport: '%?env.CONTEMBER_PORT::number%',\n\t\tmonitoringPort: '%?env.CONTEMBER_MONITORING_PORT::number%',\n\t\tworkerCount: '%?env.CONTEMBER_WORKER_COUNT::string%',\n\t\tapplicationWorker: '%?env.CONTEMBER_APPLICATION_WORKER::string%',\n\t\tshutdownDelayMs: '%?env.CONTEMBER_SHUTDOWN_DELAY_MS::number%',\n\t\thttp: {\n\t\t\trequestBodySize: '%?env.CONTEMBER_HTTP_REQUEST_BODY_SIZE::string%',\n\t\t\tsuppressAccessLog: '%?env.CONTEMBER_HTTP_SUPPRESS_ACCESS_LOG::string%',\n\t\t\ttrustedProxies: '%?env.CONTEMBER_HTTP_TRUSTED_PROXIES::string%',\n\t\t\tresponseStatusHeader: '%?env.CONTEMBER_HTTP_RESPONSE_STATUS_HEADER::string%',\n\t\t\tgeoCountryHeader: '%?env.CONTEMBER_HTTP_GEO_COUNTRY_HEADER::string%',\n\t\t\trequestMemoryBudget: {\n\t\t\t\twarnBytes: '%?env.CONTEMBER_HTTP_REQUEST_MEMORY_BUDGET_WARN_BYTES::number%',\n\t\t\t\tmaxBytes: '%?env.CONTEMBER_HTTP_REQUEST_MEMORY_BUDGET_MAX_BYTES::number%',\n\t\t\t},\n\t\t},\n\t\tpanel: {\n\t\t\tenabled: '%?env.CONTEMBER_PANEL_ENABLED::bool%',\n\t\t\tpath: '%?env.CONTEMBER_PANEL_PATH%',\n\t\t},\n\t\tcontentApi: {\n\t\t\tschemaCacheTtlSeconds: '%?env.CONTEMBER_CONTENT_API_SCHEMA_CACHE_TTL_SECONDS::number%',\n\t\t\tschemaCacheMaxEntries: '%?env.CONTEMBER_CONTENT_API_SCHEMA_CACHE_MAX_ENTRIES::number%',\n\t\t\tforcePrimaryHeader: '%?env.CONTEMBER_CONTENT_API_FORCE_PRIMARY_HEADER::bool%',\n\t\t\twhereOptimizer: {\n\t\t\t\tdisable: '%?env.CONTEMBER_CONTENT_API_WHERE_OPTIMIZER_DISABLE::bool%',\n\t\t\t\tmaxCrossOptimizationInput: '%?env.CONTEMBER_CONTENT_API_MAX_CROSS_OPTIMIZATION_INPUT::number%',\n\t\t\t},\n\t\t},\n\t\tprojectGroup: {\n\t\t\tdomainMapping: '%?env.CONTEMBER_PROJECT_GROUP_DOMAIN_MAPPING%',\n\t\t\tconfigHeader: '%?env.CONTEMBER_PROJECT_GROUP_CONFIG_HEADER%',\n\t\t\tconfigEncryptionKey: '%?env.CONTEMBER_PROJECT_GROUP_CONFIG_ENCRYPTION_KEY%',\n\t\t},\n\t\tlogging: {\n\t\t\tsentry: {\n\t\t\t\tdsn: '%?env.SENTRY_DSN%',\n\t\t\t},\n\t\t},\n\t\ttelemetry: {\n\t\t\ttraces: {\n\t\t\t\tenabled: '%?env.CONTEMBER_TELEMETRY_TRACES_ENABLED::bool%',\n\t\t\t\texporter: {\n\t\t\t\t\ttype: '%?env.CONTEMBER_TELEMETRY_EXPORTER_TYPE%',\n\t\t\t\t\tendpoint: '%?env.CONTEMBER_TELEMETRY_OTLP_ENDPOINT%',\n\t\t\t\t\ttimeoutMs: '%?env.CONTEMBER_TELEMETRY_OTLP_TIMEOUT_MS::number%',\n\t\t\t\t},\n\t\t\t\tsampler: '%?env.CONTEMBER_TELEMETRY_SAMPLER%',\n\t\t\t\tsamplerRatio: '%?env.CONTEMBER_TELEMETRY_SAMPLER_RATIO::number%',\n\t\t\t\tacceptIncoming: '%?env.CONTEMBER_TELEMETRY_ACCEPT_INCOMING%',\n\t\t\t\tpropagateToWebhooks: '%?env.CONTEMBER_TELEMETRY_PROPAGATE_TO_WEBHOOKS::bool%',\n\t\t\t\ttraceIdResponseHeader: '%?env.CONTEMBER_TELEMETRY_TRACE_ID_RESPONSE_HEADER::bool%',\n\t\t\t\tmaxSpansPerRequest: '%?env.CONTEMBER_TELEMETRY_MAX_SPANS_PER_REQUEST::number%',\n\t\t\t\tsql: {\n\t\t\t\t\tenabled: '%?env.CONTEMBER_TELEMETRY_SQL_ENABLED::bool%',\n\t\t\t\t\tincludeQueryText: '%?env.CONTEMBER_TELEMETRY_SQL_INCLUDE_QUERY_TEXT::bool%',\n\t\t\t\t\tminDurationMs: '%?env.CONTEMBER_TELEMETRY_SQL_MIN_DURATION_MS::number%',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\ttest: {\n\t\t\ttransactions: '%?env.CONTEMBER_TEST_TRANSACTIONS::bool%',\n\t\t\ttransactionTtlSeconds: '%?env.CONTEMBER_TEST_TRANSACTION_TTL_SECONDS::number%',\n\t\t},\n\t},\n}\n"],"names":[],"mappings":"AAAA,MAAM,yBAAyB,CAAC,WAAmB;AAClD,SAAO;AAAA,IACN,KAAK,KAAK,MAAM;AAAA,IAChB,gBAAgB,KAAK,MAAM;AAAA,IAC3B,oBAAoB,KAAK,MAAM;AAAA,IAC/B,eAAe,KAAK,MAAM;AAAA,IAC1B,qBAAqB,KAAK,MAAM;AAAA,IAChC,WAAW,KAAK,MAAM;AAAA,IACtB,yBAAyB,KAAK,MAAM;AAAA,IACpC,0BAA0B,KAAK,MAAM;AAAA,IACrC,MAAM;AAAA,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AAA,MACL,cAAc;AAAA,MACd,uBAAuB;AAAA,IAAA;AAAA,EACxB;AAEF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectConfigResolver.cjs","sources":["../../../../../packages/engine-http/src/config/projectConfigResolver.ts"],"sourcesContent":["import { Merger, ParametersResolver, resolveParameters, UndefinedParameterError } from '@contember/config-loader'\nimport * as Typesafe from '@contember/typesafe'\nimport { projectConfigSchema } from './configSchema.js'\nimport { TenantConfig } from './config.js'\nimport { ProjectConfig, ProjectSecrets } from '../project/config.js'\nimport { ConfigProcessor } from './ConfigProcessor.js'\n\nexport type ProjectConfigResolver = (\n\tslug: string,\n\tadditionalConfig: any,\n\tsecrets: ProjectSecrets,\n\ttenantConfig: TenantConfig,\n) => ProjectConfig\n\ntype Env = Record<string, string>\n\nexport const createProjectConfigResolver =\n\t(env: Env, config: any, configProcessors: ConfigProcessor<any>[]): ProjectConfigResolver =>\n\t(slug, additionalConfig, secrets, tenantConfig): ProjectConfig => {\n\t\tconst mergedConfig = Merger.merge(\n\t\t\tconfig.projectDefaults as any,\n\t\t\t(config?.projects as any)?.[slug] as any,\n\t\t\tadditionalConfig,\n\t\t)\n\t\tconst resolvedConfig = resolveParameters(mergedConfig, createProjectParametersResolver(slug, env, secrets))\n\n\t\tif (!resolvedConfig.stages) {\n\t\t\tresolvedConfig.stages = { [resolvedConfig.stageSlug ?? 'live']: {} }\n\t\t}\n\n\t\tconst projectConfigSchemaWithPlugins = configProcessors.reduce(\n\t\t\t(schema, current) => {\n\t\t\t\tif (!current.getProjectConfigSchema) {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn Typesafe.intersection(schema, current.getProjectConfigSchema(slug))\n\t\t\t},\n\t\t\tprojectConfigSchema,\n\t\t)\n\t\tconst projectConfig = projectConfigSchemaWithPlugins(resolvedConfig, ['project', slug])\n\t\tif (!('host' in projectConfig.db)) {\n\t\t\treturn {\n\t\t\t\t...projectConfig,\n\t\t\t\tdb: {\n\t\t\t\t\t...tenantConfig.db,\n\t\t\t\t\t...projectConfig.db,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t...projectConfig,\n\t\t\tdb: projectConfig.db,\n\t\t}\n\t}\n\nconst createProjectParametersResolver = (slug: string, env: Env, secrets: ProjectSecrets): ParametersResolver => parts => {\n\tif (parts[0] === 'project') {\n\t\tif (parts[1] === 'env') {\n\t\t\tconst envName = parts[2]\n\t\t\tconst projectEnvName = projectNameToEnvName(slug)\n\t\t\tconst envValue = env[projectEnvName + '_' + envName] || env['DEFAULT_' + envName]\n\t\t\tif (envValue === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`ENV variable \"${projectEnvName + '_' + envName}\" not found.`)\n\t\t\t}\n\t\t\treturn envValue\n\t\t} else if (parts[1] === 'slug') {\n\t\t\treturn slug\n\t\t} else if (parts[1] === 'secret') {\n\t\t\tconst key = parts.slice(2).join('.')\n\t\t\tconst value = secrets[key]\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`Project secret ${parts[2]} not found`)\n\t\t\t}\n\t\t\treturn value\n\t\t}\n\t}\n\tthrow new UndefinedParameterError(`Parameter \"${parts.join('.')}\" not found.`)\n}\n\
|
|
1
|
+
{"version":3,"file":"projectConfigResolver.cjs","sources":["../../../../../packages/engine-http/src/config/projectConfigResolver.ts"],"sourcesContent":["import { Merger, ParametersResolver, resolveParameters, UndefinedParameterError } from '@contember/config-loader'\nimport * as Typesafe from '@contember/typesafe'\nimport { projectConfigSchema } from './configSchema.js'\nimport { TenantConfig } from './config.js'\nimport { ProjectConfig, ProjectSecrets } from '../project/config.js'\nimport { ConfigProcessor } from './ConfigProcessor.js'\n\nexport type ProjectConfigResolver = (\n\tslug: string,\n\tadditionalConfig: any,\n\tsecrets: ProjectSecrets,\n\ttenantConfig: TenantConfig,\n) => ProjectConfig\n\ntype Env = Record<string, string>\n\nexport const createProjectConfigResolver =\n\t(env: Env, config: any, configProcessors: ConfigProcessor<any>[]): ProjectConfigResolver =>\n\t(slug, additionalConfig, secrets, tenantConfig): ProjectConfig => {\n\t\tconst mergedConfig = Merger.merge(\n\t\t\tconfig.projectDefaults as any,\n\t\t\t(config?.projects as any)?.[slug] as any,\n\t\t\tadditionalConfig,\n\t\t)\n\t\tconst resolvedConfig = resolveParameters(mergedConfig, createProjectParametersResolver(slug, env, secrets))\n\n\t\tif (!resolvedConfig.stages) {\n\t\t\tresolvedConfig.stages = { [resolvedConfig.stageSlug ?? 'live']: {} }\n\t\t}\n\n\t\tconst projectConfigSchemaWithPlugins = configProcessors.reduce(\n\t\t\t(schema, current) => {\n\t\t\t\tif (!current.getProjectConfigSchema) {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn Typesafe.intersection(schema, current.getProjectConfigSchema(slug))\n\t\t\t},\n\t\t\tprojectConfigSchema,\n\t\t)\n\t\tconst projectConfig = projectConfigSchemaWithPlugins(resolvedConfig, ['project', slug])\n\t\tif (!('host' in projectConfig.db)) {\n\t\t\treturn {\n\t\t\t\t...projectConfig,\n\t\t\t\tdb: {\n\t\t\t\t\t...tenantConfig.db,\n\t\t\t\t\t...projectConfig.db,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t...projectConfig,\n\t\t\tdb: projectConfig.db,\n\t\t}\n\t}\n\nconst createProjectParametersResolver = (slug: string, env: Env, secrets: ProjectSecrets): ParametersResolver => parts => {\n\tif (parts[0] === 'project') {\n\t\tif (parts[1] === 'env') {\n\t\t\tconst envName = parts[2]\n\t\t\tconst projectEnvName = projectNameToEnvName(slug)\n\t\t\tconst envValue = env[projectEnvName + '_' + envName] || env['DEFAULT_' + envName]\n\t\t\tif (envValue === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`ENV variable \"${projectEnvName + '_' + envName}\" not found.`)\n\t\t\t}\n\t\t\treturn envValue\n\t\t} else if (parts[1] === 'slug') {\n\t\t\treturn slug\n\t\t} else if (parts[1] === 'secret') {\n\t\t\tconst key = parts.slice(2).join('.')\n\t\t\tconst value = secrets[key]\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`Project secret ${parts[2]} not found`)\n\t\t\t}\n\t\t\treturn value\n\t\t}\n\t}\n\tthrow new UndefinedParameterError(`Parameter \"${parts.join('.')}\" not found.`)\n}\n\nexport const projectNameToEnvName = (projectName: string): string => {\n\tconst envName = projectName.toUpperCase().replace(/-/g, '_')\n\tif (envName === 'TENANT') {\n\t\tthrow new Error('Forbidden project name')\n\t}\n\treturn envName\n}\n"],"names":["Merger","resolveParameters","Typesafe","projectConfigSchema","UndefinedParameterError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBO,MAAM,8BACZ,CAAC,KAAU,QAAa,qBACxB,CAAC,MAAM,kBAAkB,SAAS,iBAAgC;AACjE,QAAM,eAAeA,aAAAA,OAAO;AAAA,IAC3B,OAAO;AAAA,IACN,QAAQ,WAAmB,IAAI;AAAA,IAChC;AAAA,EAAA;AAED,QAAM,iBAAiBC,aAAAA,kBAAkB,cAAc,gCAAgC,MAAM,KAAK,OAAO,CAAC;AAE1G,MAAI,CAAC,eAAe,QAAQ;AAC3B,mBAAe,SAAS,EAAE,CAAC,eAAe,aAAa,MAAM,GAAG,GAAC;AAAA,EAClE;AAEA,QAAM,iCAAiC,iBAAiB;AAAA,IACvD,CAAC,QAAQ,YAAY;AACpB,UAAI,CAAC,QAAQ,wBAAwB;AACpC,eAAO;AAAA,MACR;AACA,aAAOC,oBAAS,aAAa,QAAQ,QAAQ,uBAAuB,IAAI,CAAC;AAAA,IAC1E;AAAA,IACAC,aAAAA;AAAAA,EAAA;AAED,QAAM,gBAAgB,+BAA+B,gBAAgB,CAAC,WAAW,IAAI,CAAC;AACtF,MAAI,EAAE,UAAU,cAAc,KAAK;AAClC,WAAO;AAAA,MACN,GAAG;AAAA,MACH,IAAI;AAAA,QACH,GAAG,aAAa;AAAA,QAChB,GAAG,cAAc;AAAA,MAAA;AAAA,IAClB;AAAA,EAEF;AACA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,IAAI,cAAc;AAAA,EAAA;AAEpB;AAED,MAAM,kCAAkC,CAAC,MAAc,KAAU,YAAgD,CAAA,UAAS;AACzH,MAAI,MAAM,CAAC,MAAM,WAAW;AAC3B,QAAI,MAAM,CAAC,MAAM,OAAO;AACvB,YAAM,UAAU,MAAM,CAAC;AACvB,YAAM,iBAAiB,qBAAqB,IAAI;AAChD,YAAM,WAAW,IAAI,iBAAiB,MAAM,OAAO,KAAK,IAAI,aAAa,OAAO;AAChF,UAAI,aAAa,QAAW;AAC3B,cAAM,IAAIC,aAAAA,wBAAwB,iBAAiB,iBAAiB,MAAM,OAAO,cAAc;AAAA,MAChG;AACA,aAAO;AAAA,IACR,WAAW,MAAM,CAAC,MAAM,QAAQ;AAC/B,aAAO;AAAA,IACR,WAAW,MAAM,CAAC,MAAM,UAAU;AACjC,YAAM,MAAM,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG;AACnC,YAAM,QAAQ,QAAQ,GAAG;AACzB,UAAI,UAAU,QAAW;AACxB,cAAM,IAAIA,aAAAA,wBAAwB,kBAAkB,MAAM,CAAC,CAAC,YAAY;AAAA,MACzE;AACA,aAAO;AAAA,IACR;AAAA,EACD;AACA,QAAM,IAAIA,aAAAA,wBAAwB,cAAc,MAAM,KAAK,GAAG,CAAC,cAAc;AAC9E;AAEO,MAAM,uBAAuB,CAAC,gBAAgC;AACpE,QAAM,UAAU,YAAY,YAAA,EAAc,QAAQ,MAAM,GAAG;AAC3D,MAAI,YAAY,UAAU;AACzB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EACzC;AACA,SAAO;AACR;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectConfigResolver.js","sources":["../../../../../packages/engine-http/src/config/projectConfigResolver.ts"],"sourcesContent":["import { Merger, ParametersResolver, resolveParameters, UndefinedParameterError } from '@contember/config-loader'\nimport * as Typesafe from '@contember/typesafe'\nimport { projectConfigSchema } from './configSchema.js'\nimport { TenantConfig } from './config.js'\nimport { ProjectConfig, ProjectSecrets } from '../project/config.js'\nimport { ConfigProcessor } from './ConfigProcessor.js'\n\nexport type ProjectConfigResolver = (\n\tslug: string,\n\tadditionalConfig: any,\n\tsecrets: ProjectSecrets,\n\ttenantConfig: TenantConfig,\n) => ProjectConfig\n\ntype Env = Record<string, string>\n\nexport const createProjectConfigResolver =\n\t(env: Env, config: any, configProcessors: ConfigProcessor<any>[]): ProjectConfigResolver =>\n\t(slug, additionalConfig, secrets, tenantConfig): ProjectConfig => {\n\t\tconst mergedConfig = Merger.merge(\n\t\t\tconfig.projectDefaults as any,\n\t\t\t(config?.projects as any)?.[slug] as any,\n\t\t\tadditionalConfig,\n\t\t)\n\t\tconst resolvedConfig = resolveParameters(mergedConfig, createProjectParametersResolver(slug, env, secrets))\n\n\t\tif (!resolvedConfig.stages) {\n\t\t\tresolvedConfig.stages = { [resolvedConfig.stageSlug ?? 'live']: {} }\n\t\t}\n\n\t\tconst projectConfigSchemaWithPlugins = configProcessors.reduce(\n\t\t\t(schema, current) => {\n\t\t\t\tif (!current.getProjectConfigSchema) {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn Typesafe.intersection(schema, current.getProjectConfigSchema(slug))\n\t\t\t},\n\t\t\tprojectConfigSchema,\n\t\t)\n\t\tconst projectConfig = projectConfigSchemaWithPlugins(resolvedConfig, ['project', slug])\n\t\tif (!('host' in projectConfig.db)) {\n\t\t\treturn {\n\t\t\t\t...projectConfig,\n\t\t\t\tdb: {\n\t\t\t\t\t...tenantConfig.db,\n\t\t\t\t\t...projectConfig.db,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t...projectConfig,\n\t\t\tdb: projectConfig.db,\n\t\t}\n\t}\n\nconst createProjectParametersResolver = (slug: string, env: Env, secrets: ProjectSecrets): ParametersResolver => parts => {\n\tif (parts[0] === 'project') {\n\t\tif (parts[1] === 'env') {\n\t\t\tconst envName = parts[2]\n\t\t\tconst projectEnvName = projectNameToEnvName(slug)\n\t\t\tconst envValue = env[projectEnvName + '_' + envName] || env['DEFAULT_' + envName]\n\t\t\tif (envValue === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`ENV variable \"${projectEnvName + '_' + envName}\" not found.`)\n\t\t\t}\n\t\t\treturn envValue\n\t\t} else if (parts[1] === 'slug') {\n\t\t\treturn slug\n\t\t} else if (parts[1] === 'secret') {\n\t\t\tconst key = parts.slice(2).join('.')\n\t\t\tconst value = secrets[key]\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`Project secret ${parts[2]} not found`)\n\t\t\t}\n\t\t\treturn value\n\t\t}\n\t}\n\tthrow new UndefinedParameterError(`Parameter \"${parts.join('.')}\" not found.`)\n}\n\
|
|
1
|
+
{"version":3,"file":"projectConfigResolver.js","sources":["../../../../../packages/engine-http/src/config/projectConfigResolver.ts"],"sourcesContent":["import { Merger, ParametersResolver, resolveParameters, UndefinedParameterError } from '@contember/config-loader'\nimport * as Typesafe from '@contember/typesafe'\nimport { projectConfigSchema } from './configSchema.js'\nimport { TenantConfig } from './config.js'\nimport { ProjectConfig, ProjectSecrets } from '../project/config.js'\nimport { ConfigProcessor } from './ConfigProcessor.js'\n\nexport type ProjectConfigResolver = (\n\tslug: string,\n\tadditionalConfig: any,\n\tsecrets: ProjectSecrets,\n\ttenantConfig: TenantConfig,\n) => ProjectConfig\n\ntype Env = Record<string, string>\n\nexport const createProjectConfigResolver =\n\t(env: Env, config: any, configProcessors: ConfigProcessor<any>[]): ProjectConfigResolver =>\n\t(slug, additionalConfig, secrets, tenantConfig): ProjectConfig => {\n\t\tconst mergedConfig = Merger.merge(\n\t\t\tconfig.projectDefaults as any,\n\t\t\t(config?.projects as any)?.[slug] as any,\n\t\t\tadditionalConfig,\n\t\t)\n\t\tconst resolvedConfig = resolveParameters(mergedConfig, createProjectParametersResolver(slug, env, secrets))\n\n\t\tif (!resolvedConfig.stages) {\n\t\t\tresolvedConfig.stages = { [resolvedConfig.stageSlug ?? 'live']: {} }\n\t\t}\n\n\t\tconst projectConfigSchemaWithPlugins = configProcessors.reduce(\n\t\t\t(schema, current) => {\n\t\t\t\tif (!current.getProjectConfigSchema) {\n\t\t\t\t\treturn schema\n\t\t\t\t}\n\t\t\t\treturn Typesafe.intersection(schema, current.getProjectConfigSchema(slug))\n\t\t\t},\n\t\t\tprojectConfigSchema,\n\t\t)\n\t\tconst projectConfig = projectConfigSchemaWithPlugins(resolvedConfig, ['project', slug])\n\t\tif (!('host' in projectConfig.db)) {\n\t\t\treturn {\n\t\t\t\t...projectConfig,\n\t\t\t\tdb: {\n\t\t\t\t\t...tenantConfig.db,\n\t\t\t\t\t...projectConfig.db,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t...projectConfig,\n\t\t\tdb: projectConfig.db,\n\t\t}\n\t}\n\nconst createProjectParametersResolver = (slug: string, env: Env, secrets: ProjectSecrets): ParametersResolver => parts => {\n\tif (parts[0] === 'project') {\n\t\tif (parts[1] === 'env') {\n\t\t\tconst envName = parts[2]\n\t\t\tconst projectEnvName = projectNameToEnvName(slug)\n\t\t\tconst envValue = env[projectEnvName + '_' + envName] || env['DEFAULT_' + envName]\n\t\t\tif (envValue === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`ENV variable \"${projectEnvName + '_' + envName}\" not found.`)\n\t\t\t}\n\t\t\treturn envValue\n\t\t} else if (parts[1] === 'slug') {\n\t\t\treturn slug\n\t\t} else if (parts[1] === 'secret') {\n\t\t\tconst key = parts.slice(2).join('.')\n\t\t\tconst value = secrets[key]\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new UndefinedParameterError(`Project secret ${parts[2]} not found`)\n\t\t\t}\n\t\t\treturn value\n\t\t}\n\t}\n\tthrow new UndefinedParameterError(`Parameter \"${parts.join('.')}\" not found.`)\n}\n\nexport const projectNameToEnvName = (projectName: string): string => {\n\tconst envName = projectName.toUpperCase().replace(/-/g, '_')\n\tif (envName === 'TENANT') {\n\t\tthrow new Error('Forbidden project name')\n\t}\n\treturn envName\n}\n"],"names":[],"mappings":";;;AAgBO,MAAM,8BACZ,CAAC,KAAU,QAAa,qBACxB,CAAC,MAAM,kBAAkB,SAAS,iBAAgC;AACjE,QAAM,eAAe,OAAO;AAAA,IAC3B,OAAO;AAAA,IACN,QAAQ,WAAmB,IAAI;AAAA,IAChC;AAAA,EAAA;AAED,QAAM,iBAAiB,kBAAkB,cAAc,gCAAgC,MAAM,KAAK,OAAO,CAAC;AAE1G,MAAI,CAAC,eAAe,QAAQ;AAC3B,mBAAe,SAAS,EAAE,CAAC,eAAe,aAAa,MAAM,GAAG,GAAC;AAAA,EAClE;AAEA,QAAM,iCAAiC,iBAAiB;AAAA,IACvD,CAAC,QAAQ,YAAY;AACpB,UAAI,CAAC,QAAQ,wBAAwB;AACpC,eAAO;AAAA,MACR;AACA,aAAO,SAAS,aAAa,QAAQ,QAAQ,uBAAuB,IAAI,CAAC;AAAA,IAC1E;AAAA,IACA;AAAA,EAAA;AAED,QAAM,gBAAgB,+BAA+B,gBAAgB,CAAC,WAAW,IAAI,CAAC;AACtF,MAAI,EAAE,UAAU,cAAc,KAAK;AAClC,WAAO;AAAA,MACN,GAAG;AAAA,MACH,IAAI;AAAA,QACH,GAAG,aAAa;AAAA,QAChB,GAAG,cAAc;AAAA,MAAA;AAAA,IAClB;AAAA,EAEF;AACA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,IAAI,cAAc;AAAA,EAAA;AAEpB;AAED,MAAM,kCAAkC,CAAC,MAAc,KAAU,YAAgD,CAAA,UAAS;AACzH,MAAI,MAAM,CAAC,MAAM,WAAW;AAC3B,QAAI,MAAM,CAAC,MAAM,OAAO;AACvB,YAAM,UAAU,MAAM,CAAC;AACvB,YAAM,iBAAiB,qBAAqB,IAAI;AAChD,YAAM,WAAW,IAAI,iBAAiB,MAAM,OAAO,KAAK,IAAI,aAAa,OAAO;AAChF,UAAI,aAAa,QAAW;AAC3B,cAAM,IAAI,wBAAwB,iBAAiB,iBAAiB,MAAM,OAAO,cAAc;AAAA,MAChG;AACA,aAAO;AAAA,IACR,WAAW,MAAM,CAAC,MAAM,QAAQ;AAC/B,aAAO;AAAA,IACR,WAAW,MAAM,CAAC,MAAM,UAAU;AACjC,YAAM,MAAM,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG;AACnC,YAAM,QAAQ,QAAQ,GAAG;AACzB,UAAI,UAAU,QAAW;AACxB,cAAM,IAAI,wBAAwB,kBAAkB,MAAM,CAAC,CAAC,YAAY;AAAA,MACzE;AACA,aAAO;AAAA,IACR;AAAA,EACD;AACA,QAAM,IAAI,wBAAwB,cAAc,MAAM,KAAK,GAAG,CAAC,cAAc;AAC9E;AAEO,MAAM,uBAAuB,CAAC,gBAAgC;AACpE,QAAM,UAAU,YAAY,YAAA,EAAc,QAAQ,MAAM,GAAG;AAC3D,MAAI,YAAY,UAAU;AACzB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EACzC;AACA,SAAO;AACR;"}
|
|
@@ -2,18 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const engineContentApi = require("@contember/engine-content-api");
|
|
4
4
|
const engineSystemApi = require("@contember/engine-system-api");
|
|
5
|
+
const Database = require("@contember/database");
|
|
5
6
|
const HttpResponse = require("../common/HttpResponse.cjs");
|
|
6
7
|
require("ipaddr.js");
|
|
8
|
+
require("@contember/engine-tenant-api");
|
|
9
|
+
const truthyHeader = require("../utils/truthyHeader.cjs");
|
|
7
10
|
const debugHeader = "x-contember-debug";
|
|
8
11
|
const testSessionHeader = "x-contember-test-session";
|
|
12
|
+
const forcePrimaryHeader = "x-contember-force-primary";
|
|
9
13
|
class ContentApiControllerFactory {
|
|
10
|
-
constructor(notModifiedChecker, executionContainerFactory, handlerFactory, projectContextResolver, graphQlSchemaFactory, testTransactionService) {
|
|
14
|
+
constructor(notModifiedChecker, executionContainerFactory, handlerFactory, projectContextResolver, graphQlSchemaFactory, testTransactionService, forcePrimaryHeaderEnabled, memoryBudgetOptions) {
|
|
11
15
|
this.notModifiedChecker = notModifiedChecker;
|
|
12
16
|
this.executionContainerFactory = executionContainerFactory;
|
|
13
17
|
this.handlerFactory = handlerFactory;
|
|
14
18
|
this.projectContextResolver = projectContextResolver;
|
|
15
19
|
this.graphQlSchemaFactory = graphQlSchemaFactory;
|
|
16
20
|
this.testTransactionService = testTransactionService;
|
|
21
|
+
this.forcePrimaryHeaderEnabled = forcePrimaryHeaderEnabled;
|
|
22
|
+
this.memoryBudgetOptions = memoryBudgetOptions;
|
|
17
23
|
}
|
|
18
24
|
create() {
|
|
19
25
|
const handlerCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -26,7 +32,9 @@ class ContentApiControllerFactory {
|
|
|
26
32
|
const logger = context.logger.child({
|
|
27
33
|
project: project.slug
|
|
28
34
|
});
|
|
29
|
-
const
|
|
35
|
+
const forcePrimary = this.forcePrimaryHeaderEnabled && truthyHeader.isTruthyHeader(request, forcePrimaryHeader);
|
|
36
|
+
const markMutations = this.forcePrimaryHeaderEnabled && projectContainer.readConnection !== projectContainer.connection;
|
|
37
|
+
const systemDatabase = forcePrimary ? projectContainer.systemDatabaseContext : projectContainer.systemReadDatabaseContext;
|
|
30
38
|
const stage = await systemDatabase.queryHandler.fetch(new engineSystemApi.StageBySlugQuery(params.stageSlug));
|
|
31
39
|
if (!stage) {
|
|
32
40
|
return new HttpResponse.HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`);
|
|
@@ -104,14 +112,30 @@ class ContentApiControllerFactory {
|
|
|
104
112
|
await timer("GraphQL", () => handler({
|
|
105
113
|
request: koa.request,
|
|
106
114
|
response: koa.response,
|
|
107
|
-
createContext: ({ operation }) => {
|
|
115
|
+
createContext: ({ operation, queryHash }) => {
|
|
116
|
+
if (operation === "mutation" && markMutations) {
|
|
117
|
+
koa.response.set("X-Contember-Mutation", "1");
|
|
118
|
+
}
|
|
108
119
|
koa.state.graphql = {
|
|
109
120
|
operationName: operation
|
|
110
121
|
};
|
|
111
|
-
const baseConnection = operation === "query" ? projectContainer.readConnection : projectContainer.connection;
|
|
122
|
+
const baseConnection = operation === "query" && !forcePrimary ? projectContainer.readConnection : projectContainer.connection;
|
|
112
123
|
const maxConnectionsPerRequest = "maxConnectionsPerRequest" in project.db ? project.db.maxConnectionsPerRequest : void 0;
|
|
113
124
|
const connection = maxConnectionsPerRequest !== void 0 ? baseConnection.withMaxConnections(maxConnectionsPerRequest) : baseConnection;
|
|
125
|
+
const memoryBudget = this.memoryBudgetOptions ? new Database.RequestMemoryBudget(this.memoryBudgetOptions) : void 0;
|
|
114
126
|
const contentDatabase = testContentDatabase ?? connection.createClient(stage.schema, { module: "content" });
|
|
127
|
+
if (memoryBudget) {
|
|
128
|
+
const logMemory = () => {
|
|
129
|
+
koa.res.off("finish", logMemory);
|
|
130
|
+
koa.res.off("close", logMemory);
|
|
131
|
+
const memory = memoryBudget.snapshot();
|
|
132
|
+
if (memory.warningThresholdExceeded) {
|
|
133
|
+
logger2.warn("Content request memory usage", { operation, queryHash, ...memory });
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
koa.res.once("finish", logMemory);
|
|
137
|
+
koa.res.once("close", logMemory);
|
|
138
|
+
}
|
|
115
139
|
const identityVariables = engineContentApi.createAclVariables(schema.acl, memberships);
|
|
116
140
|
let identityId = authResult.identityId;
|
|
117
141
|
if (authResult.assumedIdentityId && memberships.some((it) => schema.acl.roles[it.role].system?.assumeIdentity)) {
|
|
@@ -119,6 +143,7 @@ class ContentApiControllerFactory {
|
|
|
119
143
|
}
|
|
120
144
|
const executionContainer = this.executionContainerFactory.create({
|
|
121
145
|
db: contentDatabase,
|
|
146
|
+
memoryBudget,
|
|
122
147
|
identityVariables,
|
|
123
148
|
identityId,
|
|
124
149
|
schema,
|
|
@@ -136,6 +161,7 @@ class ContentApiControllerFactory {
|
|
|
136
161
|
});
|
|
137
162
|
return {
|
|
138
163
|
db: contentDatabase,
|
|
164
|
+
memoryBudget,
|
|
139
165
|
identityVariables,
|
|
140
166
|
identityId,
|
|
141
167
|
executionContainer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentApiControllerFactory.cjs","sources":["../../../../../packages/engine-http/src/content/ContentApiControllerFactory.ts"],"sourcesContent":["import { createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'\nimport { StageBySlugQuery } from '@contember/engine-system-api'\nimport { Client } from '@contember/database'\nimport { GraphQLSchema } from 'graphql'\nimport { HttpController } from '../application/index.js'\nimport { HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport { GraphQLKoaState } from '../graphql/index.js'\nimport { ProjectContextResolver } from '../project-common/index.js'\nimport { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryHandlerFactory.js'\nimport { GraphQlSchemaFactory } from './GraphQlSchemaFactory.js'\nimport { NotModifiedChecker } from './NotModifiedChecker.js'\nimport { TestTransactionService } from '../testing/index.js'\n\nconst debugHeader = 'x-contember-debug'\nconst testSessionHeader = 'x-contember-test-session'\n\nexport class ContentApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly notModifiedChecker: NotModifiedChecker,\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly handlerFactory: ContentQueryHandlerFactory,\n\t\tprivate readonly projectContextResolver: ProjectContextResolver,\n\t\tprivate readonly graphQlSchemaFactory: GraphQlSchemaFactory,\n\t\tprivate readonly testTransactionService: TestTransactionService,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\tconst handlerCache = new WeakMap<GraphQLSchema, ContentQueryHandler>()\n\t\treturn async context => {\n\t\t\tconst { params, timer, projectGroup, authResult, request, koa, clientIp } = context\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\t\t\tconst { projectContainer, project } = await this.projectContextResolver.resolve(context)\n\n\t\t\tconst logger = context.logger.child({\n\t\t\t\tproject: project.slug,\n\t\t\t})\n\n\t\t\tconst systemDatabase = projectContainer.systemReadDatabaseContext\n\t\t\tconst stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))\n\t\t\tif (!stage) {\n\t\t\t\treturn new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)\n\t\t\t}\n\t\t\tconst notModifiedRes = await this.notModifiedChecker.checkNotModified({\n\t\t\t\trequest: context.request,\n\t\t\t\tbody: context.body,\n\t\t\t\ttimer: context.timer,\n\t\t\t\tsystemDatabase,\n\t\t\t\tstageId: stage.id,\n\t\t\t})\n\t\t\tif (notModifiedRes?.isModified === false) {\n\t\t\t\treturn new HttpResponse(304)\n\t\t\t}\n\n\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabase, stage: stage.slug, normalize: true })\n\t\t\tconst schema = schemaWithMeta.schema\n\t\t\tconst { effective: memberships, fetched: fetchedMemberships } = await timer(\n\t\t\t\t'MembershipFetch',\n\t\t\t\t() =>\n\t\t\t\t\tprojectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\t\trequest: koa,\n\t\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\t\tpersonId: authResult.personId ?? undefined,\n\t\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t)\n\n\t\t\tlogger.debug('Memberships fetched', { memberships })\n\n\t\t\tconst debugHeaderValue = request.headers[debugHeader]\n\t\t\tif (Array.isArray(debugHeaderValue)) {\n\t\t\t\treturn new HttpErrorResponse(400, `Invalid format of ${debugHeader}`)\n\t\t\t}\n\t\t\tconst requestDebug = debugHeaderValue === '1' && fetchedMemberships.some(it => schema.acl.roles[it.role]?.debug)\n\t\t\tif (requestDebug) {\n\t\t\t\tcontext.requestDebugMode = true\n\t\t\t}\n\n\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\tconst { schema: graphQlSchema, permissions, allPermissions } = await timer(\n\t\t\t\t'GraphQLSchemaCreate',\n\t\t\t\t() =>\n\t\t\t\t\tthis.graphQlSchemaFactory.create(schema, {\n\t\t\t\t\t\tprojectRoles: projectRoles,\n\t\t\t\t\t}, project),\n\t\t\t)\n\n\t\t\tconst schemaDatabaseMetadata = await projectContainer.projectDatabaseMetadataResolver.resolveDatabaseMetadata(systemDatabase, schema, stage.schema)\n\n\t\t\t// Test-transaction mode: if the request carries a session header, bind its content DB\n\t\t\t// client to the session's pinned (rolled-back-later) transaction. Decided here, from the\n\t\t\t// request itself — no async-context routing.\n\t\t\tlet testContentDatabase: Client | undefined\n\t\t\tif (this.testTransactionService.isEnabled()) {\n\t\t\t\tconst headerValue = request.headers[testSessionHeader]\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tconst token = Array.isArray(headerValue) ? headerValue[0] : headerValue\n\t\t\t\t\ttestContentDatabase = await this.testTransactionService.resolveContentClient(\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\tproject.slug,\n\t\t\t\t\t\tprojectContainer.connection,\n\t\t\t\t\t\tstage.schema,\n\t\t\t\t\t\t{ module: 'content' },\n\t\t\t\t\t)\n\t\t\t\t\tif (!testContentDatabase) {\n\t\t\t\t\t\treturn new HttpErrorResponse(400, 'Unknown or expired test transaction session')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst handler = await (async () => {\n\t\t\t\tconst existingHandler = handlerCache.get(graphQlSchema)\n\t\t\t\tif (existingHandler) {\n\t\t\t\t\treturn existingHandler\n\t\t\t\t}\n\t\t\t\tconst newHandler = await this.handlerFactory.create(graphQlSchema)\n\t\t\t\thandlerCache.set(graphQlSchema, newHandler)\n\t\t\t\treturn newHandler\n\t\t\t})()\n\n\t\t\tawait logger.scope(async logger => {\n\t\t\t\tlogger.debug('Content query processing started')\n\n\t\t\t\tawait timer('GraphQL', () =>\n\t\t\t\t\thandler({\n\t\t\t\t\t\trequest: koa.request,\n\t\t\t\t\t\tresponse: koa.response,\n\t\t\t\t\t\tcreateContext: ({ operation }) => {\n\t\t\t\t\t\t\t;(koa.state as GraphQLKoaState).graphql = {\n\t\t\t\t\t\t\t\toperationName: operation,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst baseConnection = operation === 'query' ? projectContainer.readConnection : projectContainer.connection\n\t\t\t\t\t\t\tconst maxConnectionsPerRequest = 'maxConnectionsPerRequest' in project.db\n\t\t\t\t\t\t\t\t? project.db.maxConnectionsPerRequest\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t// Optionally cap how many pool connections this single request may hold concurrently,\n\t\t\t\t\t\t\t// so one request cannot starve the shared pool under high concurrency. Defaults to unlimited.\n\t\t\t\t\t\t\tconst connection = maxConnectionsPerRequest !== undefined\n\t\t\t\t\t\t\t\t? baseConnection.withMaxConnections(maxConnectionsPerRequest)\n\t\t\t\t\t\t\t\t: baseConnection\n\t\t\t\t\t\t\tconst contentDatabase = testContentDatabase ?? connection.createClient(stage.schema, { module: 'content' })\n\n\t\t\t\t\t\t\tconst identityVariables = createAclVariables(schema.acl, memberships)\n\t\t\t\t\t\t\tlet identityId = authResult.identityId\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tauthResult.assumedIdentityId\n\t\t\t\t\t\t\t\t&& memberships.some(it => schema.acl.roles[it.role].system?.assumeIdentity)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tidentityId = authResult.assumedIdentityId\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tschemaMeta: { id: schemaWithMeta.meta.id },\n\t\t\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\t\t\tpermissions,\n\t\t\t\t\t\t\t\tallPermissions,\n\t\t\t\t\t\t\t\tsystemSchema: projectContainer.systemDatabaseContextFactory.schemaName,\n\t\t\t\t\t\t\t\tstage,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t\tuserInfo: {\n\t\t\t\t\t\t\t\t\tipAddress: clientIp,\n\t\t\t\t\t\t\t\t\tuserAgent: authResult.clientUserAgent ?? null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\texecutionContainer,\n\t\t\t\t\t\t\t\ttimer,\n\t\t\t\t\t\t\t\trequestDebug,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\tlogger.debug('Content query finished')\n\t\t\t})\n\n\t\t\tnotModifiedRes?.setResponseHeader(context.response)\n\t\t}\n\t}\n}\n"],"names":["HttpErrorResponse","StageBySlugQuery","HttpResponse","logger","createAclVariables"],"mappings":";;;;;;AAaA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAEnB,MAAM,4BAA4B;AAAA,EACxC,YACkB,oBACA,2BACA,gBACA,wBACA,sBACA,wBAChB;AANgB,SAAA,qBAAA;AACA,SAAA,4BAAA;AACA,SAAA,iBAAA;AACA,SAAA,yBAAA;AACA,SAAA,uBAAA;AACA,SAAA,yBAAA;AAAA,EAElB;AAAA,EAEA,SAAyB;AACxB,UAAM,mCAAmB,QAAA;AACzB,WAAO,OAAM,YAAW;AACvB,YAAM,EAAE,QAAQ,OAAO,cAAc,YAAY,SAAS,KAAK,aAAa;AAC5E,UAAI,CAAC,YAAY;AAChB,eAAO,IA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IACnD;AAAA,EACD;AACD;;"}
|
|
1
|
+
{"version":3,"file":"ContentApiControllerFactory.cjs","sources":["../../../../../packages/engine-http/src/content/ContentApiControllerFactory.ts"],"sourcesContent":["import { createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'\nimport { StageBySlugQuery } from '@contember/engine-system-api'\nimport { Client, RequestMemoryBudget, RequestMemoryBudgetOptions } from '@contember/database'\nimport { GraphQLSchema } from 'graphql'\nimport { HttpController } from '../application/index.js'\nimport { HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport { GraphQLKoaState } from '../graphql/index.js'\nimport { ProjectContextResolver } from '../project-common/index.js'\nimport { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryHandlerFactory.js'\nimport { GraphQlSchemaFactory } from './GraphQlSchemaFactory.js'\nimport { NotModifiedChecker } from './NotModifiedChecker.js'\nimport { TestTransactionService } from '../testing/index.js'\nimport { isTruthyHeader } from '../utils/truthyHeader.js'\n\nconst debugHeader = 'x-contember-debug'\nconst testSessionHeader = 'x-contember-test-session'\nconst forcePrimaryHeader = 'x-contember-force-primary'\n\nexport class ContentApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly notModifiedChecker: NotModifiedChecker,\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly handlerFactory: ContentQueryHandlerFactory,\n\t\tprivate readonly projectContextResolver: ProjectContextResolver,\n\t\tprivate readonly graphQlSchemaFactory: GraphQlSchemaFactory,\n\t\tprivate readonly testTransactionService: TestTransactionService,\n\t\tprivate readonly forcePrimaryHeaderEnabled: boolean,\n\t\tprivate readonly memoryBudgetOptions?: RequestMemoryBudgetOptions,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\tconst handlerCache = new WeakMap<GraphQLSchema, ContentQueryHandler>()\n\t\treturn async context => {\n\t\t\tconst { params, timer, projectGroup, authResult, request, koa, clientIp } = context\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\t\t\tconst { projectContainer, project } = await this.projectContextResolver.resolve(context)\n\n\t\t\tconst logger = context.logger.child({\n\t\t\t\tproject: project.slug,\n\t\t\t})\n\n\t\t\tconst forcePrimary = this.forcePrimaryHeaderEnabled && isTruthyHeader(request, forcePrimaryHeader)\n\t\t\t// Without a replica, forced reads change nothing, so clients need not open a window.\n\t\t\tconst markMutations = this.forcePrimaryHeaderEnabled && projectContainer.readConnection !== projectContainer.connection\n\t\t\tconst systemDatabase = forcePrimary ? projectContainer.systemDatabaseContext : projectContainer.systemReadDatabaseContext\n\t\t\tconst stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))\n\t\t\tif (!stage) {\n\t\t\t\treturn new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)\n\t\t\t}\n\t\t\tconst notModifiedRes = await this.notModifiedChecker.checkNotModified({\n\t\t\t\trequest: context.request,\n\t\t\t\tbody: context.body,\n\t\t\t\ttimer: context.timer,\n\t\t\t\tsystemDatabase,\n\t\t\t\tstageId: stage.id,\n\t\t\t})\n\t\t\tif (notModifiedRes?.isModified === false) {\n\t\t\t\treturn new HttpResponse(304)\n\t\t\t}\n\n\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabase, stage: stage.slug, normalize: true })\n\t\t\tconst schema = schemaWithMeta.schema\n\t\t\tconst { effective: memberships, fetched: fetchedMemberships } = await timer(\n\t\t\t\t'MembershipFetch',\n\t\t\t\t() =>\n\t\t\t\t\tprojectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\t\trequest: koa,\n\t\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\t\tpersonId: authResult.personId ?? undefined,\n\t\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t)\n\n\t\t\tlogger.debug('Memberships fetched', { memberships })\n\n\t\t\tconst debugHeaderValue = request.headers[debugHeader]\n\t\t\tif (Array.isArray(debugHeaderValue)) {\n\t\t\t\treturn new HttpErrorResponse(400, `Invalid format of ${debugHeader}`)\n\t\t\t}\n\t\t\tconst requestDebug = debugHeaderValue === '1' && fetchedMemberships.some(it => schema.acl.roles[it.role]?.debug)\n\t\t\tif (requestDebug) {\n\t\t\t\tcontext.requestDebugMode = true\n\t\t\t}\n\n\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\tconst { schema: graphQlSchema, permissions, allPermissions } = await timer(\n\t\t\t\t'GraphQLSchemaCreate',\n\t\t\t\t() =>\n\t\t\t\t\tthis.graphQlSchemaFactory.create(schema, {\n\t\t\t\t\t\tprojectRoles: projectRoles,\n\t\t\t\t\t}, project),\n\t\t\t)\n\n\t\t\tconst schemaDatabaseMetadata = await projectContainer.projectDatabaseMetadataResolver.resolveDatabaseMetadata(systemDatabase, schema, stage.schema)\n\n\t\t\t// Test-transaction mode: if the request carries a session header, bind its content DB\n\t\t\t// client to the session's pinned (rolled-back-later) transaction. Decided here, from the\n\t\t\t// request itself — no async-context routing.\n\t\t\tlet testContentDatabase: Client | undefined\n\t\t\tif (this.testTransactionService.isEnabled()) {\n\t\t\t\tconst headerValue = request.headers[testSessionHeader]\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tconst token = Array.isArray(headerValue) ? headerValue[0] : headerValue\n\t\t\t\t\ttestContentDatabase = await this.testTransactionService.resolveContentClient(\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\tproject.slug,\n\t\t\t\t\t\tprojectContainer.connection,\n\t\t\t\t\t\tstage.schema,\n\t\t\t\t\t\t{ module: 'content' },\n\t\t\t\t\t)\n\t\t\t\t\tif (!testContentDatabase) {\n\t\t\t\t\t\treturn new HttpErrorResponse(400, 'Unknown or expired test transaction session')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst handler = await (async () => {\n\t\t\t\tconst existingHandler = handlerCache.get(graphQlSchema)\n\t\t\t\tif (existingHandler) {\n\t\t\t\t\treturn existingHandler\n\t\t\t\t}\n\t\t\t\tconst newHandler = await this.handlerFactory.create(graphQlSchema)\n\t\t\t\thandlerCache.set(graphQlSchema, newHandler)\n\t\t\t\treturn newHandler\n\t\t\t})()\n\n\t\t\tawait logger.scope(async logger => {\n\t\t\t\tlogger.debug('Content query processing started')\n\n\t\t\t\tawait timer('GraphQL', () =>\n\t\t\t\t\thandler({\n\t\t\t\t\t\trequest: koa.request,\n\t\t\t\t\t\tresponse: koa.response,\n\t\t\t\t\t\tcreateContext: ({ operation, queryHash }) => {\n\t\t\t\t\t\t\t// Clients open a primary read window only on this marker, so it must not be sent while the header is ignored.\n\t\t\t\t\t\t\tif (operation === 'mutation' && markMutations) {\n\t\t\t\t\t\t\t\tkoa.response.set('X-Contember-Mutation', '1')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t;(koa.state as GraphQLKoaState).graphql = {\n\t\t\t\t\t\t\t\toperationName: operation,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst baseConnection = operation === 'query' && !forcePrimary ? projectContainer.readConnection : projectContainer.connection\n\t\t\t\t\t\t\tconst maxConnectionsPerRequest = 'maxConnectionsPerRequest' in project.db\n\t\t\t\t\t\t\t\t? project.db.maxConnectionsPerRequest\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t// Optionally cap how many pool connections this single request may hold concurrently,\n\t\t\t\t\t\t\t// so one request cannot starve the shared pool under high concurrency. Defaults to unlimited.\n\t\t\t\t\t\t\tconst connection = maxConnectionsPerRequest !== undefined\n\t\t\t\t\t\t\t\t? baseConnection.withMaxConnections(maxConnectionsPerRequest)\n\t\t\t\t\t\t\t\t: baseConnection\n\t\t\t\t\t\t\tconst memoryBudget = this.memoryBudgetOptions\n\t\t\t\t\t\t\t\t? new RequestMemoryBudget(this.memoryBudgetOptions)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\tconst contentDatabase = testContentDatabase ?? connection.createClient(stage.schema, { module: 'content' })\n\t\t\t\t\t\t\tif (memoryBudget) {\n\t\t\t\t\t\t\t\tconst logMemory = () => {\n\t\t\t\t\t\t\t\t\tkoa.res.off('finish', logMemory)\n\t\t\t\t\t\t\t\t\tkoa.res.off('close', logMemory)\n\t\t\t\t\t\t\t\t\tconst memory = memoryBudget.snapshot()\n\t\t\t\t\t\t\t\t\tif (memory.warningThresholdExceeded) {\n\t\t\t\t\t\t\t\t\t\tlogger.warn('Content request memory usage', { operation, queryHash, ...memory })\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tkoa.res.once('finish', logMemory)\n\t\t\t\t\t\t\t\tkoa.res.once('close', logMemory)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst identityVariables = createAclVariables(schema.acl, memberships)\n\t\t\t\t\t\t\tlet identityId = authResult.identityId\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tauthResult.assumedIdentityId\n\t\t\t\t\t\t\t\t&& memberships.some(it => schema.acl.roles[it.role].system?.assumeIdentity)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tidentityId = authResult.assumedIdentityId\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tmemoryBudget,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tschemaMeta: { id: schemaWithMeta.meta.id },\n\t\t\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\t\t\tpermissions,\n\t\t\t\t\t\t\t\tallPermissions,\n\t\t\t\t\t\t\t\tsystemSchema: projectContainer.systemDatabaseContextFactory.schemaName,\n\t\t\t\t\t\t\t\tstage,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t\tuserInfo: {\n\t\t\t\t\t\t\t\t\tipAddress: clientIp,\n\t\t\t\t\t\t\t\t\tuserAgent: authResult.clientUserAgent ?? null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tmemoryBudget,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\texecutionContainer,\n\t\t\t\t\t\t\t\ttimer,\n\t\t\t\t\t\t\t\trequestDebug,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\tlogger.debug('Content query finished')\n\t\t\t})\n\n\t\t\tnotModifiedRes?.setResponseHeader(context.response)\n\t\t}\n\t}\n}\n"],"names":["HttpErrorResponse","isTruthyHeader","StageBySlugQuery","HttpResponse","logger","RequestMemoryBudget","createAclVariables"],"mappings":";;;;;;;;;AAcA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAEpB,MAAM,4BAA4B;AAAA,EACxC,YACkB,oBACA,2BACA,gBACA,wBACA,sBACA,wBACA,2BACA,qBAChB;AARgB,SAAA,qBAAA;AACA,SAAA,4BAAA;AACA,SAAA,iBAAA;AACA,SAAA,yBAAA;AACA,SAAA,uBAAA;AACA,SAAA,yBAAA;AACA,SAAA,4BAAA;AACA,SAAA,sBAAA;AAAA,EAElB;AAAA,EAEA,SAAyB;AACxB,UAAM,mCAAmB,QAAA;AACzB,WAAO,OAAM,YAAW;AACvB,YAAM,EAAE,QAAQ,OAAO,cAAc,YAAY,SAAS,KAAK,aAAa;AAC5E,UAAI,CAAC,YAAY;AAChB,eAAO,IAAIA,aAAAA,kBAAkB,KAAK,yBAAyB;AAAA,MAC5D;A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GAAG,IAAI,EAAE,QAAQ,cAAc,GACzE;AACD,2BAAa,WAAW;AAAA,YACzB;AAEA,kBAAM,qBAAqB,KAAK,0BAA0B,OAAO;AAAA,cAChE,IAAI;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA,YAAY,EAAE,IAAI,eAAe,KAAK,GAAA;AAAA,cACtC;AAAA,cACA;AAAA,cACA;AAAA,cACA,cAAc,iBAAiB,6BAA6B;AAAA,cAC5D;AAAA,cACA;AAAA,cACA,UAAU;AAAA,gBACT,WAAW;AAAA,gBACX,WAAW,WAAW,mBAAmB;AAAA,cAAA;AAAA,YAC1C,CACA;AAED,mBAAO;AAAA,cACN,IAAI;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA;AAAA,UAEF;AAAA,QAAA,CACA,CAAC;AACHF,gBAAO,MAAM,wBAAwB;AAAA,MACtC,CAAC;AAED,sBAAgB,kBAAkB,QAAQ,QAAQ;AAAA,IACnD;AAAA,EACD;AACD;;"}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { createAclVariables } from "@contember/engine-content-api";
|
|
2
2
|
import { StageBySlugQuery } from "@contember/engine-system-api";
|
|
3
|
+
import { RequestMemoryBudget } from "@contember/database";
|
|
3
4
|
import { HttpErrorResponse, HttpResponse } from "../common/HttpResponse.js";
|
|
4
5
|
import "ipaddr.js";
|
|
6
|
+
import "@contember/engine-tenant-api";
|
|
7
|
+
import { isTruthyHeader } from "../utils/truthyHeader.js";
|
|
5
8
|
const debugHeader = "x-contember-debug";
|
|
6
9
|
const testSessionHeader = "x-contember-test-session";
|
|
10
|
+
const forcePrimaryHeader = "x-contember-force-primary";
|
|
7
11
|
class ContentApiControllerFactory {
|
|
8
|
-
constructor(notModifiedChecker, executionContainerFactory, handlerFactory, projectContextResolver, graphQlSchemaFactory, testTransactionService) {
|
|
12
|
+
constructor(notModifiedChecker, executionContainerFactory, handlerFactory, projectContextResolver, graphQlSchemaFactory, testTransactionService, forcePrimaryHeaderEnabled, memoryBudgetOptions) {
|
|
9
13
|
this.notModifiedChecker = notModifiedChecker;
|
|
10
14
|
this.executionContainerFactory = executionContainerFactory;
|
|
11
15
|
this.handlerFactory = handlerFactory;
|
|
12
16
|
this.projectContextResolver = projectContextResolver;
|
|
13
17
|
this.graphQlSchemaFactory = graphQlSchemaFactory;
|
|
14
18
|
this.testTransactionService = testTransactionService;
|
|
19
|
+
this.forcePrimaryHeaderEnabled = forcePrimaryHeaderEnabled;
|
|
20
|
+
this.memoryBudgetOptions = memoryBudgetOptions;
|
|
15
21
|
}
|
|
16
22
|
create() {
|
|
17
23
|
const handlerCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -24,7 +30,9 @@ class ContentApiControllerFactory {
|
|
|
24
30
|
const logger = context.logger.child({
|
|
25
31
|
project: project.slug
|
|
26
32
|
});
|
|
27
|
-
const
|
|
33
|
+
const forcePrimary = this.forcePrimaryHeaderEnabled && isTruthyHeader(request, forcePrimaryHeader);
|
|
34
|
+
const markMutations = this.forcePrimaryHeaderEnabled && projectContainer.readConnection !== projectContainer.connection;
|
|
35
|
+
const systemDatabase = forcePrimary ? projectContainer.systemDatabaseContext : projectContainer.systemReadDatabaseContext;
|
|
28
36
|
const stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug));
|
|
29
37
|
if (!stage) {
|
|
30
38
|
return new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`);
|
|
@@ -102,14 +110,30 @@ class ContentApiControllerFactory {
|
|
|
102
110
|
await timer("GraphQL", () => handler({
|
|
103
111
|
request: koa.request,
|
|
104
112
|
response: koa.response,
|
|
105
|
-
createContext: ({ operation }) => {
|
|
113
|
+
createContext: ({ operation, queryHash }) => {
|
|
114
|
+
if (operation === "mutation" && markMutations) {
|
|
115
|
+
koa.response.set("X-Contember-Mutation", "1");
|
|
116
|
+
}
|
|
106
117
|
koa.state.graphql = {
|
|
107
118
|
operationName: operation
|
|
108
119
|
};
|
|
109
|
-
const baseConnection = operation === "query" ? projectContainer.readConnection : projectContainer.connection;
|
|
120
|
+
const baseConnection = operation === "query" && !forcePrimary ? projectContainer.readConnection : projectContainer.connection;
|
|
110
121
|
const maxConnectionsPerRequest = "maxConnectionsPerRequest" in project.db ? project.db.maxConnectionsPerRequest : void 0;
|
|
111
122
|
const connection = maxConnectionsPerRequest !== void 0 ? baseConnection.withMaxConnections(maxConnectionsPerRequest) : baseConnection;
|
|
123
|
+
const memoryBudget = this.memoryBudgetOptions ? new RequestMemoryBudget(this.memoryBudgetOptions) : void 0;
|
|
112
124
|
const contentDatabase = testContentDatabase ?? connection.createClient(stage.schema, { module: "content" });
|
|
125
|
+
if (memoryBudget) {
|
|
126
|
+
const logMemory = () => {
|
|
127
|
+
koa.res.off("finish", logMemory);
|
|
128
|
+
koa.res.off("close", logMemory);
|
|
129
|
+
const memory = memoryBudget.snapshot();
|
|
130
|
+
if (memory.warningThresholdExceeded) {
|
|
131
|
+
logger2.warn("Content request memory usage", { operation, queryHash, ...memory });
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
koa.res.once("finish", logMemory);
|
|
135
|
+
koa.res.once("close", logMemory);
|
|
136
|
+
}
|
|
113
137
|
const identityVariables = createAclVariables(schema.acl, memberships);
|
|
114
138
|
let identityId = authResult.identityId;
|
|
115
139
|
if (authResult.assumedIdentityId && memberships.some((it) => schema.acl.roles[it.role].system?.assumeIdentity)) {
|
|
@@ -117,6 +141,7 @@ class ContentApiControllerFactory {
|
|
|
117
141
|
}
|
|
118
142
|
const executionContainer = this.executionContainerFactory.create({
|
|
119
143
|
db: contentDatabase,
|
|
144
|
+
memoryBudget,
|
|
120
145
|
identityVariables,
|
|
121
146
|
identityId,
|
|
122
147
|
schema,
|
|
@@ -134,6 +159,7 @@ class ContentApiControllerFactory {
|
|
|
134
159
|
});
|
|
135
160
|
return {
|
|
136
161
|
db: contentDatabase,
|
|
162
|
+
memoryBudget,
|
|
137
163
|
identityVariables,
|
|
138
164
|
identityId,
|
|
139
165
|
executionContainer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentApiControllerFactory.js","sources":["../../../../../packages/engine-http/src/content/ContentApiControllerFactory.ts"],"sourcesContent":["import { createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'\nimport { StageBySlugQuery } from '@contember/engine-system-api'\nimport { Client } from '@contember/database'\nimport { GraphQLSchema } from 'graphql'\nimport { HttpController } from '../application/index.js'\nimport { HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport { GraphQLKoaState } from '../graphql/index.js'\nimport { ProjectContextResolver } from '../project-common/index.js'\nimport { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryHandlerFactory.js'\nimport { GraphQlSchemaFactory } from './GraphQlSchemaFactory.js'\nimport { NotModifiedChecker } from './NotModifiedChecker.js'\nimport { TestTransactionService } from '../testing/index.js'\n\nconst debugHeader = 'x-contember-debug'\nconst testSessionHeader = 'x-contember-test-session'\n\nexport class ContentApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly notModifiedChecker: NotModifiedChecker,\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly handlerFactory: ContentQueryHandlerFactory,\n\t\tprivate readonly projectContextResolver: ProjectContextResolver,\n\t\tprivate readonly graphQlSchemaFactory: GraphQlSchemaFactory,\n\t\tprivate readonly testTransactionService: TestTransactionService,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\tconst handlerCache = new WeakMap<GraphQLSchema, ContentQueryHandler>()\n\t\treturn async context => {\n\t\t\tconst { params, timer, projectGroup, authResult, request, koa, clientIp } = context\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\t\t\tconst { projectContainer, project } = await this.projectContextResolver.resolve(context)\n\n\t\t\tconst logger = context.logger.child({\n\t\t\t\tproject: project.slug,\n\t\t\t})\n\n\t\t\tconst systemDatabase = projectContainer.systemReadDatabaseContext\n\t\t\tconst stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))\n\t\t\tif (!stage) {\n\t\t\t\treturn new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)\n\t\t\t}\n\t\t\tconst notModifiedRes = await this.notModifiedChecker.checkNotModified({\n\t\t\t\trequest: context.request,\n\t\t\t\tbody: context.body,\n\t\t\t\ttimer: context.timer,\n\t\t\t\tsystemDatabase,\n\t\t\t\tstageId: stage.id,\n\t\t\t})\n\t\t\tif (notModifiedRes?.isModified === false) {\n\t\t\t\treturn new HttpResponse(304)\n\t\t\t}\n\n\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabase, stage: stage.slug, normalize: true })\n\t\t\tconst schema = schemaWithMeta.schema\n\t\t\tconst { effective: memberships, fetched: fetchedMemberships } = await timer(\n\t\t\t\t'MembershipFetch',\n\t\t\t\t() =>\n\t\t\t\t\tprojectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\t\trequest: koa,\n\t\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\t\tpersonId: authResult.personId ?? undefined,\n\t\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t)\n\n\t\t\tlogger.debug('Memberships fetched', { memberships })\n\n\t\t\tconst debugHeaderValue = request.headers[debugHeader]\n\t\t\tif (Array.isArray(debugHeaderValue)) {\n\t\t\t\treturn new HttpErrorResponse(400, `Invalid format of ${debugHeader}`)\n\t\t\t}\n\t\t\tconst requestDebug = debugHeaderValue === '1' && fetchedMemberships.some(it => schema.acl.roles[it.role]?.debug)\n\t\t\tif (requestDebug) {\n\t\t\t\tcontext.requestDebugMode = true\n\t\t\t}\n\n\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\tconst { schema: graphQlSchema, permissions, allPermissions } = await timer(\n\t\t\t\t'GraphQLSchemaCreate',\n\t\t\t\t() =>\n\t\t\t\t\tthis.graphQlSchemaFactory.create(schema, {\n\t\t\t\t\t\tprojectRoles: projectRoles,\n\t\t\t\t\t}, project),\n\t\t\t)\n\n\t\t\tconst schemaDatabaseMetadata = await projectContainer.projectDatabaseMetadataResolver.resolveDatabaseMetadata(systemDatabase, schema, stage.schema)\n\n\t\t\t// Test-transaction mode: if the request carries a session header, bind its content DB\n\t\t\t// client to the session's pinned (rolled-back-later) transaction. Decided here, from the\n\t\t\t// request itself — no async-context routing.\n\t\t\tlet testContentDatabase: Client | undefined\n\t\t\tif (this.testTransactionService.isEnabled()) {\n\t\t\t\tconst headerValue = request.headers[testSessionHeader]\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tconst token = Array.isArray(headerValue) ? headerValue[0] : headerValue\n\t\t\t\t\ttestContentDatabase = await this.testTransactionService.resolveContentClient(\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\tproject.slug,\n\t\t\t\t\t\tprojectContainer.connection,\n\t\t\t\t\t\tstage.schema,\n\t\t\t\t\t\t{ module: 'content' },\n\t\t\t\t\t)\n\t\t\t\t\tif (!testContentDatabase) {\n\t\t\t\t\t\treturn new HttpErrorResponse(400, 'Unknown or expired test transaction session')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst handler = await (async () => {\n\t\t\t\tconst existingHandler = handlerCache.get(graphQlSchema)\n\t\t\t\tif (existingHandler) {\n\t\t\t\t\treturn existingHandler\n\t\t\t\t}\n\t\t\t\tconst newHandler = await this.handlerFactory.create(graphQlSchema)\n\t\t\t\thandlerCache.set(graphQlSchema, newHandler)\n\t\t\t\treturn newHandler\n\t\t\t})()\n\n\t\t\tawait logger.scope(async logger => {\n\t\t\t\tlogger.debug('Content query processing started')\n\n\t\t\t\tawait timer('GraphQL', () =>\n\t\t\t\t\thandler({\n\t\t\t\t\t\trequest: koa.request,\n\t\t\t\t\t\tresponse: koa.response,\n\t\t\t\t\t\tcreateContext: ({ operation }) => {\n\t\t\t\t\t\t\t;(koa.state as GraphQLKoaState).graphql = {\n\t\t\t\t\t\t\t\toperationName: operation,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst baseConnection = operation === 'query' ? projectContainer.readConnection : projectContainer.connection\n\t\t\t\t\t\t\tconst maxConnectionsPerRequest = 'maxConnectionsPerRequest' in project.db\n\t\t\t\t\t\t\t\t? project.db.maxConnectionsPerRequest\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t// Optionally cap how many pool connections this single request may hold concurrently,\n\t\t\t\t\t\t\t// so one request cannot starve the shared pool under high concurrency. Defaults to unlimited.\n\t\t\t\t\t\t\tconst connection = maxConnectionsPerRequest !== undefined\n\t\t\t\t\t\t\t\t? baseConnection.withMaxConnections(maxConnectionsPerRequest)\n\t\t\t\t\t\t\t\t: baseConnection\n\t\t\t\t\t\t\tconst contentDatabase = testContentDatabase ?? connection.createClient(stage.schema, { module: 'content' })\n\n\t\t\t\t\t\t\tconst identityVariables = createAclVariables(schema.acl, memberships)\n\t\t\t\t\t\t\tlet identityId = authResult.identityId\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tauthResult.assumedIdentityId\n\t\t\t\t\t\t\t\t&& memberships.some(it => schema.acl.roles[it.role].system?.assumeIdentity)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tidentityId = authResult.assumedIdentityId\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tschemaMeta: { id: schemaWithMeta.meta.id },\n\t\t\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\t\t\tpermissions,\n\t\t\t\t\t\t\t\tallPermissions,\n\t\t\t\t\t\t\t\tsystemSchema: projectContainer.systemDatabaseContextFactory.schemaName,\n\t\t\t\t\t\t\t\tstage,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t\tuserInfo: {\n\t\t\t\t\t\t\t\t\tipAddress: clientIp,\n\t\t\t\t\t\t\t\t\tuserAgent: authResult.clientUserAgent ?? null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\texecutionContainer,\n\t\t\t\t\t\t\t\ttimer,\n\t\t\t\t\t\t\t\trequestDebug,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\tlogger.debug('Content query finished')\n\t\t\t})\n\n\t\t\tnotModifiedRes?.setResponseHeader(context.response)\n\t\t}\n\t}\n}\n"],"names":["logger"],"mappings":";;;;AAaA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAEnB,MAAM,4BAA4B;AAAA,EACxC,YACkB,oBACA,2BACA,gBACA,wBACA,sBACA,wBAChB;AANgB,SAAA,qBAAA;AACA,SAAA,4BAAA;AACA,SAAA,iBAAA;AACA,SAAA,yBAAA;AACA,SAAA,uBAAA;AACA,SAAA,yBAAA;AAAA,EAElB;AAAA,EAEA,SAAyB;AACxB,UAAM,mCAAmB,QAAA;AACzB,WAAO,OAAM,YAAW;AACvB,YAAM,EAAE,QAAQ,OAAO,cAAc,YAAY,SAAS,KAAK,aAAa;AAC5E,UAAI,CAAC,YAAY;AAChB,eAAO,IAAI,kBAAkB,KAAK,yBAAyB;AAAA,MAC5D;AACA,YAAM,EAAE,kBAAkB,QAAA,IAAY,MAAM,KAAK,uBAAuB,QA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AA0B,UAAU;AAAA,cACzC,eAAe;AAAA,YAAA;AAGhB,kBAAM,iBAAiB,cAAc,UAAU,iBAAiB,iBAAiB,iBAAiB;AAClG,kBAAM,2BAA2B,8BAA8B,QAAQ,KACpE,QAAQ,GAAG,2BACX;AAGH,kBAAM,aAAa,6BAA6B,SAC7C,eAAe,mBAAmB,wBAAwB,IAC1D;AACH,kBAAM,kBAAkB,uBAAuB,WAAW,aAAa,MAAM,QAAQ,EAAE,QAAQ,WAAW;AAE1G,kBAAM,oBAAoB,mBAAmB,OAAO,KAAK,WAAW;AACpE,gBAAI,aAAa,WAAW;AAC5B,gBACC,WAAW,qBACR,YAAY,KAAK,CAAA,OAAM,OAAO,IAAI,MAAM,GAAG,IAAI,EAAE,QAAQ,cAAc,GACzE;AACD,2BAAa,WAAW;AAAA,YACzB;AAEA,kBAAM,qBAAqB,KAAK,0BAA0B,OAAO;AAAA,cAChE,IAAI;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA,YAAY,EAAE,IAAI,eAAe,KAAK,GAAA;AAAA,cACtC;AAAA,cACA;AAAA,cACA;AAAA,cACA,cAAc,iBAAiB,6BAA6B;AAAA,cAC5D;AAAA,cACA;AAAA,cACA,UAAU;AAAA,gBACT,WAAW;AAAA,gBACX,WAAW,WAAW,mBAAmB;AAAA,cAAA;AAAA,YAC1C,CACA;AAED,mBAAO;AAAA,cACN,IAAI;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA;AAAA,UAEF;AAAA,QAAA,CACA,CAAC;AACHA,gBAAO,MAAM,wBAAwB;AAAA,MACtC,CAAC;AAED,sBAAgB,kBAAkB,QAAQ,QAAQ;AAAA,IACnD;AAAA,EACD;AACD;"}
|
|
1
|
+
{"version":3,"file":"ContentApiControllerFactory.js","sources":["../../../../../packages/engine-http/src/content/ContentApiControllerFactory.ts"],"sourcesContent":["import { createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'\nimport { StageBySlugQuery } from '@contember/engine-system-api'\nimport { Client, RequestMemoryBudget, RequestMemoryBudgetOptions } from '@contember/database'\nimport { GraphQLSchema } from 'graphql'\nimport { HttpController } from '../application/index.js'\nimport { HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport { GraphQLKoaState } from '../graphql/index.js'\nimport { ProjectContextResolver } from '../project-common/index.js'\nimport { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryHandlerFactory.js'\nimport { GraphQlSchemaFactory } from './GraphQlSchemaFactory.js'\nimport { NotModifiedChecker } from './NotModifiedChecker.js'\nimport { TestTransactionService } from '../testing/index.js'\nimport { isTruthyHeader } from '../utils/truthyHeader.js'\n\nconst debugHeader = 'x-contember-debug'\nconst testSessionHeader = 'x-contember-test-session'\nconst forcePrimaryHeader = 'x-contember-force-primary'\n\nexport class ContentApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly notModifiedChecker: NotModifiedChecker,\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly handlerFactory: ContentQueryHandlerFactory,\n\t\tprivate readonly projectContextResolver: ProjectContextResolver,\n\t\tprivate readonly graphQlSchemaFactory: GraphQlSchemaFactory,\n\t\tprivate readonly testTransactionService: TestTransactionService,\n\t\tprivate readonly forcePrimaryHeaderEnabled: boolean,\n\t\tprivate readonly memoryBudgetOptions?: RequestMemoryBudgetOptions,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\tconst handlerCache = new WeakMap<GraphQLSchema, ContentQueryHandler>()\n\t\treturn async context => {\n\t\t\tconst { params, timer, projectGroup, authResult, request, koa, clientIp } = context\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\t\t\tconst { projectContainer, project } = await this.projectContextResolver.resolve(context)\n\n\t\t\tconst logger = context.logger.child({\n\t\t\t\tproject: project.slug,\n\t\t\t})\n\n\t\t\tconst forcePrimary = this.forcePrimaryHeaderEnabled && isTruthyHeader(request, forcePrimaryHeader)\n\t\t\t// Without a replica, forced reads change nothing, so clients need not open a window.\n\t\t\tconst markMutations = this.forcePrimaryHeaderEnabled && projectContainer.readConnection !== projectContainer.connection\n\t\t\tconst systemDatabase = forcePrimary ? projectContainer.systemDatabaseContext : projectContainer.systemReadDatabaseContext\n\t\t\tconst stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))\n\t\t\tif (!stage) {\n\t\t\t\treturn new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)\n\t\t\t}\n\t\t\tconst notModifiedRes = await this.notModifiedChecker.checkNotModified({\n\t\t\t\trequest: context.request,\n\t\t\t\tbody: context.body,\n\t\t\t\ttimer: context.timer,\n\t\t\t\tsystemDatabase,\n\t\t\t\tstageId: stage.id,\n\t\t\t})\n\t\t\tif (notModifiedRes?.isModified === false) {\n\t\t\t\treturn new HttpResponse(304)\n\t\t\t}\n\n\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabase, stage: stage.slug, normalize: true })\n\t\t\tconst schema = schemaWithMeta.schema\n\t\t\tconst { effective: memberships, fetched: fetchedMemberships } = await timer(\n\t\t\t\t'MembershipFetch',\n\t\t\t\t() =>\n\t\t\t\t\tprojectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\t\trequest: koa,\n\t\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\t\tpersonId: authResult.personId ?? undefined,\n\t\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t)\n\n\t\t\tlogger.debug('Memberships fetched', { memberships })\n\n\t\t\tconst debugHeaderValue = request.headers[debugHeader]\n\t\t\tif (Array.isArray(debugHeaderValue)) {\n\t\t\t\treturn new HttpErrorResponse(400, `Invalid format of ${debugHeader}`)\n\t\t\t}\n\t\t\tconst requestDebug = debugHeaderValue === '1' && fetchedMemberships.some(it => schema.acl.roles[it.role]?.debug)\n\t\t\tif (requestDebug) {\n\t\t\t\tcontext.requestDebugMode = true\n\t\t\t}\n\n\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\tconst { schema: graphQlSchema, permissions, allPermissions } = await timer(\n\t\t\t\t'GraphQLSchemaCreate',\n\t\t\t\t() =>\n\t\t\t\t\tthis.graphQlSchemaFactory.create(schema, {\n\t\t\t\t\t\tprojectRoles: projectRoles,\n\t\t\t\t\t}, project),\n\t\t\t)\n\n\t\t\tconst schemaDatabaseMetadata = await projectContainer.projectDatabaseMetadataResolver.resolveDatabaseMetadata(systemDatabase, schema, stage.schema)\n\n\t\t\t// Test-transaction mode: if the request carries a session header, bind its content DB\n\t\t\t// client to the session's pinned (rolled-back-later) transaction. Decided here, from the\n\t\t\t// request itself — no async-context routing.\n\t\t\tlet testContentDatabase: Client | undefined\n\t\t\tif (this.testTransactionService.isEnabled()) {\n\t\t\t\tconst headerValue = request.headers[testSessionHeader]\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tconst token = Array.isArray(headerValue) ? headerValue[0] : headerValue\n\t\t\t\t\ttestContentDatabase = await this.testTransactionService.resolveContentClient(\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\tproject.slug,\n\t\t\t\t\t\tprojectContainer.connection,\n\t\t\t\t\t\tstage.schema,\n\t\t\t\t\t\t{ module: 'content' },\n\t\t\t\t\t)\n\t\t\t\t\tif (!testContentDatabase) {\n\t\t\t\t\t\treturn new HttpErrorResponse(400, 'Unknown or expired test transaction session')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst handler = await (async () => {\n\t\t\t\tconst existingHandler = handlerCache.get(graphQlSchema)\n\t\t\t\tif (existingHandler) {\n\t\t\t\t\treturn existingHandler\n\t\t\t\t}\n\t\t\t\tconst newHandler = await this.handlerFactory.create(graphQlSchema)\n\t\t\t\thandlerCache.set(graphQlSchema, newHandler)\n\t\t\t\treturn newHandler\n\t\t\t})()\n\n\t\t\tawait logger.scope(async logger => {\n\t\t\t\tlogger.debug('Content query processing started')\n\n\t\t\t\tawait timer('GraphQL', () =>\n\t\t\t\t\thandler({\n\t\t\t\t\t\trequest: koa.request,\n\t\t\t\t\t\tresponse: koa.response,\n\t\t\t\t\t\tcreateContext: ({ operation, queryHash }) => {\n\t\t\t\t\t\t\t// Clients open a primary read window only on this marker, so it must not be sent while the header is ignored.\n\t\t\t\t\t\t\tif (operation === 'mutation' && markMutations) {\n\t\t\t\t\t\t\t\tkoa.response.set('X-Contember-Mutation', '1')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t;(koa.state as GraphQLKoaState).graphql = {\n\t\t\t\t\t\t\t\toperationName: operation,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst baseConnection = operation === 'query' && !forcePrimary ? projectContainer.readConnection : projectContainer.connection\n\t\t\t\t\t\t\tconst maxConnectionsPerRequest = 'maxConnectionsPerRequest' in project.db\n\t\t\t\t\t\t\t\t? project.db.maxConnectionsPerRequest\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t// Optionally cap how many pool connections this single request may hold concurrently,\n\t\t\t\t\t\t\t// so one request cannot starve the shared pool under high concurrency. Defaults to unlimited.\n\t\t\t\t\t\t\tconst connection = maxConnectionsPerRequest !== undefined\n\t\t\t\t\t\t\t\t? baseConnection.withMaxConnections(maxConnectionsPerRequest)\n\t\t\t\t\t\t\t\t: baseConnection\n\t\t\t\t\t\t\tconst memoryBudget = this.memoryBudgetOptions\n\t\t\t\t\t\t\t\t? new RequestMemoryBudget(this.memoryBudgetOptions)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\tconst contentDatabase = testContentDatabase ?? connection.createClient(stage.schema, { module: 'content' })\n\t\t\t\t\t\t\tif (memoryBudget) {\n\t\t\t\t\t\t\t\tconst logMemory = () => {\n\t\t\t\t\t\t\t\t\tkoa.res.off('finish', logMemory)\n\t\t\t\t\t\t\t\t\tkoa.res.off('close', logMemory)\n\t\t\t\t\t\t\t\t\tconst memory = memoryBudget.snapshot()\n\t\t\t\t\t\t\t\t\tif (memory.warningThresholdExceeded) {\n\t\t\t\t\t\t\t\t\t\tlogger.warn('Content request memory usage', { operation, queryHash, ...memory })\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tkoa.res.once('finish', logMemory)\n\t\t\t\t\t\t\t\tkoa.res.once('close', logMemory)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst identityVariables = createAclVariables(schema.acl, memberships)\n\t\t\t\t\t\t\tlet identityId = authResult.identityId\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tauthResult.assumedIdentityId\n\t\t\t\t\t\t\t\t&& memberships.some(it => schema.acl.roles[it.role].system?.assumeIdentity)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tidentityId = authResult.assumedIdentityId\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tmemoryBudget,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tschemaMeta: { id: schemaWithMeta.meta.id },\n\t\t\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\t\t\tpermissions,\n\t\t\t\t\t\t\t\tallPermissions,\n\t\t\t\t\t\t\t\tsystemSchema: projectContainer.systemDatabaseContextFactory.schemaName,\n\t\t\t\t\t\t\t\tstage,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t\tuserInfo: {\n\t\t\t\t\t\t\t\t\tipAddress: clientIp,\n\t\t\t\t\t\t\t\t\tuserAgent: authResult.clientUserAgent ?? null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tmemoryBudget,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\texecutionContainer,\n\t\t\t\t\t\t\t\ttimer,\n\t\t\t\t\t\t\t\trequestDebug,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\tlogger.debug('Content query finished')\n\t\t\t})\n\n\t\t\tnotModifiedRes?.setResponseHeader(context.response)\n\t\t}\n\t}\n}\n"],"names":["logger"],"mappings":";;;;;;;AAcA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAEpB,MAAM,4BAA4B;AAAA,EACxC,YACkB,oBACA,2BACA,gBACA,wBACA,sBACA,wBACA,2BACA,qBAChB;AARgB,SAAA,qBAAA;AACA,SAAA,4BAAA;AACA,SAAA,iBAAA;AACA,SAAA,yBAAA;AACA,SAAA,uBAAA;AACA,SAAA,yBAAA;AACA,SAAA,4BAAA;AACA,SAAA,sBAAA;AAAA,EAElB;AAAA,EAEA,SAAyB;AACxB,UAAM,mCAAmB,QAAA;AACzB,WAAO,OAAM,YAAW;AACvB,YAAM,EAAE,QAAQ,OAAO,cAAc,YAAY,SAAS,KAAK,aAAa;AAC5E,UAAI,CAAC,YAAY;AAChB,eAAO,IAAI,kBAAkB,KAAK,yBAAyB;AAAA,MAC5D;AACA,YAAM,EAAE,kBAAkB,QAAA,IAAY,MAAM,KAAK,uBAAuB,QAAQ,OAAO;AAEvF,YAAM,SAAS,QAAQ,OAAO,MAAM;AAAA,QACnC,SAAS,QAAQ;AAAA,MAAA,CACjB;AAED,YAAM,eAAe,KAAK,6BAA6B,eAAe,SAAS,kBAAkB;AAEjG,YAAM,gBAAgB,KAAK,6BAA6B,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;AAAA,cACA,UAAU;AAAA,gBACT,WAAW;AAAA,gBACX,WAAW,WAAW,mBAAmB;AAAA,cAAA;AAAA,YAC1C,CACA;AAED,mBAAO;AAAA,cACN,IAAI;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA;AAAA,UAEF;AAAA,QAAA,CACA,CAAC;AACHA,gBAAO,MAAM,wBAAwB;AAAA,MACtC,CAAC;AAED,sBAAgB,kBAAkB,QAAQ,QAAQ;AAAA,IACnD;AAAA,EACD;AACD;"}
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const node_timers = require("node:timers");
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
7
|
class ContentApiSpecificCache {
|
|
8
8
|
constructor(options) {
|
|
9
9
|
this.options = options;
|
|
10
10
|
__publicField(this, "cache", /* @__PURE__ */ new WeakMap());
|
|
11
|
+
__publicField(this, "recency", /* @__PURE__ */ new Set());
|
|
11
12
|
}
|
|
12
13
|
fetch(objectKey, scalarKey, createValue) {
|
|
13
14
|
let cacheMap = this.cache.get(objectKey);
|
|
@@ -16,24 +17,51 @@ class ContentApiSpecificCache {
|
|
|
16
17
|
this.cache.set(objectKey, cacheMap);
|
|
17
18
|
}
|
|
18
19
|
const cacheValue = cacheMap.get(scalarKey);
|
|
19
|
-
let timer;
|
|
20
|
-
if (this.options.ttlSeconds) {
|
|
21
|
-
const cacheMapRef = new WeakRef(cacheMap);
|
|
22
|
-
timer = setTimeout(() => {
|
|
23
|
-
cacheMapRef.deref()?.delete(scalarKey);
|
|
24
|
-
}, this.options.ttlSeconds * 1e3);
|
|
25
|
-
}
|
|
26
20
|
if (cacheValue) {
|
|
27
|
-
|
|
28
|
-
cacheValue.timer = timer;
|
|
21
|
+
this.markUsed(cacheValue);
|
|
29
22
|
return cacheValue.value;
|
|
30
23
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
const entry = {
|
|
25
|
+
value: createValue(),
|
|
26
|
+
recency: { cacheMapRef: new WeakRef(cacheMap), scalarKey }
|
|
27
|
+
};
|
|
28
|
+
cacheMap.set(scalarKey, entry);
|
|
29
|
+
this.markUsed(entry);
|
|
30
|
+
this.evictOverLimit();
|
|
31
|
+
return entry.value;
|
|
32
|
+
}
|
|
33
|
+
markUsed(entry) {
|
|
34
|
+
node_timers.clearTimeout(entry.timer);
|
|
35
|
+
if (this.options.ttlSeconds) {
|
|
36
|
+
const token = entry.recency;
|
|
37
|
+
entry.timer = setTimeout(() => this.remove(token), this.options.ttlSeconds * 1e3);
|
|
38
|
+
}
|
|
39
|
+
if (this.options.maxEntries) {
|
|
40
|
+
this.recency.delete(entry.recency);
|
|
41
|
+
this.recency.add(entry.recency);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
evictOverLimit() {
|
|
45
|
+
const maxEntries = this.options.maxEntries;
|
|
46
|
+
if (!maxEntries) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
for (const token of this.recency) {
|
|
50
|
+
if (this.recency.size <= maxEntries) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.remove(token);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
remove(token) {
|
|
57
|
+
this.recency.delete(token);
|
|
58
|
+
const cacheMap = token.cacheMapRef.deref();
|
|
59
|
+
const entry = cacheMap?.get(token.scalarKey);
|
|
60
|
+
if (!cacheMap || entry?.recency !== token) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
node_timers.clearTimeout(entry.timer);
|
|
64
|
+
cacheMap.delete(token.scalarKey);
|
|
37
65
|
}
|
|
38
66
|
}
|
|
39
67
|
exports.ContentApiSpecificCache = ContentApiSpecificCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentApiSpecificCache.cjs","sources":["../../../../../packages/engine-http/src/content/ContentApiSpecificCache.ts"],"sourcesContent":["import { clearTimeout } from 'node:timers'\n\ntype Entry<V> = {\n\ttimer?: ReturnType<typeof setTimeout>\n\tvalue: V\n}\n\nexport class ContentApiSpecificCache<ObjectKey extends object, Value> {\n\tprivate cache = new WeakMap<ObjectKey, Map<string, Entry<Value>>>()\n\n\tconstructor(\n\t\tprivate options: {\n\t\t\tttlSeconds?: number\n\t\t},\n\t) {\n\t}\n\n\tpublic fetch(objectKey: ObjectKey, scalarKey: string, createValue: () => Value): Value {\n\t\tlet cacheMap = this.cache.get(objectKey)\n\n\t\tif (!cacheMap) {\n\t\t\tcacheMap = new Map()\n\t\t\tthis.cache.set(objectKey, cacheMap)\n\t\t}\n\n\t\tconst cacheValue = cacheMap.get(scalarKey)\n\n\t\
|
|
1
|
+
{"version":3,"file":"ContentApiSpecificCache.cjs","sources":["../../../../../packages/engine-http/src/content/ContentApiSpecificCache.ts"],"sourcesContent":["import { clearTimeout } from 'node:timers'\n\ntype RecencyToken<V> = {\n\t// weak, so the recency order keeps neither the Map nor its ObjectKey alive\n\tcacheMapRef: WeakRef<Map<string, Entry<V>>>\n\tscalarKey: string\n}\n\ntype Entry<V> = {\n\ttimer?: ReturnType<typeof setTimeout>\n\tvalue: V\n\trecency: RecencyToken<V>\n}\n\nexport class ContentApiSpecificCache<ObjectKey extends object, Value> {\n\tprivate cache = new WeakMap<ObjectKey, Map<string, Entry<Value>>>()\n\n\t// Least recently used first, tracked only with maxEntries: nothing else removes a token whose Map was garbage-collected.\n\t// With maxEntries, such a token stays counted until it is evicted as the oldest.\n\tprivate recency = new Set<RecencyToken<Value>>()\n\n\tconstructor(\n\t\tprivate options: {\n\t\t\tttlSeconds?: number\n\t\t\tmaxEntries?: number\n\t\t},\n\t) {\n\t}\n\n\tpublic fetch(objectKey: ObjectKey, scalarKey: string, createValue: () => Value): Value {\n\t\tlet cacheMap = this.cache.get(objectKey)\n\n\t\tif (!cacheMap) {\n\t\t\tcacheMap = new Map()\n\t\t\tthis.cache.set(objectKey, cacheMap)\n\t\t}\n\n\t\tconst cacheValue = cacheMap.get(scalarKey)\n\t\tif (cacheValue) {\n\t\t\tthis.markUsed(cacheValue)\n\t\t\treturn cacheValue.value\n\t\t}\n\n\t\tconst entry: Entry<Value> = {\n\t\t\tvalue: createValue(),\n\t\t\trecency: { cacheMapRef: new WeakRef(cacheMap), scalarKey },\n\t\t}\n\t\tcacheMap.set(scalarKey, entry)\n\t\tthis.markUsed(entry)\n\t\tthis.evictOverLimit()\n\n\t\treturn entry.value\n\t}\n\n\tprivate markUsed(entry: Entry<Value>): void {\n\t\tclearTimeout(entry.timer)\n\t\tif (this.options.ttlSeconds) {\n\t\t\tconst token = entry.recency\n\t\t\tentry.timer = setTimeout(() => this.remove(token), this.options.ttlSeconds * 1000)\n\t\t}\n\t\tif (this.options.maxEntries) {\n\t\t\tthis.recency.delete(entry.recency)\n\t\t\tthis.recency.add(entry.recency)\n\t\t}\n\t}\n\n\tprivate evictOverLimit(): void {\n\t\tconst maxEntries = this.options.maxEntries\n\t\tif (!maxEntries) {\n\t\t\treturn\n\t\t}\n\t\tfor (const token of this.recency) {\n\t\t\tif (this.recency.size <= maxEntries) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.remove(token)\n\t\t}\n\t}\n\n\tprivate remove(token: RecencyToken<Value>): void {\n\t\tthis.recency.delete(token)\n\t\tconst cacheMap = token.cacheMapRef.deref()\n\t\tconst entry = cacheMap?.get(token.scalarKey)\n\t\tif (!cacheMap || entry?.recency !== token) {\n\t\t\treturn\n\t\t}\n\t\tclearTimeout(entry.timer)\n\t\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pC;AAAA,MACD;AACA,WAAK,OAAO,KAAK;AAAA,IAClB;AAAA,EACD;AAAA,EAEQ,OAAO,OAAkC;AAChD,SAAK,QAAQ,OAAO,KAAK;AACzB,UAAM,WAAW,MAAM,YAAY,MAAA;AACnC,UAAM,QAAQ,UAAU,IAAI,MAAM,SAAS;AAC3C,QAAI,CAAC,YAAY,OAAO,YAAY,OAAO;AAC1C;AAAA,IACD;AACAA,gBAAAA,aAAa,MAAM,KAAK;AACxB,aAAS,OAAO,MAAM,SAAS;AAAA,EAChC;AACD;;"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { clearTimeout } from "node:timers";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
class ContentApiSpecificCache {
|
|
6
6
|
constructor(options) {
|
|
7
7
|
this.options = options;
|
|
8
8
|
__publicField(this, "cache", /* @__PURE__ */ new WeakMap());
|
|
9
|
+
__publicField(this, "recency", /* @__PURE__ */ new Set());
|
|
9
10
|
}
|
|
10
11
|
fetch(objectKey, scalarKey, createValue) {
|
|
11
12
|
let cacheMap = this.cache.get(objectKey);
|
|
@@ -14,24 +15,51 @@ class ContentApiSpecificCache {
|
|
|
14
15
|
this.cache.set(objectKey, cacheMap);
|
|
15
16
|
}
|
|
16
17
|
const cacheValue = cacheMap.get(scalarKey);
|
|
17
|
-
let timer;
|
|
18
|
-
if (this.options.ttlSeconds) {
|
|
19
|
-
const cacheMapRef = new WeakRef(cacheMap);
|
|
20
|
-
timer = setTimeout(() => {
|
|
21
|
-
cacheMapRef.deref()?.delete(scalarKey);
|
|
22
|
-
}, this.options.ttlSeconds * 1e3);
|
|
23
|
-
}
|
|
24
18
|
if (cacheValue) {
|
|
25
|
-
|
|
26
|
-
cacheValue.timer = timer;
|
|
19
|
+
this.markUsed(cacheValue);
|
|
27
20
|
return cacheValue.value;
|
|
28
21
|
}
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
const entry = {
|
|
23
|
+
value: createValue(),
|
|
24
|
+
recency: { cacheMapRef: new WeakRef(cacheMap), scalarKey }
|
|
25
|
+
};
|
|
26
|
+
cacheMap.set(scalarKey, entry);
|
|
27
|
+
this.markUsed(entry);
|
|
28
|
+
this.evictOverLimit();
|
|
29
|
+
return entry.value;
|
|
30
|
+
}
|
|
31
|
+
markUsed(entry) {
|
|
32
|
+
clearTimeout(entry.timer);
|
|
33
|
+
if (this.options.ttlSeconds) {
|
|
34
|
+
const token = entry.recency;
|
|
35
|
+
entry.timer = setTimeout(() => this.remove(token), this.options.ttlSeconds * 1e3);
|
|
36
|
+
}
|
|
37
|
+
if (this.options.maxEntries) {
|
|
38
|
+
this.recency.delete(entry.recency);
|
|
39
|
+
this.recency.add(entry.recency);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
evictOverLimit() {
|
|
43
|
+
const maxEntries = this.options.maxEntries;
|
|
44
|
+
if (!maxEntries) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const token of this.recency) {
|
|
48
|
+
if (this.recency.size <= maxEntries) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.remove(token);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
remove(token) {
|
|
55
|
+
this.recency.delete(token);
|
|
56
|
+
const cacheMap = token.cacheMapRef.deref();
|
|
57
|
+
const entry = cacheMap?.get(token.scalarKey);
|
|
58
|
+
if (!cacheMap || entry?.recency !== token) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
clearTimeout(entry.timer);
|
|
62
|
+
cacheMap.delete(token.scalarKey);
|
|
35
63
|
}
|
|
36
64
|
}
|
|
37
65
|
export {
|