@revealui/core 0.2.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/compression.d.ts.map +1 -1
- package/dist/api/payload-optimization.d.ts.map +1 -1
- package/dist/api/rate-limit.d.ts +29 -28
- package/dist/api/rate-limit.d.ts.map +1 -1
- package/dist/api/rate-limit.js +63 -3
- package/dist/api/response-cache.d.ts.map +1 -1
- package/dist/api/response-cache.js +1 -1
- package/dist/api/rest.d.ts.map +1 -1
- package/dist/api/rest.js +3 -2
- package/dist/auth/access.d.ts.map +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/cache/query-cache.d.ts +12 -10
- package/dist/cache/query-cache.d.ts.map +1 -1
- package/dist/cache/query-cache.js +38 -42
- package/dist/caching/index.d.ts +6 -0
- package/dist/caching/index.d.ts.map +1 -0
- package/dist/caching/index.js +5 -0
- package/dist/client/admin/RichText.d.ts +1 -1
- package/dist/client/admin/RichText.d.ts.map +1 -1
- package/dist/client/admin/components/AdminDashboard.d.ts.map +1 -1
- package/dist/client/admin/components/AdminDashboard.js +195 -205
- package/dist/client/admin/components/CollectionList.d.ts.map +1 -1
- package/dist/client/admin/components/DocumentForm.d.ts.map +1 -1
- package/dist/client/admin/components/DocumentForm.js +130 -6
- package/dist/client/admin/components/GlobalForm.d.ts.map +1 -1
- package/dist/client/admin/context/ServerFunctionContext.d.ts +8 -0
- package/dist/client/admin/context/ServerFunctionContext.d.ts.map +1 -0
- package/dist/client/admin/context/ServerFunctionContext.js +15 -0
- package/dist/client/admin/i18n/en.d.ts.map +1 -1
- package/dist/client/admin/index.d.ts +1 -0
- package/dist/client/admin/index.d.ts.map +1 -1
- package/dist/client/admin/index.js +1 -0
- package/dist/client/admin/layout.d.ts +1 -1
- package/dist/client/admin/layout.d.ts.map +1 -1
- package/dist/client/admin/layout.js +3 -2
- package/dist/client/admin/page.d.ts.map +1 -1
- package/dist/client/admin/utils/apiClient.d.ts.map +1 -1
- package/dist/client/admin/utils/apiClient.js +0 -4
- package/dist/client/admin/utils/index.d.ts +0 -1
- package/dist/client/admin/utils/index.d.ts.map +1 -1
- package/dist/client/admin/utils/index.js +0 -1
- package/dist/client/admin/utils/serializeConfig.d.ts.map +1 -1
- package/dist/client/hooks.d.ts.map +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/richtext/RichTextEditor.d.ts.map +1 -1
- package/dist/client/richtext/components/ImageNodeComponent.d.ts.map +1 -1
- package/dist/client/richtext/components/ImageNodeComponent.js +0 -1
- package/dist/client/richtext/components/ImageUploadButton.d.ts +2 -0
- package/dist/client/richtext/components/ImageUploadButton.d.ts.map +1 -1
- package/dist/client/richtext/components/ImageUploadButton.js +30 -15
- package/dist/client/richtext/index.d.ts.map +1 -1
- package/dist/client/richtext/nodes/DecoratorBlockNode.d.ts.map +1 -1
- package/dist/client/richtext/nodes/ImageNode.d.ts.map +1 -1
- package/dist/client/richtext/plugins/CollaborationPlugin.d.ts.map +1 -1
- package/dist/client/richtext/plugins/CursorsOverlayPlugin.d.ts.map +1 -1
- package/dist/client/richtext/plugins/FloatingToolbarPlugin.d.ts.map +1 -1
- package/dist/client/richtext/plugins/FloatingToolbarPlugin.js +1 -3
- package/dist/client/richtext/plugins/ImagePlugin.d.ts.map +1 -1
- package/dist/client/richtext/plugins/ToolbarPlugin.d.ts.map +1 -1
- package/dist/client/ui/index.d.ts.map +1 -1
- package/dist/client/ui/index.js +1 -1
- package/dist/collections/CollectionOperations.d.ts +7 -7
- package/dist/collections/CollectionOperations.d.ts.map +1 -1
- package/dist/collections/CollectionOperations.js +15 -1
- package/dist/collections/hooks.d.ts.map +1 -1
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/collections/operations/create.d.ts +4 -5
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +35 -6
- package/dist/collections/operations/createMany.d.ts +12 -0
- package/dist/collections/operations/createMany.d.ts.map +1 -0
- package/dist/collections/operations/createMany.js +43 -0
- package/dist/collections/operations/delete.d.ts +1 -1
- package/dist/collections/operations/delete.d.ts.map +1 -1
- package/dist/collections/operations/delete.js +31 -2
- package/dist/collections/operations/deleteMany.d.ts +11 -0
- package/dist/collections/operations/deleteMany.d.ts.map +1 -0
- package/dist/collections/operations/deleteMany.js +50 -0
- package/dist/collections/operations/fieldHooks.d.ts +2 -2
- package/dist/collections/operations/fieldHooks.d.ts.map +1 -1
- package/dist/collections/operations/fieldHooks.js +4 -4
- package/dist/collections/operations/find.d.ts +2 -4
- package/dist/collections/operations/find.d.ts.map +1 -1
- package/dist/collections/operations/find.js +115 -8
- package/dist/collections/operations/findById.d.ts +3 -4
- package/dist/collections/operations/findById.d.ts.map +1 -1
- package/dist/collections/operations/findById.js +53 -1
- package/dist/collections/operations/sqlAdapter.d.ts +23 -0
- package/dist/collections/operations/sqlAdapter.d.ts.map +1 -0
- package/dist/collections/operations/sqlAdapter.js +76 -0
- package/dist/collections/operations/update.d.ts +3 -5
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +103 -11
- package/dist/collections/operations/updateMany.d.ts +11 -0
- package/dist/collections/operations/updateMany.d.ts.map +1 -0
- package/dist/collections/operations/updateMany.js +52 -0
- package/dist/collections/registry.d.ts +12 -0
- package/dist/collections/registry.d.ts.map +1 -0
- package/dist/collections/registry.js +38 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/utils.d.ts +0 -10
- package/dist/config/utils.d.ts.map +1 -1
- package/dist/config/utils.js +0 -13
- package/dist/database/index.d.ts +3 -0
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +1 -5
- package/dist/database/safe-parse.d.ts.map +1 -1
- package/dist/database/ssl-config.d.ts.map +1 -1
- package/dist/database/type-adapter.d.ts.map +1 -1
- package/dist/database/universal-postgres.d.ts.map +1 -1
- package/dist/database/universal-postgres.js +6 -1
- package/dist/dataloader.d.ts.map +1 -1
- package/dist/error-handling/error-boundary.d.ts.map +1 -1
- package/dist/error-handling/error-reporter.d.ts +1 -1
- package/dist/error-handling/error-reporter.d.ts.map +1 -1
- package/dist/error-handling/error-reporter.js +19 -5
- package/dist/error-handling/fallback-components.d.ts.map +1 -1
- package/dist/error-handling/fallback-components.js +1 -1
- package/dist/error-handling/index.d.ts +2 -4
- package/dist/error-handling/index.d.ts.map +1 -1
- package/dist/error-handling/index.js +1 -4
- package/dist/factories/builders.d.ts.map +1 -1
- package/dist/factories/index.d.ts.map +1 -1
- package/dist/features.d.ts +7 -7
- package/dist/features.d.ts.map +1 -1
- package/dist/features.js +2 -2
- package/dist/fieldTraversal.d.ts.map +1 -1
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/getDefaultValue.d.ts.map +1 -1
- package/dist/fields/getFieldPaths.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
- package/dist/generated/types/cms.d.ts.map +1 -1
- package/dist/generated/types/cms.js +0 -1
- package/dist/generated/types/neon.d.ts.map +1 -1
- package/dist/generated/types/neon.js +4 -2
- package/dist/globals/GlobalOperations.d.ts.map +1 -1
- package/dist/globals/GlobalOperations.js +16 -4
- package/dist/globals/index.d.ts.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -5
- package/dist/instance/RevealUIInstance.d.ts.map +1 -1
- package/dist/instance/RevealUIInstance.js +6 -19
- package/dist/instance/index.d.ts.map +1 -1
- package/dist/instance/logger.d.ts.map +1 -1
- package/dist/instance/methods/create.d.ts.map +1 -1
- package/dist/instance/methods/create.js +0 -3
- package/dist/instance/methods/delete.d.ts.map +1 -1
- package/dist/instance/methods/delete.js +1 -4
- package/dist/instance/methods/find.d.ts.map +1 -1
- package/dist/instance/methods/find.js +0 -3
- package/dist/instance/methods/findById.d.ts.map +1 -1
- package/dist/instance/methods/findById.js +0 -3
- package/dist/instance/methods/hooks.d.ts.map +1 -1
- package/dist/instance/methods/update.d.ts.map +1 -1
- package/dist/instance/methods/update.js +0 -3
- package/dist/jobs/index.d.ts +16 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +14 -0
- package/dist/jobs/queue.d.ts +57 -0
- package/dist/jobs/queue.d.ts.map +1 -0
- package/dist/jobs/queue.js +134 -0
- package/dist/license-encryption.d.ts +21 -0
- package/dist/license-encryption.d.ts.map +1 -0
- package/dist/license-encryption.js +74 -0
- package/dist/license.d.ts +26 -3
- package/dist/license.d.ts.map +1 -1
- package/dist/license.js +87 -7
- package/dist/monitoring/alerts.d.ts +4 -4
- package/dist/monitoring/alerts.d.ts.map +1 -1
- package/dist/monitoring/cleanup-manager.d.ts.map +1 -1
- package/dist/monitoring/health-monitor.d.ts.map +1 -1
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/process-registry.d.ts.map +1 -1
- package/dist/monitoring/query-monitor.d.ts.map +1 -1
- package/dist/monitoring/types.d.ts.map +1 -1
- package/dist/monitoring/zombie-detector.d.ts.map +1 -1
- package/dist/monitoring/zombie-detector.js +5 -0
- package/dist/nextjs/index.d.ts.map +1 -1
- package/dist/nextjs/utilities.d.ts.map +1 -1
- package/dist/nextjs/withRevealUI.d.ts.map +1 -1
- package/dist/observability/alerts.d.ts.map +1 -1
- package/dist/observability/alerts.js +1 -2
- package/dist/observability/health-check.d.ts +0 -4
- package/dist/observability/health-check.d.ts.map +1 -1
- package/dist/observability/health-check.js +0 -36
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/logger.d.ts.map +1 -1
- package/dist/observability/logger.js +1 -1
- package/dist/observability/metrics.d.ts.map +1 -1
- package/dist/observability/tracing.d.ts.map +1 -1
- package/dist/observability/tracing.js +0 -1
- package/dist/plugins/form-builder.d.ts.map +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/nested-docs.d.ts +4 -0
- package/dist/plugins/nested-docs.d.ts.map +1 -1
- package/dist/plugins/nested-docs.js +50 -6
- package/dist/plugins/redirects.d.ts.map +1 -1
- package/dist/queries/index.d.ts.map +1 -1
- package/dist/queries/queryBuilder.d.ts.map +1 -1
- package/dist/queries/queryBuilder.js +13 -5
- package/dist/relationships/analyzer.d.ts.map +1 -1
- package/dist/relationships/analyzer.js +8 -0
- package/dist/relationships/index.d.ts.map +1 -1
- package/dist/relationships/populate-core.d.ts +57 -0
- package/dist/relationships/populate-core.d.ts.map +1 -0
- package/dist/relationships/populate-core.js +116 -0
- package/dist/relationships/populate-helpers.d.ts +5 -51
- package/dist/relationships/populate-helpers.d.ts.map +1 -1
- package/dist/relationships/populate-helpers.js +4 -109
- package/dist/relationships/population.d.ts +1 -9
- package/dist/relationships/population.d.ts.map +1 -1
- package/dist/relationships/population.js +8 -3
- package/dist/revealui.d.ts.map +1 -1
- package/dist/richtext/exports/client/rcc.d.ts.map +1 -1
- package/dist/richtext/exports/client/rcc.js +1 -1
- package/dist/richtext/exports/server/rsc.d.ts +17 -0
- package/dist/richtext/exports/server/rsc.d.ts.map +1 -1
- package/dist/richtext/exports/server/rsc.js +61 -5
- package/dist/richtext/index.d.ts.map +1 -1
- package/dist/richtext/lexical.d.ts.map +1 -1
- package/dist/security/index.d.ts +3 -16
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +3 -16
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/renderPage.d.ts.map +1 -1
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -4
- package/dist/storage/vercel-blob.d.ts.map +1 -1
- package/dist/storage/vercel-blob.js +3 -0
- package/dist/translations/index.d.ts.map +1 -1
- package/dist/types/access.d.ts.map +1 -1
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/cms.d.ts.map +1 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/extensions.d.ts.map +1 -1
- package/dist/types/frontend.d.ts.map +1 -1
- package/dist/types/generated.d.ts.map +1 -1
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces/app.d.ts.map +1 -1
- package/dist/types/jobs.d.ts.map +1 -1
- package/dist/types/legacy.d.ts.map +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/query.d.ts.map +1 -1
- package/dist/types/request.d.ts.map +1 -1
- package/dist/types/richtext.d.ts.map +1 -1
- package/dist/types/runtime.d.ts +60 -1
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/user.d.ts.map +1 -1
- package/dist/utils/access-conversion.d.ts.map +1 -1
- package/dist/utils/api-wrapper.d.ts.map +1 -1
- package/dist/utils/api-wrapper.js +1 -1
- package/dist/utils/block-conversion.d.ts.map +1 -1
- package/dist/utils/cache.d.ts.map +1 -1
- package/dist/utils/deep-clone.js +0 -1
- package/dist/utils/error-responses.d.ts.map +1 -1
- package/dist/utils/error-responses.js +2 -3
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +103 -0
- package/dist/utils/field-conversion.d.ts +1 -1
- package/dist/utils/field-conversion.d.ts.map +1 -1
- package/dist/utils/flattenResult.d.ts.map +1 -1
- package/dist/utils/flattenResult.js +0 -1
- package/dist/utils/getBlockSelect.d.ts.map +1 -1
- package/dist/utils/getSelectMode.d.ts.map +1 -1
- package/dist/utils/isValidID.d.ts.map +1 -1
- package/dist/utils/json-parsing.d.ts.map +1 -1
- package/dist/utils/logger-client.d.ts.map +1 -1
- package/dist/utils/logger-server.d.ts.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/request-context.d.ts.map +1 -1
- package/dist/utils/stripUnselectedFields.d.ts.map +1 -1
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/package.json +58 -26
- package/dist/caching/app-cache.d.ts +0 -237
- package/dist/caching/app-cache.d.ts.map +0 -1
- package/dist/caching/app-cache.js +0 -430
- package/dist/caching/cdn-config.d.ts +0 -155
- package/dist/caching/cdn-config.d.ts.map +0 -1
- package/dist/caching/cdn-config.js +0 -411
- package/dist/caching/edge-cache.d.ts +0 -177
- package/dist/caching/edge-cache.d.ts.map +0 -1
- package/dist/caching/edge-cache.js +0 -385
- package/dist/caching/service-worker.d.ts +0 -154
- package/dist/caching/service-worker.d.ts.map +0 -1
- package/dist/caching/service-worker.js +0 -437
- package/dist/client/admin/utils/auth.d.ts +0 -23
- package/dist/client/admin/utils/auth.d.ts.map +0 -1
- package/dist/client/admin/utils/auth.js +0 -52
- package/dist/client/http/client.d.ts +0 -15
- package/dist/client/http/client.d.ts.map +0 -1
- package/dist/client/http/client.js +0 -49
- package/dist/client/http/fetchBanner.d.ts +0 -18
- package/dist/client/http/fetchBanner.d.ts.map +0 -1
- package/dist/client/http/fetchBanner.js +0 -44
- package/dist/client/http/fetchCard.d.ts +0 -18
- package/dist/client/http/fetchCard.d.ts.map +0 -1
- package/dist/client/http/fetchCard.js +0 -46
- package/dist/client/http/fetchEvents.d.ts +0 -18
- package/dist/client/http/fetchEvents.d.ts.map +0 -1
- package/dist/client/http/fetchEvents.js +0 -44
- package/dist/client/http/fetchHero.d.ts +0 -17
- package/dist/client/http/fetchHero.d.ts.map +0 -1
- package/dist/client/http/fetchHero.js +0 -55
- package/dist/client/http/fetchMainInfos.d.ts +0 -17
- package/dist/client/http/fetchMainInfos.d.ts.map +0 -1
- package/dist/client/http/fetchMainInfos.js +0 -44
- package/dist/client/http/fetchVideos.d.ts +0 -13
- package/dist/client/http/fetchVideos.d.ts.map +0 -1
- package/dist/client/http/fetchVideos.js +0 -36
- package/dist/client/http/index.d.ts +0 -19
- package/dist/client/http/index.d.ts.map +0 -1
- package/dist/client/http/index.js +0 -11
- package/dist/error-handling/circuit-breaker.d.ts +0 -262
- package/dist/error-handling/circuit-breaker.d.ts.map +0 -1
- package/dist/error-handling/circuit-breaker.js +0 -542
- package/dist/error-handling/retry.d.ts +0 -194
- package/dist/error-handling/retry.d.ts.map +0 -1
- package/dist/error-handling/retry.js +0 -450
- package/dist/errors/index.d.ts +0 -23
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -40
- package/dist/generated/agents/index.d.ts +0 -8
- package/dist/generated/agents/index.d.ts.map +0 -1
- package/dist/generated/agents/index.js +0 -7
- package/dist/generated/components/index.d.ts +0 -8
- package/dist/generated/components/index.d.ts.map +0 -1
- package/dist/generated/components/index.js +0 -7
- package/dist/generated/functions/index.d.ts +0 -8
- package/dist/generated/functions/index.d.ts.map +0 -1
- package/dist/generated/functions/index.js +0 -7
- package/dist/generated/hooks/index.d.ts +0 -8
- package/dist/generated/hooks/index.d.ts.map +0 -1
- package/dist/generated/hooks/index.js +0 -7
- package/dist/generated/plans/index.d.ts +0 -8
- package/dist/generated/plans/index.d.ts.map +0 -1
- package/dist/generated/plans/index.js +0 -7
- package/dist/generated/prompts/index.d.ts +0 -8
- package/dist/generated/prompts/index.d.ts.map +0 -1
- package/dist/generated/prompts/index.js +0 -7
- package/dist/generated/tools/index.d.ts +0 -8
- package/dist/generated/tools/index.d.ts.map +0 -1
- package/dist/generated/tools/index.js +0 -7
- package/dist/generated/types/supabase.d.ts +0 -193
- package/dist/generated/types/supabase.d.ts.map +0 -1
- package/dist/generated/types/supabase.js +0 -5
- package/dist/optimization/asset-optimizer.d.ts +0 -202
- package/dist/optimization/asset-optimizer.d.ts.map +0 -1
- package/dist/optimization/asset-optimizer.js +0 -312
- package/dist/optimization/build-optimizer.d.ts +0 -202
- package/dist/optimization/build-optimizer.d.ts.map +0 -1
- package/dist/optimization/build-optimizer.js +0 -271
- package/dist/optimization/bundle-analyzer.d.ts +0 -98
- package/dist/optimization/bundle-analyzer.d.ts.map +0 -1
- package/dist/optimization/bundle-analyzer.js +0 -322
- package/dist/optimization/code-splitting.d.ts +0 -131
- package/dist/optimization/code-splitting.d.ts.map +0 -1
- package/dist/optimization/code-splitting.js +0 -277
- package/dist/plugin/index.d.ts +0 -12
- package/dist/plugin/index.d.ts.map +0 -1
- package/dist/plugin/index.js +0 -4
- package/dist/security/audit.d.ts +0 -188
- package/dist/security/audit.d.ts.map +0 -1
- package/dist/security/audit.js +0 -431
- package/dist/security/auth.d.ts +0 -241
- package/dist/security/auth.d.ts.map +0 -1
- package/dist/security/auth.js +0 -476
- package/dist/security/authorization.d.ts +0 -235
- package/dist/security/authorization.d.ts.map +0 -1
- package/dist/security/authorization.js +0 -434
- package/dist/security/encryption.d.ts +0 -214
- package/dist/security/encryption.d.ts.map +0 -1
- package/dist/security/encryption.js +0 -517
- package/dist/security/gdpr.d.ts +0 -300
- package/dist/security/gdpr.d.ts.map +0 -1
- package/dist/security/gdpr.js +0 -465
- package/dist/security/headers.d.ts +0 -182
- package/dist/security/headers.d.ts.map +0 -1
- package/dist/security/headers.js +0 -402
- package/dist/utils/jwt-validation.d.ts +0 -14
- package/dist/utils/jwt-validation.d.ts.map +0 -1
- package/dist/utils/jwt-validation.js +0 -36
- package/dist/utils/request-headers.d.ts +0 -15
- package/dist/utils/request-headers.d.ts.map +0 -1
- package/dist/utils/request-headers.js +0 -31
|
@@ -1,542 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Circuit Breaker Pattern
|
|
3
|
-
*
|
|
4
|
-
* Prevents cascading failures by stopping requests to failing services
|
|
5
|
-
*/
|
|
6
|
-
import { logger } from '../observability/logger.js';
|
|
7
|
-
const DEFAULT_CONFIG = {
|
|
8
|
-
failureThreshold: 5,
|
|
9
|
-
successThreshold: 2,
|
|
10
|
-
timeout: 60000,
|
|
11
|
-
resetTimeout: 30000,
|
|
12
|
-
volumeThreshold: 10,
|
|
13
|
-
errorFilter: () => true,
|
|
14
|
-
onStateChange: () => { },
|
|
15
|
-
onTrip: () => { },
|
|
16
|
-
onReset: () => { },
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Circuit Breaker implementation
|
|
20
|
-
*/
|
|
21
|
-
export class CircuitBreaker {
|
|
22
|
-
state = 'closed';
|
|
23
|
-
failures = 0;
|
|
24
|
-
successes = 0;
|
|
25
|
-
consecutiveFailures = 0;
|
|
26
|
-
consecutiveSuccesses = 0;
|
|
27
|
-
totalCalls = 0;
|
|
28
|
-
totalFailures = 0;
|
|
29
|
-
totalSuccesses = 0;
|
|
30
|
-
lastFailureTime;
|
|
31
|
-
lastSuccessTime;
|
|
32
|
-
stateChangedAt = Date.now();
|
|
33
|
-
resetTimer;
|
|
34
|
-
config;
|
|
35
|
-
constructor(config = {}) {
|
|
36
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Execute function with circuit breaker
|
|
40
|
-
*/
|
|
41
|
-
async execute(fn) {
|
|
42
|
-
// Check if circuit is open
|
|
43
|
-
if (this.state === 'open') {
|
|
44
|
-
// Check if reset timeout has passed
|
|
45
|
-
if (Date.now() - this.stateChangedAt >= this.config.resetTimeout) {
|
|
46
|
-
this.transitionTo('half-open');
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
throw new CircuitBreakerOpenError('Circuit breaker is open');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
this.totalCalls++;
|
|
53
|
-
try {
|
|
54
|
-
const result = await fn();
|
|
55
|
-
this.onSuccess();
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
60
|
-
this.onFailure(err);
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Handle successful execution
|
|
66
|
-
*/
|
|
67
|
-
onSuccess() {
|
|
68
|
-
this.successes++;
|
|
69
|
-
this.consecutiveSuccesses++;
|
|
70
|
-
this.totalSuccesses++;
|
|
71
|
-
this.consecutiveFailures = 0;
|
|
72
|
-
this.lastSuccessTime = Date.now();
|
|
73
|
-
if (this.state === 'half-open') {
|
|
74
|
-
// Check if we can close the circuit
|
|
75
|
-
if (this.consecutiveSuccesses >= this.config.successThreshold) {
|
|
76
|
-
this.transitionTo('closed');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Reset failure count in closed state
|
|
80
|
-
if (this.state === 'closed') {
|
|
81
|
-
this.failures = 0;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Handle failed execution
|
|
86
|
-
*/
|
|
87
|
-
onFailure(error) {
|
|
88
|
-
// Check if error should count
|
|
89
|
-
if (!this.config.errorFilter(error)) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this.failures++;
|
|
93
|
-
this.consecutiveFailures++;
|
|
94
|
-
this.totalFailures++;
|
|
95
|
-
this.consecutiveSuccesses = 0;
|
|
96
|
-
this.lastFailureTime = Date.now();
|
|
97
|
-
if (this.state === 'half-open') {
|
|
98
|
-
// Immediately open circuit on failure in half-open state
|
|
99
|
-
this.transitionTo('open');
|
|
100
|
-
}
|
|
101
|
-
else if (this.state === 'closed') {
|
|
102
|
-
// Check if we should open the circuit
|
|
103
|
-
if (this.consecutiveFailures >= this.config.failureThreshold &&
|
|
104
|
-
this.totalCalls >= this.config.volumeThreshold) {
|
|
105
|
-
this.transitionTo('open');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Transition to new state
|
|
111
|
-
*/
|
|
112
|
-
transitionTo(newState) {
|
|
113
|
-
if (this.state === newState)
|
|
114
|
-
return;
|
|
115
|
-
const oldState = this.state;
|
|
116
|
-
this.state = newState;
|
|
117
|
-
this.stateChangedAt = Date.now();
|
|
118
|
-
// Reset counters
|
|
119
|
-
if (newState === 'half-open' || newState === 'closed') {
|
|
120
|
-
this.consecutiveFailures = 0;
|
|
121
|
-
this.consecutiveSuccesses = 0;
|
|
122
|
-
}
|
|
123
|
-
// Clear reset timer
|
|
124
|
-
if (this.resetTimer) {
|
|
125
|
-
clearTimeout(this.resetTimer);
|
|
126
|
-
this.resetTimer = undefined;
|
|
127
|
-
}
|
|
128
|
-
// Set reset timer for open state
|
|
129
|
-
if (newState === 'open') {
|
|
130
|
-
this.resetTimer = setTimeout(() => {
|
|
131
|
-
this.transitionTo('half-open');
|
|
132
|
-
}, this.config.resetTimeout);
|
|
133
|
-
this.config.onTrip();
|
|
134
|
-
}
|
|
135
|
-
// Circuit reset
|
|
136
|
-
if (newState === 'closed' && oldState === 'half-open') {
|
|
137
|
-
this.failures = 0;
|
|
138
|
-
this.config.onReset();
|
|
139
|
-
}
|
|
140
|
-
this.config.onStateChange(newState);
|
|
141
|
-
logger.info(`Circuit breaker state changed: ${oldState} -> ${newState}`, this.getStats());
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Get current state
|
|
145
|
-
*/
|
|
146
|
-
getState() {
|
|
147
|
-
return this.state;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Get statistics
|
|
151
|
-
*/
|
|
152
|
-
getStats() {
|
|
153
|
-
return {
|
|
154
|
-
state: this.state,
|
|
155
|
-
failures: this.failures,
|
|
156
|
-
successes: this.successes,
|
|
157
|
-
consecutiveFailures: this.consecutiveFailures,
|
|
158
|
-
consecutiveSuccesses: this.consecutiveSuccesses,
|
|
159
|
-
totalCalls: this.totalCalls,
|
|
160
|
-
totalFailures: this.totalFailures,
|
|
161
|
-
totalSuccesses: this.totalSuccesses,
|
|
162
|
-
lastFailureTime: this.lastFailureTime,
|
|
163
|
-
lastSuccessTime: this.lastSuccessTime,
|
|
164
|
-
stateChangedAt: this.stateChangedAt,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Manually open circuit
|
|
169
|
-
*/
|
|
170
|
-
trip() {
|
|
171
|
-
this.transitionTo('open');
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Manually close circuit
|
|
175
|
-
*/
|
|
176
|
-
reset() {
|
|
177
|
-
this.failures = 0;
|
|
178
|
-
this.successes = 0;
|
|
179
|
-
this.consecutiveFailures = 0;
|
|
180
|
-
this.consecutiveSuccesses = 0;
|
|
181
|
-
this.transitionTo('closed');
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Force state to half-open
|
|
185
|
-
*/
|
|
186
|
-
halfOpen() {
|
|
187
|
-
this.transitionTo('half-open');
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Check if circuit is open
|
|
191
|
-
*/
|
|
192
|
-
isOpen() {
|
|
193
|
-
return this.state === 'open';
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Check if circuit is closed
|
|
197
|
-
*/
|
|
198
|
-
isClosed() {
|
|
199
|
-
return this.state === 'closed';
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Check if circuit is half-open
|
|
203
|
-
*/
|
|
204
|
-
isHalfOpen() {
|
|
205
|
-
return this.state === 'half-open';
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Get failure rate
|
|
209
|
-
*/
|
|
210
|
-
getFailureRate() {
|
|
211
|
-
if (this.totalCalls === 0)
|
|
212
|
-
return 0;
|
|
213
|
-
return this.totalFailures / this.totalCalls;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Get success rate
|
|
217
|
-
*/
|
|
218
|
-
getSuccessRate() {
|
|
219
|
-
if (this.totalCalls === 0)
|
|
220
|
-
return 0;
|
|
221
|
-
return this.totalSuccesses / this.totalCalls;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Cleanup
|
|
225
|
-
*/
|
|
226
|
-
destroy() {
|
|
227
|
-
if (this.resetTimer) {
|
|
228
|
-
clearTimeout(this.resetTimer);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Circuit breaker open error
|
|
234
|
-
*/
|
|
235
|
-
export class CircuitBreakerOpenError extends Error {
|
|
236
|
-
constructor(message = 'Circuit breaker is open') {
|
|
237
|
-
super(message);
|
|
238
|
-
this.name = 'CircuitBreakerOpenError';
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Circuit breaker registry
|
|
243
|
-
*/
|
|
244
|
-
export class CircuitBreakerRegistry {
|
|
245
|
-
breakers = new Map();
|
|
246
|
-
/**
|
|
247
|
-
* Get or create circuit breaker
|
|
248
|
-
*/
|
|
249
|
-
get(name, config) {
|
|
250
|
-
let breaker = this.breakers.get(name);
|
|
251
|
-
if (!breaker) {
|
|
252
|
-
breaker = new CircuitBreaker(config);
|
|
253
|
-
this.breakers.set(name, breaker);
|
|
254
|
-
}
|
|
255
|
-
return breaker;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Check if breaker exists
|
|
259
|
-
*/
|
|
260
|
-
has(name) {
|
|
261
|
-
return this.breakers.has(name);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Remove circuit breaker
|
|
265
|
-
*/
|
|
266
|
-
remove(name) {
|
|
267
|
-
const breaker = this.breakers.get(name);
|
|
268
|
-
if (breaker) {
|
|
269
|
-
breaker.destroy();
|
|
270
|
-
return this.breakers.delete(name);
|
|
271
|
-
}
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Get all breakers
|
|
276
|
-
*/
|
|
277
|
-
getAll() {
|
|
278
|
-
return new Map(this.breakers);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Get all statistics
|
|
282
|
-
*/
|
|
283
|
-
getAllStats() {
|
|
284
|
-
const stats = {};
|
|
285
|
-
for (const [name, breaker] of this.breakers) {
|
|
286
|
-
stats[name] = breaker.getStats();
|
|
287
|
-
}
|
|
288
|
-
return stats;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Reset all breakers
|
|
292
|
-
*/
|
|
293
|
-
resetAll() {
|
|
294
|
-
for (const breaker of this.breakers.values()) {
|
|
295
|
-
breaker.reset();
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Clear all breakers
|
|
300
|
-
*/
|
|
301
|
-
clear() {
|
|
302
|
-
for (const breaker of this.breakers.values()) {
|
|
303
|
-
breaker.destroy();
|
|
304
|
-
}
|
|
305
|
-
this.breakers.clear();
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Global circuit breaker registry
|
|
310
|
-
*/
|
|
311
|
-
export const circuitBreakerRegistry = new CircuitBreakerRegistry();
|
|
312
|
-
/**
|
|
313
|
-
* Create circuit breaker decorator
|
|
314
|
-
*/
|
|
315
|
-
export function CircuitBreak(nameOrConfig = {}) {
|
|
316
|
-
return (target, propertyKey, descriptor) => {
|
|
317
|
-
const originalMethod = descriptor.value;
|
|
318
|
-
const name = typeof nameOrConfig === 'string'
|
|
319
|
-
? nameOrConfig
|
|
320
|
-
: `${target.constructor.name}.${propertyKey}`;
|
|
321
|
-
const config = typeof nameOrConfig === 'object' ? nameOrConfig : undefined;
|
|
322
|
-
descriptor.value = async function (...args) {
|
|
323
|
-
const breaker = circuitBreakerRegistry.get(name, config);
|
|
324
|
-
return breaker.execute(() => originalMethod.apply(this, args));
|
|
325
|
-
};
|
|
326
|
-
return descriptor;
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Execute with circuit breaker
|
|
331
|
-
*/
|
|
332
|
-
export async function withCircuitBreaker(name, fn, config) {
|
|
333
|
-
const breaker = circuitBreakerRegistry.get(name, config);
|
|
334
|
-
return breaker.execute(fn);
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Create circuit breaker middleware
|
|
338
|
-
*/
|
|
339
|
-
export function createCircuitBreakerMiddleware(name, config) {
|
|
340
|
-
const breaker = circuitBreakerRegistry.get(name, config);
|
|
341
|
-
return async (_request, next) => {
|
|
342
|
-
return breaker.execute(next);
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Circuit breaker for fetch
|
|
347
|
-
*/
|
|
348
|
-
export async function fetchWithCircuitBreaker(name, url, init, config) {
|
|
349
|
-
const breaker = circuitBreakerRegistry.get(name, config);
|
|
350
|
-
return breaker.execute(async () => {
|
|
351
|
-
const response = await fetch(url, init);
|
|
352
|
-
// Treat 5xx errors as failures
|
|
353
|
-
if (response.status >= 500) {
|
|
354
|
-
const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
355
|
-
error.statusCode = response.status;
|
|
356
|
-
throw error;
|
|
357
|
-
}
|
|
358
|
-
return response;
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Adaptive circuit breaker with dynamic thresholds
|
|
363
|
-
*/
|
|
364
|
-
export class AdaptiveCircuitBreaker extends CircuitBreaker {
|
|
365
|
-
errorRateWindow = [];
|
|
366
|
-
windowSize = 100;
|
|
367
|
-
adaptiveThreshold;
|
|
368
|
-
constructor(config = {}) {
|
|
369
|
-
super(config);
|
|
370
|
-
this.adaptiveThreshold = config.failureThreshold || 5;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Execute with adaptive thresholds
|
|
374
|
-
*/
|
|
375
|
-
async execute(fn) {
|
|
376
|
-
try {
|
|
377
|
-
const result = await super.execute(fn);
|
|
378
|
-
this.recordSuccess();
|
|
379
|
-
return result;
|
|
380
|
-
}
|
|
381
|
-
catch (error) {
|
|
382
|
-
this.recordFailure();
|
|
383
|
-
throw error;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Record success in window
|
|
388
|
-
*/
|
|
389
|
-
recordSuccess() {
|
|
390
|
-
this.errorRateWindow.push(0);
|
|
391
|
-
this.trimWindow();
|
|
392
|
-
this.adjustThreshold();
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Record failure in window
|
|
396
|
-
*/
|
|
397
|
-
recordFailure() {
|
|
398
|
-
this.errorRateWindow.push(1);
|
|
399
|
-
this.trimWindow();
|
|
400
|
-
this.adjustThreshold();
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Trim window to size
|
|
404
|
-
*/
|
|
405
|
-
trimWindow() {
|
|
406
|
-
if (this.errorRateWindow.length > this.windowSize) {
|
|
407
|
-
this.errorRateWindow.shift();
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Adjust threshold based on error rate
|
|
412
|
-
*/
|
|
413
|
-
adjustThreshold() {
|
|
414
|
-
const errorRate = this.getWindowErrorRate();
|
|
415
|
-
// Increase threshold if error rate is low
|
|
416
|
-
if (errorRate < 0.1) {
|
|
417
|
-
this.adaptiveThreshold = Math.min(this.adaptiveThreshold + 1, 20);
|
|
418
|
-
}
|
|
419
|
-
// Decrease threshold if error rate is high
|
|
420
|
-
else if (errorRate > 0.5) {
|
|
421
|
-
this.adaptiveThreshold = Math.max(this.adaptiveThreshold - 1, 2);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Get error rate in window
|
|
426
|
-
*/
|
|
427
|
-
getWindowErrorRate() {
|
|
428
|
-
if (this.errorRateWindow.length === 0)
|
|
429
|
-
return 0;
|
|
430
|
-
const errors = this.errorRateWindow.reduce((sum, val) => sum + val, 0);
|
|
431
|
-
return errors / this.errorRateWindow.length;
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Get adaptive threshold
|
|
435
|
-
*/
|
|
436
|
-
getAdaptiveThreshold() {
|
|
437
|
-
return this.adaptiveThreshold;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Bulkhead pattern - limit concurrent executions
|
|
442
|
-
*/
|
|
443
|
-
export class Bulkhead {
|
|
444
|
-
activeRequests = 0;
|
|
445
|
-
queue = [];
|
|
446
|
-
maxConcurrent;
|
|
447
|
-
maxQueue;
|
|
448
|
-
constructor(maxConcurrent = 10, maxQueue = 100) {
|
|
449
|
-
this.maxConcurrent = maxConcurrent;
|
|
450
|
-
this.maxQueue = maxQueue;
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Execute with bulkhead
|
|
454
|
-
*/
|
|
455
|
-
async execute(fn) {
|
|
456
|
-
// Check if at capacity
|
|
457
|
-
if (this.activeRequests >= this.maxConcurrent) {
|
|
458
|
-
// Check queue capacity
|
|
459
|
-
if (this.queue.length >= this.maxQueue) {
|
|
460
|
-
throw new Error('Bulkhead queue is full');
|
|
461
|
-
}
|
|
462
|
-
// Wait for slot
|
|
463
|
-
await new Promise((resolve) => {
|
|
464
|
-
this.queue.push(resolve);
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
this.activeRequests++;
|
|
468
|
-
try {
|
|
469
|
-
return await fn();
|
|
470
|
-
}
|
|
471
|
-
finally {
|
|
472
|
-
this.activeRequests--;
|
|
473
|
-
// Process queue
|
|
474
|
-
const next = this.queue.shift();
|
|
475
|
-
if (next) {
|
|
476
|
-
next();
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Get active requests
|
|
482
|
-
*/
|
|
483
|
-
getActiveRequests() {
|
|
484
|
-
return this.activeRequests;
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Get queue size
|
|
488
|
-
*/
|
|
489
|
-
getQueueSize() {
|
|
490
|
-
return this.queue.length;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Get statistics
|
|
494
|
-
*/
|
|
495
|
-
getStats() {
|
|
496
|
-
return {
|
|
497
|
-
activeRequests: this.activeRequests,
|
|
498
|
-
queueSize: this.queue.length,
|
|
499
|
-
maxConcurrent: this.maxConcurrent,
|
|
500
|
-
maxQueue: this.maxQueue,
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Combined resilience wrapper
|
|
506
|
-
*/
|
|
507
|
-
export class ResilientOperation {
|
|
508
|
-
fn;
|
|
509
|
-
circuitBreaker;
|
|
510
|
-
bulkhead;
|
|
511
|
-
constructor(fn, circuitBreaker, bulkhead) {
|
|
512
|
-
this.fn = fn;
|
|
513
|
-
this.circuitBreaker = circuitBreaker;
|
|
514
|
-
this.bulkhead = bulkhead;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Execute with all resilience patterns
|
|
518
|
-
*/
|
|
519
|
-
async execute() {
|
|
520
|
-
const executeFn = async () => {
|
|
521
|
-
if (this.bulkhead) {
|
|
522
|
-
return this.bulkhead.execute(this.fn);
|
|
523
|
-
}
|
|
524
|
-
return this.fn();
|
|
525
|
-
};
|
|
526
|
-
if (this.circuitBreaker) {
|
|
527
|
-
return this.circuitBreaker.execute(executeFn);
|
|
528
|
-
}
|
|
529
|
-
return executeFn();
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Create resilient function
|
|
534
|
-
*/
|
|
535
|
-
export function createResilientFunction(fn, options = {}) {
|
|
536
|
-
const breaker = options.circuitBreaker ? new CircuitBreaker(options.circuitBreaker) : undefined;
|
|
537
|
-
const bulkhead = options.bulkhead
|
|
538
|
-
? new Bulkhead(options.bulkhead.maxConcurrent, options.bulkhead.maxQueue)
|
|
539
|
-
: undefined;
|
|
540
|
-
const operation = new ResilientOperation(fn, breaker, bulkhead);
|
|
541
|
-
return () => operation.execute();
|
|
542
|
-
}
|