@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.
Files changed (522) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +171 -0
  3. package/dist/api/compression.d.ts +83 -0
  4. package/dist/api/compression.d.ts.map +1 -0
  5. package/dist/api/compression.js +233 -0
  6. package/dist/api/payload-optimization.d.ts +138 -0
  7. package/dist/api/payload-optimization.d.ts.map +1 -0
  8. package/dist/api/payload-optimization.js +320 -0
  9. package/dist/api/rate-limit.d.ts +114 -0
  10. package/dist/api/rate-limit.d.ts.map +1 -0
  11. package/dist/api/rate-limit.js +376 -0
  12. package/dist/api/response-cache.d.ts +125 -0
  13. package/dist/api/response-cache.d.ts.map +1 -0
  14. package/dist/api/response-cache.js +335 -0
  15. package/dist/api/rest.d.ts +54 -0
  16. package/dist/api/rest.d.ts.map +1 -0
  17. package/dist/api/rest.js +465 -0
  18. package/dist/auth/access.d.ts +25 -0
  19. package/dist/auth/access.d.ts.map +1 -0
  20. package/dist/auth/access.js +20 -0
  21. package/dist/auth/index.d.ts +2 -0
  22. package/dist/auth/index.d.ts.map +1 -0
  23. package/dist/auth/index.js +2 -0
  24. package/dist/cache/query-cache.d.ts +100 -0
  25. package/dist/cache/query-cache.d.ts.map +1 -0
  26. package/dist/cache/query-cache.js +266 -0
  27. package/dist/caching/index.d.ts +6 -0
  28. package/dist/caching/index.d.ts.map +1 -0
  29. package/dist/caching/index.js +5 -0
  30. package/dist/client/admin/RichText.d.ts +12 -0
  31. package/dist/client/admin/RichText.d.ts.map +1 -0
  32. package/dist/client/admin/RichText.js +5 -0
  33. package/dist/client/admin/components/AdminDashboard.d.ts +7 -0
  34. package/dist/client/admin/components/AdminDashboard.d.ts.map +1 -0
  35. package/dist/client/admin/components/AdminDashboard.js +308 -0
  36. package/dist/client/admin/components/CollectionList.d.ts +16 -0
  37. package/dist/client/admin/components/CollectionList.d.ts.map +1 -0
  38. package/dist/client/admin/components/CollectionList.js +67 -0
  39. package/dist/client/admin/components/DocumentForm.d.ts +11 -0
  40. package/dist/client/admin/components/DocumentForm.d.ts.map +1 -0
  41. package/dist/client/admin/components/DocumentForm.js +223 -0
  42. package/dist/client/admin/components/GlobalForm.d.ts +11 -0
  43. package/dist/client/admin/components/GlobalForm.d.ts.map +1 -0
  44. package/dist/client/admin/components/GlobalForm.js +74 -0
  45. package/dist/client/admin/context/ServerFunctionContext.d.ts +8 -0
  46. package/dist/client/admin/context/ServerFunctionContext.d.ts.map +1 -0
  47. package/dist/client/admin/context/ServerFunctionContext.js +15 -0
  48. package/dist/client/admin/i18n/en.d.ts +25 -0
  49. package/dist/client/admin/i18n/en.d.ts.map +1 -0
  50. package/dist/client/admin/i18n/en.js +25 -0
  51. package/dist/client/admin/index.d.ts +11 -0
  52. package/dist/client/admin/index.d.ts.map +1 -0
  53. package/dist/client/admin/index.js +11 -0
  54. package/dist/client/admin/layout.d.ts +10 -0
  55. package/dist/client/admin/layout.d.ts.map +1 -0
  56. package/dist/client/admin/layout.js +7 -0
  57. package/dist/client/admin/page.d.ts +38 -0
  58. package/dist/client/admin/page.d.ts.map +1 -0
  59. package/dist/client/admin/page.js +15 -0
  60. package/dist/client/admin/utils/apiClient.d.ts +110 -0
  61. package/dist/client/admin/utils/apiClient.d.ts.map +1 -0
  62. package/dist/client/admin/utils/apiClient.js +216 -0
  63. package/dist/client/admin/utils/index.d.ts +5 -0
  64. package/dist/client/admin/utils/index.d.ts.map +1 -0
  65. package/dist/client/admin/utils/index.js +4 -0
  66. package/dist/client/admin/utils/serializeConfig.d.ts +7 -0
  67. package/dist/client/admin/utils/serializeConfig.d.ts.map +1 -0
  68. package/dist/client/admin/utils/serializeConfig.js +35 -0
  69. package/dist/client/hooks.d.ts +18 -0
  70. package/dist/client/hooks.d.ts.map +1 -0
  71. package/dist/client/hooks.js +29 -0
  72. package/dist/client/index.d.ts +11 -0
  73. package/dist/client/index.d.ts.map +1 -0
  74. package/dist/client/index.js +13 -0
  75. package/dist/client/richtext/RichTextEditor.d.ts +48 -0
  76. package/dist/client/richtext/RichTextEditor.d.ts.map +1 -0
  77. package/dist/client/richtext/RichTextEditor.js +360 -0
  78. package/dist/client/richtext/components/ImageNodeComponent.d.ts +9 -0
  79. package/dist/client/richtext/components/ImageNodeComponent.d.ts.map +1 -0
  80. package/dist/client/richtext/components/ImageNodeComponent.js +98 -0
  81. package/dist/client/richtext/components/ImageUploadButton.d.ts +13 -0
  82. package/dist/client/richtext/components/ImageUploadButton.d.ts.map +1 -0
  83. package/dist/client/richtext/components/ImageUploadButton.js +118 -0
  84. package/dist/client/richtext/index.d.ts +92 -0
  85. package/dist/client/richtext/index.d.ts.map +1 -0
  86. package/dist/client/richtext/index.js +74 -0
  87. package/dist/client/richtext/nodes/DecoratorBlockNode.d.ts +20 -0
  88. package/dist/client/richtext/nodes/DecoratorBlockNode.d.ts.map +1 -0
  89. package/dist/client/richtext/nodes/DecoratorBlockNode.js +29 -0
  90. package/dist/client/richtext/nodes/ImageNode.d.ts +51 -0
  91. package/dist/client/richtext/nodes/ImageNode.d.ts.map +1 -0
  92. package/dist/client/richtext/nodes/ImageNode.js +95 -0
  93. package/dist/client/richtext/plugins/CollaborationPlugin.d.ts +13 -0
  94. package/dist/client/richtext/plugins/CollaborationPlugin.d.ts.map +1 -0
  95. package/dist/client/richtext/plugins/CollaborationPlugin.js +8 -0
  96. package/dist/client/richtext/plugins/CursorsOverlayPlugin.d.ts +4 -0
  97. package/dist/client/richtext/plugins/CursorsOverlayPlugin.d.ts.map +1 -0
  98. package/dist/client/richtext/plugins/CursorsOverlayPlugin.js +50 -0
  99. package/dist/client/richtext/plugins/FloatingToolbarPlugin.d.ts +7 -0
  100. package/dist/client/richtext/plugins/FloatingToolbarPlugin.d.ts.map +1 -0
  101. package/dist/client/richtext/plugins/FloatingToolbarPlugin.js +246 -0
  102. package/dist/client/richtext/plugins/ImagePlugin.d.ts +3 -0
  103. package/dist/client/richtext/plugins/ImagePlugin.d.ts.map +1 -0
  104. package/dist/client/richtext/plugins/ImagePlugin.js +73 -0
  105. package/dist/client/richtext/plugins/PastePlugin.d.ts +2 -0
  106. package/dist/client/richtext/plugins/PastePlugin.d.ts.map +1 -0
  107. package/dist/client/richtext/plugins/PastePlugin.js +36 -0
  108. package/dist/client/richtext/plugins/ToolbarPlugin.d.ts +8 -0
  109. package/dist/client/richtext/plugins/ToolbarPlugin.d.ts.map +1 -0
  110. package/dist/client/richtext/plugins/ToolbarPlugin.js +204 -0
  111. package/dist/client/ui/index.d.ts +111 -0
  112. package/dist/client/ui/index.d.ts.map +1 -0
  113. package/dist/client/ui/index.js +130 -0
  114. package/dist/collections/CollectionOperations.d.ts +27 -0
  115. package/dist/collections/CollectionOperations.d.ts.map +1 -0
  116. package/dist/collections/CollectionOperations.js +48 -0
  117. package/dist/collections/hooks.d.ts +11 -0
  118. package/dist/collections/hooks.d.ts.map +1 -0
  119. package/dist/collections/hooks.js +35 -0
  120. package/dist/collections/index.d.ts +2 -0
  121. package/dist/collections/index.d.ts.map +1 -0
  122. package/dist/collections/index.js +1 -0
  123. package/dist/collections/operations/create.d.ts +9 -0
  124. package/dist/collections/operations/create.d.ts.map +1 -0
  125. package/dist/collections/operations/create.js +130 -0
  126. package/dist/collections/operations/createMany.d.ts +12 -0
  127. package/dist/collections/operations/createMany.d.ts.map +1 -0
  128. package/dist/collections/operations/createMany.js +43 -0
  129. package/dist/collections/operations/delete.d.ts +10 -0
  130. package/dist/collections/operations/delete.d.ts.map +1 -0
  131. package/dist/collections/operations/delete.js +45 -0
  132. package/dist/collections/operations/deleteMany.d.ts +11 -0
  133. package/dist/collections/operations/deleteMany.d.ts.map +1 -0
  134. package/dist/collections/operations/deleteMany.js +50 -0
  135. package/dist/collections/operations/fieldHooks.d.ts +21 -0
  136. package/dist/collections/operations/fieldHooks.d.ts.map +1 -0
  137. package/dist/collections/operations/fieldHooks.js +51 -0
  138. package/dist/collections/operations/find.d.ts +8 -0
  139. package/dist/collections/operations/find.d.ts.map +1 -0
  140. package/dist/collections/operations/find.js +231 -0
  141. package/dist/collections/operations/findById.d.ts +14 -0
  142. package/dist/collections/operations/findById.d.ts.map +1 -0
  143. package/dist/collections/operations/findById.js +111 -0
  144. package/dist/collections/operations/sqlAdapter.d.ts +23 -0
  145. package/dist/collections/operations/sqlAdapter.d.ts.map +1 -0
  146. package/dist/collections/operations/sqlAdapter.js +108 -0
  147. package/dist/collections/operations/update.d.ts +8 -0
  148. package/dist/collections/operations/update.d.ts.map +1 -0
  149. package/dist/collections/operations/update.js +226 -0
  150. package/dist/collections/operations/updateMany.d.ts +11 -0
  151. package/dist/collections/operations/updateMany.d.ts.map +1 -0
  152. package/dist/collections/operations/updateMany.js +52 -0
  153. package/dist/collections/registry.d.ts +12 -0
  154. package/dist/collections/registry.d.ts.map +1 -0
  155. package/dist/collections/registry.js +38 -0
  156. package/dist/config/index.d.ts +9 -0
  157. package/dist/config/index.d.ts.map +1 -0
  158. package/dist/config/index.js +61 -0
  159. package/dist/config/runtime.d.ts +22 -0
  160. package/dist/config/runtime.d.ts.map +1 -0
  161. package/dist/config/runtime.js +32 -0
  162. package/dist/config/utils.d.ts +2 -0
  163. package/dist/config/utils.d.ts.map +1 -0
  164. package/dist/config/utils.js +21 -0
  165. package/dist/database/index.d.ts +4 -0
  166. package/dist/database/index.d.ts.map +1 -0
  167. package/dist/database/index.js +2 -0
  168. package/dist/database/safe-parse.d.ts +26 -0
  169. package/dist/database/safe-parse.d.ts.map +1 -0
  170. package/dist/database/safe-parse.js +42 -0
  171. package/dist/database/ssl-config.d.ts +9 -0
  172. package/dist/database/ssl-config.d.ts.map +1 -0
  173. package/dist/database/ssl-config.js +7 -0
  174. package/dist/database/type-adapter.d.ts +113 -0
  175. package/dist/database/type-adapter.d.ts.map +1 -0
  176. package/dist/database/type-adapter.js +97 -0
  177. package/dist/database/universal-postgres.d.ts +45 -0
  178. package/dist/database/universal-postgres.d.ts.map +1 -0
  179. package/dist/database/universal-postgres.js +531 -0
  180. package/dist/dataloader.d.ts +26 -0
  181. package/dist/dataloader.d.ts.map +1 -0
  182. package/dist/dataloader.js +176 -0
  183. package/dist/error-handling/error-boundary.d.ts +94 -0
  184. package/dist/error-handling/error-boundary.d.ts.map +1 -0
  185. package/dist/error-handling/error-boundary.js +285 -0
  186. package/dist/error-handling/error-reporter.d.ts +214 -0
  187. package/dist/error-handling/error-reporter.d.ts.map +1 -0
  188. package/dist/error-handling/error-reporter.js +491 -0
  189. package/dist/error-handling/fallback-components.d.ts +131 -0
  190. package/dist/error-handling/fallback-components.d.ts.map +1 -0
  191. package/dist/error-handling/fallback-components.js +371 -0
  192. package/dist/error-handling/index.d.ts +14 -0
  193. package/dist/error-handling/index.d.ts.map +1 -0
  194. package/dist/error-handling/index.js +12 -0
  195. package/dist/factories/builders.d.ts +50 -0
  196. package/dist/factories/builders.d.ts.map +1 -0
  197. package/dist/factories/builders.js +77 -0
  198. package/dist/factories/index.d.ts +2 -0
  199. package/dist/factories/index.d.ts.map +1 -0
  200. package/dist/factories/index.js +1 -0
  201. package/dist/features.d.ts +88 -0
  202. package/dist/features.d.ts.map +1 -0
  203. package/dist/features.js +105 -0
  204. package/dist/fieldTraversal.d.ts +26 -0
  205. package/dist/fieldTraversal.d.ts.map +1 -0
  206. package/dist/fieldTraversal.js +132 -0
  207. package/dist/fields/config/types.d.ts +48 -0
  208. package/dist/fields/config/types.d.ts.map +1 -0
  209. package/dist/fields/config/types.js +20 -0
  210. package/dist/fields/getDefaultValue.d.ts +16 -0
  211. package/dist/fields/getDefaultValue.d.ts.map +1 -0
  212. package/dist/fields/getDefaultValue.js +20 -0
  213. package/dist/fields/getFieldPaths.d.ts +25 -0
  214. package/dist/fields/getFieldPaths.d.ts.map +1 -0
  215. package/dist/fields/getFieldPaths.js +23 -0
  216. package/dist/fields/hooks/afterRead/index.d.ts +36 -0
  217. package/dist/fields/hooks/afterRead/index.d.ts.map +1 -0
  218. package/dist/fields/hooks/afterRead/index.js +70 -0
  219. package/dist/fields/hooks/afterRead/promise.d.ts +46 -0
  220. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -0
  221. package/dist/fields/hooks/afterRead/promise.js +178 -0
  222. package/dist/fields/hooks/afterRead/traverseFields.d.ts +44 -0
  223. package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -0
  224. package/dist/fields/hooks/afterRead/traverseFields.js +37 -0
  225. package/dist/generated/index.d.ts +10 -0
  226. package/dist/generated/index.d.ts.map +1 -0
  227. package/dist/generated/index.js +9 -0
  228. package/dist/generated/types/cms.d.ts +1766 -0
  229. package/dist/generated/types/cms.d.ts.map +1 -0
  230. package/dist/generated/types/cms.js +11 -0
  231. package/dist/generated/types/index.d.ts +16 -0
  232. package/dist/generated/types/index.d.ts.map +1 -0
  233. package/dist/generated/types/index.js +21 -0
  234. package/dist/generated/types/neon.d.ts +11 -0
  235. package/dist/generated/types/neon.d.ts.map +1 -0
  236. package/dist/generated/types/neon.js +13 -0
  237. package/dist/globals/GlobalOperations.d.ts +24 -0
  238. package/dist/globals/GlobalOperations.d.ts.map +1 -0
  239. package/dist/globals/GlobalOperations.js +165 -0
  240. package/dist/globals/index.d.ts +2 -0
  241. package/dist/globals/index.d.ts.map +1 -0
  242. package/dist/globals/index.js +1 -0
  243. package/dist/index.d.ts +75 -0
  244. package/dist/index.d.ts.map +1 -0
  245. package/dist/index.js +136 -0
  246. package/dist/instance/RevealUIInstance.d.ts +6 -0
  247. package/dist/instance/RevealUIInstance.d.ts.map +1 -0
  248. package/dist/instance/RevealUIInstance.js +293 -0
  249. package/dist/instance/index.d.ts +3 -0
  250. package/dist/instance/index.d.ts.map +1 -0
  251. package/dist/instance/index.js +2 -0
  252. package/dist/instance/logger.d.ts +31 -0
  253. package/dist/instance/logger.d.ts.map +1 -0
  254. package/dist/instance/logger.js +42 -0
  255. package/dist/instance/methods/create.d.ts +10 -0
  256. package/dist/instance/methods/create.d.ts.map +1 -0
  257. package/dist/instance/methods/create.js +38 -0
  258. package/dist/instance/methods/delete.d.ts +10 -0
  259. package/dist/instance/methods/delete.d.ts.map +1 -0
  260. package/dist/instance/methods/delete.js +24 -0
  261. package/dist/instance/methods/find.d.ts +10 -0
  262. package/dist/instance/methods/find.d.ts.map +1 -0
  263. package/dist/instance/methods/find.js +20 -0
  264. package/dist/instance/methods/findById.d.ts +13 -0
  265. package/dist/instance/methods/findById.d.ts.map +1 -0
  266. package/dist/instance/methods/findById.js +20 -0
  267. package/dist/instance/methods/hooks.d.ts +14 -0
  268. package/dist/instance/methods/hooks.d.ts.map +1 -0
  269. package/dist/instance/methods/hooks.js +34 -0
  270. package/dist/instance/methods/update.d.ts +10 -0
  271. package/dist/instance/methods/update.d.ts.map +1 -0
  272. package/dist/instance/methods/update.js +42 -0
  273. package/dist/jobs/index.d.ts +16 -0
  274. package/dist/jobs/index.d.ts.map +1 -0
  275. package/dist/jobs/index.js +14 -0
  276. package/dist/jobs/queue.d.ts +57 -0
  277. package/dist/jobs/queue.d.ts.map +1 -0
  278. package/dist/jobs/queue.js +134 -0
  279. package/dist/license-encryption.d.ts +21 -0
  280. package/dist/license-encryption.d.ts.map +1 -0
  281. package/dist/license-encryption.js +74 -0
  282. package/dist/license.d.ts +99 -0
  283. package/dist/license.d.ts.map +1 -0
  284. package/dist/license.js +262 -0
  285. package/dist/monitoring/alerts.d.ts +118 -0
  286. package/dist/monitoring/alerts.d.ts.map +1 -0
  287. package/dist/monitoring/alerts.js +324 -0
  288. package/dist/monitoring/cleanup-manager.d.ts +71 -0
  289. package/dist/monitoring/cleanup-manager.d.ts.map +1 -0
  290. package/dist/monitoring/cleanup-manager.js +226 -0
  291. package/dist/monitoring/health-monitor.d.ts +22 -0
  292. package/dist/monitoring/health-monitor.d.ts.map +1 -0
  293. package/dist/monitoring/health-monitor.js +142 -0
  294. package/dist/monitoring/index.d.ts +14 -0
  295. package/dist/monitoring/index.d.ts.map +1 -0
  296. package/dist/monitoring/index.js +17 -0
  297. package/dist/monitoring/process-registry.d.ts +97 -0
  298. package/dist/monitoring/process-registry.d.ts.map +1 -0
  299. package/dist/monitoring/process-registry.js +222 -0
  300. package/dist/monitoring/query-monitor.d.ts +153 -0
  301. package/dist/monitoring/query-monitor.d.ts.map +1 -0
  302. package/dist/monitoring/query-monitor.js +209 -0
  303. package/dist/monitoring/types.d.ts +231 -0
  304. package/dist/monitoring/types.d.ts.map +1 -0
  305. package/dist/monitoring/types.js +42 -0
  306. package/dist/monitoring/zombie-detector.d.ts +81 -0
  307. package/dist/monitoring/zombie-detector.d.ts.map +1 -0
  308. package/dist/monitoring/zombie-detector.js +236 -0
  309. package/dist/nextjs/index.d.ts +4 -0
  310. package/dist/nextjs/index.d.ts.map +1 -0
  311. package/dist/nextjs/index.js +3 -0
  312. package/dist/nextjs/utilities.d.ts +5 -0
  313. package/dist/nextjs/utilities.d.ts.map +1 -0
  314. package/dist/nextjs/utilities.js +16 -0
  315. package/dist/nextjs/withRevealUI.d.ts +20 -0
  316. package/dist/nextjs/withRevealUI.d.ts.map +1 -0
  317. package/dist/nextjs/withRevealUI.js +181 -0
  318. package/dist/observability/alerts.d.ts +138 -0
  319. package/dist/observability/alerts.d.ts.map +1 -0
  320. package/dist/observability/alerts.js +389 -0
  321. package/dist/observability/health-check.d.ts +91 -0
  322. package/dist/observability/health-check.d.ts.map +1 -0
  323. package/dist/observability/health-check.js +345 -0
  324. package/dist/observability/index.d.ts +12 -0
  325. package/dist/observability/index.d.ts.map +1 -0
  326. package/dist/observability/index.js +11 -0
  327. package/dist/observability/logger.d.ts +47 -0
  328. package/dist/observability/logger.d.ts.map +1 -0
  329. package/dist/observability/logger.js +140 -0
  330. package/dist/observability/metrics.d.ts +205 -0
  331. package/dist/observability/metrics.d.ts.map +1 -0
  332. package/dist/observability/metrics.js +429 -0
  333. package/dist/observability/tracing.d.ts +149 -0
  334. package/dist/observability/tracing.d.ts.map +1 -0
  335. package/dist/observability/tracing.js +380 -0
  336. package/dist/plugins/form-builder.d.ts +115 -0
  337. package/dist/plugins/form-builder.d.ts.map +1 -0
  338. package/dist/plugins/form-builder.js +239 -0
  339. package/dist/plugins/index.d.ts +5 -0
  340. package/dist/plugins/index.d.ts.map +1 -0
  341. package/dist/plugins/index.js +4 -0
  342. package/dist/plugins/nested-docs.d.ts +12 -0
  343. package/dist/plugins/nested-docs.d.ts.map +1 -0
  344. package/dist/plugins/nested-docs.js +111 -0
  345. package/dist/plugins/redirects.d.ts +17 -0
  346. package/dist/plugins/redirects.d.ts.map +1 -0
  347. package/dist/plugins/redirects.js +62 -0
  348. package/dist/queries/index.d.ts +2 -0
  349. package/dist/queries/index.d.ts.map +1 -0
  350. package/dist/queries/index.js +1 -0
  351. package/dist/queries/queryBuilder.d.ts +47 -0
  352. package/dist/queries/queryBuilder.d.ts.map +1 -0
  353. package/dist/queries/queryBuilder.js +276 -0
  354. package/dist/relationships/analyzer.d.ts +39 -0
  355. package/dist/relationships/analyzer.d.ts.map +1 -0
  356. package/dist/relationships/analyzer.js +135 -0
  357. package/dist/relationships/index.d.ts +3 -0
  358. package/dist/relationships/index.d.ts.map +1 -0
  359. package/dist/relationships/index.js +2 -0
  360. package/dist/relationships/populate-core.d.ts +57 -0
  361. package/dist/relationships/populate-core.d.ts.map +1 -0
  362. package/dist/relationships/populate-core.js +116 -0
  363. package/dist/relationships/populate-helpers.d.ts +58 -0
  364. package/dist/relationships/populate-helpers.d.ts.map +1 -0
  365. package/dist/relationships/populate-helpers.js +82 -0
  366. package/dist/relationships/population.d.ts +34 -0
  367. package/dist/relationships/population.d.ts.map +1 -0
  368. package/dist/relationships/population.js +193 -0
  369. package/dist/revealui.d.ts +46 -0
  370. package/dist/revealui.d.ts.map +1 -0
  371. package/dist/revealui.js +92 -0
  372. package/dist/richtext/exports/client/rcc.d.ts +37 -0
  373. package/dist/richtext/exports/client/rcc.d.ts.map +1 -0
  374. package/dist/richtext/exports/client/rcc.js +182 -0
  375. package/dist/richtext/exports/server/rsc.d.ts +134 -0
  376. package/dist/richtext/exports/server/rsc.d.ts.map +1 -0
  377. package/dist/richtext/exports/server/rsc.js +344 -0
  378. package/dist/richtext/index.d.ts +161 -0
  379. package/dist/richtext/index.d.ts.map +1 -0
  380. package/dist/richtext/index.js +243 -0
  381. package/dist/richtext/lexical.d.ts +23 -0
  382. package/dist/richtext/lexical.d.ts.map +1 -0
  383. package/dist/richtext/lexical.js +35 -0
  384. package/dist/security/index.d.ts +6 -0
  385. package/dist/security/index.d.ts.map +1 -0
  386. package/dist/security/index.js +5 -0
  387. package/dist/server/index.d.ts +21 -0
  388. package/dist/server/index.d.ts.map +1 -0
  389. package/dist/server/index.js +28 -0
  390. package/dist/server/renderPage.d.ts +69 -0
  391. package/dist/server/renderPage.d.ts.map +1 -0
  392. package/dist/server/renderPage.js +109 -0
  393. package/dist/storage/index.d.ts +2 -0
  394. package/dist/storage/index.d.ts.map +1 -0
  395. package/dist/storage/index.js +2 -0
  396. package/dist/storage/vercel-blob.d.ts +17 -0
  397. package/dist/storage/vercel-blob.d.ts.map +1 -0
  398. package/dist/storage/vercel-blob.js +86 -0
  399. package/dist/translations/index.d.ts +17 -0
  400. package/dist/translations/index.d.ts.map +1 -0
  401. package/dist/translations/index.js +1 -0
  402. package/dist/types/access.d.ts +67 -0
  403. package/dist/types/access.d.ts.map +1 -0
  404. package/dist/types/access.js +8 -0
  405. package/dist/types/api.d.ts +57 -0
  406. package/dist/types/api.d.ts.map +1 -0
  407. package/dist/types/api.js +8 -0
  408. package/dist/types/cms.d.ts +8 -0
  409. package/dist/types/cms.d.ts.map +1 -0
  410. package/dist/types/cms.js +6 -0
  411. package/dist/types/config.d.ts +152 -0
  412. package/dist/types/config.d.ts.map +1 -0
  413. package/dist/types/config.js +9 -0
  414. package/dist/types/core.d.ts +11 -0
  415. package/dist/types/core.d.ts.map +1 -0
  416. package/dist/types/core.js +9 -0
  417. package/dist/types/extensions.d.ts +116 -0
  418. package/dist/types/extensions.d.ts.map +1 -0
  419. package/dist/types/extensions.js +8 -0
  420. package/dist/types/frontend.d.ts +53 -0
  421. package/dist/types/frontend.d.ts.map +1 -0
  422. package/dist/types/frontend.js +7 -0
  423. package/dist/types/generated.d.ts +12 -0
  424. package/dist/types/generated.d.ts.map +1 -0
  425. package/dist/types/generated.js +10 -0
  426. package/dist/types/hooks.d.ts +53 -0
  427. package/dist/types/hooks.d.ts.map +1 -0
  428. package/dist/types/hooks.js +8 -0
  429. package/dist/types/index.d.ts +49 -0
  430. package/dist/types/index.d.ts.map +1 -0
  431. package/dist/types/index.js +61 -0
  432. package/dist/types/interfaces/app.d.ts +50 -0
  433. package/dist/types/interfaces/app.d.ts.map +1 -0
  434. package/dist/types/interfaces/app.js +5 -0
  435. package/dist/types/jobs.d.ts +112 -0
  436. package/dist/types/jobs.d.ts.map +1 -0
  437. package/dist/types/jobs.js +7 -0
  438. package/dist/types/legacy.d.ts +147 -0
  439. package/dist/types/legacy.d.ts.map +1 -0
  440. package/dist/types/legacy.js +8 -0
  441. package/dist/types/plugins.d.ts +17 -0
  442. package/dist/types/plugins.d.ts.map +1 -0
  443. package/dist/types/plugins.js +8 -0
  444. package/dist/types/query.d.ts +99 -0
  445. package/dist/types/query.d.ts.map +1 -0
  446. package/dist/types/query.js +24 -0
  447. package/dist/types/request.d.ts +40 -0
  448. package/dist/types/request.d.ts.map +1 -0
  449. package/dist/types/request.js +8 -0
  450. package/dist/types/richtext.d.ts +23 -0
  451. package/dist/types/richtext.d.ts.map +1 -0
  452. package/dist/types/richtext.js +8 -0
  453. package/dist/types/runtime.d.ts +275 -0
  454. package/dist/types/runtime.d.ts.map +1 -0
  455. package/dist/types/runtime.js +9 -0
  456. package/dist/types/schema.d.ts +9 -0
  457. package/dist/types/schema.d.ts.map +1 -0
  458. package/dist/types/schema.js +7 -0
  459. package/dist/types/user.d.ts +48 -0
  460. package/dist/types/user.d.ts.map +1 -0
  461. package/dist/types/user.js +8 -0
  462. package/dist/utils/access-conversion.d.ts +17 -0
  463. package/dist/utils/access-conversion.d.ts.map +1 -0
  464. package/dist/utils/access-conversion.js +96 -0
  465. package/dist/utils/api-wrapper.d.ts +63 -0
  466. package/dist/utils/api-wrapper.d.ts.map +1 -0
  467. package/dist/utils/api-wrapper.js +151 -0
  468. package/dist/utils/block-conversion.d.ts +21 -0
  469. package/dist/utils/block-conversion.d.ts.map +1 -0
  470. package/dist/utils/block-conversion.js +109 -0
  471. package/dist/utils/cache.d.ts +86 -0
  472. package/dist/utils/cache.d.ts.map +1 -0
  473. package/dist/utils/cache.js +154 -0
  474. package/dist/utils/deep-clone.d.ts +25 -0
  475. package/dist/utils/deep-clone.d.ts.map +1 -0
  476. package/dist/utils/deep-clone.js +114 -0
  477. package/dist/utils/error-responses.d.ts +57 -0
  478. package/dist/utils/error-responses.d.ts.map +1 -0
  479. package/dist/utils/error-responses.js +95 -0
  480. package/dist/utils/errors.d.ts +133 -0
  481. package/dist/utils/errors.d.ts.map +1 -0
  482. package/dist/utils/errors.js +500 -0
  483. package/dist/utils/field-conversion.d.ts +40 -0
  484. package/dist/utils/field-conversion.d.ts.map +1 -0
  485. package/dist/utils/field-conversion.js +275 -0
  486. package/dist/utils/flattenResult.d.ts +7 -0
  487. package/dist/utils/flattenResult.d.ts.map +1 -0
  488. package/dist/utils/flattenResult.js +22 -0
  489. package/dist/utils/getBlockSelect.d.ts +12 -0
  490. package/dist/utils/getBlockSelect.d.ts.map +1 -0
  491. package/dist/utils/getBlockSelect.js +12 -0
  492. package/dist/utils/getSelectMode.d.ts +8 -0
  493. package/dist/utils/getSelectMode.d.ts.map +1 -0
  494. package/dist/utils/getSelectMode.js +21 -0
  495. package/dist/utils/isValidID.d.ts +5 -0
  496. package/dist/utils/isValidID.d.ts.map +1 -0
  497. package/dist/utils/isValidID.js +13 -0
  498. package/dist/utils/json-parsing.d.ts +48 -0
  499. package/dist/utils/json-parsing.d.ts.map +1 -0
  500. package/dist/utils/json-parsing.js +130 -0
  501. package/dist/utils/logger-client.d.ts +32 -0
  502. package/dist/utils/logger-client.d.ts.map +1 -0
  503. package/dist/utils/logger-client.js +55 -0
  504. package/dist/utils/logger-server.d.ts +32 -0
  505. package/dist/utils/logger-server.d.ts.map +1 -0
  506. package/dist/utils/logger-server.js +68 -0
  507. package/dist/utils/logger.d.ts +14 -0
  508. package/dist/utils/logger.d.ts.map +1 -0
  509. package/dist/utils/logger.js +12 -0
  510. package/dist/utils/request-context.d.ts +143 -0
  511. package/dist/utils/request-context.d.ts.map +1 -0
  512. package/dist/utils/request-context.js +168 -0
  513. package/dist/utils/stripUnselectedFields.d.ts +10 -0
  514. package/dist/utils/stripUnselectedFields.d.ts.map +1 -0
  515. package/dist/utils/stripUnselectedFields.js +20 -0
  516. package/dist/utils/type-guards.d.ts +33 -0
  517. package/dist/utils/type-guards.d.ts.map +1 -0
  518. package/dist/utils/type-guards.js +63 -0
  519. package/dist/utils/user.d.ts +14 -0
  520. package/dist/utils/user.d.ts.map +1 -0
  521. package/dist/utils/user.js +15 -0
  522. package/package.json +302 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 RevealUI Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # @revealui/core
2
+
3
+ The core runtime engine for RevealUI — collections, admin UI, rich text, security, observability, and plugins.
4
+
5
+ ## Features
6
+
7
+ - **Collections & CRUD** — Define content types with field hooks, access control, and validation
8
+ - **Admin Dashboard** — Ready-to-use React admin UI (collection browser, document editor, global forms)
9
+ - **Rich Text** — Lexical-based editor with 20+ features (bold, headings, lists, links, images, blocks)
10
+ - **Security** — CORS, CSP, HSTS, RBAC/ABAC policy engine, encryption (AES-256-GCM), audit logging
11
+ - **GDPR Compliance** — Consent management, data export, deletion, anonymization, breach reporting
12
+ - **Observability** — Structured logging, process health monitoring, alert system, graceful shutdown
13
+ - **Plugins** — Extensible plugin system (form builder, nested docs, redirects)
14
+ - **Feature Gating** — Tier-based licensing (free, pro, max, enterprise/Forge) with JWT license keys
15
+ - **Database** — PostgreSQL adapters (NeonDB + PGlite for testing), connection pooling, SSL/TLS
16
+ - **Storage** — Pluggable storage interface (Vercel Blob adapter included)
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pnpm add @revealui/core
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Configuration
27
+
28
+ ```typescript
29
+ import { buildConfig } from '@revealui/core/config'
30
+
31
+ const config = buildConfig({
32
+ collections: [Posts, Categories, Users],
33
+ globals: [Settings, Navigation],
34
+ plugins: [formBuilder(), nestedDocs()],
35
+ })
36
+ ```
37
+
38
+ ### Collections
39
+
40
+ ```typescript
41
+ import type { RevealUICollection } from '@revealui/core'
42
+
43
+ const Posts: RevealUICollection = {
44
+ slug: 'posts',
45
+ fields: [
46
+ { name: 'title', type: 'text', required: true },
47
+ { name: 'content', type: 'richText' },
48
+ { name: 'status', type: 'select', options: ['draft', 'published'] },
49
+ ],
50
+ hooks: {
51
+ beforeChange: [({ data }) => ({ ...data, updatedAt: new Date() })],
52
+ },
53
+ access: {
54
+ read: () => true,
55
+ create: ({ req }) => !!req.user,
56
+ },
57
+ }
58
+ ```
59
+
60
+ ### Server-Side API
61
+
62
+ ```typescript
63
+ import { revealui } from '@revealui/core/server'
64
+
65
+ // Create, read, update, delete
66
+ const post = await revealui.create({ collection: 'posts', data: { title: 'Hello' } })
67
+ const posts = await revealui.find({ collection: 'posts', where: { status: { equals: 'published' } } })
68
+ ```
69
+
70
+ ### Admin UI (React)
71
+
72
+ ```typescript
73
+ import { AdminDashboard } from '@revealui/core/admin'
74
+
75
+ // Full admin interface with collection browser, document editor, global forms
76
+ function App() {
77
+ return <AdminDashboard />
78
+ }
79
+ ```
80
+
81
+ ### Rich Text
82
+
83
+ ```typescript
84
+ import { RichTextEditor, BoldFeature, HeadingFeature, ListFeature } from '@revealui/core/richtext/client'
85
+
86
+ <RichTextEditor
87
+ features={[BoldFeature(), HeadingFeature(), ListFeature()]}
88
+ onChange={(json) => console.log(json)}
89
+ />
90
+ ```
91
+
92
+ ### Feature Gating
93
+
94
+ ```typescript
95
+ import { isLicensed, isFeatureEnabled } from '@revealui/core/features'
96
+
97
+ if (isLicensed('pro')) {
98
+ // Pro-tier feature
99
+ }
100
+
101
+ if (isFeatureEnabled('ai')) {
102
+ // AI features enabled
103
+ }
104
+ ```
105
+
106
+ ## Exports
107
+
108
+ | Subpath | Purpose |
109
+ |---------|---------|
110
+ | `@revealui/core` | Main entry (RevealUI instance) |
111
+ | `@revealui/core/server` | Server-side CRUD API |
112
+ | `@revealui/core/client` | Client-side React hooks and utilities |
113
+ | `@revealui/core/config` | Configuration builder |
114
+ | `@revealui/core/admin` | Admin dashboard components |
115
+ | `@revealui/core/richtext` | Rich text server utilities |
116
+ | `@revealui/core/richtext/client` | Lexical editor React components |
117
+ | `@revealui/core/richtext/html` | HTML serialization |
118
+ | `@revealui/core/richtext/rsc` | React Server Component support |
119
+ | `@revealui/core/security` | Security infrastructure |
120
+ | `@revealui/core/auth` | Auth utilities |
121
+ | `@revealui/core/database` | Database adapters |
122
+ | `@revealui/core/storage` | Storage adapters |
123
+ | `@revealui/core/plugins` | Plugin system |
124
+ | `@revealui/core/features` | Feature flags |
125
+ | `@revealui/core/license` | License validation |
126
+ | `@revealui/core/monitoring` | Health monitoring |
127
+ | `@revealui/core/observability/logger` | Structured logging |
128
+ | `@revealui/core/types` | TypeScript type definitions |
129
+ | `@revealui/core/nextjs` | Next.js integration middleware |
130
+ | `@revealui/core/utils/*` | Utilities (cache, deep-clone, errors) |
131
+
132
+ ## Development
133
+
134
+ ```bash
135
+ # Build
136
+ pnpm build
137
+
138
+ # Type check
139
+ pnpm typecheck
140
+
141
+ # Run tests
142
+ pnpm test
143
+
144
+ # Watch mode
145
+ pnpm dev
146
+ ```
147
+
148
+ ## When to Use This
149
+
150
+ - You're building a content-driven app and need collections, admin UI, and CRUD out of the box
151
+ - You need RBAC/ABAC access control, GDPR compliance, or feature gating by license tier
152
+ - You want a rich text editor (Lexical) integrated with your CMS
153
+ - **Not** for standalone UI components — use `@revealui/presentation`
154
+ - **Not** for raw database queries — use `@revealui/db` directly
155
+
156
+ ## JOSHUA Alignment
157
+
158
+ - **Sovereign**: Self-hosted runtime engine — no SaaS dependency for content management, auth, or storage
159
+ - **Unified**: One `buildConfig()` call wires collections, globals, plugins, security, and feature gates into a single configuration
160
+ - **Adaptive**: Plugin system and tier-based feature gating let the platform evolve without breaking existing deployments
161
+
162
+ ## Related
163
+
164
+ - [Contracts Package](../contracts/README.md) — Zod schemas and TypeScript types
165
+ - [DB Package](../db/README.md) — Drizzle ORM schema
166
+ - [Auth Package](../auth/README.md) — Authentication system
167
+ - [Architecture Guide](../../docs/ARCHITECTURE.md)
168
+
169
+ ## License
170
+
171
+ MIT
@@ -0,0 +1,83 @@
1
+ /**
2
+ * API Response Compression Middleware
3
+ *
4
+ * Implements gzip and brotli compression for API responses
5
+ */
6
+ import { type NextRequest, NextResponse } from 'next/server';
7
+ interface CompressionOptions {
8
+ threshold?: number;
9
+ level?: number;
10
+ preferBrotli?: boolean;
11
+ excludeTypes?: string[];
12
+ }
13
+ /**
14
+ * Compress API response
15
+ */
16
+ export declare function compressResponse(request: NextRequest, response: NextResponse, options?: CompressionOptions): Promise<NextResponse>;
17
+ /**
18
+ * Create compression middleware
19
+ */
20
+ export declare function createCompressionMiddleware(options?: CompressionOptions): (request: NextRequest, next: () => Promise<NextResponse>) => Promise<NextResponse<unknown>>;
21
+ /**
22
+ * Calculate compression ratio
23
+ */
24
+ export declare function getCompressionRatio(originalSize: number, compressedSize: number): number;
25
+ /**
26
+ * Get compression stats
27
+ */
28
+ export interface CompressionStats {
29
+ originalSize: number;
30
+ compressedSize: number;
31
+ compressionRatio: number;
32
+ encoding: string;
33
+ savings: number;
34
+ }
35
+ export declare function getCompressionStats(originalBody: string | Uint8Array, compressedBody: Uint8Array, encoding: string): CompressionStats;
36
+ /**
37
+ * Preset compression configurations
38
+ */
39
+ export declare const COMPRESSION_PRESETS: {
40
+ readonly fast: {
41
+ readonly threshold: 512;
42
+ readonly level: 3;
43
+ readonly preferBrotli: false;
44
+ };
45
+ readonly balanced: {
46
+ readonly threshold: 1024;
47
+ readonly level: 6;
48
+ readonly preferBrotli: true;
49
+ };
50
+ readonly max: {
51
+ readonly threshold: 512;
52
+ readonly level: 9;
53
+ readonly preferBrotli: true;
54
+ };
55
+ readonly static: {
56
+ readonly threshold: 1024;
57
+ readonly level: 9;
58
+ readonly preferBrotli: true;
59
+ };
60
+ readonly api: {
61
+ readonly threshold: 512;
62
+ readonly level: 6;
63
+ readonly preferBrotli: true;
64
+ readonly excludeTypes: readonly ["image/png", "image/jpeg", "image/gif", "image/webp", "video/mp4", "application/zip", "application/gzip", "application/pdf"];
65
+ };
66
+ };
67
+ /**
68
+ * Compress JSON response
69
+ */
70
+ export declare function compressJSON(data: unknown, encoding?: 'gzip' | 'br', level?: number): Promise<Uint8Array>;
71
+ /**
72
+ * Decompress response
73
+ */
74
+ export declare function decompressBody(body: Uint8Array, encoding: string): Promise<Uint8Array>;
75
+ /**
76
+ * Check if compression is supported
77
+ */
78
+ export declare function isCompressionSupported(request: NextRequest): {
79
+ gzip: boolean;
80
+ brotli: boolean;
81
+ };
82
+ export {};
83
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/api/compression.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG7D,UAAU,kBAAkB;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AA4GD;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,YAAY,EACtB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,YAAY,CAAC,CAuCvB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,kBAAuB,IAC5D,SAAS,WAAW,EAAE,MAAM,MAAM,OAAO,CAAC,YAAY,CAAC,oCAItE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAExF;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,GAAG,UAAU,EACjC,cAAc,EAAE,UAAU,EAC1B,QAAQ,EAAE,MAAM,GACf,gBAAgB,CAelB;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CtB,CAAC;AAEX;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,OAAO,EACb,QAAQ,GAAE,MAAM,GAAG,IAAa,EAChC,KAAK,GAAE,MAAU,GAChB,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAkB5F;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,WAAW,GAAG;IAC5D,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;CACjB,CAOA"}
@@ -0,0 +1,233 @@
1
+ /**
2
+ * API Response Compression Middleware
3
+ *
4
+ * Implements gzip and brotli compression for API responses
5
+ */
6
+ import { NextResponse } from 'next/server';
7
+ import { logger } from '../observability/logger.js';
8
+ const DEFAULT_OPTIONS = {
9
+ threshold: 1024, // 1KB minimum
10
+ level: 6, // Balanced compression
11
+ preferBrotli: true,
12
+ excludeTypes: [
13
+ 'image/png',
14
+ 'image/jpeg',
15
+ 'image/gif',
16
+ 'image/webp',
17
+ 'video/mp4',
18
+ 'application/zip',
19
+ 'application/gzip',
20
+ 'application/pdf',
21
+ ],
22
+ };
23
+ /**
24
+ * Check if response should be compressed
25
+ */
26
+ function shouldCompress(response, options) {
27
+ const contentType = response.headers.get('content-type') || '';
28
+ const contentLength = parseInt(response.headers.get('content-length') || '0', 10);
29
+ // Check if already compressed
30
+ if (response.headers.get('content-encoding')) {
31
+ return false;
32
+ }
33
+ // Check content type exclusions
34
+ if (options.excludeTypes?.some((type) => contentType.includes(type))) {
35
+ return false;
36
+ }
37
+ // Check size threshold
38
+ if (contentLength > 0 && contentLength < (options.threshold || 0)) {
39
+ return false;
40
+ }
41
+ return true;
42
+ }
43
+ /**
44
+ * Get best compression encoding from Accept-Encoding header
45
+ */
46
+ function getBestEncoding(request, preferBrotli) {
47
+ const acceptEncoding = request.headers.get('accept-encoding') || '';
48
+ const supportsBrotli = acceptEncoding.includes('br');
49
+ const supportsGzip = acceptEncoding.includes('gzip');
50
+ if (preferBrotli && supportsBrotli) {
51
+ return 'br';
52
+ }
53
+ if (supportsGzip) {
54
+ return 'gzip';
55
+ }
56
+ if (supportsBrotli) {
57
+ return 'br';
58
+ }
59
+ return null;
60
+ }
61
+ /**
62
+ * Compress response body
63
+ */
64
+ async function compressBody(body, encoding, _level) {
65
+ const textEncoder = new TextEncoder();
66
+ const data = typeof body === 'string' ? textEncoder.encode(body) : body;
67
+ if (encoding === 'gzip') {
68
+ // Use CompressionStream API (available in modern environments)
69
+ const stream = new Response(data).body?.pipeThrough(new CompressionStream('gzip'));
70
+ const compressed = await new Response(stream).arrayBuffer();
71
+ return new Uint8Array(compressed);
72
+ }
73
+ if (encoding === 'br') {
74
+ // Brotli compression
75
+ // Note: CompressionStream('deflate-raw') is available, but not 'br' in all environments
76
+ // Fallback to gzip if brotli not available
77
+ try {
78
+ const stream = new Response(data).body?.pipeThrough(new CompressionStream('deflate'));
79
+ const compressed = await new Response(stream).arrayBuffer();
80
+ return new Uint8Array(compressed);
81
+ }
82
+ catch {
83
+ // Fallback to gzip
84
+ const stream = new Response(data).body?.pipeThrough(new CompressionStream('gzip'));
85
+ const compressed = await new Response(stream).arrayBuffer();
86
+ return new Uint8Array(compressed);
87
+ }
88
+ }
89
+ return data;
90
+ }
91
+ /**
92
+ * Compress API response
93
+ */
94
+ export async function compressResponse(request, response, options = {}) {
95
+ const opts = { ...DEFAULT_OPTIONS, ...options };
96
+ // Check if should compress
97
+ if (!shouldCompress(response, opts)) {
98
+ return response;
99
+ }
100
+ // Get best encoding
101
+ const encoding = getBestEncoding(request, opts.preferBrotli ?? true);
102
+ if (!encoding) {
103
+ return response;
104
+ }
105
+ try {
106
+ // Get response body
107
+ const body = await response.text();
108
+ // Compress body
109
+ const compressed = await compressBody(body, encoding, opts.level || 6);
110
+ // Create new response with compressed body
111
+ const newResponse = new NextResponse(compressed, {
112
+ status: response.status,
113
+ statusText: response.statusText,
114
+ headers: response.headers,
115
+ });
116
+ // Set compression headers
117
+ newResponse.headers.set('content-encoding', encoding);
118
+ newResponse.headers.set('content-length', compressed.length.toString());
119
+ newResponse.headers.delete('content-length'); // Let runtime set it
120
+ newResponse.headers.set('vary', 'Accept-Encoding');
121
+ return newResponse;
122
+ }
123
+ catch (error) {
124
+ logger.error('Compression error', error instanceof Error ? error : new Error(String(error)));
125
+ return response;
126
+ }
127
+ }
128
+ /**
129
+ * Create compression middleware
130
+ */
131
+ export function createCompressionMiddleware(options = {}) {
132
+ return async (request, next) => {
133
+ const response = await next();
134
+ return compressResponse(request, response, options);
135
+ };
136
+ }
137
+ /**
138
+ * Calculate compression ratio
139
+ */
140
+ export function getCompressionRatio(originalSize, compressedSize) {
141
+ return ((originalSize - compressedSize) / originalSize) * 100;
142
+ }
143
+ export function getCompressionStats(originalBody, compressedBody, encoding) {
144
+ const originalSize = typeof originalBody === 'string' ? new Blob([originalBody]).size : originalBody.length;
145
+ const compressedSize = compressedBody.length;
146
+ const compressionRatio = getCompressionRatio(originalSize, compressedSize);
147
+ const savings = originalSize - compressedSize;
148
+ return {
149
+ originalSize,
150
+ compressedSize,
151
+ compressionRatio,
152
+ encoding,
153
+ savings,
154
+ };
155
+ }
156
+ /**
157
+ * Preset compression configurations
158
+ */
159
+ export const COMPRESSION_PRESETS = {
160
+ // Fast compression, lower ratio
161
+ fast: {
162
+ threshold: 512,
163
+ level: 3,
164
+ preferBrotli: false,
165
+ },
166
+ // Balanced compression
167
+ balanced: {
168
+ threshold: 1024,
169
+ level: 6,
170
+ preferBrotli: true,
171
+ },
172
+ // Maximum compression, slower
173
+ max: {
174
+ threshold: 512,
175
+ level: 9,
176
+ preferBrotli: true,
177
+ },
178
+ // For static assets
179
+ static: {
180
+ threshold: 1024,
181
+ level: 9,
182
+ preferBrotli: true,
183
+ },
184
+ // For API responses
185
+ api: {
186
+ threshold: 512,
187
+ level: 6,
188
+ preferBrotli: true,
189
+ excludeTypes: [
190
+ 'image/png',
191
+ 'image/jpeg',
192
+ 'image/gif',
193
+ 'image/webp',
194
+ 'video/mp4',
195
+ 'application/zip',
196
+ 'application/gzip',
197
+ 'application/pdf',
198
+ ],
199
+ },
200
+ };
201
+ /**
202
+ * Compress JSON response
203
+ */
204
+ export async function compressJSON(data, encoding = 'gzip', level = 6) {
205
+ const json = JSON.stringify(data);
206
+ return compressBody(json, encoding, level);
207
+ }
208
+ /**
209
+ * Decompress response
210
+ */
211
+ export async function decompressBody(body, encoding) {
212
+ if (encoding === 'gzip') {
213
+ const stream = new Response(body).body?.pipeThrough(new DecompressionStream('gzip'));
214
+ const decompressed = await new Response(stream).arrayBuffer();
215
+ return new Uint8Array(decompressed);
216
+ }
217
+ if (encoding === 'br' || encoding === 'deflate') {
218
+ const stream = new Response(body).body?.pipeThrough(new DecompressionStream('deflate'));
219
+ const decompressed = await new Response(stream).arrayBuffer();
220
+ return new Uint8Array(decompressed);
221
+ }
222
+ return body;
223
+ }
224
+ /**
225
+ * Check if compression is supported
226
+ */
227
+ export function isCompressionSupported(request) {
228
+ const acceptEncoding = request.headers.get('accept-encoding') || '';
229
+ return {
230
+ gzip: acceptEncoding.includes('gzip'),
231
+ brotli: acceptEncoding.includes('br'),
232
+ };
233
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * API Payload Optimization
3
+ *
4
+ * Reduces payload size through field selection, pagination, and data transformation
5
+ */
6
+ interface PaginationOptions {
7
+ page?: number;
8
+ limit?: number;
9
+ cursor?: string;
10
+ defaultLimit?: number;
11
+ maxLimit?: number;
12
+ }
13
+ interface PaginatedResponse<T> {
14
+ data: T[];
15
+ pagination: {
16
+ page?: number;
17
+ limit: number;
18
+ total?: number;
19
+ hasMore: boolean;
20
+ nextCursor?: string | null;
21
+ prevCursor?: string | null;
22
+ };
23
+ }
24
+ interface FieldSelectionOptions {
25
+ include?: string[];
26
+ exclude?: string[];
27
+ defaultFields?: string[];
28
+ }
29
+ /**
30
+ * Paginate array of items
31
+ */
32
+ export declare function paginateArray<T>(items: T[], options?: PaginationOptions): PaginatedResponse<T>;
33
+ /**
34
+ * Create cursor for cursor-based pagination
35
+ */
36
+ export declare function createCursor(item: Record<string, unknown>, field?: string): string;
37
+ /**
38
+ * Parse cursor
39
+ */
40
+ export declare function parseCursor(cursor: string): {
41
+ field: string;
42
+ value: unknown;
43
+ } | null;
44
+ /**
45
+ * Select fields from object
46
+ */
47
+ export declare function selectFields<T extends Record<string, unknown>>(obj: T, options: FieldSelectionOptions): Partial<T>;
48
+ /**
49
+ * Select fields from array of objects
50
+ */
51
+ export declare function selectFieldsFromArray<T extends Record<string, unknown>>(items: T[], options: FieldSelectionOptions): Partial<T>[];
52
+ /**
53
+ * Remove null and undefined values
54
+ */
55
+ export declare function removeEmpty<T extends Record<string, unknown>>(obj: T): Partial<T>;
56
+ /**
57
+ * Flatten nested object
58
+ */
59
+ export declare function flattenObject(obj: Record<string, unknown>, prefix?: string): Record<string, unknown>;
60
+ /**
61
+ * Minimize JSON response size
62
+ */
63
+ export declare function minimizeJSON(data: unknown): string;
64
+ /**
65
+ * Format JSON response (for development)
66
+ */
67
+ export declare function formatJSON(data: unknown): string;
68
+ /**
69
+ * Remove sensitive fields
70
+ */
71
+ export declare function sanitizeResponse<T extends Record<string, unknown>>(obj: T, sensitiveFields?: string[]): Partial<T>;
72
+ /**
73
+ * Transform timestamps to ISO strings
74
+ */
75
+ export declare function transformDates<T extends Record<string, unknown>>(obj: T): T;
76
+ /**
77
+ * Calculate payload size in bytes
78
+ */
79
+ export declare function getPayloadSize(data: unknown): number;
80
+ /**
81
+ * Get payload size in human-readable format
82
+ */
83
+ export declare function formatPayloadSize(bytes: number): string;
84
+ /**
85
+ * Optimize payload by removing unnecessary data
86
+ */
87
+ export interface OptimizationResult<T> {
88
+ data: T;
89
+ originalSize: number;
90
+ optimizedSize: number;
91
+ savings: number;
92
+ savingsPercent: number;
93
+ }
94
+ export declare function optimizePayload<T>(data: T, options?: FieldSelectionOptions & {
95
+ removeEmpty?: boolean;
96
+ transformDates?: boolean;
97
+ sanitize?: boolean;
98
+ }): OptimizationResult<T>;
99
+ /**
100
+ * Create API response with optimized payload
101
+ */
102
+ export declare function createOptimizedResponse<T>(data: T, options?: {
103
+ pagination?: PaginationOptions;
104
+ fields?: FieldSelectionOptions;
105
+ optimize?: boolean;
106
+ compress?: boolean;
107
+ }): {
108
+ data: unknown;
109
+ meta?: {
110
+ pagination?: PaginatedResponse<T>['pagination'];
111
+ size?: {
112
+ original: string;
113
+ optimized: string;
114
+ savings: string;
115
+ };
116
+ };
117
+ };
118
+ /**
119
+ * Parse field selection from query params
120
+ */
121
+ export declare function parseFieldsFromQuery(query: string): FieldSelectionOptions;
122
+ /**
123
+ * Parse pagination from query params
124
+ */
125
+ export declare function parsePaginationFromQuery(query: string): PaginationOptions;
126
+ /**
127
+ * Batch responses to reduce round trips
128
+ */
129
+ export declare function batchResponses<T>(responses: Array<{
130
+ key: string;
131
+ data: T;
132
+ }>): Record<string, T>;
133
+ /**
134
+ * Create partial response (for large objects)
135
+ */
136
+ export declare function createPartialResponse<T extends Record<string, unknown>>(obj: T, maxDepth?: number, currentDepth?: number): Partial<T> | string;
137
+ export {};
138
+ //# sourceMappingURL=payload-optimization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-optimization.d.ts","sourceRoot":"","sources":["../../src/api/payload-optimization.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,iBAAiB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,iBAAiB,CAAC,CAAC;I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