@beechcms/core 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (389) hide show
  1. package/dist/auth/account-email.d.ts +3 -0
  2. package/dist/auth/account-email.d.ts.map +1 -0
  3. package/dist/auth/account-email.js +9 -0
  4. package/dist/auth/password-reset-token.repository.d.ts +13 -2
  5. package/dist/auth/password-reset-token.repository.d.ts.map +1 -1
  6. package/dist/auth/user.repository.d.ts +69 -4
  7. package/dist/auth/user.repository.d.ts.map +1 -1
  8. package/dist/automations-grammar-words.d.ts +2 -0
  9. package/dist/automations-grammar-words.d.ts.map +1 -0
  10. package/dist/automations-grammar-words.js +8 -0
  11. package/dist/automations.repository.interface.d.ts +19 -0
  12. package/dist/automations.repository.interface.d.ts.map +1 -0
  13. package/dist/automations.repository.interface.js +3 -0
  14. package/dist/automations.runner.interface.d.ts +10 -0
  15. package/dist/automations.runner.interface.d.ts.map +1 -0
  16. package/dist/automations.runner.interface.js +3 -0
  17. package/dist/automations.runner.stub.d.ts +5 -0
  18. package/dist/automations.runner.stub.d.ts.map +1 -0
  19. package/dist/automations.runner.stub.js +7 -0
  20. package/dist/automations.types.d.ts +75 -0
  21. package/dist/automations.types.d.ts.map +1 -0
  22. package/dist/automations.types.js +3 -0
  23. package/dist/clock.d.ts +25 -0
  24. package/dist/clock.d.ts.map +1 -0
  25. package/dist/clock.js +11 -0
  26. package/dist/common/canonical-json.d.ts +31 -0
  27. package/dist/common/canonical-json.d.ts.map +1 -0
  28. package/dist/common/canonical-json.js +91 -0
  29. package/dist/content/content-scan.repository.d.ts +1 -1
  30. package/dist/content/content.repository.d.ts +154 -3
  31. package/dist/content/content.repository.d.ts.map +1 -1
  32. package/dist/content/content.repository.js +62 -0
  33. package/dist/content/deletion-ledger.d.ts +39 -0
  34. package/dist/content/deletion-ledger.d.ts.map +1 -0
  35. package/dist/content/deletion-ledger.js +3 -0
  36. package/dist/content/seed-media-purge.repository.d.ts +34 -0
  37. package/dist/content/seed-media-purge.repository.d.ts.map +1 -0
  38. package/dist/content/seed-media-purge.repository.js +3 -0
  39. package/dist/content/seed.repository.d.ts +14 -0
  40. package/dist/content/seed.repository.d.ts.map +1 -1
  41. package/dist/content-scan.repository.d.ts +9 -0
  42. package/dist/content-scan.repository.d.ts.map +1 -0
  43. package/dist/content-scan.repository.js +3 -0
  44. package/dist/content.repository.d.ts +247 -0
  45. package/dist/content.repository.d.ts.map +1 -0
  46. package/dist/content.repository.js +59 -0
  47. package/dist/dashboard-layout/content-view.d.ts +757 -0
  48. package/dist/dashboard-layout/content-view.d.ts.map +1 -0
  49. package/dist/dashboard-layout/content-view.js +285 -0
  50. package/dist/dashboard-layout/content-view.repository.d.ts +39 -0
  51. package/dist/dashboard-layout/content-view.repository.d.ts.map +1 -0
  52. package/dist/dashboard-layout/content-view.repository.js +3 -0
  53. package/dist/dashboard-layout/dashboard-layout.d.ts +5 -0
  54. package/dist/dashboard-layout/dashboard-layout.d.ts.map +1 -1
  55. package/dist/dashboard-layout/dashboard-layout.js +17 -9
  56. package/dist/dashboard-layout/kanban/kanban.d.ts +32 -18
  57. package/dist/dashboard-layout/kanban/kanban.d.ts.map +1 -1
  58. package/dist/dashboard-layout/kanban/kanban.js +45 -21
  59. package/dist/dashboard-layout/seed-layout.d.ts +22 -31
  60. package/dist/dashboard-layout/seed-layout.d.ts.map +1 -1
  61. package/dist/dashboard-layout/seed-layout.js +93 -18
  62. package/dist/dashboard-layout/seed-layout.repository.d.ts +1 -5
  63. package/dist/dashboard-layout/seed-layout.repository.d.ts.map +1 -1
  64. package/dist/dashboard-layout.d.ts +154 -0
  65. package/dist/dashboard-layout.d.ts.map +1 -0
  66. package/dist/dashboard-layout.js +186 -0
  67. package/dist/dashboard-layout.repository.d.ts +18 -0
  68. package/dist/dashboard-layout.repository.d.ts.map +1 -0
  69. package/dist/dashboard-layout.repository.js +3 -0
  70. package/dist/dashboard-permissions.d.ts +3 -0
  71. package/dist/dashboard-permissions.d.ts.map +1 -0
  72. package/dist/dashboard-permissions.js +11 -0
  73. package/dist/dashboard-scopes.d.ts +12 -0
  74. package/dist/dashboard-scopes.d.ts.map +1 -0
  75. package/dist/dashboard-scopes.js +30 -0
  76. package/dist/define-seed.d.ts +3 -0
  77. package/dist/define-seed.d.ts.map +1 -0
  78. package/dist/define-seed.js +5 -0
  79. package/dist/demo-data.repository.d.ts +5 -0
  80. package/dist/demo-data.repository.d.ts.map +1 -0
  81. package/dist/demo-data.repository.js +3 -0
  82. package/dist/email.provider.d.ts +32 -0
  83. package/dist/email.provider.d.ts.map +1 -0
  84. package/dist/email.provider.js +4 -0
  85. package/dist/engine/ddl/ddl.d.ts +247 -0
  86. package/dist/engine/ddl/ddl.d.ts.map +1 -0
  87. package/dist/engine/ddl/ddl.js +653 -0
  88. package/dist/engine/ddl/schema-mutator.d.ts +29 -0
  89. package/dist/engine/ddl/schema-mutator.d.ts.map +1 -0
  90. package/dist/engine/ddl/schema-mutator.js +3 -0
  91. package/dist/engine/ddl/seed-ddl-destructive.d.ts +40 -0
  92. package/dist/engine/ddl/seed-ddl-destructive.d.ts.map +1 -0
  93. package/dist/engine/ddl/seed-ddl-destructive.js +149 -0
  94. package/dist/engine/ddl/seed-ddl.d.ts +43 -0
  95. package/dist/engine/ddl/seed-ddl.d.ts.map +1 -0
  96. package/dist/engine/ddl/seed-ddl.js +115 -0
  97. package/dist/engine/ddl/seed-purge-guards.d.ts +7 -0
  98. package/dist/engine/ddl/seed-purge-guards.d.ts.map +1 -0
  99. package/dist/engine/ddl/seed-purge-guards.js +19 -0
  100. package/dist/engine/engine.d.ts +4 -3
  101. package/dist/engine/engine.d.ts.map +1 -1
  102. package/dist/engine/engine.js +4 -3
  103. package/dist/engine/introspection/introspection.d.ts +101 -0
  104. package/dist/engine/introspection/introspection.d.ts.map +1 -0
  105. package/dist/engine/introspection/introspection.js +127 -0
  106. package/dist/engine/introspection/relation-audit.d.ts +46 -0
  107. package/dist/engine/introspection/relation-audit.d.ts.map +1 -0
  108. package/dist/engine/introspection/relation-audit.js +103 -0
  109. package/dist/engine/introspection/schema-fingerprint.d.ts +74 -0
  110. package/dist/engine/introspection/schema-fingerprint.d.ts.map +1 -0
  111. package/dist/engine/introspection/schema-fingerprint.js +102 -0
  112. package/dist/engine/introspection.d.ts +101 -0
  113. package/dist/engine/introspection.d.ts.map +1 -0
  114. package/dist/engine/introspection.js +127 -0
  115. package/dist/engine/localization/localization.d.ts +127 -0
  116. package/dist/engine/localization/localization.d.ts.map +1 -0
  117. package/dist/engine/localization/localization.js +212 -0
  118. package/dist/engine/localization.d.ts +127 -0
  119. package/dist/engine/localization.d.ts.map +1 -0
  120. package/dist/engine/localization.js +212 -0
  121. package/dist/engine/privacy/policies.d.ts +58 -0
  122. package/dist/engine/privacy/policies.d.ts.map +1 -0
  123. package/dist/engine/privacy/policies.js +191 -0
  124. package/dist/engine/privacy/privacy.service.d.ts +78 -0
  125. package/dist/engine/privacy/privacy.service.d.ts.map +1 -0
  126. package/dist/engine/privacy/privacy.service.js +138 -0
  127. package/dist/engine/privacy.service.d.ts.map +1 -1
  128. package/dist/engine/query/active-clause.d.ts +19 -0
  129. package/dist/engine/query/active-clause.d.ts.map +1 -0
  130. package/dist/engine/query/active-clause.js +27 -0
  131. package/dist/engine/query/query.d.ts +36 -0
  132. package/dist/engine/query/query.d.ts.map +1 -0
  133. package/dist/engine/query/query.js +393 -0
  134. package/dist/engine/query/relations.d.ts +28 -0
  135. package/dist/engine/query/relations.d.ts.map +1 -0
  136. package/dist/engine/query/relations.js +25 -0
  137. package/dist/engine/query/serialize.d.ts +22 -0
  138. package/dist/engine/query/serialize.d.ts.map +1 -0
  139. package/dist/engine/query/serialize.js +175 -0
  140. package/dist/engine/schema-fingerprint.d.ts +73 -0
  141. package/dist/engine/schema-fingerprint.d.ts.map +1 -0
  142. package/dist/engine/schema-fingerprint.js +97 -0
  143. package/dist/engine/seed-registry.d.ts.map +1 -1
  144. package/dist/engine/seeds/candidate-ids.d.ts +14 -0
  145. package/dist/engine/seeds/candidate-ids.d.ts.map +1 -0
  146. package/dist/engine/seeds/candidate-ids.js +40 -0
  147. package/dist/engine/seeds/define-seed.d.ts +3 -0
  148. package/dist/engine/seeds/define-seed.d.ts.map +1 -0
  149. package/dist/engine/seeds/define-seed.js +5 -0
  150. package/dist/engine/seeds/seed-definition-diff.d.ts +38 -0
  151. package/dist/engine/seeds/seed-definition-diff.d.ts.map +1 -0
  152. package/dist/engine/seeds/seed-definition-diff.js +51 -0
  153. package/dist/engine/seeds/seed-registry.d.ts +88 -0
  154. package/dist/engine/seeds/seed-registry.d.ts.map +1 -0
  155. package/dist/engine/seeds/seed-registry.js +194 -0
  156. package/dist/engine/seeds/seed-types-generator.d.ts +25 -0
  157. package/dist/engine/seeds/seed-types-generator.d.ts.map +1 -0
  158. package/dist/engine/seeds/seed-types-generator.js +116 -0
  159. package/dist/engine/seeds/seed-validation.d.ts +35 -0
  160. package/dist/engine/seeds/seed-validation.d.ts.map +1 -0
  161. package/dist/engine/seeds/seed-validation.js +384 -0
  162. package/dist/engine/seeds/seeds.d.ts +20 -0
  163. package/dist/engine/seeds/seeds.d.ts.map +1 -0
  164. package/dist/engine/seeds/seeds.js +21 -0
  165. package/dist/engine/seeds/tag-migration.d.ts +73 -0
  166. package/dist/engine/seeds/tag-migration.d.ts.map +1 -0
  167. package/dist/engine/seeds/tag-migration.js +212 -0
  168. package/dist/engine/seeds/tag-options.d.ts +15 -0
  169. package/dist/engine/seeds/tag-options.d.ts.map +1 -0
  170. package/dist/engine/seeds/tag-options.js +111 -0
  171. package/dist/engine/seeds/tag-value.d.ts +31 -0
  172. package/dist/engine/seeds/tag-value.d.ts.map +1 -0
  173. package/dist/engine/seeds/tag-value.js +51 -0
  174. package/dist/engine/types.d.ts +59 -7
  175. package/dist/engine/types.d.ts.map +1 -1
  176. package/dist/engine/validation/cache.d.ts.map +1 -1
  177. package/dist/engine/validation/cache.js +20 -4
  178. package/dist/engine/validation/emptiness.d.ts +12 -0
  179. package/dist/engine/validation/emptiness.d.ts.map +1 -0
  180. package/dist/engine/validation/emptiness.js +33 -0
  181. package/dist/engine/validation/index.d.ts +11 -0
  182. package/dist/engine/validation/index.d.ts.map +1 -1
  183. package/dist/engine/validation/index.js +29 -33
  184. package/dist/engine/validation/primitives.d.ts +12 -0
  185. package/dist/engine/validation/primitives.d.ts.map +1 -1
  186. package/dist/engine/validation/primitives.js +22 -0
  187. package/dist/engine/validation/richtext-sanitizer.d.ts +9 -1
  188. package/dist/engine/validation/richtext-sanitizer.d.ts.map +1 -1
  189. package/dist/engine/validation/richtext-sanitizer.js +36 -7
  190. package/dist/engine/validation/schema-builders.d.ts +16 -0
  191. package/dist/engine/validation/schema-builders.d.ts.map +1 -1
  192. package/dist/engine/validation/schema-builders.js +125 -18
  193. package/dist/engine.d.ts +144 -0
  194. package/dist/engine.d.ts.map +1 -0
  195. package/dist/engine.js +741 -0
  196. package/dist/file-types.d.ts +13 -0
  197. package/dist/file-types.d.ts.map +1 -0
  198. package/dist/file-types.js +85 -0
  199. package/dist/hooks.d.ts +29 -0
  200. package/dist/hooks.d.ts.map +1 -0
  201. package/dist/hooks.js +3 -0
  202. package/dist/id-generator.d.ts +26 -0
  203. package/dist/id-generator.d.ts.map +1 -0
  204. package/dist/id-generator.js +12 -0
  205. package/dist/idempotency.repository.d.ts +13 -0
  206. package/dist/idempotency.repository.d.ts.map +1 -0
  207. package/dist/idempotency.repository.js +3 -0
  208. package/dist/index.d.ts +34 -11
  209. package/dist/index.d.ts.map +1 -1
  210. package/dist/index.js +34 -11
  211. package/dist/kanban-position.repository.d.ts +19 -0
  212. package/dist/kanban-position.repository.d.ts.map +1 -0
  213. package/dist/kanban-position.repository.js +3 -0
  214. package/dist/kanban.d.ts +75 -0
  215. package/dist/kanban.d.ts.map +1 -0
  216. package/dist/kanban.js +82 -0
  217. package/dist/layout-permissions.d.ts +3 -0
  218. package/dist/layout-permissions.d.ts.map +1 -0
  219. package/dist/layout-permissions.js +11 -0
  220. package/dist/media/file-types.d.ts +12 -0
  221. package/dist/media/file-types.d.ts.map +1 -1
  222. package/dist/media/file-types.js +24 -4
  223. package/dist/media/image-transformer.d.ts +34 -0
  224. package/dist/media/image-transformer.d.ts.map +1 -0
  225. package/dist/media/image-transformer.js +3 -0
  226. package/dist/media/magic-bytes.d.ts.map +1 -1
  227. package/dist/media/magic-bytes.js +19 -9
  228. package/dist/media/media-transform.d.ts +92 -0
  229. package/dist/media/media-transform.d.ts.map +1 -0
  230. package/dist/media/media-transform.js +197 -0
  231. package/dist/media/media.repository.d.ts +5 -0
  232. package/dist/media/media.repository.d.ts.map +1 -1
  233. package/dist/media.repository.d.ts +61 -0
  234. package/dist/media.repository.d.ts.map +1 -0
  235. package/dist/media.repository.js +3 -0
  236. package/dist/notifications/notification.repository.d.ts +11 -2
  237. package/dist/notifications/notification.repository.d.ts.map +1 -1
  238. package/dist/oauth/authorization-code.repository.d.ts +10 -5
  239. package/dist/oauth/authorization-code.repository.d.ts.map +1 -1
  240. package/dist/oauth/role-guard.d.ts +30 -11
  241. package/dist/oauth/role-guard.d.ts.map +1 -1
  242. package/dist/oauth/role-guard.js +27 -5
  243. package/dist/oauth/token.repository.d.ts +2 -0
  244. package/dist/oauth/token.repository.d.ts.map +1 -1
  245. package/dist/policies.d.ts +10 -0
  246. package/dist/policies.d.ts.map +1 -0
  247. package/dist/policies.js +33 -0
  248. package/dist/queue/queue.interface.d.ts +9 -1
  249. package/dist/queue/queue.interface.d.ts.map +1 -1
  250. package/dist/queue/queue.stub.d.ts +1 -1
  251. package/dist/queue/queue.stub.d.ts.map +1 -1
  252. package/dist/queue/queue.stub.js +2 -3
  253. package/dist/queue.interface.d.ts +39 -0
  254. package/dist/queue.interface.d.ts.map +1 -0
  255. package/dist/queue.interface.js +3 -0
  256. package/dist/queue.stub.d.ts +6 -0
  257. package/dist/queue.stub.d.ts.map +1 -0
  258. package/dist/queue.stub.js +8 -0
  259. package/dist/rate-limit/token-bucket-rate-limiter.d.ts +7 -0
  260. package/dist/rate-limit/token-bucket-rate-limiter.d.ts.map +1 -1
  261. package/dist/rate-limit/token-bucket-rate-limiter.js +66 -0
  262. package/dist/rbac/evaluate.d.ts +57 -0
  263. package/dist/rbac/evaluate.d.ts.map +1 -0
  264. package/dist/rbac/evaluate.js +113 -0
  265. package/dist/rbac/invitation.repository.d.ts +84 -0
  266. package/dist/rbac/invitation.repository.d.ts.map +1 -0
  267. package/dist/rbac/invitation.repository.js +3 -0
  268. package/dist/rbac/permissions.d.ts +39 -0
  269. package/dist/rbac/permissions.d.ts.map +1 -0
  270. package/dist/rbac/permissions.js +43 -0
  271. package/dist/rbac/types.d.ts +130 -0
  272. package/dist/rbac/types.d.ts.map +1 -0
  273. package/dist/rbac/types.js +4 -0
  274. package/dist/relations.d.ts +28 -0
  275. package/dist/relations.d.ts.map +1 -0
  276. package/dist/relations.js +25 -0
  277. package/dist/richtext-render.d.ts +11 -0
  278. package/dist/richtext-render.d.ts.map +1 -0
  279. package/dist/richtext-render.js +87 -0
  280. package/dist/richtext.d.ts +11 -0
  281. package/dist/richtext.d.ts.map +1 -0
  282. package/dist/richtext.js +13 -0
  283. package/dist/scheduler.interface.d.ts +4 -0
  284. package/dist/scheduler.interface.d.ts.map +1 -0
  285. package/dist/scheduler.interface.js +3 -0
  286. package/dist/scheduler.stub.d.ts +5 -0
  287. package/dist/scheduler.stub.d.ts.map +1 -0
  288. package/dist/scheduler.stub.js +7 -0
  289. package/dist/schema/canonical.d.ts +15 -0
  290. package/dist/schema/canonical.d.ts.map +1 -0
  291. package/dist/schema/canonical.js +37 -0
  292. package/dist/schema/define.d.ts +42 -0
  293. package/dist/schema/define.d.ts.map +1 -0
  294. package/dist/schema/define.js +56 -0
  295. package/dist/schema/emit.d.ts +14 -0
  296. package/dist/schema/emit.d.ts.map +1 -0
  297. package/dist/schema/emit.js +43 -0
  298. package/dist/schema/index.d.ts +12 -0
  299. package/dist/schema/index.d.ts.map +1 -0
  300. package/dist/schema/index.js +13 -0
  301. package/dist/schema/manifest-seeds.d.ts +12 -0
  302. package/dist/schema/manifest-seeds.d.ts.map +1 -0
  303. package/dist/schema/manifest-seeds.js +48 -0
  304. package/dist/schema/manifest-validation.d.ts +13 -0
  305. package/dist/schema/manifest-validation.d.ts.map +1 -0
  306. package/dist/schema/manifest-validation.js +41 -0
  307. package/dist/schema/manifest.types.d.ts +54 -0
  308. package/dist/schema/manifest.types.d.ts.map +1 -0
  309. package/dist/schema/manifest.types.js +7 -0
  310. package/dist/schema-mutator.d.ts +26 -0
  311. package/dist/schema-mutator.d.ts.map +1 -0
  312. package/dist/schema-mutator.js +3 -0
  313. package/dist/search/search.repository.d.ts +5 -4
  314. package/dist/search/search.repository.d.ts.map +1 -1
  315. package/dist/search/vector-extractor.d.ts.map +1 -1
  316. package/dist/search/vector-extractor.js +23 -2
  317. package/dist/search/vector.repository.d.ts +2 -1
  318. package/dist/search/vector.repository.d.ts.map +1 -1
  319. package/dist/security/time-trap-token.repository.d.ts +5 -3
  320. package/dist/security/time-trap-token.repository.d.ts.map +1 -1
  321. package/dist/seed-ddl-destructive.d.ts +40 -0
  322. package/dist/seed-ddl-destructive.d.ts.map +1 -0
  323. package/dist/seed-ddl-destructive.js +149 -0
  324. package/dist/seed-ddl.d.ts +40 -0
  325. package/dist/seed-ddl.d.ts.map +1 -0
  326. package/dist/seed-ddl.js +100 -0
  327. package/dist/seed-layout.d.ts +145 -0
  328. package/dist/seed-layout.d.ts.map +1 -0
  329. package/dist/seed-layout.js +192 -0
  330. package/dist/seed-layout.repository.d.ts +22 -0
  331. package/dist/seed-layout.repository.d.ts.map +1 -0
  332. package/dist/seed-layout.repository.js +3 -0
  333. package/dist/seed-registry.d.ts +71 -0
  334. package/dist/seed-registry.d.ts.map +1 -0
  335. package/dist/seed-registry.js +143 -0
  336. package/dist/seed-types-generator.d.ts +1 -1
  337. package/dist/seed-types-generator.d.ts.map +1 -1
  338. package/dist/seed-validation.d.ts +23 -0
  339. package/dist/seed-validation.d.ts.map +1 -0
  340. package/dist/seed-validation.js +224 -0
  341. package/dist/seed.repository.d.ts +37 -0
  342. package/dist/seed.repository.d.ts.map +1 -0
  343. package/dist/seed.repository.js +3 -0
  344. package/dist/seeds.d.ts +20 -0
  345. package/dist/seeds.d.ts.map +1 -0
  346. package/dist/seeds.js +21 -0
  347. package/dist/settings/site-settings.repository.d.ts +8 -0
  348. package/dist/settings/site-settings.repository.d.ts.map +1 -1
  349. package/dist/site-settings.repository.d.ts +16 -0
  350. package/dist/site-settings.repository.d.ts.map +1 -0
  351. package/dist/site-settings.repository.js +3 -0
  352. package/dist/slug-utils.d.ts +18 -0
  353. package/dist/slug-utils.d.ts.map +1 -0
  354. package/dist/slug-utils.js +32 -0
  355. package/dist/storage.d.ts +46 -0
  356. package/dist/storage.d.ts.map +1 -0
  357. package/dist/storage.js +3 -0
  358. package/dist/transfer/csv.d.ts +34 -0
  359. package/dist/transfer/csv.d.ts.map +1 -0
  360. package/dist/transfer/csv.js +135 -0
  361. package/dist/transfer/flat-seed.d.ts +13 -0
  362. package/dist/transfer/flat-seed.d.ts.map +1 -0
  363. package/dist/transfer/flat-seed.js +50 -0
  364. package/dist/transfer/index.d.ts +7 -0
  365. package/dist/transfer/index.d.ts.map +1 -0
  366. package/dist/transfer/index.js +8 -0
  367. package/dist/transfer/ndjson.d.ts +25 -0
  368. package/dist/transfer/ndjson.d.ts.map +1 -0
  369. package/dist/transfer/ndjson.js +62 -0
  370. package/dist/transfer/row-mapping.d.ts +36 -0
  371. package/dist/transfer/row-mapping.d.ts.map +1 -0
  372. package/dist/transfer/row-mapping.js +97 -0
  373. package/dist/transfer/transfer.constants.d.ts +20 -0
  374. package/dist/transfer/transfer.constants.d.ts.map +1 -0
  375. package/dist/transfer/transfer.constants.js +21 -0
  376. package/dist/transfer/transfer.types.d.ts +46 -0
  377. package/dist/transfer/transfer.types.d.ts.map +1 -0
  378. package/dist/transfer/transfer.types.js +6 -0
  379. package/dist/types.d.ts +243 -0
  380. package/dist/types.d.ts.map +1 -0
  381. package/dist/types.js +3 -0
  382. package/dist/validation.d.ts +50 -0
  383. package/dist/validation.d.ts.map +1 -0
  384. package/dist/validation.js +660 -0
  385. package/dist/webhook-validation.d.ts +3 -0
  386. package/dist/webhook-validation.d.ts.map +1 -0
  387. package/dist/webhook-validation.js +6 -0
  388. package/package.json +11 -6
  389. package/dist/.tsbuildinfo +0 -1
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @module engine/localization
3
+ * Field-level localization primitives for the Botanical Engine. A localized branch keeps its native
4
+ * TEXT column and stores a locale dictionary in it (`{"it":"Scarpa","en":"Shoe"}`), so ids, relations
5
+ * and metrics are untouched and toggling `Branch.localized` never emits DDL. Pure functions: no I/O and
6
+ * no settings access — callers pass the project's {@link LocaleConfig}.
7
+ */
8
+ import type { Branch, BranchType, Seed } from '../types.js';
9
+ /**
10
+ * Locale code grammar (v1): ISO 639 language (2–3 lowercase letters), optionally followed by an ISO 3166
11
+ * region (2 uppercase letters) or a UN M.49 area (3 digits) — `it`, `en`, `pt-BR`, `es-419`. Script
12
+ * subtags (`zh-Hant`) are outside v1. The grammar doubles as an injection guard: validated codes are
13
+ * later interpolated into SQLite JSON paths.
14
+ */
15
+ export declare const LOCALE_CODE_RE: RegExp;
16
+ /** Branch types that may carry `localized: true`. */
17
+ export declare const LOCALIZABLE_BRANCH_TYPES: ReadonlySet<BranchType>;
18
+ /**
19
+ * Project-level language configuration. Invariant (guaranteed by its producer): `locales` is non-empty,
20
+ * every entry matches {@link LOCALE_CODE_RE}, and it contains `defaultLocale`.
21
+ */
22
+ export interface LocaleConfig {
23
+ readonly locales: readonly string[];
24
+ readonly defaultLocale: string;
25
+ }
26
+ /** A locale dictionary as stored in the branch column: locale code → value. */
27
+ export type LocalizedDictionary = Record<string, unknown>;
28
+ /**
29
+ * A validated write for a localized branch: registered locale code → new value, or `null` meaning
30
+ * "clear this locale". Locales absent from the patch must be left untouched by the write path.
31
+ */
32
+ export type LocalizedPatch = Record<string, unknown>;
33
+ /** True when `value` is a string matching {@link LOCALE_CODE_RE}. */
34
+ export declare function isLocaleCode(value: unknown): value is string;
35
+ /**
36
+ * True when the branch is localized AND its type supports it. A malformed definition that slipped past
37
+ * seed validation (e.g. `localized: true` on a `number`) is treated as not localized, never as a dictionary.
38
+ */
39
+ export declare function isLocalizedBranch(branch: Pick<Branch, 'type' | 'localized'>): boolean;
40
+ /**
41
+ * Structural check used on READ paths (no config available): a non-empty plain object whose every key
42
+ * matches the locale-code grammar. A richtext envelope (`schemaVersion`, `doc`) and a TipTap doc
43
+ * (`type`, `content`) never match.
44
+ */
45
+ export declare function isLocaleDictionary(value: unknown): value is LocalizedDictionary;
46
+ /**
47
+ * Stricter check used on WRITE paths: a locale dictionary with at least one REGISTERED locale key.
48
+ * Without the registration requirement a legitimate json value such as `{"url": "…", "alt": "…"}` —
49
+ * whose keys happen to match the grammar — would be read as a dictionary of unregistered locales and
50
+ * silently emptied.
51
+ */
52
+ export declare function isLocalizedWriteDictionary(value: unknown, config: LocaleConfig): value is LocalizedDictionary;
53
+ /**
54
+ * Normalises any accepted write value of a localized branch into a {@link LocalizedPatch}:
55
+ * - a write dictionary keeps its registered locales, in `config.locales` order; unregistered locale
56
+ * keys are dropped;
57
+ * - any other value (string, richtext doc, non-dictionary json) is the default-locale value;
58
+ * - `null`, `undefined` and blank strings become `null` ("clear this locale").
59
+ * Idempotent: a patch passed back in yields the same patch.
60
+ */
61
+ export declare function toLocalizedPatch(value: unknown, config: LocaleConfig): LocalizedPatch;
62
+ /**
63
+ * Removes `null` / `undefined` / blank-string entries. Returns `null` when nothing remains, so an
64
+ * all-cleared dictionary is stored as SQL NULL rather than `{}`. Keys are otherwise preserved as-is —
65
+ * including locales no longer registered, which must never be dropped by a write (brief §2, no data loss).
66
+ */
67
+ export declare function compactLocalizedDictionary(value: LocalizedDictionary): LocalizedDictionary | null;
68
+ /**
69
+ * The settings subset {@link resolveLocaleConfig} reads. Structural, so this module stays free of
70
+ * settings imports; `SiteSettings` satisfies it.
71
+ */
72
+ export interface LocaleSettings {
73
+ readonly locales?: readonly string[] | null;
74
+ readonly defaultLocale?: string | null;
75
+ readonly defaultLanguage: string;
76
+ }
77
+ /**
78
+ * Builds the project's {@link LocaleConfig}, repairing whatever a hand-edited settings row could break so
79
+ * the LocaleConfig invariant always holds:
80
+ * - `locales`: the stored list minus invalid codes and duplicates; when nothing remains (never configured,
81
+ * `[]`, corrupt), the implicit single-language config `[defaultLanguage]` (brief §2), which keeps the
82
+ * feature invisible to a mono-lingual project;
83
+ * - `defaultLocale`: the stored value when it belongs to `locales`, else `locales[0]`.
84
+ */
85
+ export declare function resolveLocaleConfig(settings: LocaleSettings): LocaleConfig;
86
+ /**
87
+ * Merges a write into the value stored for a localized branch. The write path's only way to persist a
88
+ * localized value, so a translation the write does not mention is never dropped (brief §2):
89
+ * - `write === null` clears the whole field (an explicit null keeps its pre-localization meaning);
90
+ * - otherwise the write is normalised with {@link toLocalizedPatch}: every registered locale it names
91
+ * overwrites that locale, a `null` entry clears that locale only, and every other stored locale —
92
+ * including ones no longer registered — is kept as-is;
93
+ * - a stored legacy value (written before the branch became localized) is the default-locale value.
94
+ * @returns The compacted dictionary, or `null` when no locale keeps a value.
95
+ */
96
+ export declare function applyLocalizedPatch(branch: Pick<Branch, 'type' | 'localized'>, stored: unknown, write: unknown, config: LocaleConfig): LocalizedDictionary | null;
97
+ /** Aliases of the localized branches a write carries — the fields it must merge rather than replace. */
98
+ export declare function localizedAliasesIn(seed: Pick<Seed, 'branches'>, data: Record<string, unknown>): string[];
99
+ /**
100
+ * Returns `data` with every localized branch it carries merged into `stored` via
101
+ * {@link applyLocalizedPatch}; other keys pass through untouched. `stored` is the entry's current values
102
+ * (`null` on create, which only compacts). Returns `data` itself when `config` is undefined or no localized
103
+ * branch is written.
104
+ */
105
+ export declare function mergeLocalizedFields(seed: Pick<Seed, 'branches'>, stored: Record<string, unknown> | null, data: Record<string, unknown>, config: LocaleConfig | undefined): Record<string, unknown>;
106
+ /**
107
+ * Resolves a stored localized value to one language: the requested locale, then the default locale, then the
108
+ * first stored translation (stored key order), then `null`. A legacy value that is not a dictionary is returned
109
+ * as-is. Non-localized branches return `value` unchanged. `buildSelectQuery` applies the same chain in SQL, so
110
+ * filters and ORDER BY compare exactly what a reader sees.
111
+ */
112
+ export declare function resolveLocalizedValue(branch: Pick<Branch, 'type' | 'localized'>, value: unknown, locale: string, config: LocaleConfig): unknown;
113
+ /**
114
+ * Returns a copy of `data` with every localized branch resolved to `locale` (default: the default locale)
115
+ * via {@link resolveLocalizedValue}. Returns `data` itself when `config` is undefined.
116
+ */
117
+ export declare function resolveLocalizedFields(seed: Pick<Seed, 'branches'>, data: Record<string, unknown>, config: LocaleConfig | undefined, locale?: string): Record<string, unknown>;
118
+ /**
119
+ * The whole dictionary of a stored localized value, for readers asking every language (`?lang=all`):
120
+ * a stored dictionary as-is — unregistered locales included, nothing is hidden (brief §2) — a legacy
121
+ * value as `{ [defaultLocale]: value }` (the write path's reading of it), a blank value as `null`.
122
+ * Non-localized branches return `value` unchanged.
123
+ */
124
+ export declare function asLocaleDictionary(branch: Pick<Branch, 'type' | 'localized'>, value: unknown, config: LocaleConfig): unknown;
125
+ /** Returns a copy of `data` with every localized branch it carries passed through {@link asLocaleDictionary}. */
126
+ export declare function asLocaleDictionaries(seed: Pick<Seed, 'branches'>, data: Record<string, unknown>, config: LocaleConfig): Record<string, unknown>;
127
+ //# sourceMappingURL=localization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../../src/engine/localization/localization.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAG3D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,QAA4C,CAAA;AAEvE,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,UAA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,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,EAC1C,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,YAAY,GACnB,OAAO,CAIT;AAED,iHAAiH;AACjH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,EAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,YAAY,GACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB"}
@@ -0,0 +1,212 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2024–2026 Flavio De Musso
3
+ import { cleanString, isPlainObject } from '../validation/primitives.js';
4
+ /**
5
+ * Locale code grammar (v1): ISO 639 language (2–3 lowercase letters), optionally followed by an ISO 3166
6
+ * region (2 uppercase letters) or a UN M.49 area (3 digits) — `it`, `en`, `pt-BR`, `es-419`. Script
7
+ * subtags (`zh-Hant`) are outside v1. The grammar doubles as an injection guard: validated codes are
8
+ * later interpolated into SQLite JSON paths.
9
+ */
10
+ export const LOCALE_CODE_RE = /^[a-z]{2,3}(?:-(?:[A-Z]{2}|[0-9]{3}))?$/;
11
+ /** Branch types that may carry `localized: true`. */
12
+ export const LOCALIZABLE_BRANCH_TYPES = new Set(['text', 'richtext', 'json']);
13
+ /** True when `value` is a string matching {@link LOCALE_CODE_RE}. */
14
+ export function isLocaleCode(value) {
15
+ return typeof value === 'string' && LOCALE_CODE_RE.test(value);
16
+ }
17
+ /**
18
+ * True when the branch is localized AND its type supports it. A malformed definition that slipped past
19
+ * seed validation (e.g. `localized: true` on a `number`) is treated as not localized, never as a dictionary.
20
+ */
21
+ export function isLocalizedBranch(branch) {
22
+ return branch.localized === true && LOCALIZABLE_BRANCH_TYPES.has(branch.type);
23
+ }
24
+ /**
25
+ * Structural check used on READ paths (no config available): a non-empty plain object whose every key
26
+ * matches the locale-code grammar. A richtext envelope (`schemaVersion`, `doc`) and a TipTap doc
27
+ * (`type`, `content`) never match.
28
+ */
29
+ export function isLocaleDictionary(value) {
30
+ if (!isPlainObject(value))
31
+ return false;
32
+ const keys = Object.keys(value);
33
+ return keys.length > 0 && keys.every(isLocaleCode);
34
+ }
35
+ /**
36
+ * Stricter check used on WRITE paths: a locale dictionary with at least one REGISTERED locale key.
37
+ * Without the registration requirement a legitimate json value such as `{"url": "…", "alt": "…"}` —
38
+ * whose keys happen to match the grammar — would be read as a dictionary of unregistered locales and
39
+ * silently emptied.
40
+ */
41
+ export function isLocalizedWriteDictionary(value, config) {
42
+ return isLocaleDictionary(value) && Object.keys(value).some((key) => config.locales.includes(key));
43
+ }
44
+ function isBlankLocaleValue(value) {
45
+ return value === null || value === undefined || (typeof value === 'string' && cleanString(value) === '');
46
+ }
47
+ /**
48
+ * Normalises any accepted write value of a localized branch into a {@link LocalizedPatch}:
49
+ * - a write dictionary keeps its registered locales, in `config.locales` order; unregistered locale
50
+ * keys are dropped;
51
+ * - any other value (string, richtext doc, non-dictionary json) is the default-locale value;
52
+ * - `null`, `undefined` and blank strings become `null` ("clear this locale").
53
+ * Idempotent: a patch passed back in yields the same patch.
54
+ */
55
+ export function toLocalizedPatch(value, config) {
56
+ const source = isLocalizedWriteDictionary(value, config)
57
+ ? value
58
+ : { [config.defaultLocale]: value };
59
+ const patch = {};
60
+ for (const locale of config.locales) {
61
+ if (!Object.hasOwn(source, locale))
62
+ continue;
63
+ patch[locale] = isBlankLocaleValue(source[locale]) ? null : source[locale];
64
+ }
65
+ return patch;
66
+ }
67
+ /**
68
+ * Removes `null` / `undefined` / blank-string entries. Returns `null` when nothing remains, so an
69
+ * all-cleared dictionary is stored as SQL NULL rather than `{}`. Keys are otherwise preserved as-is —
70
+ * including locales no longer registered, which must never be dropped by a write (brief §2, no data loss).
71
+ */
72
+ export function compactLocalizedDictionary(value) {
73
+ const compact = {};
74
+ for (const [locale, localeValue] of Object.entries(value)) {
75
+ if (isBlankLocaleValue(localeValue))
76
+ continue;
77
+ compact[locale] = localeValue;
78
+ }
79
+ return Object.keys(compact).length > 0 ? compact : null;
80
+ }
81
+ /** Content locale used when neither stored `locales` nor a valid `defaultLanguage` is available. */
82
+ const FALLBACK_LOCALE = 'en';
83
+ /**
84
+ * Builds the project's {@link LocaleConfig}, repairing whatever a hand-edited settings row could break so
85
+ * the LocaleConfig invariant always holds:
86
+ * - `locales`: the stored list minus invalid codes and duplicates; when nothing remains (never configured,
87
+ * `[]`, corrupt), the implicit single-language config `[defaultLanguage]` (brief §2), which keeps the
88
+ * feature invisible to a mono-lingual project;
89
+ * - `defaultLocale`: the stored value when it belongs to `locales`, else `locales[0]`.
90
+ */
91
+ export function resolveLocaleConfig(settings) {
92
+ const stored = [...new Set((settings.locales ?? []).filter(isLocaleCode))];
93
+ const implicit = isLocaleCode(settings.defaultLanguage) ? settings.defaultLanguage : FALLBACK_LOCALE;
94
+ const locales = stored.length > 0 ? stored : [implicit];
95
+ const defaultLocale = settings.defaultLocale && locales.includes(settings.defaultLocale)
96
+ ? settings.defaultLocale
97
+ : locales[0];
98
+ return { locales, defaultLocale };
99
+ }
100
+ /**
101
+ * True when a STORED value of a localized branch is a locale dictionary. Text and richtext cannot hold an
102
+ * object keyed only by locale codes for any other reason; json can (`{"url": "…", "alt": "…"}`), so a json
103
+ * object counts only when at least one key is a registered locale — otherwise it is a legacy value written
104
+ * before the branch became localized.
105
+ */
106
+ function isStoredLocaleDictionary(branch, value, config) {
107
+ if (!isLocalizedBranch(branch) || !isLocaleDictionary(value))
108
+ return false;
109
+ return branch.type !== 'json' || Object.keys(value).some((key) => config.locales.includes(key));
110
+ }
111
+ /**
112
+ * Merges a write into the value stored for a localized branch. The write path's only way to persist a
113
+ * localized value, so a translation the write does not mention is never dropped (brief §2):
114
+ * - `write === null` clears the whole field (an explicit null keeps its pre-localization meaning);
115
+ * - otherwise the write is normalised with {@link toLocalizedPatch}: every registered locale it names
116
+ * overwrites that locale, a `null` entry clears that locale only, and every other stored locale —
117
+ * including ones no longer registered — is kept as-is;
118
+ * - a stored legacy value (written before the branch became localized) is the default-locale value.
119
+ * @returns The compacted dictionary, or `null` when no locale keeps a value.
120
+ */
121
+ export function applyLocalizedPatch(branch, stored, write, config) {
122
+ if (write === null)
123
+ return null;
124
+ const merged = isStoredLocaleDictionary(branch, stored, config)
125
+ ? { ...stored }
126
+ : isBlankLocaleValue(stored) ? {} : { [config.defaultLocale]: stored };
127
+ Object.assign(merged, toLocalizedPatch(write, config));
128
+ return compactLocalizedDictionary(merged);
129
+ }
130
+ /** Aliases of the localized branches a write carries — the fields it must merge rather than replace. */
131
+ export function localizedAliasesIn(seed, data) {
132
+ return seed.branches
133
+ .filter((branch) => isLocalizedBranch(branch) && Object.hasOwn(data, branch.alias) && data[branch.alias] !== undefined)
134
+ .map((branch) => branch.alias);
135
+ }
136
+ /**
137
+ * Returns `data` with every localized branch it carries merged into `stored` via
138
+ * {@link applyLocalizedPatch}; other keys pass through untouched. `stored` is the entry's current values
139
+ * (`null` on create, which only compacts). Returns `data` itself when `config` is undefined or no localized
140
+ * branch is written.
141
+ */
142
+ export function mergeLocalizedFields(seed, stored, data, config) {
143
+ if (!config)
144
+ return data;
145
+ const aliases = localizedAliasesIn(seed, data);
146
+ if (aliases.length === 0)
147
+ return data;
148
+ const merged = { ...data };
149
+ for (const branch of seed.branches) {
150
+ if (!aliases.includes(branch.alias))
151
+ continue;
152
+ merged[branch.alias] = applyLocalizedPatch(branch, stored?.[branch.alias], data[branch.alias], config);
153
+ }
154
+ return merged;
155
+ }
156
+ /**
157
+ * Resolves a stored localized value to one language: the requested locale, then the default locale, then the
158
+ * first stored translation (stored key order), then `null`. A legacy value that is not a dictionary is returned
159
+ * as-is. Non-localized branches return `value` unchanged. `buildSelectQuery` applies the same chain in SQL, so
160
+ * filters and ORDER BY compare exactly what a reader sees.
161
+ */
162
+ export function resolveLocalizedValue(branch, value, locale, config) {
163
+ if (!isStoredLocaleDictionary(branch, value, config))
164
+ return value;
165
+ if (!isBlankLocaleValue(value[locale]))
166
+ return value[locale];
167
+ if (!isBlankLocaleValue(value[config.defaultLocale]))
168
+ return value[config.defaultLocale];
169
+ // An implicit config follows `defaultLanguage`; changing it before languages are configured leaves every
170
+ // dictionary without its default key. Returning null there would blank the public site (brief §2).
171
+ const firstStored = Object.values(value).find((translation) => !isBlankLocaleValue(translation));
172
+ return firstStored ?? null;
173
+ }
174
+ /**
175
+ * Returns a copy of `data` with every localized branch resolved to `locale` (default: the default locale)
176
+ * via {@link resolveLocalizedValue}. Returns `data` itself when `config` is undefined.
177
+ */
178
+ export function resolveLocalizedFields(seed, data, config, locale) {
179
+ if (!config)
180
+ return data;
181
+ const target = locale ?? config.defaultLocale;
182
+ const resolved = { ...data };
183
+ for (const branch of seed.branches) {
184
+ if (isLocalizedBranch(branch) && Object.hasOwn(resolved, branch.alias)) {
185
+ resolved[branch.alias] = resolveLocalizedValue(branch, resolved[branch.alias], target, config);
186
+ }
187
+ }
188
+ return resolved;
189
+ }
190
+ /**
191
+ * The whole dictionary of a stored localized value, for readers asking every language (`?lang=all`):
192
+ * a stored dictionary as-is — unregistered locales included, nothing is hidden (brief §2) — a legacy
193
+ * value as `{ [defaultLocale]: value }` (the write path's reading of it), a blank value as `null`.
194
+ * Non-localized branches return `value` unchanged.
195
+ */
196
+ export function asLocaleDictionary(branch, value, config) {
197
+ if (!isLocalizedBranch(branch))
198
+ return value;
199
+ if (isStoredLocaleDictionary(branch, value, config))
200
+ return value;
201
+ return isBlankLocaleValue(value) ? null : { [config.defaultLocale]: value };
202
+ }
203
+ /** Returns a copy of `data` with every localized branch it carries passed through {@link asLocaleDictionary}. */
204
+ export function asLocaleDictionaries(seed, data, config) {
205
+ const expanded = { ...data };
206
+ for (const branch of seed.branches) {
207
+ if (isLocalizedBranch(branch) && Object.hasOwn(expanded, branch.alias)) {
208
+ expanded[branch.alias] = asLocaleDictionary(branch, expanded[branch.alias], config);
209
+ }
210
+ }
211
+ return expanded;
212
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @module engine/localization
3
+ * Field-level localization primitives for the Botanical Engine. A localized branch keeps its native
4
+ * TEXT column and stores a locale dictionary in it (`{"it":"Scarpa","en":"Shoe"}`), so ids, relations
5
+ * and metrics are untouched and toggling `Branch.localized` never emits DDL. Pure functions: no I/O and
6
+ * no settings access — callers pass the project's {@link LocaleConfig}.
7
+ */
8
+ import type { Branch, BranchType, Seed } from './types.js';
9
+ /**
10
+ * Locale code grammar (v1): ISO 639 language (2–3 lowercase letters), optionally followed by an ISO 3166
11
+ * region (2 uppercase letters) or a UN M.49 area (3 digits) — `it`, `en`, `pt-BR`, `es-419`. Script
12
+ * subtags (`zh-Hant`) are outside v1. The grammar doubles as an injection guard: validated codes are
13
+ * later interpolated into SQLite JSON paths.
14
+ */
15
+ export declare const LOCALE_CODE_RE: RegExp;
16
+ /** Branch types that may carry `localized: true`. */
17
+ export declare const LOCALIZABLE_BRANCH_TYPES: ReadonlySet<BranchType>;
18
+ /**
19
+ * Project-level language configuration. Invariant (guaranteed by its producer): `locales` is non-empty,
20
+ * every entry matches {@link LOCALE_CODE_RE}, and it contains `defaultLocale`.
21
+ */
22
+ export interface LocaleConfig {
23
+ readonly locales: readonly string[];
24
+ readonly defaultLocale: string;
25
+ }
26
+ /** A locale dictionary as stored in the branch column: locale code → value. */
27
+ export type LocalizedDictionary = Record<string, unknown>;
28
+ /**
29
+ * A validated write for a localized branch: registered locale code → new value, or `null` meaning
30
+ * "clear this locale". Locales absent from the patch must be left untouched by the write path.
31
+ */
32
+ export type LocalizedPatch = Record<string, unknown>;
33
+ /** True when `value` is a string matching {@link LOCALE_CODE_RE}. */
34
+ export declare function isLocaleCode(value: unknown): value is string;
35
+ /**
36
+ * True when the branch is localized AND its type supports it. A malformed definition that slipped past
37
+ * seed validation (e.g. `localized: true` on a `number`) is treated as not localized, never as a dictionary.
38
+ */
39
+ export declare function isLocalizedBranch(branch: Pick<Branch, 'type' | 'localized'>): boolean;
40
+ /**
41
+ * Structural check used on READ paths (no config available): a non-empty plain object whose every key
42
+ * matches the locale-code grammar. A richtext envelope (`schemaVersion`, `doc`) and a TipTap doc
43
+ * (`type`, `content`) never match.
44
+ */
45
+ export declare function isLocaleDictionary(value: unknown): value is LocalizedDictionary;
46
+ /**
47
+ * Stricter check used on WRITE paths: a locale dictionary with at least one REGISTERED locale key.
48
+ * Without the registration requirement a legitimate json value such as `{"url": "…", "alt": "…"}` —
49
+ * whose keys happen to match the grammar — would be read as a dictionary of unregistered locales and
50
+ * silently emptied.
51
+ */
52
+ export declare function isLocalizedWriteDictionary(value: unknown, config: LocaleConfig): value is LocalizedDictionary;
53
+ /**
54
+ * Normalises any accepted write value of a localized branch into a {@link LocalizedPatch}:
55
+ * - a write dictionary keeps its registered locales, in `config.locales` order; unregistered locale
56
+ * keys are dropped;
57
+ * - any other value (string, richtext doc, non-dictionary json) is the default-locale value;
58
+ * - `null`, `undefined` and blank strings become `null` ("clear this locale").
59
+ * Idempotent: a patch passed back in yields the same patch.
60
+ */
61
+ export declare function toLocalizedPatch(value: unknown, config: LocaleConfig): LocalizedPatch;
62
+ /**
63
+ * Removes `null` / `undefined` / blank-string entries. Returns `null` when nothing remains, so an
64
+ * all-cleared dictionary is stored as SQL NULL rather than `{}`. Keys are otherwise preserved as-is —
65
+ * including locales no longer registered, which must never be dropped by a write (brief §2, no data loss).
66
+ */
67
+ export declare function compactLocalizedDictionary(value: LocalizedDictionary): LocalizedDictionary | null;
68
+ /**
69
+ * The settings subset {@link resolveLocaleConfig} reads. Structural, so this module stays free of
70
+ * settings imports; `SiteSettings` satisfies it.
71
+ */
72
+ export interface LocaleSettings {
73
+ readonly locales?: readonly string[] | null;
74
+ readonly defaultLocale?: string | null;
75
+ readonly defaultLanguage: string;
76
+ }
77
+ /**
78
+ * Builds the project's {@link LocaleConfig}, repairing whatever a hand-edited settings row could break so
79
+ * the LocaleConfig invariant always holds:
80
+ * - `locales`: the stored list minus invalid codes and duplicates; when nothing remains (never configured,
81
+ * `[]`, corrupt), the implicit single-language config `[defaultLanguage]` (brief §2), which keeps the
82
+ * feature invisible to a mono-lingual project;
83
+ * - `defaultLocale`: the stored value when it belongs to `locales`, else `locales[0]`.
84
+ */
85
+ export declare function resolveLocaleConfig(settings: LocaleSettings): LocaleConfig;
86
+ /**
87
+ * Merges a write into the value stored for a localized branch. The write path's only way to persist a
88
+ * localized value, so a translation the write does not mention is never dropped (brief §2):
89
+ * - `write === null` clears the whole field (an explicit null keeps its pre-localization meaning);
90
+ * - otherwise the write is normalised with {@link toLocalizedPatch}: every registered locale it names
91
+ * overwrites that locale, a `null` entry clears that locale only, and every other stored locale —
92
+ * including ones no longer registered — is kept as-is;
93
+ * - a stored legacy value (written before the branch became localized) is the default-locale value.
94
+ * @returns The compacted dictionary, or `null` when no locale keeps a value.
95
+ */
96
+ export declare function applyLocalizedPatch(branch: Pick<Branch, 'type' | 'localized'>, stored: unknown, write: unknown, config: LocaleConfig): LocalizedDictionary | null;
97
+ /** Aliases of the localized branches a write carries — the fields it must merge rather than replace. */
98
+ export declare function localizedAliasesIn(seed: Pick<Seed, 'branches'>, data: Record<string, unknown>): string[];
99
+ /**
100
+ * Returns `data` with every localized branch it carries merged into `stored` via
101
+ * {@link applyLocalizedPatch}; other keys pass through untouched. `stored` is the entry's current values
102
+ * (`null` on create, which only compacts). Returns `data` itself when `config` is undefined or no localized
103
+ * branch is written.
104
+ */
105
+ export declare function mergeLocalizedFields(seed: Pick<Seed, 'branches'>, stored: Record<string, unknown> | null, data: Record<string, unknown>, config: LocaleConfig | undefined): Record<string, unknown>;
106
+ /**
107
+ * Resolves a stored localized value to one language: the requested locale, then the default locale, then the
108
+ * first stored translation (stored key order), then `null`. A legacy value that is not a dictionary is returned
109
+ * as-is. Non-localized branches return `value` unchanged. `buildSelectQuery` applies the same chain in SQL, so
110
+ * filters and ORDER BY compare exactly what a reader sees.
111
+ */
112
+ export declare function resolveLocalizedValue(branch: Pick<Branch, 'type' | 'localized'>, value: unknown, locale: string, config: LocaleConfig): unknown;
113
+ /**
114
+ * Returns a copy of `data` with every localized branch resolved to `locale` (default: the default locale)
115
+ * via {@link resolveLocalizedValue}. Returns `data` itself when `config` is undefined.
116
+ */
117
+ export declare function resolveLocalizedFields(seed: Pick<Seed, 'branches'>, data: Record<string, unknown>, config: LocaleConfig | undefined, locale?: string): Record<string, unknown>;
118
+ /**
119
+ * The whole dictionary of a stored localized value, for readers asking every language (`?lang=all`):
120
+ * a stored dictionary as-is — unregistered locales included, nothing is hidden (brief §2) — a legacy
121
+ * value as `{ [defaultLocale]: value }` (the write path's reading of it), a blank value as `null`.
122
+ * Non-localized branches return `value` unchanged.
123
+ */
124
+ export declare function asLocaleDictionary(branch: Pick<Branch, 'type' | 'localized'>, value: unknown, config: LocaleConfig): unknown;
125
+ /** Returns a copy of `data` with every localized branch it carries passed through {@link asLocaleDictionary}. */
126
+ export declare function asLocaleDictionaries(seed: Pick<Seed, 'branches'>, data: Record<string, unknown>, config: LocaleConfig): Record<string, unknown>;
127
+ //# sourceMappingURL=localization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/engine/localization.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAG1D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,QAA4C,CAAA;AAEvE,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,UAAU,CAAqD,CAAA;AAElH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAC/B;AAED,+EAA+E;AAC/E,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzD;;;GAGG;AACH,MAAM,MAAM,cAAc,GA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