@revealui/core 0.0.0-canary-20260409021642
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/LICENSE +22 -0
- package/README.md +171 -0
- package/dist/api/compression.d.ts +83 -0
- package/dist/api/compression.d.ts.map +1 -0
- package/dist/api/compression.js +233 -0
- package/dist/api/payload-optimization.d.ts +138 -0
- package/dist/api/payload-optimization.d.ts.map +1 -0
- package/dist/api/payload-optimization.js +320 -0
- package/dist/api/rate-limit.d.ts +114 -0
- package/dist/api/rate-limit.d.ts.map +1 -0
- package/dist/api/rate-limit.js +376 -0
- package/dist/api/response-cache.d.ts +125 -0
- package/dist/api/response-cache.d.ts.map +1 -0
- package/dist/api/response-cache.js +335 -0
- package/dist/api/rest.d.ts +54 -0
- package/dist/api/rest.d.ts.map +1 -0
- package/dist/api/rest.js +465 -0
- package/dist/auth/access.d.ts +25 -0
- package/dist/auth/access.d.ts.map +1 -0
- package/dist/auth/access.js +20 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/cache/query-cache.d.ts +100 -0
- package/dist/cache/query-cache.d.ts.map +1 -0
- package/dist/cache/query-cache.js +266 -0
- 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 +12 -0
- package/dist/client/admin/RichText.d.ts.map +1 -0
- package/dist/client/admin/RichText.js +5 -0
- package/dist/client/admin/components/AdminDashboard.d.ts +7 -0
- package/dist/client/admin/components/AdminDashboard.d.ts.map +1 -0
- package/dist/client/admin/components/AdminDashboard.js +308 -0
- package/dist/client/admin/components/CollectionList.d.ts +16 -0
- package/dist/client/admin/components/CollectionList.d.ts.map +1 -0
- package/dist/client/admin/components/CollectionList.js +67 -0
- package/dist/client/admin/components/DocumentForm.d.ts +11 -0
- package/dist/client/admin/components/DocumentForm.d.ts.map +1 -0
- package/dist/client/admin/components/DocumentForm.js +223 -0
- package/dist/client/admin/components/GlobalForm.d.ts +11 -0
- package/dist/client/admin/components/GlobalForm.d.ts.map +1 -0
- package/dist/client/admin/components/GlobalForm.js +74 -0
- 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 +25 -0
- package/dist/client/admin/i18n/en.d.ts.map +1 -0
- package/dist/client/admin/i18n/en.js +25 -0
- package/dist/client/admin/index.d.ts +11 -0
- package/dist/client/admin/index.d.ts.map +1 -0
- package/dist/client/admin/index.js +11 -0
- package/dist/client/admin/layout.d.ts +10 -0
- package/dist/client/admin/layout.d.ts.map +1 -0
- package/dist/client/admin/layout.js +7 -0
- package/dist/client/admin/page.d.ts +38 -0
- package/dist/client/admin/page.d.ts.map +1 -0
- package/dist/client/admin/page.js +15 -0
- package/dist/client/admin/utils/apiClient.d.ts +110 -0
- package/dist/client/admin/utils/apiClient.d.ts.map +1 -0
- package/dist/client/admin/utils/apiClient.js +216 -0
- package/dist/client/admin/utils/index.d.ts +5 -0
- package/dist/client/admin/utils/index.d.ts.map +1 -0
- package/dist/client/admin/utils/index.js +4 -0
- package/dist/client/admin/utils/serializeConfig.d.ts +7 -0
- package/dist/client/admin/utils/serializeConfig.d.ts.map +1 -0
- package/dist/client/admin/utils/serializeConfig.js +35 -0
- package/dist/client/hooks.d.ts +18 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +29 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +13 -0
- package/dist/client/richtext/RichTextEditor.d.ts +48 -0
- package/dist/client/richtext/RichTextEditor.d.ts.map +1 -0
- package/dist/client/richtext/RichTextEditor.js +360 -0
- package/dist/client/richtext/components/ImageNodeComponent.d.ts +9 -0
- package/dist/client/richtext/components/ImageNodeComponent.d.ts.map +1 -0
- package/dist/client/richtext/components/ImageNodeComponent.js +98 -0
- package/dist/client/richtext/components/ImageUploadButton.d.ts +13 -0
- package/dist/client/richtext/components/ImageUploadButton.d.ts.map +1 -0
- package/dist/client/richtext/components/ImageUploadButton.js +118 -0
- package/dist/client/richtext/index.d.ts +92 -0
- package/dist/client/richtext/index.d.ts.map +1 -0
- package/dist/client/richtext/index.js +74 -0
- package/dist/client/richtext/nodes/DecoratorBlockNode.d.ts +20 -0
- package/dist/client/richtext/nodes/DecoratorBlockNode.d.ts.map +1 -0
- package/dist/client/richtext/nodes/DecoratorBlockNode.js +29 -0
- package/dist/client/richtext/nodes/ImageNode.d.ts +51 -0
- package/dist/client/richtext/nodes/ImageNode.d.ts.map +1 -0
- package/dist/client/richtext/nodes/ImageNode.js +95 -0
- package/dist/client/richtext/plugins/CollaborationPlugin.d.ts +13 -0
- package/dist/client/richtext/plugins/CollaborationPlugin.d.ts.map +1 -0
- package/dist/client/richtext/plugins/CollaborationPlugin.js +8 -0
- package/dist/client/richtext/plugins/CursorsOverlayPlugin.d.ts +4 -0
- package/dist/client/richtext/plugins/CursorsOverlayPlugin.d.ts.map +1 -0
- package/dist/client/richtext/plugins/CursorsOverlayPlugin.js +50 -0
- package/dist/client/richtext/plugins/FloatingToolbarPlugin.d.ts +7 -0
- package/dist/client/richtext/plugins/FloatingToolbarPlugin.d.ts.map +1 -0
- package/dist/client/richtext/plugins/FloatingToolbarPlugin.js +246 -0
- package/dist/client/richtext/plugins/ImagePlugin.d.ts +3 -0
- package/dist/client/richtext/plugins/ImagePlugin.d.ts.map +1 -0
- package/dist/client/richtext/plugins/ImagePlugin.js +73 -0
- package/dist/client/richtext/plugins/PastePlugin.d.ts +2 -0
- package/dist/client/richtext/plugins/PastePlugin.d.ts.map +1 -0
- package/dist/client/richtext/plugins/PastePlugin.js +36 -0
- package/dist/client/richtext/plugins/ToolbarPlugin.d.ts +8 -0
- package/dist/client/richtext/plugins/ToolbarPlugin.d.ts.map +1 -0
- package/dist/client/richtext/plugins/ToolbarPlugin.js +204 -0
- package/dist/client/ui/index.d.ts +111 -0
- package/dist/client/ui/index.d.ts.map +1 -0
- package/dist/client/ui/index.js +130 -0
- package/dist/collections/CollectionOperations.d.ts +27 -0
- package/dist/collections/CollectionOperations.d.ts.map +1 -0
- package/dist/collections/CollectionOperations.js +48 -0
- package/dist/collections/hooks.d.ts +11 -0
- package/dist/collections/hooks.d.ts.map +1 -0
- package/dist/collections/hooks.js +35 -0
- package/dist/collections/index.d.ts +2 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js +1 -0
- package/dist/collections/operations/create.d.ts +9 -0
- package/dist/collections/operations/create.d.ts.map +1 -0
- package/dist/collections/operations/create.js +130 -0
- 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 +10 -0
- package/dist/collections/operations/delete.d.ts.map +1 -0
- package/dist/collections/operations/delete.js +45 -0
- 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 +21 -0
- package/dist/collections/operations/fieldHooks.d.ts.map +1 -0
- package/dist/collections/operations/fieldHooks.js +51 -0
- package/dist/collections/operations/find.d.ts +8 -0
- package/dist/collections/operations/find.d.ts.map +1 -0
- package/dist/collections/operations/find.js +231 -0
- package/dist/collections/operations/findById.d.ts +14 -0
- package/dist/collections/operations/findById.d.ts.map +1 -0
- package/dist/collections/operations/findById.js +111 -0
- 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 +108 -0
- package/dist/collections/operations/update.d.ts +8 -0
- package/dist/collections/operations/update.d.ts.map +1 -0
- package/dist/collections/operations/update.js +226 -0
- 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 +9 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +61 -0
- package/dist/config/runtime.d.ts +22 -0
- package/dist/config/runtime.d.ts.map +1 -0
- package/dist/config/runtime.js +32 -0
- package/dist/config/utils.d.ts +2 -0
- package/dist/config/utils.d.ts.map +1 -0
- package/dist/config/utils.js +21 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +2 -0
- package/dist/database/safe-parse.d.ts +26 -0
- package/dist/database/safe-parse.d.ts.map +1 -0
- package/dist/database/safe-parse.js +42 -0
- package/dist/database/ssl-config.d.ts +9 -0
- package/dist/database/ssl-config.d.ts.map +1 -0
- package/dist/database/ssl-config.js +7 -0
- package/dist/database/type-adapter.d.ts +113 -0
- package/dist/database/type-adapter.d.ts.map +1 -0
- package/dist/database/type-adapter.js +97 -0
- package/dist/database/universal-postgres.d.ts +45 -0
- package/dist/database/universal-postgres.d.ts.map +1 -0
- package/dist/database/universal-postgres.js +531 -0
- package/dist/dataloader.d.ts +26 -0
- package/dist/dataloader.d.ts.map +1 -0
- package/dist/dataloader.js +176 -0
- package/dist/error-handling/error-boundary.d.ts +94 -0
- package/dist/error-handling/error-boundary.d.ts.map +1 -0
- package/dist/error-handling/error-boundary.js +285 -0
- package/dist/error-handling/error-reporter.d.ts +214 -0
- package/dist/error-handling/error-reporter.d.ts.map +1 -0
- package/dist/error-handling/error-reporter.js +491 -0
- package/dist/error-handling/fallback-components.d.ts +131 -0
- package/dist/error-handling/fallback-components.d.ts.map +1 -0
- package/dist/error-handling/fallback-components.js +371 -0
- package/dist/error-handling/index.d.ts +14 -0
- package/dist/error-handling/index.d.ts.map +1 -0
- package/dist/error-handling/index.js +12 -0
- package/dist/factories/builders.d.ts +50 -0
- package/dist/factories/builders.d.ts.map +1 -0
- package/dist/factories/builders.js +77 -0
- package/dist/factories/index.d.ts +2 -0
- package/dist/factories/index.d.ts.map +1 -0
- package/dist/factories/index.js +1 -0
- package/dist/features.d.ts +88 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +105 -0
- package/dist/fieldTraversal.d.ts +26 -0
- package/dist/fieldTraversal.d.ts.map +1 -0
- package/dist/fieldTraversal.js +132 -0
- package/dist/fields/config/types.d.ts +48 -0
- package/dist/fields/config/types.d.ts.map +1 -0
- package/dist/fields/config/types.js +20 -0
- package/dist/fields/getDefaultValue.d.ts +16 -0
- package/dist/fields/getDefaultValue.d.ts.map +1 -0
- package/dist/fields/getDefaultValue.js +20 -0
- package/dist/fields/getFieldPaths.d.ts +25 -0
- package/dist/fields/getFieldPaths.d.ts.map +1 -0
- package/dist/fields/getFieldPaths.js +23 -0
- package/dist/fields/hooks/afterRead/index.d.ts +36 -0
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -0
- package/dist/fields/hooks/afterRead/index.js +70 -0
- package/dist/fields/hooks/afterRead/promise.d.ts +46 -0
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -0
- package/dist/fields/hooks/afterRead/promise.js +178 -0
- package/dist/fields/hooks/afterRead/traverseFields.d.ts +44 -0
- package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -0
- package/dist/fields/hooks/afterRead/traverseFields.js +37 -0
- package/dist/generated/index.d.ts +10 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +9 -0
- package/dist/generated/types/cms.d.ts +1766 -0
- package/dist/generated/types/cms.d.ts.map +1 -0
- package/dist/generated/types/cms.js +11 -0
- package/dist/generated/types/index.d.ts +16 -0
- package/dist/generated/types/index.d.ts.map +1 -0
- package/dist/generated/types/index.js +21 -0
- package/dist/generated/types/neon.d.ts +11 -0
- package/dist/generated/types/neon.d.ts.map +1 -0
- package/dist/generated/types/neon.js +13 -0
- package/dist/globals/GlobalOperations.d.ts +24 -0
- package/dist/globals/GlobalOperations.d.ts.map +1 -0
- package/dist/globals/GlobalOperations.js +165 -0
- package/dist/globals/index.d.ts +2 -0
- package/dist/globals/index.d.ts.map +1 -0
- package/dist/globals/index.js +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +136 -0
- package/dist/instance/RevealUIInstance.d.ts +6 -0
- package/dist/instance/RevealUIInstance.d.ts.map +1 -0
- package/dist/instance/RevealUIInstance.js +293 -0
- package/dist/instance/index.d.ts +3 -0
- package/dist/instance/index.d.ts.map +1 -0
- package/dist/instance/index.js +2 -0
- package/dist/instance/logger.d.ts +31 -0
- package/dist/instance/logger.d.ts.map +1 -0
- package/dist/instance/logger.js +42 -0
- package/dist/instance/methods/create.d.ts +10 -0
- package/dist/instance/methods/create.d.ts.map +1 -0
- package/dist/instance/methods/create.js +38 -0
- package/dist/instance/methods/delete.d.ts +10 -0
- package/dist/instance/methods/delete.d.ts.map +1 -0
- package/dist/instance/methods/delete.js +24 -0
- package/dist/instance/methods/find.d.ts +10 -0
- package/dist/instance/methods/find.d.ts.map +1 -0
- package/dist/instance/methods/find.js +20 -0
- package/dist/instance/methods/findById.d.ts +13 -0
- package/dist/instance/methods/findById.d.ts.map +1 -0
- package/dist/instance/methods/findById.js +20 -0
- package/dist/instance/methods/hooks.d.ts +14 -0
- package/dist/instance/methods/hooks.d.ts.map +1 -0
- package/dist/instance/methods/hooks.js +34 -0
- package/dist/instance/methods/update.d.ts +10 -0
- package/dist/instance/methods/update.d.ts.map +1 -0
- package/dist/instance/methods/update.js +42 -0
- 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 +99 -0
- package/dist/license.d.ts.map +1 -0
- package/dist/license.js +262 -0
- package/dist/monitoring/alerts.d.ts +118 -0
- package/dist/monitoring/alerts.d.ts.map +1 -0
- package/dist/monitoring/alerts.js +324 -0
- package/dist/monitoring/cleanup-manager.d.ts +71 -0
- package/dist/monitoring/cleanup-manager.d.ts.map +1 -0
- package/dist/monitoring/cleanup-manager.js +226 -0
- package/dist/monitoring/health-monitor.d.ts +22 -0
- package/dist/monitoring/health-monitor.d.ts.map +1 -0
- package/dist/monitoring/health-monitor.js +142 -0
- package/dist/monitoring/index.d.ts +14 -0
- package/dist/monitoring/index.d.ts.map +1 -0
- package/dist/monitoring/index.js +17 -0
- package/dist/monitoring/process-registry.d.ts +97 -0
- package/dist/monitoring/process-registry.d.ts.map +1 -0
- package/dist/monitoring/process-registry.js +222 -0
- package/dist/monitoring/query-monitor.d.ts +153 -0
- package/dist/monitoring/query-monitor.d.ts.map +1 -0
- package/dist/monitoring/query-monitor.js +209 -0
- package/dist/monitoring/types.d.ts +231 -0
- package/dist/monitoring/types.d.ts.map +1 -0
- package/dist/monitoring/types.js +42 -0
- package/dist/monitoring/zombie-detector.d.ts +81 -0
- package/dist/monitoring/zombie-detector.d.ts.map +1 -0
- package/dist/monitoring/zombie-detector.js +236 -0
- package/dist/nextjs/index.d.ts +4 -0
- package/dist/nextjs/index.d.ts.map +1 -0
- package/dist/nextjs/index.js +3 -0
- package/dist/nextjs/utilities.d.ts +5 -0
- package/dist/nextjs/utilities.d.ts.map +1 -0
- package/dist/nextjs/utilities.js +16 -0
- package/dist/nextjs/withRevealUI.d.ts +20 -0
- package/dist/nextjs/withRevealUI.d.ts.map +1 -0
- package/dist/nextjs/withRevealUI.js +181 -0
- package/dist/observability/alerts.d.ts +138 -0
- package/dist/observability/alerts.d.ts.map +1 -0
- package/dist/observability/alerts.js +389 -0
- package/dist/observability/health-check.d.ts +91 -0
- package/dist/observability/health-check.d.ts.map +1 -0
- package/dist/observability/health-check.js +345 -0
- package/dist/observability/index.d.ts +12 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +11 -0
- package/dist/observability/logger.d.ts +47 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +140 -0
- package/dist/observability/metrics.d.ts +205 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +429 -0
- package/dist/observability/tracing.d.ts +149 -0
- package/dist/observability/tracing.d.ts.map +1 -0
- package/dist/observability/tracing.js +380 -0
- package/dist/plugins/form-builder.d.ts +115 -0
- package/dist/plugins/form-builder.d.ts.map +1 -0
- package/dist/plugins/form-builder.js +239 -0
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/nested-docs.d.ts +12 -0
- package/dist/plugins/nested-docs.d.ts.map +1 -0
- package/dist/plugins/nested-docs.js +111 -0
- package/dist/plugins/redirects.d.ts +17 -0
- package/dist/plugins/redirects.d.ts.map +1 -0
- package/dist/plugins/redirects.js +62 -0
- package/dist/queries/index.d.ts +2 -0
- package/dist/queries/index.d.ts.map +1 -0
- package/dist/queries/index.js +1 -0
- package/dist/queries/queryBuilder.d.ts +47 -0
- package/dist/queries/queryBuilder.d.ts.map +1 -0
- package/dist/queries/queryBuilder.js +276 -0
- package/dist/relationships/analyzer.d.ts +39 -0
- package/dist/relationships/analyzer.d.ts.map +1 -0
- package/dist/relationships/analyzer.js +135 -0
- package/dist/relationships/index.d.ts +3 -0
- package/dist/relationships/index.d.ts.map +1 -0
- package/dist/relationships/index.js +2 -0
- 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 +58 -0
- package/dist/relationships/populate-helpers.d.ts.map +1 -0
- package/dist/relationships/populate-helpers.js +82 -0
- package/dist/relationships/population.d.ts +34 -0
- package/dist/relationships/population.d.ts.map +1 -0
- package/dist/relationships/population.js +193 -0
- package/dist/revealui.d.ts +46 -0
- package/dist/revealui.d.ts.map +1 -0
- package/dist/revealui.js +92 -0
- package/dist/richtext/exports/client/rcc.d.ts +37 -0
- package/dist/richtext/exports/client/rcc.d.ts.map +1 -0
- package/dist/richtext/exports/client/rcc.js +182 -0
- package/dist/richtext/exports/server/rsc.d.ts +134 -0
- package/dist/richtext/exports/server/rsc.d.ts.map +1 -0
- package/dist/richtext/exports/server/rsc.js +344 -0
- package/dist/richtext/index.d.ts +161 -0
- package/dist/richtext/index.d.ts.map +1 -0
- package/dist/richtext/index.js +243 -0
- package/dist/richtext/lexical.d.ts +23 -0
- package/dist/richtext/lexical.d.ts.map +1 -0
- package/dist/richtext/lexical.js +35 -0
- package/dist/security/index.d.ts +6 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +5 -0
- package/dist/server/index.d.ts +21 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +28 -0
- package/dist/server/renderPage.d.ts +69 -0
- package/dist/server/renderPage.d.ts.map +1 -0
- package/dist/server/renderPage.js +109 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/vercel-blob.d.ts +17 -0
- package/dist/storage/vercel-blob.d.ts.map +1 -0
- package/dist/storage/vercel-blob.js +86 -0
- package/dist/translations/index.d.ts +17 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +1 -0
- package/dist/types/access.d.ts +67 -0
- package/dist/types/access.d.ts.map +1 -0
- package/dist/types/access.js +8 -0
- package/dist/types/api.d.ts +57 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +8 -0
- package/dist/types/cms.d.ts +8 -0
- package/dist/types/cms.d.ts.map +1 -0
- package/dist/types/cms.js +6 -0
- package/dist/types/config.d.ts +152 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +9 -0
- package/dist/types/core.d.ts +11 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +9 -0
- package/dist/types/extensions.d.ts +116 -0
- package/dist/types/extensions.d.ts.map +1 -0
- package/dist/types/extensions.js +8 -0
- package/dist/types/frontend.d.ts +53 -0
- package/dist/types/frontend.d.ts.map +1 -0
- package/dist/types/frontend.js +7 -0
- package/dist/types/generated.d.ts +12 -0
- package/dist/types/generated.d.ts.map +1 -0
- package/dist/types/generated.js +10 -0
- package/dist/types/hooks.d.ts +53 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/hooks.js +8 -0
- package/dist/types/index.d.ts +49 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +61 -0
- package/dist/types/interfaces/app.d.ts +50 -0
- package/dist/types/interfaces/app.d.ts.map +1 -0
- package/dist/types/interfaces/app.js +5 -0
- package/dist/types/jobs.d.ts +112 -0
- package/dist/types/jobs.d.ts.map +1 -0
- package/dist/types/jobs.js +7 -0
- package/dist/types/legacy.d.ts +147 -0
- package/dist/types/legacy.d.ts.map +1 -0
- package/dist/types/legacy.js +8 -0
- package/dist/types/plugins.d.ts +17 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/plugins.js +8 -0
- package/dist/types/query.d.ts +99 -0
- package/dist/types/query.d.ts.map +1 -0
- package/dist/types/query.js +24 -0
- package/dist/types/request.d.ts +40 -0
- package/dist/types/request.d.ts.map +1 -0
- package/dist/types/request.js +8 -0
- package/dist/types/richtext.d.ts +23 -0
- package/dist/types/richtext.d.ts.map +1 -0
- package/dist/types/richtext.js +8 -0
- package/dist/types/runtime.d.ts +275 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/runtime.js +9 -0
- package/dist/types/schema.d.ts +9 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +7 -0
- package/dist/types/user.d.ts +48 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +8 -0
- package/dist/utils/access-conversion.d.ts +17 -0
- package/dist/utils/access-conversion.d.ts.map +1 -0
- package/dist/utils/access-conversion.js +96 -0
- package/dist/utils/api-wrapper.d.ts +63 -0
- package/dist/utils/api-wrapper.d.ts.map +1 -0
- package/dist/utils/api-wrapper.js +151 -0
- package/dist/utils/block-conversion.d.ts +21 -0
- package/dist/utils/block-conversion.d.ts.map +1 -0
- package/dist/utils/block-conversion.js +109 -0
- package/dist/utils/cache.d.ts +86 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +154 -0
- package/dist/utils/deep-clone.d.ts +25 -0
- package/dist/utils/deep-clone.d.ts.map +1 -0
- package/dist/utils/deep-clone.js +114 -0
- package/dist/utils/error-responses.d.ts +57 -0
- package/dist/utils/error-responses.d.ts.map +1 -0
- package/dist/utils/error-responses.js +95 -0
- package/dist/utils/errors.d.ts +133 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +500 -0
- package/dist/utils/field-conversion.d.ts +40 -0
- package/dist/utils/field-conversion.d.ts.map +1 -0
- package/dist/utils/field-conversion.js +275 -0
- package/dist/utils/flattenResult.d.ts +7 -0
- package/dist/utils/flattenResult.d.ts.map +1 -0
- package/dist/utils/flattenResult.js +22 -0
- package/dist/utils/getBlockSelect.d.ts +12 -0
- package/dist/utils/getBlockSelect.d.ts.map +1 -0
- package/dist/utils/getBlockSelect.js +12 -0
- package/dist/utils/getSelectMode.d.ts +8 -0
- package/dist/utils/getSelectMode.d.ts.map +1 -0
- package/dist/utils/getSelectMode.js +21 -0
- package/dist/utils/isValidID.d.ts +5 -0
- package/dist/utils/isValidID.d.ts.map +1 -0
- package/dist/utils/isValidID.js +13 -0
- package/dist/utils/json-parsing.d.ts +48 -0
- package/dist/utils/json-parsing.d.ts.map +1 -0
- package/dist/utils/json-parsing.js +130 -0
- package/dist/utils/logger-client.d.ts +32 -0
- package/dist/utils/logger-client.d.ts.map +1 -0
- package/dist/utils/logger-client.js +55 -0
- package/dist/utils/logger-server.d.ts +32 -0
- package/dist/utils/logger-server.d.ts.map +1 -0
- package/dist/utils/logger-server.js +68 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +12 -0
- package/dist/utils/request-context.d.ts +143 -0
- package/dist/utils/request-context.d.ts.map +1 -0
- package/dist/utils/request-context.js +168 -0
- package/dist/utils/stripUnselectedFields.d.ts +10 -0
- package/dist/utils/stripUnselectedFields.d.ts.map +1 -0
- package/dist/utils/stripUnselectedFields.js +20 -0
- package/dist/utils/type-guards.d.ts +33 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +63 -0
- package/dist/utils/user.d.ts +14 -0
- package/dist/utils/user.d.ts.map +1 -0
- package/dist/utils/user.js +15 -0
- package/package.json +302 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Route Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps Next.js API routes to automatically set up request context,
|
|
5
|
+
* error handling, and logging.
|
|
6
|
+
*/
|
|
7
|
+
import { NextResponse } from 'next/server';
|
|
8
|
+
import { handleApiError } from './errors.js';
|
|
9
|
+
import { logger } from './logger.js';
|
|
10
|
+
import { createRequestContext, getRequestDuration, runInRequestContext, } from './request-context.js';
|
|
11
|
+
/**
|
|
12
|
+
* Wrap an API route handler with request context, logging, and error handling
|
|
13
|
+
*
|
|
14
|
+
* Benefits:
|
|
15
|
+
* - Automatic request ID generation and propagation
|
|
16
|
+
* - Request context available via getRequestContext()
|
|
17
|
+
* - Automatic error handling with proper status codes
|
|
18
|
+
* - Request/response logging with timing
|
|
19
|
+
* - All logs include request ID automatically
|
|
20
|
+
*
|
|
21
|
+
* @param handler - API route handler function
|
|
22
|
+
* @returns Wrapped handler with request context
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // app/api/users/route.ts
|
|
27
|
+
* import { withRequestContext } from '@revealui/core/utils/api-wrapper'
|
|
28
|
+
* import { NextResponse } from 'next/server'
|
|
29
|
+
*
|
|
30
|
+
* export const GET = withRequestContext(async (request) => {
|
|
31
|
+
* // Request ID automatically available in logs
|
|
32
|
+
* logger.info('Fetching users') // Includes requestId automatically
|
|
33
|
+
*
|
|
34
|
+
* const users = await db.query.users.findMany()
|
|
35
|
+
* return NextResponse.json(users)
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function withRequestContext(handler) {
|
|
40
|
+
return async (request) => {
|
|
41
|
+
// Create request context from headers
|
|
42
|
+
const context = createRequestContext({
|
|
43
|
+
headers: Object.fromEntries(request.headers.entries()),
|
|
44
|
+
path: request.nextUrl.pathname,
|
|
45
|
+
method: request.method,
|
|
46
|
+
ip: request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || undefined,
|
|
47
|
+
});
|
|
48
|
+
// Log incoming request
|
|
49
|
+
logger.info('Incoming request', {
|
|
50
|
+
method: context.method,
|
|
51
|
+
path: context.path,
|
|
52
|
+
ip: context.ip,
|
|
53
|
+
userAgent: context.userAgent,
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
// Run handler within request context
|
|
57
|
+
const response = await runInRequestContext(context, () => handler(request));
|
|
58
|
+
// Log successful response
|
|
59
|
+
const duration = getRequestDuration();
|
|
60
|
+
logger.info('Request completed', {
|
|
61
|
+
method: context.method,
|
|
62
|
+
path: context.path,
|
|
63
|
+
status: response.status,
|
|
64
|
+
duration,
|
|
65
|
+
});
|
|
66
|
+
// Add request ID to response headers
|
|
67
|
+
if (response instanceof NextResponse) {
|
|
68
|
+
response.headers.set('x-request-id', context.requestId);
|
|
69
|
+
response.headers.set('x-request-duration', duration?.toString() || '0');
|
|
70
|
+
}
|
|
71
|
+
return response;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// Handle errors with proper logging and status codes
|
|
75
|
+
const duration = getRequestDuration();
|
|
76
|
+
logger.error('Request failed', {
|
|
77
|
+
method: context.method,
|
|
78
|
+
path: context.path,
|
|
79
|
+
error: error instanceof Error ? error.message : String(error),
|
|
80
|
+
duration,
|
|
81
|
+
});
|
|
82
|
+
// Convert error to API response
|
|
83
|
+
const apiError = handleApiError(error, {
|
|
84
|
+
method: context.method,
|
|
85
|
+
path: context.path,
|
|
86
|
+
});
|
|
87
|
+
const errorResponse = NextResponse.json({
|
|
88
|
+
error: {
|
|
89
|
+
message: apiError.message,
|
|
90
|
+
code: apiError.code,
|
|
91
|
+
...(apiError.retryable !== undefined && { retryable: apiError.retryable }),
|
|
92
|
+
},
|
|
93
|
+
}, { status: apiError.statusCode });
|
|
94
|
+
// Add request ID to error response
|
|
95
|
+
errorResponse.headers.set('x-request-id', context.requestId);
|
|
96
|
+
errorResponse.headers.set('x-request-duration', duration?.toString() || '0');
|
|
97
|
+
return errorResponse;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Server action wrapper for request context
|
|
103
|
+
*
|
|
104
|
+
* Use this for Next.js Server Actions to enable request tracing
|
|
105
|
+
*
|
|
106
|
+
* @param action - Server action function
|
|
107
|
+
* @returns Wrapped action with request context
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* 'use server'
|
|
112
|
+
*
|
|
113
|
+
* import { withServerActionContext } from '@revealui/core/utils/api-wrapper'
|
|
114
|
+
*
|
|
115
|
+
* export const createUser = withServerActionContext(async (data) => {
|
|
116
|
+
* logger.info('Creating user') // Includes requestId
|
|
117
|
+
* return await db.insert(users).values(data)
|
|
118
|
+
* })
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export function withServerActionContext(action) {
|
|
122
|
+
return async (...args) => {
|
|
123
|
+
// Create request context (no headers available in server actions)
|
|
124
|
+
const context = createRequestContext({});
|
|
125
|
+
// Log server action execution
|
|
126
|
+
logger.info('Server action started', {
|
|
127
|
+
action: action.name || 'anonymous',
|
|
128
|
+
});
|
|
129
|
+
try {
|
|
130
|
+
// Run action within request context
|
|
131
|
+
const result = await runInRequestContext(context, () => action(...args));
|
|
132
|
+
// Log successful execution
|
|
133
|
+
const duration = getRequestDuration();
|
|
134
|
+
logger.info('Server action completed', {
|
|
135
|
+
action: action.name || 'anonymous',
|
|
136
|
+
duration,
|
|
137
|
+
});
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
// Log error
|
|
142
|
+
const duration = getRequestDuration();
|
|
143
|
+
logger.error('Server action failed', {
|
|
144
|
+
action: action.name || 'anonymous',
|
|
145
|
+
error: error instanceof Error ? error.message : String(error),
|
|
146
|
+
duration,
|
|
147
|
+
});
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { Block, RevealUIBlock, RevealUIContext } from '../types/index.js';
|
|
3
|
+
export declare function convertToRevealUIBlock(block: Block): RevealUIBlock;
|
|
4
|
+
export declare function convertFromRevealUIBlock(revealUIBlock: RevealUIBlock): Block;
|
|
5
|
+
export declare function enhanceBlockWithRevealUI(block: Block, revealUIOptions?: RevealUIBlock['revealUI']): RevealUIBlock;
|
|
6
|
+
/**
|
|
7
|
+
* Validate a RevealUI block
|
|
8
|
+
*
|
|
9
|
+
* @async
|
|
10
|
+
* @param block - The RevealUI block to validate
|
|
11
|
+
* @param data - The data to validate against the block
|
|
12
|
+
* @param context - The RevealUI context for validation
|
|
13
|
+
* @returns Promise resolving to a record of field errors (empty if valid)
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateRevealUIBlock(block: RevealUIBlock, data: Record<string, unknown>, context: RevealUIContext): Promise<Record<string, string>>;
|
|
16
|
+
export declare function getRevealUIBlockComponent(block: RevealUIBlock): React.ComponentType<{
|
|
17
|
+
data: Record<string, unknown>;
|
|
18
|
+
onChange: (data: Record<string, unknown>) => void;
|
|
19
|
+
revealUI?: RevealUIContext;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=block-conversion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-conversion.d.ts","sourceRoot":"","sources":["../../src/utils/block-conversion.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,KAAK,EAAS,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAItF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAalE;AAGD,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,aAAa,GAAG,KAAK,CAa5E;AAGD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,KAAK,EACZ,eAAe,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,GAC1C,aAAa,CAWf;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0BjC;AAGD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;IACnF,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B,CAAC,CAsDD"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { convertToRevealUIField } from './field-conversion.js';
|
|
3
|
+
// Convert from standard block to RevealUI block
|
|
4
|
+
export function convertToRevealUIBlock(block) {
|
|
5
|
+
return {
|
|
6
|
+
slug: block.slug,
|
|
7
|
+
fields: block.fields.map(convertToRevealUIField),
|
|
8
|
+
revealUI: {
|
|
9
|
+
category: 'content',
|
|
10
|
+
icon: 'block',
|
|
11
|
+
preview: undefined,
|
|
12
|
+
permissions: ['read', 'write'],
|
|
13
|
+
tenantScoped: false,
|
|
14
|
+
},
|
|
15
|
+
labels: block.labels || { singular: block.slug, plural: `${block.slug}s` },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// Convert from RevealUI block to standard block
|
|
19
|
+
export function convertFromRevealUIBlock(revealUIBlock) {
|
|
20
|
+
return {
|
|
21
|
+
slug: revealUIBlock.slug,
|
|
22
|
+
fields: revealUIBlock.fields.map((field) => ({
|
|
23
|
+
name: field.name,
|
|
24
|
+
type: field.type,
|
|
25
|
+
label: field.label,
|
|
26
|
+
required: field.required,
|
|
27
|
+
admin: field.admin,
|
|
28
|
+
validate: field.validate,
|
|
29
|
+
})),
|
|
30
|
+
labels: revealUIBlock.labels,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// Enhance a standard block with RevealUI features
|
|
34
|
+
export function enhanceBlockWithRevealUI(block, revealUIOptions) {
|
|
35
|
+
const revealUIBlock = convertToRevealUIBlock(block);
|
|
36
|
+
if (revealUIOptions) {
|
|
37
|
+
revealUIBlock.revealUI = {
|
|
38
|
+
...revealUIBlock.revealUI,
|
|
39
|
+
...revealUIOptions,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return revealUIBlock;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate a RevealUI block
|
|
46
|
+
*
|
|
47
|
+
* @async
|
|
48
|
+
* @param block - The RevealUI block to validate
|
|
49
|
+
* @param data - The data to validate against the block
|
|
50
|
+
* @param context - The RevealUI context for validation
|
|
51
|
+
* @returns Promise resolving to a record of field errors (empty if valid)
|
|
52
|
+
*/
|
|
53
|
+
export async function validateRevealUIBlock(block, data, context) {
|
|
54
|
+
const errors = {};
|
|
55
|
+
// Validate each field in the block
|
|
56
|
+
for (const field of block.fields) {
|
|
57
|
+
if (!field.name)
|
|
58
|
+
continue; // Skip fields without names
|
|
59
|
+
const value = data[field.name];
|
|
60
|
+
const validationContext = {
|
|
61
|
+
data,
|
|
62
|
+
siblingData: data,
|
|
63
|
+
user: context.user ?? undefined,
|
|
64
|
+
tenant: context.tenant,
|
|
65
|
+
operation: 'update',
|
|
66
|
+
};
|
|
67
|
+
// Import the validation function dynamically to avoid circular imports
|
|
68
|
+
const { validateRevealUIField } = await import('./field-conversion.js');
|
|
69
|
+
const result = validateRevealUIField(field, value, validationContext);
|
|
70
|
+
if (result !== true) {
|
|
71
|
+
errors[field.name] = result;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return errors;
|
|
75
|
+
}
|
|
76
|
+
// Get a React component for rendering a RevealUI block
|
|
77
|
+
export function getRevealUIBlockComponent(block) {
|
|
78
|
+
return function RevealUIBlockComponent({ data, onChange, revealUI }) {
|
|
79
|
+
void revealUI;
|
|
80
|
+
const blockFields = block.fields.map((field) => {
|
|
81
|
+
return {
|
|
82
|
+
name: field.name,
|
|
83
|
+
type: field.type,
|
|
84
|
+
label: field.label,
|
|
85
|
+
required: field.required,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const formatValue = (value) => {
|
|
89
|
+
if (value === null || value === undefined)
|
|
90
|
+
return '';
|
|
91
|
+
if (typeof value === 'string')
|
|
92
|
+
return value;
|
|
93
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
94
|
+
return String(value);
|
|
95
|
+
}
|
|
96
|
+
if (typeof value === 'symbol')
|
|
97
|
+
return value.description ?? value.toString();
|
|
98
|
+
if (typeof value === 'function')
|
|
99
|
+
return value.name || 'function';
|
|
100
|
+
return JSON.stringify(value);
|
|
101
|
+
};
|
|
102
|
+
return (_jsx("div", { className: "reveal-ui-block", "data-block-slug": block.slug, children: _jsx("div", { className: "reveal-ui-block-fields", children: blockFields.map((field) => {
|
|
103
|
+
const fieldName = typeof field.name === 'string' ? field.name : '';
|
|
104
|
+
const fieldLabel = typeof field.label === 'string' ? field.label : fieldName || 'Field';
|
|
105
|
+
const value = fieldName ? data[fieldName] : undefined;
|
|
106
|
+
return (_jsxs("div", { className: "reveal-ui-field", children: [_jsxs("label", { className: "reveal-ui-field-label", htmlFor: `field-${fieldName}`, children: [fieldLabel, field.required && _jsx("span", { className: "required", children: "*" })] }), _jsx("div", { className: "reveal-ui-field-input", children: _jsx("input", { type: "text", id: `field-${fieldName}`, value: formatValue(value), onChange: (e) => onChange({ ...data, [fieldName]: e.target.value }), required: field.required }) })] }, fieldName || Math.random()));
|
|
107
|
+
}) }) }));
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LRU Cache with TTL (Time To Live)
|
|
3
|
+
*
|
|
4
|
+
* Provides a cache implementation with:
|
|
5
|
+
* - TTL (Time To Live) expiration
|
|
6
|
+
* - Size limits with LRU eviction
|
|
7
|
+
* - Type-safe generic interface
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const cache = new LRUCache<string, User>({ maxSize: 100, ttlMs: 5 * 60 * 1000 })
|
|
12
|
+
* const user = await cache.fetch('user:123', () => fetchUserFromDB('123'))
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface LRUCacheOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Maximum number of entries in the cache
|
|
18
|
+
* @default 100
|
|
19
|
+
*/
|
|
20
|
+
maxSize?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Time to live in milliseconds
|
|
23
|
+
* @default 5 minutes (300000)
|
|
24
|
+
*/
|
|
25
|
+
ttlMs?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* LRU Cache with TTL for storing key-value pairs
|
|
29
|
+
*
|
|
30
|
+
* Features:
|
|
31
|
+
* - Automatic expiration based on TTL
|
|
32
|
+
* - Size limits with LRU (Least Recently Used) eviction
|
|
33
|
+
* - Type-safe generic interface
|
|
34
|
+
*/
|
|
35
|
+
export declare class LRUCache<K = string, V = unknown> {
|
|
36
|
+
private cache;
|
|
37
|
+
private readonly maxSize;
|
|
38
|
+
private readonly ttlMs;
|
|
39
|
+
constructor(options?: LRUCacheOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Fetch a value from cache or compute it using the fetcher function
|
|
42
|
+
*
|
|
43
|
+
* @param key - Cache key
|
|
44
|
+
* @param fetcher - Function to fetch the value if not in cache
|
|
45
|
+
* @returns The cached or newly fetched value
|
|
46
|
+
*/
|
|
47
|
+
fetch(key: K, fetcher: () => Promise<V> | V): Promise<V>;
|
|
48
|
+
/**
|
|
49
|
+
* Get a value from cache without fetching (returns undefined if not found or expired)
|
|
50
|
+
*
|
|
51
|
+
* @param key - Cache key
|
|
52
|
+
* @returns The cached value or undefined
|
|
53
|
+
*/
|
|
54
|
+
get(key: K): V | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Set a value in the cache
|
|
57
|
+
*
|
|
58
|
+
* @param key - Cache key
|
|
59
|
+
* @param value - Value to cache
|
|
60
|
+
*/
|
|
61
|
+
set(key: K, value: V): void;
|
|
62
|
+
/**
|
|
63
|
+
* Delete a value from the cache
|
|
64
|
+
*
|
|
65
|
+
* @param key - Cache key
|
|
66
|
+
* @returns true if the entry was deleted, false if it didn't exist
|
|
67
|
+
*/
|
|
68
|
+
delete(key: K): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Clear all entries from the cache
|
|
71
|
+
*/
|
|
72
|
+
clear(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current size of the cache
|
|
75
|
+
*/
|
|
76
|
+
get size(): number;
|
|
77
|
+
/**
|
|
78
|
+
* Evict expired entries and LRU entries if at capacity
|
|
79
|
+
*/
|
|
80
|
+
private evictIfNeeded;
|
|
81
|
+
/**
|
|
82
|
+
* Clean up expired entries (can be called periodically)
|
|
83
|
+
*/
|
|
84
|
+
cleanup(): void;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAQD;;;;;;;GAOG;AACH,qBAAa,QAAQ,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO;IAC3C,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,OAAO,GAAE,eAAoB;IAKzC;;;;;;OAMG;IACG,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA8B9D;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAiB1B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAW3B;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIvB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,OAAO,CAAC,aAAa;IA4BrB;;OAEG;IACH,OAAO,IAAI,IAAI;CAQhB"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LRU Cache with TTL (Time To Live)
|
|
3
|
+
*
|
|
4
|
+
* Provides a cache implementation with:
|
|
5
|
+
* - TTL (Time To Live) expiration
|
|
6
|
+
* - Size limits with LRU eviction
|
|
7
|
+
* - Type-safe generic interface
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const cache = new LRUCache<string, User>({ maxSize: 100, ttlMs: 5 * 60 * 1000 })
|
|
12
|
+
* const user = await cache.fetch('user:123', () => fetchUserFromDB('123'))
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* LRU Cache with TTL for storing key-value pairs
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Automatic expiration based on TTL
|
|
20
|
+
* - Size limits with LRU (Least Recently Used) eviction
|
|
21
|
+
* - Type-safe generic interface
|
|
22
|
+
*/
|
|
23
|
+
export class LRUCache {
|
|
24
|
+
cache = new Map();
|
|
25
|
+
maxSize;
|
|
26
|
+
ttlMs;
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
this.maxSize = options.maxSize ?? 100;
|
|
29
|
+
this.ttlMs = options.ttlMs ?? 5 * 60 * 1000; // 5 minutes default
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fetch a value from cache or compute it using the fetcher function
|
|
33
|
+
*
|
|
34
|
+
* @param key - Cache key
|
|
35
|
+
* @param fetcher - Function to fetch the value if not in cache
|
|
36
|
+
* @returns The cached or newly fetched value
|
|
37
|
+
*/
|
|
38
|
+
async fetch(key, fetcher) {
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
const cached = this.cache.get(key);
|
|
41
|
+
// Check if cached entry exists and is still valid
|
|
42
|
+
if (cached && cached.expiresAt > now) {
|
|
43
|
+
// Update last accessed time for LRU
|
|
44
|
+
cached.lastAccessed = now;
|
|
45
|
+
return cached.data;
|
|
46
|
+
}
|
|
47
|
+
// Remove expired entry if present
|
|
48
|
+
if (cached) {
|
|
49
|
+
this.cache.delete(key);
|
|
50
|
+
}
|
|
51
|
+
// Evict least recently used entries if at capacity
|
|
52
|
+
this.evictIfNeeded();
|
|
53
|
+
// Fetch fresh data
|
|
54
|
+
const data = await fetcher();
|
|
55
|
+
this.cache.set(key, {
|
|
56
|
+
data,
|
|
57
|
+
expiresAt: now + this.ttlMs,
|
|
58
|
+
lastAccessed: now,
|
|
59
|
+
});
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get a value from cache without fetching (returns undefined if not found or expired)
|
|
64
|
+
*
|
|
65
|
+
* @param key - Cache key
|
|
66
|
+
* @returns The cached value or undefined
|
|
67
|
+
*/
|
|
68
|
+
get(key) {
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
const cached = this.cache.get(key);
|
|
71
|
+
if (cached && cached.expiresAt > now) {
|
|
72
|
+
cached.lastAccessed = now;
|
|
73
|
+
return cached.data;
|
|
74
|
+
}
|
|
75
|
+
// Remove expired entry
|
|
76
|
+
if (cached) {
|
|
77
|
+
this.cache.delete(key);
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Set a value in the cache
|
|
83
|
+
*
|
|
84
|
+
* @param key - Cache key
|
|
85
|
+
* @param value - Value to cache
|
|
86
|
+
*/
|
|
87
|
+
set(key, value) {
|
|
88
|
+
const now = Date.now();
|
|
89
|
+
this.evictIfNeeded();
|
|
90
|
+
this.cache.set(key, {
|
|
91
|
+
data: value,
|
|
92
|
+
expiresAt: now + this.ttlMs,
|
|
93
|
+
lastAccessed: now,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Delete a value from the cache
|
|
98
|
+
*
|
|
99
|
+
* @param key - Cache key
|
|
100
|
+
* @returns true if the entry was deleted, false if it didn't exist
|
|
101
|
+
*/
|
|
102
|
+
delete(key) {
|
|
103
|
+
return this.cache.delete(key);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Clear all entries from the cache
|
|
107
|
+
*/
|
|
108
|
+
clear() {
|
|
109
|
+
this.cache.clear();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the current size of the cache
|
|
113
|
+
*/
|
|
114
|
+
get size() {
|
|
115
|
+
return this.cache.size;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Evict expired entries and LRU entries if at capacity
|
|
119
|
+
*/
|
|
120
|
+
evictIfNeeded() {
|
|
121
|
+
const now = Date.now();
|
|
122
|
+
// First, remove all expired entries
|
|
123
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
124
|
+
if (entry.expiresAt <= now) {
|
|
125
|
+
this.cache.delete(key);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// If still at capacity, remove least recently used entry
|
|
129
|
+
if (this.cache.size >= this.maxSize) {
|
|
130
|
+
let lruKey;
|
|
131
|
+
let lruTime = Infinity;
|
|
132
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
133
|
+
if (entry.lastAccessed < lruTime) {
|
|
134
|
+
lruTime = entry.lastAccessed;
|
|
135
|
+
lruKey = key;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (lruKey !== undefined) {
|
|
139
|
+
this.cache.delete(lruKey);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Clean up expired entries (can be called periodically)
|
|
145
|
+
*/
|
|
146
|
+
cleanup() {
|
|
147
|
+
const now = Date.now();
|
|
148
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
149
|
+
if (entry.expiresAt <= now) {
|
|
150
|
+
this.cache.delete(key);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep Clone Utility
|
|
3
|
+
*
|
|
4
|
+
* Properly deep clones objects, handling edge cases that JSON.parse(JSON.stringify()) misses:
|
|
5
|
+
* - Preserves Date objects
|
|
6
|
+
* - Handles undefined values (by omitting them, which is acceptable for our use case)
|
|
7
|
+
* - Handles null values correctly
|
|
8
|
+
* - Works with plain objects and arrays
|
|
9
|
+
* - Handles Map, Set, RegExp, TypedArrays, ArrayBuffer
|
|
10
|
+
* - Throws on circular references (fail-fast is better than silent corruption)
|
|
11
|
+
*
|
|
12
|
+
* This is a comprehensive deep clone implementation suitable for production use.
|
|
13
|
+
* Moved from @revealui/ai/memory/utils/deep-clone.ts to @revealui/core/utils/deep-clone.ts
|
|
14
|
+
* for shared usage across the framework.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Deep clones a plain object or array.
|
|
18
|
+
*
|
|
19
|
+
* @param obj - Object to clone
|
|
20
|
+
* @param visited - Internal parameter to track visited objects (for circular reference detection)
|
|
21
|
+
* @returns Deep cloned object
|
|
22
|
+
* @throws Error if object contains circular references
|
|
23
|
+
*/
|
|
24
|
+
export declare function deepClone<T>(obj: T, visited?: WeakMap<object, unknown>): T;
|
|
25
|
+
//# sourceMappingURL=deep-clone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-clone.d.ts","sourceRoot":"","sources":["../../src/utils/deep-clone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,2BAAiC,GAAG,CAAC,CAuHhF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep Clone Utility
|
|
3
|
+
*
|
|
4
|
+
* Properly deep clones objects, handling edge cases that JSON.parse(JSON.stringify()) misses:
|
|
5
|
+
* - Preserves Date objects
|
|
6
|
+
* - Handles undefined values (by omitting them, which is acceptable for our use case)
|
|
7
|
+
* - Handles null values correctly
|
|
8
|
+
* - Works with plain objects and arrays
|
|
9
|
+
* - Handles Map, Set, RegExp, TypedArrays, ArrayBuffer
|
|
10
|
+
* - Throws on circular references (fail-fast is better than silent corruption)
|
|
11
|
+
*
|
|
12
|
+
* This is a comprehensive deep clone implementation suitable for production use.
|
|
13
|
+
* Moved from @revealui/ai/memory/utils/deep-clone.ts to @revealui/core/utils/deep-clone.ts
|
|
14
|
+
* for shared usage across the framework.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Deep clones a plain object or array.
|
|
18
|
+
*
|
|
19
|
+
* @param obj - Object to clone
|
|
20
|
+
* @param visited - Internal parameter to track visited objects (for circular reference detection)
|
|
21
|
+
* @returns Deep cloned object
|
|
22
|
+
* @throws Error if object contains circular references
|
|
23
|
+
*/
|
|
24
|
+
export function deepClone(obj, visited = new WeakMap()) {
|
|
25
|
+
// Handle primitives and null
|
|
26
|
+
if (obj === null || typeof obj !== 'object') {
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
// Check for circular references
|
|
30
|
+
if (visited.has(obj)) {
|
|
31
|
+
throw new Error('Circular reference detected in object');
|
|
32
|
+
}
|
|
33
|
+
// Handle Date objects
|
|
34
|
+
if (obj instanceof Date) {
|
|
35
|
+
return new Date(obj.getTime());
|
|
36
|
+
}
|
|
37
|
+
// Handle RegExp objects
|
|
38
|
+
if (obj instanceof RegExp) {
|
|
39
|
+
return new RegExp(obj.source, obj.flags);
|
|
40
|
+
}
|
|
41
|
+
// Handle Map objects
|
|
42
|
+
if (obj instanceof Map) {
|
|
43
|
+
visited.set(obj, new Map());
|
|
44
|
+
const cloned = new Map();
|
|
45
|
+
for (const [key, value] of obj.entries()) {
|
|
46
|
+
cloned.set(deepClone(key, visited), deepClone(value, visited));
|
|
47
|
+
}
|
|
48
|
+
visited.delete(obj);
|
|
49
|
+
return cloned;
|
|
50
|
+
}
|
|
51
|
+
// Handle Set objects
|
|
52
|
+
if (obj instanceof Set) {
|
|
53
|
+
visited.set(obj, new Set());
|
|
54
|
+
const cloned = new Set();
|
|
55
|
+
for (const value of obj.values()) {
|
|
56
|
+
cloned.add(deepClone(value, visited));
|
|
57
|
+
}
|
|
58
|
+
visited.delete(obj);
|
|
59
|
+
return cloned;
|
|
60
|
+
}
|
|
61
|
+
// Handle TypedArrays (Uint8Array, Int32Array, etc.)
|
|
62
|
+
if (ArrayBuffer.isView(obj)) {
|
|
63
|
+
const typedArray = obj;
|
|
64
|
+
const TypedArrayConstructor = obj.constructor;
|
|
65
|
+
return new TypedArrayConstructor(typedArray.buffer.slice(), typedArray.byteOffset, typedArray.length);
|
|
66
|
+
}
|
|
67
|
+
// Handle ArrayBuffer
|
|
68
|
+
if (obj instanceof ArrayBuffer) {
|
|
69
|
+
return obj.slice(0);
|
|
70
|
+
}
|
|
71
|
+
// Handle arrays
|
|
72
|
+
if (Array.isArray(obj)) {
|
|
73
|
+
visited.set(obj, []);
|
|
74
|
+
const array = obj;
|
|
75
|
+
const cloned = array.map((item) => deepClone(item, visited));
|
|
76
|
+
visited.delete(obj);
|
|
77
|
+
return cloned;
|
|
78
|
+
}
|
|
79
|
+
// Handle plain objects
|
|
80
|
+
if (typeof obj === 'object') {
|
|
81
|
+
visited.set(obj, {});
|
|
82
|
+
const cloned = {};
|
|
83
|
+
const objRecord = obj;
|
|
84
|
+
for (const key in objRecord) {
|
|
85
|
+
if (Object.hasOwn(objRecord, key)) {
|
|
86
|
+
const value = objRecord[key];
|
|
87
|
+
// Skip undefined (JSON.stringify behavior)
|
|
88
|
+
if (value === undefined) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
cloned[key] = deepClone(value, visited);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
visited.delete(obj);
|
|
96
|
+
// If we hit a circular reference or other issue, throw with context
|
|
97
|
+
throw new Error(`Failed to deep clone object: ${error instanceof Error ? error.message : String(error)} at key "${key}"`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
visited.delete(obj);
|
|
102
|
+
return cloned;
|
|
103
|
+
}
|
|
104
|
+
// Handle functions - return as-is (can't clone functions)
|
|
105
|
+
if (typeof obj === 'function') {
|
|
106
|
+
return obj;
|
|
107
|
+
}
|
|
108
|
+
// Handle symbols - return as-is (symbols are unique by design)
|
|
109
|
+
if (typeof obj === 'symbol') {
|
|
110
|
+
return obj;
|
|
111
|
+
}
|
|
112
|
+
// Fallback for other types
|
|
113
|
+
return obj;
|
|
114
|
+
}
|