@heyo-sh/heyo-cms 0.0.0-stage → 0.1.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 (382) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -2
  3. package/dist/access/index.d.ts +9 -0
  4. package/dist/access/index.d.ts.map +1 -0
  5. package/dist/access/permissions.d.ts +54 -0
  6. package/dist/access/permissions.d.ts.map +1 -0
  7. package/dist/adapters/astro.d.ts +38 -0
  8. package/dist/adapters/astro.d.ts.map +1 -0
  9. package/dist/adapters/astro.js +1 -0
  10. package/dist/adapters/next.d.ts +31 -0
  11. package/dist/adapters/next.d.ts.map +1 -0
  12. package/dist/adapters/next.js +1 -0
  13. package/dist/adapters/nuxt.d.ts +47 -0
  14. package/dist/adapters/nuxt.d.ts.map +1 -0
  15. package/dist/adapters/nuxt.js +1 -0
  16. package/dist/adapters/react-router.d.ts +29 -0
  17. package/dist/adapters/react-router.d.ts.map +1 -0
  18. package/dist/adapters/react-router.js +1 -0
  19. package/dist/adapters/sveltekit.d.ts +37 -0
  20. package/dist/adapters/sveltekit.d.ts.map +1 -0
  21. package/dist/adapters/sveltekit.js +1 -0
  22. package/dist/ai/assistant/context.d.ts +64 -0
  23. package/dist/ai/assistant/context.d.ts.map +1 -0
  24. package/dist/ai/assistant/limits.d.ts +10 -0
  25. package/dist/ai/assistant/limits.d.ts.map +1 -0
  26. package/dist/ai/assistant/plans.d.ts +83 -0
  27. package/dist/ai/assistant/plans.d.ts.map +1 -0
  28. package/dist/ai/assistant/prompt.d.ts +22 -0
  29. package/dist/ai/assistant/prompt.d.ts.map +1 -0
  30. package/dist/ai/assistant/run.d.ts +59 -0
  31. package/dist/ai/assistant/run.d.ts.map +1 -0
  32. package/dist/ai/assistant/runtime.d.ts +35 -0
  33. package/dist/ai/assistant/runtime.d.ts.map +1 -0
  34. package/dist/ai/assistant/schema.d.ts +66 -0
  35. package/dist/ai/assistant/schema.d.ts.map +1 -0
  36. package/dist/ai/assistant/tools.d.ts +41 -0
  37. package/dist/ai/assistant/tools.d.ts.map +1 -0
  38. package/dist/ai/assistant/values.d.ts +33 -0
  39. package/dist/ai/assistant/values.d.ts.map +1 -0
  40. package/dist/ai/crypto.d.ts +12 -0
  41. package/dist/ai/crypto.d.ts.map +1 -0
  42. package/dist/ai/index.d.ts +19 -0
  43. package/dist/ai/index.d.ts.map +1 -0
  44. package/dist/ai/pi.d.ts +89 -0
  45. package/dist/ai/pi.d.ts.map +1 -0
  46. package/dist/ai/registry.d.ts +66 -0
  47. package/dist/ai/registry.d.ts.map +1 -0
  48. package/dist/ai/service.d.ts +31 -0
  49. package/dist/ai/service.d.ts.map +1 -0
  50. package/dist/ai/variant-translation.d.ts +6 -0
  51. package/dist/ai/variant-translation.d.ts.map +1 -0
  52. package/dist/ai.d.ts +12 -0
  53. package/dist/ai.d.ts.map +1 -0
  54. package/dist/ai.js +1 -0
  55. package/dist/auth/config.d.ts +65 -0
  56. package/dist/auth/config.d.ts.map +1 -0
  57. package/dist/auth/crypto.d.ts +44 -0
  58. package/dist/auth/crypto.d.ts.map +1 -0
  59. package/dist/auth/index.d.ts +15 -0
  60. package/dist/auth/index.d.ts.map +1 -0
  61. package/dist/auth/oauth.d.ts +93 -0
  62. package/dist/auth/oauth.d.ts.map +1 -0
  63. package/dist/auth/service.d.ts +38 -0
  64. package/dist/auth/service.d.ts.map +1 -0
  65. package/dist/auth/totp.d.ts +34 -0
  66. package/dist/auth/totp.d.ts.map +1 -0
  67. package/dist/auth.d.ts +9 -0
  68. package/dist/auth.d.ts.map +1 -0
  69. package/dist/auth.js +1 -0
  70. package/dist/cli.d.ts +3 -0
  71. package/dist/cli.d.ts.map +1 -0
  72. package/dist/cli.js +30 -0
  73. package/dist/client/index.d.ts +51 -0
  74. package/dist/client/index.d.ts.map +1 -0
  75. package/dist/client/types.d.ts +340 -0
  76. package/dist/client/types.d.ts.map +1 -0
  77. package/dist/client.d.ts +46 -0
  78. package/dist/client.d.ts.map +1 -0
  79. package/dist/client.js +1 -0
  80. package/dist/config.d.ts +31 -0
  81. package/dist/config.d.ts.map +1 -0
  82. package/dist/config.js +1 -0
  83. package/dist/content/export.d.ts +28 -0
  84. package/dist/content/export.d.ts.map +1 -0
  85. package/dist/content/import.d.ts +65 -0
  86. package/dist/content/import.d.ts.map +1 -0
  87. package/dist/content/records.d.ts +73 -0
  88. package/dist/content/records.d.ts.map +1 -0
  89. package/dist/content.d.ts +12 -0
  90. package/dist/content.d.ts.map +1 -0
  91. package/dist/content.js +1 -0
  92. package/dist/db/d1.d.ts +29 -0
  93. package/dist/db/d1.d.ts.map +1 -0
  94. package/dist/db/d1.js +1 -0
  95. package/dist/db/mongodb.d.ts +128 -0
  96. package/dist/db/mongodb.d.ts.map +1 -0
  97. package/dist/db/mongodb.js +2 -0
  98. package/dist/db/postgres.d.ts +37 -0
  99. package/dist/db/postgres.d.ts.map +1 -0
  100. package/dist/db/postgres.js +1 -0
  101. package/dist/db/sql/adapter.d.ts +57 -0
  102. package/dist/db/sql/adapter.d.ts.map +1 -0
  103. package/dist/db/sql/compile.d.ts +50 -0
  104. package/dist/db/sql/compile.d.ts.map +1 -0
  105. package/dist/db/sql/ddl.d.ts +34 -0
  106. package/dist/db/sql/ddl.d.ts.map +1 -0
  107. package/dist/db/sql/dialect.d.ts +35 -0
  108. package/dist/db/sql/dialect.d.ts.map +1 -0
  109. package/dist/db/sql/driver.d.ts +34 -0
  110. package/dist/db/sql/driver.d.ts.map +1 -0
  111. package/dist/db/sql/introspect.d.ts +15 -0
  112. package/dist/db/sql/introspect.d.ts.map +1 -0
  113. package/dist/db/sqlite.d.ts +39 -0
  114. package/dist/db/sqlite.d.ts.map +1 -0
  115. package/dist/db/sqlite.js +1 -0
  116. package/dist/defaults.d.ts +5 -0
  117. package/dist/defaults.d.ts.map +1 -0
  118. package/dist/duration.d.ts +12 -0
  119. package/dist/duration.d.ts.map +1 -0
  120. package/dist/editor/builtin.d.ts +45 -0
  121. package/dist/editor/builtin.d.ts.map +1 -0
  122. package/dist/editor/index.d.ts +14 -0
  123. package/dist/editor/index.d.ts.map +1 -0
  124. package/dist/editor/markdown.d.ts +19 -0
  125. package/dist/editor/markdown.d.ts.map +1 -0
  126. package/dist/editor/registry.d.ts +30 -0
  127. package/dist/editor/registry.d.ts.map +1 -0
  128. package/dist/editor/serialize.d.ts +41 -0
  129. package/dist/editor/serialize.d.ts.map +1 -0
  130. package/dist/editor.d.ts +10 -0
  131. package/dist/editor.d.ts.map +1 -0
  132. package/dist/editor.js +1 -0
  133. package/dist/engine/access.d.ts +33 -0
  134. package/dist/engine/access.d.ts.map +1 -0
  135. package/dist/engine/activity.d.ts +16 -0
  136. package/dist/engine/activity.d.ts.map +1 -0
  137. package/dist/engine/cursor.d.ts +19 -0
  138. package/dist/engine/cursor.d.ts.map +1 -0
  139. package/dist/engine/documents.d.ts +81 -0
  140. package/dist/engine/documents.d.ts.map +1 -0
  141. package/dist/engine/engine.d.ts +276 -0
  142. package/dist/engine/engine.d.ts.map +1 -0
  143. package/dist/engine/field-access.d.ts +21 -0
  144. package/dist/engine/field-access.d.ts.map +1 -0
  145. package/dist/engine/hooks.d.ts +58 -0
  146. package/dist/engine/hooks.d.ts.map +1 -0
  147. package/dist/engine/index.d.ts +20 -0
  148. package/dist/engine/index.d.ts.map +1 -0
  149. package/dist/engine/jobs.d.ts +63 -0
  150. package/dist/engine/jobs.d.ts.map +1 -0
  151. package/dist/engine/locales.d.ts +40 -0
  152. package/dist/engine/locales.d.ts.map +1 -0
  153. package/dist/engine/outbox.d.ts +81 -0
  154. package/dist/engine/outbox.d.ts.map +1 -0
  155. package/dist/engine/relations.d.ts +60 -0
  156. package/dist/engine/relations.d.ts.map +1 -0
  157. package/dist/engine/scoped-db.d.ts +13 -0
  158. package/dist/engine/scoped-db.d.ts.map +1 -0
  159. package/dist/engine/trash.d.ts +25 -0
  160. package/dist/engine/trash.d.ts.map +1 -0
  161. package/dist/errors.d.ts +42 -0
  162. package/dist/errors.d.ts.map +1 -0
  163. package/dist/fields/builtin.d.ts +142 -0
  164. package/dist/fields/builtin.d.ts.map +1 -0
  165. package/dist/fields/index.d.ts +3 -0
  166. package/dist/fields/index.d.ts.map +1 -0
  167. package/dist/fields/registry.d.ts +35 -0
  168. package/dist/fields/registry.d.ts.map +1 -0
  169. package/dist/fields.d.ts +8 -0
  170. package/dist/fields.d.ts.map +1 -0
  171. package/dist/fields.js +1 -0
  172. package/dist/http/guard.d.ts +45 -0
  173. package/dist/http/guard.d.ts.map +1 -0
  174. package/dist/http/handler.d.ts +31 -0
  175. package/dist/http/handler.d.ts.map +1 -0
  176. package/dist/http/index.d.ts +13 -0
  177. package/dist/http/index.d.ts.map +1 -0
  178. package/dist/http/openapi.d.ts +5 -0
  179. package/dist/http/openapi.d.ts.map +1 -0
  180. package/dist/http/params.d.ts +32 -0
  181. package/dist/http/params.d.ts.map +1 -0
  182. package/dist/http/request-db.d.ts +19 -0
  183. package/dist/http/request-db.d.ts.map +1 -0
  184. package/dist/http/respond.d.ts +48 -0
  185. package/dist/http/respond.d.ts.map +1 -0
  186. package/dist/http/rich-text.d.ts +30 -0
  187. package/dist/http/rich-text.d.ts.map +1 -0
  188. package/dist/http/router.d.ts +55 -0
  189. package/dist/http/router.d.ts.map +1 -0
  190. package/dist/http/routes/access.d.ts +13 -0
  191. package/dist/http/routes/access.d.ts.map +1 -0
  192. package/dist/http/routes/admin.d.ts +28 -0
  193. package/dist/http/routes/admin.d.ts.map +1 -0
  194. package/dist/http/routes/ai.d.ts +26 -0
  195. package/dist/http/routes/ai.d.ts.map +1 -0
  196. package/dist/http/routes/auth.d.ts +13 -0
  197. package/dist/http/routes/auth.d.ts.map +1 -0
  198. package/dist/http/routes/documents.d.ts +24 -0
  199. package/dist/http/routes/documents.d.ts.map +1 -0
  200. package/dist/http/routes/generate.d.ts +5 -0
  201. package/dist/http/routes/generate.d.ts.map +1 -0
  202. package/dist/http/routes/media.d.ts +28 -0
  203. package/dist/http/routes/media.d.ts.map +1 -0
  204. package/dist/http/routes/panel.d.ts +20 -0
  205. package/dist/http/routes/panel.d.ts.map +1 -0
  206. package/dist/http/routes/system.d.ts +25 -0
  207. package/dist/http/routes/system.d.ts.map +1 -0
  208. package/dist/http/routes/webhooks.d.ts +17 -0
  209. package/dist/http/routes/webhooks.d.ts.map +1 -0
  210. package/dist/http/spec.d.ts +28 -0
  211. package/dist/http/spec.d.ts.map +1 -0
  212. package/dist/http.d.ts +17 -0
  213. package/dist/http.d.ts.map +1 -0
  214. package/dist/http.js +1 -0
  215. package/dist/i18n/index.d.ts +12 -0
  216. package/dist/i18n/index.d.ts.map +1 -0
  217. package/dist/i18n/names.d.ts +25 -0
  218. package/dist/i18n/names.d.ts.map +1 -0
  219. package/dist/ids.d.ts +28 -0
  220. package/dist/ids.d.ts.map +1 -0
  221. package/dist/index-2757kej5.js +2 -0
  222. package/dist/index-2kb5nbxx.js +2 -0
  223. package/dist/index-2z1qe5mw.js +2 -0
  224. package/dist/index-34s342fz.js +2 -0
  225. package/dist/index-5ngtc7gy.js +2 -0
  226. package/dist/index-7a231xfp.js +2 -0
  227. package/dist/index-7k091gpe.js +2 -0
  228. package/dist/index-9g2n7xa6.js +2 -0
  229. package/dist/index-9x1z3b85.js +5 -0
  230. package/dist/index-9zqnf6gx.js +23 -0
  231. package/dist/index-b2ecggck.js +26 -0
  232. package/dist/index-cbwwtcm4.js +2 -0
  233. package/dist/index-ebtj6ebd.js +0 -0
  234. package/dist/index-g4crf47y.js +0 -0
  235. package/dist/index-gpwcmmvr.js +2 -0
  236. package/dist/index-hq05mc1n.js +3 -0
  237. package/dist/index-hy1x46nf.js +2 -0
  238. package/dist/index-k8wbg1dw.js +2 -0
  239. package/dist/index-kbsgt44t.js +2 -0
  240. package/dist/index-m82a0shw.js +2 -0
  241. package/dist/index-md79xr6h.js +5 -0
  242. package/dist/index-nvgwyykk.js +40 -0
  243. package/dist/index-ty698y02.js +2 -0
  244. package/dist/index-vq2978e7.js +14 -0
  245. package/dist/index-vxw0a03g.js +2 -0
  246. package/dist/index-wj8y1xcj.js +2 -0
  247. package/dist/index-x72d1hzh.js +2 -0
  248. package/dist/index-y5mwknr9.js +2 -0
  249. package/dist/index-ymq6jsar.js +2 -0
  250. package/dist/index.d.ts +25 -0
  251. package/dist/index.d.ts.map +1 -0
  252. package/dist/index.js +1 -0
  253. package/dist/jobs/runner.d.ts +77 -0
  254. package/dist/jobs/runner.d.ts.map +1 -0
  255. package/dist/jobs.d.ts +11 -0
  256. package/dist/jobs.d.ts.map +1 -0
  257. package/dist/jobs.js +1 -0
  258. package/dist/media/document.d.ts +28 -0
  259. package/dist/media/document.d.ts.map +1 -0
  260. package/dist/media/gc.d.ts +46 -0
  261. package/dist/media/gc.d.ts.map +1 -0
  262. package/dist/media/index.d.ts +20 -0
  263. package/dist/media/index.d.ts.map +1 -0
  264. package/dist/media/pipeline.d.ts +36 -0
  265. package/dist/media/pipeline.d.ts.map +1 -0
  266. package/dist/media/probe.d.ts +6 -0
  267. package/dist/media/probe.d.ts.map +1 -0
  268. package/dist/media/service.d.ts +26 -0
  269. package/dist/media/service.d.ts.map +1 -0
  270. package/dist/media/sharp.d.ts +28 -0
  271. package/dist/media/sharp.d.ts.map +1 -0
  272. package/dist/media/strip.d.ts +16 -0
  273. package/dist/media/strip.d.ts.map +1 -0
  274. package/dist/media/usages.d.ts +69 -0
  275. package/dist/media/usages.d.ts.map +1 -0
  276. package/dist/media/variants.d.ts +50 -0
  277. package/dist/media/variants.d.ts.map +1 -0
  278. package/dist/migrations.d.ts +115 -0
  279. package/dist/migrations.d.ts.map +1 -0
  280. package/dist/migrations.js +1 -0
  281. package/dist/panel.d.ts +31 -0
  282. package/dist/panel.d.ts.map +1 -0
  283. package/dist/query.d.ts +40 -0
  284. package/dist/query.d.ts.map +1 -0
  285. package/dist/query.js +1 -0
  286. package/dist/run-3r72dwhs.js +6 -0
  287. package/dist/schema/describe.d.ts +19 -0
  288. package/dist/schema/describe.d.ts.map +1 -0
  289. package/dist/schema/index.d.ts +5 -0
  290. package/dist/schema/index.d.ts.map +1 -0
  291. package/dist/schema/plan.d.ts +20 -0
  292. package/dist/schema/plan.d.ts.map +1 -0
  293. package/dist/schema/snapshot.d.ts +22 -0
  294. package/dist/schema/snapshot.d.ts.map +1 -0
  295. package/dist/schema/system.d.ts +22 -0
  296. package/dist/schema/system.d.ts.map +1 -0
  297. package/dist/schema.d.ts +7 -0
  298. package/dist/schema.d.ts.map +1 -0
  299. package/dist/schema.js +1 -0
  300. package/dist/storage/bytes.d.ts +17 -0
  301. package/dist/storage/bytes.d.ts.map +1 -0
  302. package/dist/storage/http.d.ts +43 -0
  303. package/dist/storage/http.d.ts.map +1 -0
  304. package/dist/storage/local.d.ts +31 -0
  305. package/dist/storage/local.d.ts.map +1 -0
  306. package/dist/storage/providers.d.ts +95 -0
  307. package/dist/storage/providers.d.ts.map +1 -0
  308. package/dist/storage/sign.d.ts +53 -0
  309. package/dist/storage/sign.d.ts.map +1 -0
  310. package/dist/strings.d.ts +13 -0
  311. package/dist/strings.d.ts.map +1 -0
  312. package/dist/telemetry.d.ts +137 -0
  313. package/dist/telemetry.d.ts.map +1 -0
  314. package/dist/telemetry.js +1 -0
  315. package/dist/types/activity.d.ts +68 -0
  316. package/dist/types/activity.d.ts.map +1 -0
  317. package/dist/types/actor.d.ts +26 -0
  318. package/dist/types/actor.d.ts.map +1 -0
  319. package/dist/types/ai.d.ts +357 -0
  320. package/dist/types/ai.d.ts.map +1 -0
  321. package/dist/types/api.d.ts +212 -0
  322. package/dist/types/api.d.ts.map +1 -0
  323. package/dist/types/auth.d.ts +310 -0
  324. package/dist/types/auth.d.ts.map +1 -0
  325. package/dist/types/config.d.ts +632 -0
  326. package/dist/types/config.d.ts.map +1 -0
  327. package/dist/types/database.d.ts +75 -0
  328. package/dist/types/database.d.ts.map +1 -0
  329. package/dist/types/editor.d.ts +140 -0
  330. package/dist/types/editor.d.ts.map +1 -0
  331. package/dist/types/events.d.ts +72 -0
  332. package/dist/types/events.d.ts.map +1 -0
  333. package/dist/types/fields.d.ts +142 -0
  334. package/dist/types/fields.d.ts.map +1 -0
  335. package/dist/types/hooks.d.ts +142 -0
  336. package/dist/types/hooks.d.ts.map +1 -0
  337. package/dist/types/index.d.ts +25 -0
  338. package/dist/types/index.d.ts.map +1 -0
  339. package/dist/types/instance.d.ts +263 -0
  340. package/dist/types/instance.d.ts.map +1 -0
  341. package/dist/types/jobs.d.ts +78 -0
  342. package/dist/types/jobs.d.ts.map +1 -0
  343. package/dist/types/json.d.ts +24 -0
  344. package/dist/types/json.d.ts.map +1 -0
  345. package/dist/types/locales.d.ts +30 -0
  346. package/dist/types/locales.d.ts.map +1 -0
  347. package/dist/types/media.d.ts +245 -0
  348. package/dist/types/media.d.ts.map +1 -0
  349. package/dist/types/panel.d.ts +249 -0
  350. package/dist/types/panel.d.ts.map +1 -0
  351. package/dist/types/plugin.d.ts +172 -0
  352. package/dist/types/plugin.d.ts.map +1 -0
  353. package/dist/types/query.d.ts +101 -0
  354. package/dist/types/query.d.ts.map +1 -0
  355. package/dist/types/schema.d.ts +203 -0
  356. package/dist/types/schema.d.ts.map +1 -0
  357. package/dist/types/storage.d.ts +61 -0
  358. package/dist/types/storage.d.ts.map +1 -0
  359. package/dist/types/telemetry.d.ts +14 -0
  360. package/dist/types/telemetry.d.ts.map +1 -0
  361. package/dist/types/trash.d.ts +42 -0
  362. package/dist/types/trash.d.ts.map +1 -0
  363. package/dist/types/webhooks.d.ts +133 -0
  364. package/dist/types/webhooks.d.ts.map +1 -0
  365. package/dist/types.d.ts +8 -0
  366. package/dist/types.d.ts.map +1 -0
  367. package/dist/types.js +1 -0
  368. package/dist/uploads.d.ts +21 -0
  369. package/dist/uploads.d.ts.map +1 -0
  370. package/dist/uploads.js +9 -0
  371. package/dist/webhooks/index.d.ts +10 -0
  372. package/dist/webhooks/index.d.ts.map +1 -0
  373. package/dist/webhooks/job.d.ts +17 -0
  374. package/dist/webhooks/job.d.ts.map +1 -0
  375. package/dist/webhooks/service.d.ts +53 -0
  376. package/dist/webhooks/service.d.ts.map +1 -0
  377. package/dist/webhooks/sign.d.ts +26 -0
  378. package/dist/webhooks/sign.d.ts.map +1 -0
  379. package/dist/webhooks.d.ts +10 -0
  380. package/dist/webhooks.d.ts.map +1 -0
  381. package/dist/webhooks.js +1 -0
  382. package/package.json +183 -4
@@ -0,0 +1,81 @@
1
+ import type { Actor } from "../types/actor";
2
+ import type { ResolvedCollection } from "../types/config";
3
+ import type { ColumnValue, Row } from "../types/query";
4
+ import type { JsonObject, JsonValue } from "../types/json";
5
+ import { type LocaleContext } from "./locales";
6
+ /**
7
+ * The columns the engine owns on every document.
8
+ *
9
+ * They are accepted in an input object and ignored rather than rejected, so
10
+ * `update({ id, data: doc })` — reading a document, editing one field and
11
+ * writing the whole thing back — works without the caller having to strip
12
+ * them first.
13
+ */
14
+ export declare const systemDocumentFields: readonly ["id", "revision", "createdAt", "updatedAt", "updatedBy", "deletedAt", "purgeAfter", "scheduledAt", "scheduledPatch", "_fallback", "_localeFields"];
15
+ /**
16
+ * Turns a stored row into the document a caller sees.
17
+ *
18
+ * One locale is resolved here, once, so nothing downstream — hook, event,
19
+ * REST response, template — ever has to know which fields are translated
20
+ * (section 9).
21
+ */
22
+ export declare function rowToDocument(row: Row, collection: ResolvedCollection, locale: LocaleContext): JsonObject;
23
+ export interface StoredData {
24
+ /** The full document body as it will be written to the `data` column. */
25
+ data: JsonObject;
26
+ /** Field names the caller actually wrote, in declaration order. */
27
+ touched: string[];
28
+ }
29
+ /**
30
+ * Folds a caller's input into the stored body.
31
+ *
32
+ * The caller speaks one locale and the storage speaks all of them, so this is
33
+ * where a flat `{ title: "Hello" }` becomes `{ title: { en: "Hello" } }`
34
+ * without disturbing the other translations.
35
+ */
36
+ export declare function toStoredData(collection: ResolvedCollection, input: JsonObject, locale: LocaleContext, previous?: JsonObject): StoredData;
37
+ /**
38
+ * Validates the fields a write touched, with the field's own zod schema.
39
+ *
40
+ * Only the touched ones: a localized field is required per locale, and
41
+ * demanding every translation before a German draft can be saved would make
42
+ * partial translations impossible — which section 9 says are the norm. A
43
+ * create touches everything, so `required` is still enforced where it matters.
44
+ */
45
+ export declare function validateFields(collection: ResolvedCollection, data: JsonObject, locale: LocaleContext, fields: string[]): void;
46
+ /** Field names whose resolved value differs between two documents. */
47
+ export declare function changedFields(collection: ResolvedCollection, previous: JsonObject, next: JsonObject): string[];
48
+ /**
49
+ * A system table row as JSON.
50
+ *
51
+ * System tables use real columns and therefore snake_case, which is a storage
52
+ * detail. A `depth` expansion that handed a template `storage_key` would be
53
+ * leaking it (a `media` relation is resolved through this).
54
+ */
55
+ export declare function systemRowToJson(row: Row): JsonObject;
56
+ /**
57
+ * A scheduled change as it is stored.
58
+ *
59
+ * The locale travels with the patch because a patch is written in one
60
+ * language: applying `{ title: "Hallo" }` next Friday has to write the German
61
+ * title, not the default one (section 9). The actor travels with it because
62
+ * the change is applied as an ordinary update and therefore has to pass the
63
+ * same access control a human write would.
64
+ */
65
+ export interface ScheduledPatch {
66
+ data: JsonObject;
67
+ locale: string;
68
+ actor: Actor | null;
69
+ }
70
+ export declare function scheduledPatch(row: Row): ScheduledPatch | null;
71
+ /**
72
+ * The stored revision, defaulting to 1.
73
+ *
74
+ * A row written before the column existed reads as revision 1 rather than as
75
+ * `null`: the number means "how many times this has changed", and a document
76
+ * that has never changed since the column arrived has changed once.
77
+ */
78
+ export declare function toRevision(value: ColumnValue | undefined): number;
79
+ export declare function toIso(value: ColumnValue | undefined): string | null;
80
+ export declare function asObject(value: ColumnValue | JsonValue | undefined): JsonObject;
81
+ //# sourceMappingURL=documents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../src/engine/documents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,WAAW,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,YAC/B,IAAI,EACJ,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,CACP,CAAC;AAIX;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,aAAa,GACpB,UAAU,CA2DZ;AAED,MAAM,WAAW,UAAU;IACzB,yEAAyE;IACzE,IAAI,EAAE,UAAU,CAAC;IACjB,mEAAmE;IACnE,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,kBAAkB,EAC9B,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,UAAU,GACpB,UAAU,CA+BZ;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,kBAAkB,EAC9B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EAAE,GACf,IAAI,CA6BN;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAC3B,UAAU,EAAE,kBAAkB,EAC9B,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,UAAU,GACf,MAAM,EAAE,CAIV;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU,CAWpD;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,cAAc,GAAG,IAAI,CAQ9D;AAsBD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,CAGjE;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAInE;AAED,wBAAgB,QAAQ,CACtB,KAAK,EAAE,WAAW,GAAG,SAAS,GAAG,SAAS,GACzC,UAAU,CAKZ"}
@@ -0,0 +1,276 @@
1
+ import type { CollectionApi, GlobalApi } from "../types/api";
2
+ import type { ResolvedCmsConfig, ResolvedCollection } from "../types/config";
3
+ import type { DatabaseAdapter } from "../types/database";
4
+ import type { CmsInstance } from "../types/instance";
5
+ import type { JsonObject } from "../types/json";
6
+ import type { Tx } from "../types/query";
7
+ import type { CmsTrash } from "../types/trash";
8
+ import { JobRunner } from "./jobs";
9
+ import { type BufferedEvent, type EventDispatch, type OutboxEntryMeta } from "./outbox";
10
+ export interface EngineOptions {
11
+ config: ResolvedCmsConfig;
12
+ /** Resolved lazily: a D1 binding only exists inside a request. */
13
+ database: () => Promise<DatabaseAdapter>;
14
+ dispatch: EventDispatch;
15
+ }
16
+ /**
17
+ * What one write means.
18
+ *
19
+ * `operation` in the hook contract is CRUD and stays CRUD (section 5); this
20
+ * is the finer question the engine has to answer anyway — which event to
21
+ * emit, what the activity log should say, whether the `delete` hooks have
22
+ * already run. Keeping the two apart is what lets the trash exist without
23
+ * adding a fourth hook family nobody asked for.
24
+ */
25
+ export type WriteIntent = "create" | "update" | "trash" | "restore" | "purge" | "schedule" | "unschedule";
26
+ /**
27
+ * The engine: one read path, one write path.
28
+ *
29
+ * Every document write in the product — local API, REST, the panel, a job,
30
+ * the scheduler — goes through `runWrite`. That is a deliberate constraint
31
+ * rather than tidiness: hooks, the outbox, the activity log and the future
32
+ * versions plugin all attach at one point, and a second write path would be a
33
+ * second place for each of them to be forgotten (stage 3).
34
+ */
35
+ export declare class CmsEngine {
36
+ private readonly options;
37
+ private cms;
38
+ private readonly pipelines;
39
+ /** Collections and globals by name, for relation targets. */
40
+ private readonly byName;
41
+ /** The same by storage slug: a stored row knows its slug, not its name. */
42
+ private readonly bySlug;
43
+ /**
44
+ * Which collections can point at a file at all.
45
+ *
46
+ * Answered once per collection, because the alternative is three extra
47
+ * queries on every write to a collection that has no images — which is most
48
+ * of them.
49
+ */
50
+ private readonly media;
51
+ private outbox;
52
+ private delivery;
53
+ constructor(options: EngineOptions);
54
+ /**
55
+ * Hands the engine the instance hooks receive as `ctx.cms`.
56
+ *
57
+ * Separate from the constructor because the two refer to each other: the
58
+ * instance exposes `api`, and `api` has to be able to call back into the
59
+ * instance with access control enforced.
60
+ */
61
+ bind(cms: CmsInstance): void;
62
+ /** `cms.api`, built once: one entry per declared collection. */
63
+ buildApi(): Record<string, CollectionApi<JsonObject>>;
64
+ /** `cms.globals`: the same machinery, one row, no `find` and no `create`. */
65
+ buildGlobals(): Record<string, GlobalApi<JsonObject>>;
66
+ /** `cms.trash`: deleted documents across every collection at once. */
67
+ buildTrash(): CmsTrash;
68
+ /** `cms.jobs`: the sweeps. Returned concrete so media can register its own. */
69
+ buildJobs(): JobRunner;
70
+ /**
71
+ * Delivers everything the outbox owes.
72
+ *
73
+ * A commit already schedules a delivery in the background; this is how a
74
+ * caller waits for it — a test, a CLI, or a serverless runtime that is
75
+ * about to freeze the process. Returns what this call delivered, which may
76
+ * be zero because the background pass got there first.
77
+ */
78
+ drainEvents(limit?: number): Promise<number>;
79
+ /** Waits for in-flight deliveries. Called by `cms.close()`. */
80
+ settle(): Promise<void>;
81
+ /**
82
+ * Writes events for an operation that is not a document write.
83
+ *
84
+ * Auth is the first caller: an invitation or a role change has to reach a
85
+ * webhook the same way a document change does — inside the transaction that
86
+ * caused it, delivered after the commit — and giving it a second mechanism
87
+ * would give it a second set of failure modes (section 5).
88
+ */
89
+ appendEvents(tx: Tx, events: BufferedEvent[], meta: OutboxEntryMeta): Promise<void>;
90
+ /** Delivers what the last committed transaction queued, in the background. */
91
+ deliverSoon(): void;
92
+ private collectionApi;
93
+ private find;
94
+ private findOne;
95
+ private findById;
96
+ private count;
97
+ private create;
98
+ private update;
99
+ /**
100
+ * The delete an editor performs.
101
+ *
102
+ * With the trash on it is a soft delete and the row keeps serving every
103
+ * query that asks for `includeTrashed`; with it off, or with
104
+ * `permanent: true`, the row goes. Either way the `delete` hooks run here
105
+ * and only here: the document is leaving the live set, which is the moment
106
+ * a hook was written for. A later purge does not run them again, because a
107
+ * hook that decrements a counter must not decrement it twice for one
108
+ * document.
109
+ */
110
+ private remove;
111
+ private restore;
112
+ /**
113
+ * The permanent delete.
114
+ *
115
+ * Also the only operation that cleans up what pointed at the document:
116
+ * media usages survive the trash on purpose — an image used by a document
117
+ * an editor may still restore is not unused — so this is where they stop
118
+ * (section 6).
119
+ */
120
+ private purge;
121
+ /**
122
+ * Records a change to apply later.
123
+ *
124
+ * The patch is checked now — access, field-level write access, validation —
125
+ * and applied later as an ordinary update, so the question "may this person
126
+ * schedule a publication" is answered by the same rules that answer "may
127
+ * this person publish". The alternative, checking only at apply time, would
128
+ * accept a schedule in the panel and fail silently on a Friday night.
129
+ */
130
+ private schedule;
131
+ private unschedule;
132
+ private globalApi;
133
+ /**
134
+ * A global that nobody has saved yet reads as its defaults.
135
+ *
136
+ * No row is written: a read that writes cannot run on a replica, cannot run
137
+ * in a Worker that only has a read binding, and turns an anonymous page view
138
+ * into a database mutation.
139
+ */
140
+ private globalGet;
141
+ /**
142
+ * Makes sure the singleton has a row, and reports its id.
143
+ *
144
+ * The id is derived from the slug rather than generated, which is what makes
145
+ * this safe to call concurrently: two first saves race to insert the same
146
+ * primary key, one of them loses, and losing means the row it wanted is
147
+ * already there.
148
+ */
149
+ private ensureGlobalRow;
150
+ /**
151
+ * The defaults row: what a global is before anybody saves it.
152
+ *
153
+ * `created` is `null` for the copy `get()` invents and a date for the copy
154
+ * that is actually inserted. A global nobody has saved has no creation time,
155
+ * and inventing one would make "has this ever been configured" unanswerable.
156
+ */
157
+ private emptyGlobalRow;
158
+ /**
159
+ * Applies one due scheduled change, as an ordinary update.
160
+ *
161
+ * Claim first, then write. The claim is a conditional update — the same
162
+ * portable trick the outbox uses — so two overlapping cron invocations
163
+ * cannot both apply the same patch, on any of the three engines and without
164
+ * a lock.
165
+ */
166
+ private applyScheduled;
167
+ /** Purges one expired trash entry, as the system rather than as a person. */
168
+ private purgeExpired;
169
+ private clearSchedule;
170
+ /**
171
+ * Records a failed job item and tells the world about it.
172
+ *
173
+ * In the `jobs` table rather than only in a log: `job.failed` is in the
174
+ * event catalogue (section 7) because an operator has to be able to be
175
+ * paged for it, and a payload that only exists in stdout cannot be retried.
176
+ */
177
+ private recordFailure;
178
+ /**
179
+ * The one place a document is written.
180
+ *
181
+ * Transaction, hooks, events, activity — in that order, every time. The
182
+ * operation-specific part is the `step` callback and nothing else, which is
183
+ * what makes the later versions plugin a single attachment point rather
184
+ * than three (stage 3, section 4).
185
+ */
186
+ private runWrite;
187
+ /**
188
+ * The answer a repeated write already has.
189
+ *
190
+ * Only consulted when the caller supplied a key, so an ordinary save pays
191
+ * nothing for it. The stored document is returned verbatim: re-reading the
192
+ * row would describe the world now rather than what this call did, and a
193
+ * retry that reports somebody else's later edit as its own result is worse
194
+ * than no idempotency at all.
195
+ */
196
+ private replay;
197
+ private recordIdempotency;
198
+ private runAfter;
199
+ /**
200
+ * The events the engine itself owes, in the order a consumer expects them.
201
+ *
202
+ * `document.field.changed` is one event per field that actually changed,
203
+ * which is what makes "tell me when `status` becomes `published`" a
204
+ * subscription rather than a diff the consumer has to compute (section 7).
205
+ */
206
+ private emitDocumentEvents;
207
+ /**
208
+ * Keeps `media_usages` in step with what the document now contains.
209
+ *
210
+ * This is the whole of the media lifecycle's accounting. Nothing counts
211
+ * references at read time or at delete time; the count is maintained here,
212
+ * once, and `media-gc` only ever acts on what it says.
213
+ */
214
+ private syncMedia;
215
+ private referencesMedia;
216
+ /**
217
+ * The activity log, written by the engine inside the transaction.
218
+ *
219
+ * Built in rather than a plugin (section 11): an audit trail that can be
220
+ * switched off, or that commits separately from the change it describes, is
221
+ * not an audit trail.
222
+ */
223
+ private writeActivity;
224
+ /** Collection, trash and access filters, combined the only legal way. */
225
+ private scope;
226
+ private load;
227
+ /**
228
+ * Writes system columns on one row and reports the row as it now stands.
229
+ *
230
+ * Also the one place `revision` moves. Every write that reaches here changed
231
+ * the row, so every write bumps it — there is no "minor" update that a
232
+ * concurrent editor would not want to know about, and a token that only
233
+ * sometimes advances is a token nobody can rely on.
234
+ *
235
+ * `expected` turns the write into a compare-and-set. The comparison is in
236
+ * the `WHERE` clause rather than in a read before it: two requests that both
237
+ * read revision 17 must not both find it acceptable, and only the database
238
+ * can decide which of them wins.
239
+ */
240
+ private patch;
241
+ private assertAllowed;
242
+ private requireCollection;
243
+ /** When a document deleted now should be purged, or `null` if never. */
244
+ private purgeAt;
245
+ private expand;
246
+ /**
247
+ * Drops the fields this actor may not read.
248
+ *
249
+ * Skipped entirely when the collection declares no field rules, which is
250
+ * the overwhelmingly common case and the difference between a check and a
251
+ * cost.
252
+ */
253
+ private redact;
254
+ private pipeline;
255
+ private outboxMeta;
256
+ private outboxWorker;
257
+ /**
258
+ * Delivery after the commit, never during it.
259
+ *
260
+ * Chained rather than fired in parallel so events keep their order, and
261
+ * swallowed because a failed delivery is the outbox's problem — it is
262
+ * recorded, retried, and must not turn a successful write into a thrown
263
+ * error (section 5).
264
+ */
265
+ private scheduleDelivery;
266
+ private instance;
267
+ }
268
+ /**
269
+ * A singleton's row id, derived from its slug.
270
+ *
271
+ * Deterministic because it has to be: the row is created on first save, and a
272
+ * generated id would let two concurrent saves produce two rows for a document
273
+ * the configuration says there is exactly one of.
274
+ */
275
+ export declare function globalRowId(global: ResolvedCollection): string;
276
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/engine/engine.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,21 @@
1
+ import type { Actor } from "../types/actor";
2
+ import type { ResolvedCollection } from "../types/config";
3
+ import type { JsonObject } from "../types/json";
4
+ export declare function hasFieldAccessRules(collection: ResolvedCollection): boolean;
5
+ /**
6
+ * Removes the fields this actor may not read, in place.
7
+ *
8
+ * In place because the caller owns the document: it was just built from a
9
+ * row, and copying every document of every page to delete a key from one of
10
+ * them would be the wrong trade.
11
+ */
12
+ export declare function applyFieldReadAccess(document: JsonObject, collection: ResolvedCollection, actor: Actor | null, locale: string | null): JsonObject;
13
+ /**
14
+ * Refuses a write that touches a field the actor may not write.
15
+ *
16
+ * Refuses rather than drops: silently ignoring half a form is how an editor
17
+ * ends up believing they published something. The error names the fields, so
18
+ * a panel can mark them.
19
+ */
20
+ export declare function assertFieldWriteAccess(collection: ResolvedCollection, input: JsonObject, actor: Actor | null, locale: string | null, record?: JsonObject): void;
21
+ //# sourceMappingURL=field-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-access.d.ts","sourceRoot":"","sources":["../../src/engine/field-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAiDhD,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAG3E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,EACpB,UAAU,EAAE,kBAAkB,EAC9B,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,UAAU,CAuBZ;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,kBAAkB,EAC9B,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,MAAM,CAAC,EAAE,UAAU,GAClB,IAAI,CAmBN"}
@@ -0,0 +1,58 @@
1
+ import type { ResolvedCmsConfig } from "../types/config";
2
+ import type { CreateHookInput, HookContext, HookResult, MaybePromise, UpdateHookInput, UpdateHookOutput } from "../types/hooks";
3
+ import type { HookPipelineEntry } from "../types/instance";
4
+ import type { JsonObject } from "../types/json";
5
+ /** Where a hook came from and when it runs, carried so `inspect()` can say. */
6
+ interface Registered {
7
+ source: string;
8
+ priority: number;
9
+ }
10
+ export interface BeforeEntry<TInput> extends Registered {
11
+ run: (input: TInput, context: HookContext) => MaybePromise<HookResult<JsonObject>>;
12
+ }
13
+ export interface AfterEntry<TOutput> extends Registered {
14
+ run: (output: TOutput, context: HookContext) => MaybePromise<void>;
15
+ }
16
+ /**
17
+ * Every hook that can run on one collection, already in execution order.
18
+ *
19
+ * Built once per collection at start-up rather than looked up per write: the
20
+ * order is a property of the configuration, so computing it on every request
21
+ * would be work that cannot change its own answer.
22
+ */
23
+ export interface CollectionHookPipeline {
24
+ createBefore: BeforeEntry<CreateHookInput<JsonObject>>[];
25
+ createAfter: AfterEntry<JsonObject>[];
26
+ updateBefore: BeforeEntry<UpdateHookInput<JsonObject>>[];
27
+ updateAfter: AfterEntry<UpdateHookOutput<JsonObject>>[];
28
+ deleteBefore: BeforeEntry<JsonObject>[];
29
+ deleteAfter: AfterEntry<JsonObject>[];
30
+ }
31
+ /**
32
+ * Assembles the pipeline for one collection.
33
+ *
34
+ * Plugin hooks run first in `priority` order, the configuration's own hooks
35
+ * always run last. A user who installed a plugin can therefore always have
36
+ * the final word over it, without the plugin having to anticipate that
37
+ * (section 5).
38
+ */
39
+ export declare function buildHookPipeline(config: ResolvedCmsConfig, collection: string): CollectionHookPipeline;
40
+ /**
41
+ * Runs the `before` chain and reports what the operation should do next.
42
+ *
43
+ * One return contract for every hook, which is the part Payload gets wrong:
44
+ * `undefined` continue, `{ data }` continue with a replacement, `false` stop
45
+ * silently, `throw` stop with a status. `apply` is how a replacement folds
46
+ * back into an operation-shaped input.
47
+ */
48
+ export declare function runBeforeHooks<TInput>(entries: BeforeEntry<TInput>[], input: TInput, context: HookContext, apply: (input: TInput, data: JsonObject) => TInput): Promise<TInput | false>;
49
+ export declare function runAfterHooks<TOutput>(entries: AfterEntry<TOutput>[], output: TOutput, context: HookContext): Promise<void>;
50
+ /**
51
+ * The pipeline as `cms.inspect()` prints it.
52
+ *
53
+ * Derived from the same builder the engine runs, so the printed order cannot
54
+ * drift from the executed one — which is the entire value of printing it.
55
+ */
56
+ export declare function hookPipelineEntries(config: ResolvedCmsConfig): HookPipelineEntry[];
57
+ export {};
58
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/engine/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAEV,eAAe,EACf,WAAW,EAEX,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,+EAA+E;AAC/E,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW,CAAC,MAAM,CAAE,SAAQ,UAAU;IACrD,GAAG,EAAE,CACH,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,KACjB,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,UAAU,CAAC,OAAO,CAAE,SAAQ,UAAU;IACrD,GAAG,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACpE;AAED;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;IACzD,WAAW,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;IACtC,YAAY,EAAE,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;IACzD,WAAW,EAAE,UAAU,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;IACxD,YAAY,EAAE,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;IACxC,WAAW,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;CACvC;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CA0ExB;AAyCD;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,MAAM,EACzC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,EAC9B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,MAAM,GACjD,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAUzB;AAED,wBAAsB,aAAa,CAAC,OAAO,EACzC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,EAC9B,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GACxB,iBAAiB,EAAE,CAkCrB"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The engine: the local API, the hook pipeline and the transactional outbox.
3
+ *
4
+ * Nothing here is HTTP-aware. The router in stage 7 calls exactly the same
5
+ * functions the local API does, which is the only way `cms.api.posts.find()`
6
+ * and `GET /api/heyo-cms/posts` can be guaranteed to behave identically
7
+ * (section 10).
8
+ */
9
+ export { CmsEngine, globalRowId, type EngineOptions, type WriteIntent, } from "./engine";
10
+ export { JobRunner, type JobDefinition, type JobHost } from "./jobs";
11
+ export { listTrashed, type ListTrashedOptions } from "./trash";
12
+ export { EventBuffer, Outbox, type EventDispatch } from "./outbox";
13
+ export { buildHookPipeline, hookPipelineEntries, runAfterHooks, runBeforeHooks, type CollectionHookPipeline, } from "./hooks";
14
+ export { localeContext, resolveLocalized, type LocaleContext } from "./locales";
15
+ export { rowToDocument, scheduledPatch, toStoredData, validateFields, type ScheduledPatch, } from "./documents";
16
+ export { applyFieldReadAccess, assertFieldWriteAccess, hasFieldAccessRules, } from "./field-access";
17
+ export { RelationLoader, relationTarget } from "./relations";
18
+ export { scopedDb } from "./scoped-db";
19
+ export { cursorWhere, encodeCursor } from "./cursor";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,SAAS,EACT,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,KAAK,sBAAsB,GAC5B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,EACd,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { ResolvedCmsConfig } from "../types/config";
2
+ import type { DatabaseAdapter } from "../types/database";
3
+ import type { CmsJobs, JobFailure, JobFailureArgs, JobRunArgs, JobRunReport } from "../types/jobs";
4
+ import type { JsonObject } from "../types/json";
5
+ import type { Row } from "../types/query";
6
+ /**
7
+ * What a sweep needs from the engine.
8
+ *
9
+ * Narrow on purpose: a job may ask which rows are due and may ask the engine
10
+ * to act on one of them, and it may not write a document itself. Every write
11
+ * in the product goes through one function (stage 3), and a background worker
12
+ * is exactly the kind of caller that would quietly grow a second one.
13
+ */
14
+ export interface JobHost {
15
+ config: ResolvedCmsConfig;
16
+ database(): Promise<DatabaseAdapter>;
17
+ applyScheduled(row: Row): Promise<void>;
18
+ purgeExpired(row: Row): Promise<void>;
19
+ recordFailure(type: string, payload: JsonObject, error: unknown): Promise<void>;
20
+ }
21
+ /**
22
+ * One sweep.
23
+ *
24
+ * Split into "what is due" and "act on one of them" so the runner owns the
25
+ * batching, the counting and the failure record, and a job only has to know
26
+ * its own question. Exported because `media-gc` is registered through it, and
27
+ * a plugin will eventually register its own the same way.
28
+ */
29
+ export interface JobDefinition {
30
+ name: string;
31
+ /** Rows this job would act on, oldest obligation first. */
32
+ due(host: JobHost, now: Date, limit: number): Promise<Row[]>;
33
+ run(host: JobHost, row: Row, now: Date): Promise<void>;
34
+ /** What a failure is recorded as in the `jobs` table. */
35
+ failureType: string;
36
+ failurePayload(row: Row): JsonObject;
37
+ }
38
+ /**
39
+ * `cms.jobs`.
40
+ *
41
+ * A registry rather than hard-coded calls: `media-gc` joins the two below only
42
+ * when the configuration has an `uploads` section, a plugin will eventually
43
+ * add its own, and `cms.inspect().jobs` has to print what will actually run
44
+ * rather than what the package happens to contain.
45
+ */
46
+ export declare class JobRunner implements CmsJobs {
47
+ private readonly host;
48
+ private readonly jobs;
49
+ constructor(host: JobHost);
50
+ list(): string[];
51
+ /** Adds a sweep. Used by the media lifecycle, and later by plugins. */
52
+ register(job: JobDefinition): void;
53
+ /**
54
+ * One pass over everything that is due.
55
+ *
56
+ * A failing item never stops the sweep: one document whose scheduled change
57
+ * no longer validates must not keep every other publication waiting. Each
58
+ * failure is recorded with its payload and emitted as `job.failed`.
59
+ */
60
+ run(args?: JobRunArgs): Promise<JobRunReport>;
61
+ failures(args?: JobFailureArgs): Promise<JobFailure[]>;
62
+ }
63
+ //# sourceMappingURL=jobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../../src/engine/jobs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,cAAc,EAEd,UAAU,EACV,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAM1C;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IACrC,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,aAAa,CACX,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC7D,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU,CAAC;CACtC;AAgFD;;;;;;;GAOG;AACH,qBAAa,SAAU,YAAW,OAAO;IAG3B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAmD;IAExE,YAA6B,IAAI,EAAE,OAAO,EAAI;IAE9C,IAAI,IAAI,MAAM,EAAE,CAEf;IAED,uEAAuE;IACvE,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAEjC;IAED;;;;;;OAMG;IACG,GAAG,CAAC,IAAI,GAAE,UAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CA2CtD;IAEK,QAAQ,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAsB/D;CACF"}
@@ -0,0 +1,40 @@
1
+ import type { LocaleArgs } from "../types/api";
2
+ import type { ResolvedCmsConfig } from "../types/config";
3
+ import type { JsonObject, JsonValue } from "../types/json";
4
+ /**
5
+ * Everything a read needs to know about language, resolved once per call.
6
+ *
7
+ * Fallback is decided here and nowhere else: a field that resolves one way in
8
+ * the REST layer and another way in a hook would make `_fallback` a claim
9
+ * nobody could rely on.
10
+ */
11
+ export interface LocaleContext {
12
+ /** The locale the caller asked for. */
13
+ locale: string;
14
+ /** The order values are looked up in, starting with `locale` itself. */
15
+ chain: string[];
16
+ }
17
+ /**
18
+ * One rule, not a configuration section: a field with no value in the
19
+ * requested language is answered from `i18n.defaultLocale`, and the response
20
+ * says which fields those were. A caller that wants the gaps instead of the
21
+ * substitution passes `fallbackLocale: false` for that one call — which is
22
+ * exactly what the panel does while somebody is filling translations in.
23
+ */
24
+ export declare function localeContext(config: ResolvedCmsConfig, args?: LocaleArgs): LocaleContext;
25
+ export interface ResolvedValue {
26
+ value: JsonValue;
27
+ /** The locale the value actually came from, `null` when nothing matched. */
28
+ from: string | null;
29
+ }
30
+ /**
31
+ * Picks one locale's value out of a stored `{ [locale]: value }` map.
32
+ *
33
+ * Fallback is per field, not per document: partial translations are the norm,
34
+ * so a document with a translated title and an untranslated body has to be
35
+ * expressible (section 9).
36
+ */
37
+ export declare function resolveLocalized(stored: JsonValue | undefined, locale: LocaleContext): ResolvedValue;
38
+ /** Writes one locale into a stored map, leaving the other languages alone. */
39
+ export declare function writeLocalized(stored: JsonValue | undefined, locale: string, value: JsonValue): JsonObject;
40
+ //# sourceMappingURL=locales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../src/engine/locales.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,iBAAiB,EACzB,IAAI,GAAE,UAAe,GACpB,aAAa,CAGf;AAmBD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,SAAS,CAAC;IACjB,4EAA4E;IAC5E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,GAAG,SAAS,EAC7B,MAAM,EAAE,aAAa,GACpB,aAAa,CAOf;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,GACf,UAAU,CAIZ"}