@proseql/core 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 (342) hide show
  1. package/LICENSE +21 -0
  2. package/dist/errors/crud-errors.d.ts +98 -0
  3. package/dist/errors/crud-errors.d.ts.map +1 -0
  4. package/dist/errors/crud-errors.js +23 -0
  5. package/dist/errors/crud-errors.js.map +1 -0
  6. package/dist/errors/index.d.ts +16 -0
  7. package/dist/errors/index.d.ts.map +1 -0
  8. package/dist/errors/index.js +12 -0
  9. package/dist/errors/index.js.map +1 -0
  10. package/dist/errors/migration-errors.d.ts +22 -0
  11. package/dist/errors/migration-errors.d.ts.map +1 -0
  12. package/dist/errors/migration-errors.js +14 -0
  13. package/dist/errors/migration-errors.js.map +1 -0
  14. package/dist/errors/plugin-errors.d.ts +15 -0
  15. package/dist/errors/plugin-errors.d.ts.map +1 -0
  16. package/dist/errors/plugin-errors.js +11 -0
  17. package/dist/errors/plugin-errors.js.map +1 -0
  18. package/dist/errors/query-errors.d.ts +31 -0
  19. package/dist/errors/query-errors.d.ts.map +1 -0
  20. package/dist/errors/query-errors.js +11 -0
  21. package/dist/errors/query-errors.js.map +1 -0
  22. package/dist/errors/storage-errors.d.ts +30 -0
  23. package/dist/errors/storage-errors.d.ts.map +1 -0
  24. package/dist/errors/storage-errors.js +11 -0
  25. package/dist/errors/storage-errors.js.map +1 -0
  26. package/dist/factories/crud-factory-with-relationships.d.ts +28 -0
  27. package/dist/factories/crud-factory-with-relationships.d.ts.map +1 -0
  28. package/dist/factories/crud-factory-with-relationships.js +8 -0
  29. package/dist/factories/crud-factory-with-relationships.js.map +1 -0
  30. package/dist/factories/crud-factory.d.ts +25 -0
  31. package/dist/factories/crud-factory.d.ts.map +1 -0
  32. package/dist/factories/crud-factory.js +8 -0
  33. package/dist/factories/crud-factory.js.map +1 -0
  34. package/dist/factories/database-effect.d.ts +241 -0
  35. package/dist/factories/database-effect.d.ts.map +1 -0
  36. package/dist/factories/database-effect.js +859 -0
  37. package/dist/factories/database-effect.js.map +1 -0
  38. package/dist/hooks/hook-runner.d.ts +60 -0
  39. package/dist/hooks/hook-runner.d.ts.map +1 -0
  40. package/dist/hooks/hook-runner.js +107 -0
  41. package/dist/hooks/hook-runner.js.map +1 -0
  42. package/dist/index.d.ts +84 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +110 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/indexes/index-lookup.d.ts +33 -0
  47. package/dist/indexes/index-lookup.d.ts.map +1 -0
  48. package/dist/indexes/index-lookup.js +180 -0
  49. package/dist/indexes/index-lookup.js.map +1 -0
  50. package/dist/indexes/index-manager.d.ts +118 -0
  51. package/dist/indexes/index-manager.d.ts.map +1 -0
  52. package/dist/indexes/index-manager.js +345 -0
  53. package/dist/indexes/index-manager.js.map +1 -0
  54. package/dist/indexes/search-index.d.ts +179 -0
  55. package/dist/indexes/search-index.d.ts.map +1 -0
  56. package/dist/indexes/search-index.js +405 -0
  57. package/dist/indexes/search-index.js.map +1 -0
  58. package/dist/migrations/migration-runner.d.ts +70 -0
  59. package/dist/migrations/migration-runner.d.ts.map +1 -0
  60. package/dist/migrations/migration-runner.js +271 -0
  61. package/dist/migrations/migration-runner.js.map +1 -0
  62. package/dist/migrations/migration-types.d.ts +63 -0
  63. package/dist/migrations/migration-types.d.ts.map +1 -0
  64. package/dist/migrations/migration-types.js +5 -0
  65. package/dist/migrations/migration-types.js.map +1 -0
  66. package/dist/operations/crud/create-with-relationships.d.ts +44 -0
  67. package/dist/operations/crud/create-with-relationships.d.ts.map +1 -0
  68. package/dist/operations/crud/create-with-relationships.js +483 -0
  69. package/dist/operations/crud/create-with-relationships.js.map +1 -0
  70. package/dist/operations/crud/create.d.ts +48 -0
  71. package/dist/operations/crud/create.d.ts.map +1 -0
  72. package/dist/operations/crud/create.js +333 -0
  73. package/dist/operations/crud/create.js.map +1 -0
  74. package/dist/operations/crud/delete-with-relationships.d.ts +63 -0
  75. package/dist/operations/crud/delete-with-relationships.d.ts.map +1 -0
  76. package/dist/operations/crud/delete-with-relationships.js +395 -0
  77. package/dist/operations/crud/delete-with-relationships.js.map +1 -0
  78. package/dist/operations/crud/delete.d.ts +58 -0
  79. package/dist/operations/crud/delete.d.ts.map +1 -0
  80. package/dist/operations/crud/delete.js +267 -0
  81. package/dist/operations/crud/delete.js.map +1 -0
  82. package/dist/operations/crud/unique-check.d.ts +114 -0
  83. package/dist/operations/crud/unique-check.d.ts.map +1 -0
  84. package/dist/operations/crud/unique-check.js +383 -0
  85. package/dist/operations/crud/unique-check.js.map +1 -0
  86. package/dist/operations/crud/update-with-relationships.d.ts +45 -0
  87. package/dist/operations/crud/update-with-relationships.d.ts.map +1 -0
  88. package/dist/operations/crud/update-with-relationships.js +516 -0
  89. package/dist/operations/crud/update-with-relationships.js.map +1 -0
  90. package/dist/operations/crud/update.d.ts +91 -0
  91. package/dist/operations/crud/update.d.ts.map +1 -0
  92. package/dist/operations/crud/update.js +505 -0
  93. package/dist/operations/crud/update.js.map +1 -0
  94. package/dist/operations/crud/upsert.d.ts +52 -0
  95. package/dist/operations/crud/upsert.d.ts.map +1 -0
  96. package/dist/operations/crud/upsert.js +386 -0
  97. package/dist/operations/crud/upsert.js.map +1 -0
  98. package/dist/operations/query/aggregate.d.ts +30 -0
  99. package/dist/operations/query/aggregate.d.ts.map +1 -0
  100. package/dist/operations/query/aggregate.js +227 -0
  101. package/dist/operations/query/aggregate.js.map +1 -0
  102. package/dist/operations/query/cursor-stream.d.ts +18 -0
  103. package/dist/operations/query/cursor-stream.d.ts.map +1 -0
  104. package/dist/operations/query/cursor-stream.js +199 -0
  105. package/dist/operations/query/cursor-stream.js.map +1 -0
  106. package/dist/operations/query/filter-stream.d.ts +12 -0
  107. package/dist/operations/query/filter-stream.d.ts.map +1 -0
  108. package/dist/operations/query/filter-stream.js +167 -0
  109. package/dist/operations/query/filter-stream.js.map +1 -0
  110. package/dist/operations/query/filter.d.ts +13 -0
  111. package/dist/operations/query/filter.d.ts.map +1 -0
  112. package/dist/operations/query/filter.js +267 -0
  113. package/dist/operations/query/filter.js.map +1 -0
  114. package/dist/operations/query/paginate-stream.d.ts +11 -0
  115. package/dist/operations/query/paginate-stream.d.ts.map +1 -0
  116. package/dist/operations/query/paginate-stream.js +22 -0
  117. package/dist/operations/query/paginate-stream.js.map +1 -0
  118. package/dist/operations/query/query-helpers.d.ts +14 -0
  119. package/dist/operations/query/query-helpers.d.ts.map +1 -0
  120. package/dist/operations/query/query-helpers.js +22 -0
  121. package/dist/operations/query/query-helpers.js.map +1 -0
  122. package/dist/operations/query/resolve-computed.d.ts +142 -0
  123. package/dist/operations/query/resolve-computed.d.ts.map +1 -0
  124. package/dist/operations/query/resolve-computed.js +197 -0
  125. package/dist/operations/query/resolve-computed.js.map +1 -0
  126. package/dist/operations/query/search.d.ts +110 -0
  127. package/dist/operations/query/search.d.ts.map +1 -0
  128. package/dist/operations/query/search.js +188 -0
  129. package/dist/operations/query/search.js.map +1 -0
  130. package/dist/operations/query/select-stream.d.ts +27 -0
  131. package/dist/operations/query/select-stream.d.ts.map +1 -0
  132. package/dist/operations/query/select-stream.js +88 -0
  133. package/dist/operations/query/select-stream.js.map +1 -0
  134. package/dist/operations/query/select.d.ts +54 -0
  135. package/dist/operations/query/select.d.ts.map +1 -0
  136. package/dist/operations/query/select.js +159 -0
  137. package/dist/operations/query/select.js.map +1 -0
  138. package/dist/operations/query/sort-stream.d.ts +46 -0
  139. package/dist/operations/query/sort-stream.d.ts.map +1 -0
  140. package/dist/operations/query/sort-stream.js +158 -0
  141. package/dist/operations/query/sort-stream.js.map +1 -0
  142. package/dist/operations/query/sort.d.ts +9 -0
  143. package/dist/operations/query/sort.d.ts.map +1 -0
  144. package/dist/operations/query/sort.js +58 -0
  145. package/dist/operations/query/sort.js.map +1 -0
  146. package/dist/operations/relationships/populate-stream.d.ts +29 -0
  147. package/dist/operations/relationships/populate-stream.d.ts.map +1 -0
  148. package/dist/operations/relationships/populate-stream.js +159 -0
  149. package/dist/operations/relationships/populate-stream.js.map +1 -0
  150. package/dist/operations/relationships/populate.d.ts +15 -0
  151. package/dist/operations/relationships/populate.d.ts.map +1 -0
  152. package/dist/operations/relationships/populate.js +228 -0
  153. package/dist/operations/relationships/populate.js.map +1 -0
  154. package/dist/plugins/plugin-hooks.d.ts +25 -0
  155. package/dist/plugins/plugin-hooks.d.ts.map +1 -0
  156. package/dist/plugins/plugin-hooks.js +64 -0
  157. package/dist/plugins/plugin-hooks.js.map +1 -0
  158. package/dist/plugins/plugin-registry.d.ts +26 -0
  159. package/dist/plugins/plugin-registry.d.ts.map +1 -0
  160. package/dist/plugins/plugin-registry.js +150 -0
  161. package/dist/plugins/plugin-registry.js.map +1 -0
  162. package/dist/plugins/plugin-types.d.ts +95 -0
  163. package/dist/plugins/plugin-types.d.ts.map +1 -0
  164. package/dist/plugins/plugin-types.js +6 -0
  165. package/dist/plugins/plugin-types.js.map +1 -0
  166. package/dist/plugins/plugin-validation.d.ts +49 -0
  167. package/dist/plugins/plugin-validation.d.ts.map +1 -0
  168. package/dist/plugins/plugin-validation.js +295 -0
  169. package/dist/plugins/plugin-validation.js.map +1 -0
  170. package/dist/reactive/change-event.d.ts +44 -0
  171. package/dist/reactive/change-event.d.ts.map +1 -0
  172. package/dist/reactive/change-event.js +49 -0
  173. package/dist/reactive/change-event.js.map +1 -0
  174. package/dist/reactive/change-pubsub.d.ts +32 -0
  175. package/dist/reactive/change-pubsub.d.ts.map +1 -0
  176. package/dist/reactive/change-pubsub.js +31 -0
  177. package/dist/reactive/change-pubsub.js.map +1 -0
  178. package/dist/reactive/evaluate-query.d.ts +62 -0
  179. package/dist/reactive/evaluate-query.d.ts.map +1 -0
  180. package/dist/reactive/evaluate-query.js +57 -0
  181. package/dist/reactive/evaluate-query.js.map +1 -0
  182. package/dist/reactive/watch-by-id.d.ts +53 -0
  183. package/dist/reactive/watch-by-id.d.ts.map +1 -0
  184. package/dist/reactive/watch-by-id.js +55 -0
  185. package/dist/reactive/watch-by-id.js.map +1 -0
  186. package/dist/reactive/watch.d.ts +78 -0
  187. package/dist/reactive/watch.d.ts.map +1 -0
  188. package/dist/reactive/watch.js +133 -0
  189. package/dist/reactive/watch.js.map +1 -0
  190. package/dist/serializers/codecs/hjson.d.ts +33 -0
  191. package/dist/serializers/codecs/hjson.d.ts.map +1 -0
  192. package/dist/serializers/codecs/hjson.js +40 -0
  193. package/dist/serializers/codecs/hjson.js.map +1 -0
  194. package/dist/serializers/codecs/json.d.ts +22 -0
  195. package/dist/serializers/codecs/json.d.ts.map +1 -0
  196. package/dist/serializers/codecs/json.js +28 -0
  197. package/dist/serializers/codecs/json.js.map +1 -0
  198. package/dist/serializers/codecs/json5.d.ts +26 -0
  199. package/dist/serializers/codecs/json5.d.ts.map +1 -0
  200. package/dist/serializers/codecs/json5.js +33 -0
  201. package/dist/serializers/codecs/json5.js.map +1 -0
  202. package/dist/serializers/codecs/jsonc.d.ts +29 -0
  203. package/dist/serializers/codecs/jsonc.d.ts.map +1 -0
  204. package/dist/serializers/codecs/jsonc.js +38 -0
  205. package/dist/serializers/codecs/jsonc.js.map +1 -0
  206. package/dist/serializers/codecs/jsonl.d.ts +17 -0
  207. package/dist/serializers/codecs/jsonl.d.ts.map +1 -0
  208. package/dist/serializers/codecs/jsonl.js +31 -0
  209. package/dist/serializers/codecs/jsonl.js.map +1 -0
  210. package/dist/serializers/codecs/prose.d.ts +419 -0
  211. package/dist/serializers/codecs/prose.d.ts.map +1 -0
  212. package/dist/serializers/codecs/prose.js +1060 -0
  213. package/dist/serializers/codecs/prose.js.map +1 -0
  214. package/dist/serializers/codecs/toml.d.ts +23 -0
  215. package/dist/serializers/codecs/toml.d.ts.map +1 -0
  216. package/dist/serializers/codecs/toml.js +66 -0
  217. package/dist/serializers/codecs/toml.js.map +1 -0
  218. package/dist/serializers/codecs/toon.d.ts +20 -0
  219. package/dist/serializers/codecs/toon.d.ts.map +1 -0
  220. package/dist/serializers/codecs/toon.js +33 -0
  221. package/dist/serializers/codecs/toon.js.map +1 -0
  222. package/dist/serializers/codecs/yaml.d.ts +24 -0
  223. package/dist/serializers/codecs/yaml.d.ts.map +1 -0
  224. package/dist/serializers/codecs/yaml.js +31 -0
  225. package/dist/serializers/codecs/yaml.js.map +1 -0
  226. package/dist/serializers/format-codec.d.ts +53 -0
  227. package/dist/serializers/format-codec.d.ts.map +1 -0
  228. package/dist/serializers/format-codec.js +148 -0
  229. package/dist/serializers/format-codec.js.map +1 -0
  230. package/dist/serializers/presets.d.ts +48 -0
  231. package/dist/serializers/presets.d.ts.map +1 -0
  232. package/dist/serializers/presets.js +72 -0
  233. package/dist/serializers/presets.js.map +1 -0
  234. package/dist/serializers/serializer-service.d.ts +11 -0
  235. package/dist/serializers/serializer-service.d.ts.map +1 -0
  236. package/dist/serializers/serializer-service.js +4 -0
  237. package/dist/serializers/serializer-service.js.map +1 -0
  238. package/dist/state/collection-state.d.ts +19 -0
  239. package/dist/state/collection-state.d.ts.map +1 -0
  240. package/dist/state/collection-state.js +15 -0
  241. package/dist/state/collection-state.js.map +1 -0
  242. package/dist/state/state-operations.d.ts +38 -0
  243. package/dist/state/state-operations.d.ts.map +1 -0
  244. package/dist/state/state-operations.js +65 -0
  245. package/dist/state/state-operations.js.map +1 -0
  246. package/dist/storage/in-memory-adapter-layer.d.ts +16 -0
  247. package/dist/storage/in-memory-adapter-layer.d.ts.map +1 -0
  248. package/dist/storage/in-memory-adapter-layer.js +81 -0
  249. package/dist/storage/in-memory-adapter-layer.js.map +1 -0
  250. package/dist/storage/persistence-effect.d.ts +244 -0
  251. package/dist/storage/persistence-effect.d.ts.map +1 -0
  252. package/dist/storage/persistence-effect.js +551 -0
  253. package/dist/storage/persistence-effect.js.map +1 -0
  254. package/dist/storage/storage-service.d.ts +22 -0
  255. package/dist/storage/storage-service.d.ts.map +1 -0
  256. package/dist/storage/storage-service.js +4 -0
  257. package/dist/storage/storage-service.js.map +1 -0
  258. package/dist/storage/transforms.d.ts +183 -0
  259. package/dist/storage/transforms.d.ts.map +1 -0
  260. package/dist/storage/transforms.js +263 -0
  261. package/dist/storage/transforms.js.map +1 -0
  262. package/dist/transactions/transaction.d.ts +87 -0
  263. package/dist/transactions/transaction.d.ts.map +1 -0
  264. package/dist/transactions/transaction.js +240 -0
  265. package/dist/transactions/transaction.js.map +1 -0
  266. package/dist/types/aggregate-types.d.ts +73 -0
  267. package/dist/types/aggregate-types.d.ts.map +1 -0
  268. package/dist/types/aggregate-types.js +14 -0
  269. package/dist/types/aggregate-types.js.map +1 -0
  270. package/dist/types/computed-types.d.ts +71 -0
  271. package/dist/types/computed-types.d.ts.map +1 -0
  272. package/dist/types/computed-types.js +8 -0
  273. package/dist/types/computed-types.js.map +1 -0
  274. package/dist/types/crud-relationship-types.d.ts +180 -0
  275. package/dist/types/crud-relationship-types.d.ts.map +1 -0
  276. package/dist/types/crud-relationship-types.js +17 -0
  277. package/dist/types/crud-relationship-types.js.map +1 -0
  278. package/dist/types/crud-types.d.ts +343 -0
  279. package/dist/types/crud-types.d.ts.map +1 -0
  280. package/dist/types/crud-types.js +43 -0
  281. package/dist/types/crud-types.js.map +1 -0
  282. package/dist/types/cursor-types.d.ts +52 -0
  283. package/dist/types/cursor-types.d.ts.map +1 -0
  284. package/dist/types/cursor-types.js +2 -0
  285. package/dist/types/cursor-types.js.map +1 -0
  286. package/dist/types/database-config-types.d.ts +196 -0
  287. package/dist/types/database-config-types.d.ts.map +1 -0
  288. package/dist/types/database-config-types.js +11 -0
  289. package/dist/types/database-config-types.js.map +1 -0
  290. package/dist/types/hook-types.d.ts +158 -0
  291. package/dist/types/hook-types.d.ts.map +1 -0
  292. package/dist/types/hook-types.js +6 -0
  293. package/dist/types/hook-types.js.map +1 -0
  294. package/dist/types/index-types.d.ts +42 -0
  295. package/dist/types/index-types.d.ts.map +1 -0
  296. package/dist/types/index-types.js +8 -0
  297. package/dist/types/index-types.js.map +1 -0
  298. package/dist/types/operators.d.ts +5 -0
  299. package/dist/types/operators.d.ts.map +1 -0
  300. package/dist/types/operators.js +297 -0
  301. package/dist/types/operators.js.map +1 -0
  302. package/dist/types/query-overloads.d.ts +54 -0
  303. package/dist/types/query-overloads.d.ts.map +1 -0
  304. package/dist/types/query-overloads.js +3 -0
  305. package/dist/types/query-overloads.js.map +1 -0
  306. package/dist/types/reactive-types.d.ts +75 -0
  307. package/dist/types/reactive-types.d.ts.map +1 -0
  308. package/dist/types/reactive-types.js +7 -0
  309. package/dist/types/reactive-types.js.map +1 -0
  310. package/dist/types/schema-types.d.ts +56 -0
  311. package/dist/types/schema-types.d.ts.map +1 -0
  312. package/dist/types/schema-types.js +8 -0
  313. package/dist/types/schema-types.js.map +1 -0
  314. package/dist/types/search-types.d.ts +82 -0
  315. package/dist/types/search-types.d.ts.map +1 -0
  316. package/dist/types/search-types.js +110 -0
  317. package/dist/types/search-types.js.map +1 -0
  318. package/dist/types/types.d.ts +286 -0
  319. package/dist/types/types.d.ts.map +1 -0
  320. package/dist/types/types.js +2 -0
  321. package/dist/types/types.js.map +1 -0
  322. package/dist/utils/id-generator.d.ts +97 -0
  323. package/dist/utils/id-generator.d.ts.map +1 -0
  324. package/dist/utils/id-generator.js +247 -0
  325. package/dist/utils/id-generator.js.map +1 -0
  326. package/dist/utils/nested-path.d.ts +56 -0
  327. package/dist/utils/nested-path.d.ts.map +1 -0
  328. package/dist/utils/nested-path.js +119 -0
  329. package/dist/utils/nested-path.js.map +1 -0
  330. package/dist/utils/path.d.ts +16 -0
  331. package/dist/utils/path.d.ts.map +1 -0
  332. package/dist/utils/path.js +24 -0
  333. package/dist/utils/path.js.map +1 -0
  334. package/dist/validators/foreign-key.d.ts +49 -0
  335. package/dist/validators/foreign-key.d.ts.map +1 -0
  336. package/dist/validators/foreign-key.js +153 -0
  337. package/dist/validators/foreign-key.js.map +1 -0
  338. package/dist/validators/schema-validator.d.ts +19 -0
  339. package/dist/validators/schema-validator.d.ts.map +1 -0
  340. package/dist/validators/schema-validator.js +34 -0
  341. package/dist/validators/schema-validator.js.map +1 -0
  342. package/package.json +57 -0
@@ -0,0 +1,419 @@
1
+ import type { FormatCodec } from "../format-codec.js";
2
+ /**
3
+ * A segment in a compiled prose template.
4
+ * Either a literal text segment or a field placeholder.
5
+ */
6
+ export type ProseSegment = {
7
+ readonly type: "literal";
8
+ readonly text: string;
9
+ } | {
10
+ readonly type: "field";
11
+ readonly name: string;
12
+ };
13
+ /**
14
+ * A compiled template ready for encoding/decoding.
15
+ * Contains the ordered list of segments and extracted field names.
16
+ */
17
+ export interface CompiledTemplate {
18
+ readonly segments: ReadonlyArray<ProseSegment>;
19
+ readonly fields: ReadonlyArray<string>;
20
+ }
21
+ /**
22
+ * Options for creating a prose codec.
23
+ */
24
+ export interface ProseCodecOptions {
25
+ /** The headline template with {fieldName} placeholders */
26
+ readonly template: string;
27
+ /** Optional overflow templates for additional fields on indented lines */
28
+ readonly overflow?: ReadonlyArray<string>;
29
+ }
30
+ /**
31
+ * Compiles a template string into an ordered list of segments.
32
+ * Parses `{fieldName}` placeholders and literal text into segments.
33
+ *
34
+ * @param template - The template string with {fieldName} placeholders
35
+ * @returns A CompiledTemplate with segments and field names
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const compiled = compileTemplate('#{id} "{title}" by {author}')
40
+ * // compiled.segments = [
41
+ * // { type: "literal", text: "#" },
42
+ * // { type: "field", name: "id" },
43
+ * // { type: "literal", text: ' "' },
44
+ * // { type: "field", name: "title" },
45
+ * // { type: "literal", text: '" by ' },
46
+ * // { type: "field", name: "author" },
47
+ * // ]
48
+ * // compiled.fields = ["id", "title", "author"]
49
+ * ```
50
+ */
51
+ export declare const compileTemplate: (template: string) => CompiledTemplate;
52
+ /**
53
+ * Compiles an array of overflow template strings into CompiledTemplates.
54
+ * Each overflow template follows the same {fieldName} placeholder syntax as the headline template.
55
+ *
56
+ * @param overflow - Optional array of overflow template strings
57
+ * @returns An array of CompiledTemplate objects, or empty array if no overflow templates
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const compiled = compileOverflowTemplates(['tagged {tags}', '~ {description}'])
62
+ * // compiled[0].segments = [
63
+ * // { type: "literal", text: "tagged " },
64
+ * // { type: "field", name: "tags" },
65
+ * // ]
66
+ * // compiled[0].fields = ["tags"]
67
+ * // compiled[1].segments = [
68
+ * // { type: "literal", text: "~ " },
69
+ * // { type: "field", name: "description" },
70
+ * // ]
71
+ * // compiled[1].fields = ["description"]
72
+ * ```
73
+ */
74
+ export declare const compileOverflowTemplates: (overflow: ReadonlyArray<string> | undefined) => ReadonlyArray<CompiledTemplate>;
75
+ /**
76
+ * Serializes a value to its prose format string representation.
77
+ *
78
+ * Type mapping:
79
+ * - null/undefined → `~`
80
+ * - boolean → `true` / `false`
81
+ * - number → digit characters (e.g., `42`, `-3.14`)
82
+ * - array → `[a, b, c]` with element quoting for `,` and `]`
83
+ * - string → bare text (quoting for delimiters handled by encodeHeadline)
84
+ *
85
+ * @param value - The value to serialize
86
+ * @returns The serialized string representation
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * serializeValue(42) // "42"
91
+ * serializeValue(true) // "true"
92
+ * serializeValue(null) // "~"
93
+ * serializeValue("hello") // "hello"
94
+ * serializeValue(["a", "b"]) // "[a, b]"
95
+ * ```
96
+ */
97
+ export declare const serializeValue: (value: unknown) => string;
98
+ /**
99
+ * Deserializes a prose format string back to its typed value.
100
+ * Uses heuristic type detection:
101
+ * - Numbers: matches `/^-?\d+(\.\d+)?$/`
102
+ * - Booleans: exact match `true` or `false`
103
+ * - Null: exact match `~`
104
+ * - Arrays: starts with `[`, ends with `]`
105
+ * - Strings: default (anything not matching above)
106
+ *
107
+ * @param text - The serialized string to deserialize
108
+ * @returns The deserialized value with its inferred type
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * deserializeValue("42") // 42 (number)
113
+ * deserializeValue("-3.14") // -3.14 (number)
114
+ * deserializeValue("true") // true (boolean)
115
+ * deserializeValue("false") // false (boolean)
116
+ * deserializeValue("~") // null
117
+ * deserializeValue("[a, b, c]") // ["a", "b", "c"] (array)
118
+ * deserializeValue("hello") // "hello" (string)
119
+ * ```
120
+ */
121
+ export declare const deserializeValue: (text: string) => unknown;
122
+ /**
123
+ * Encodes a record into a headline string using a compiled template.
124
+ * Substitutes field values into the template, emitting literals verbatim.
125
+ * For non-last fields, if the serialized value contains the next literal
126
+ * delimiter, the value is quoted to prevent parsing ambiguity.
127
+ *
128
+ * @param record - The record object with field values
129
+ * @param template - The compiled template with segments and fields
130
+ * @returns The encoded headline string
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const template = compileTemplate('#{id} "{title}" by {author}')
135
+ * const record = { id: "1", title: "Dune", author: "Frank Herbert" }
136
+ * encodeHeadline(record, template)
137
+ * // → '#1 "Dune" by Frank Herbert'
138
+ *
139
+ * // When value contains the next delimiter:
140
+ * const record2 = { id: "1", title: 'Say "hello"', author: "Test" }
141
+ * encodeHeadline(record2, template)
142
+ * // → '#1 "Say \"hello\"" by Test'
143
+ * ```
144
+ */
145
+ export declare const encodeHeadline: (record: Record<string, unknown>, template: CompiledTemplate) => string;
146
+ /**
147
+ * Decodes a headline string back to a record using a compiled template.
148
+ * Performs a left-to-right scan matching literals and capturing field text between them.
149
+ * Returns null if the line doesn't match the template structure.
150
+ *
151
+ * @param line - The headline string to decode
152
+ * @param template - The compiled template with segments and fields
153
+ * @returns The decoded record object, or null if the line doesn't match
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const template = compileTemplate('#{id} "{title}" by {author}')
158
+ * decodeHeadline('#1 "Dune" by Frank Herbert', template)
159
+ * // → { id: "1", title: "Dune", author: "Frank Herbert" }
160
+ *
161
+ * decodeHeadline('This does not match', template)
162
+ * // → null
163
+ * ```
164
+ */
165
+ export declare const decodeHeadline: (line: string, template: CompiledTemplate) => Record<string, unknown> | null;
166
+ /**
167
+ * Encodes overflow fields for a record as indented lines.
168
+ * For each overflow template, if the record has a non-null/non-undefined value
169
+ * for the field in that template, emits an indented line using the template.
170
+ * Overflow fields with null or undefined values are omitted.
171
+ *
172
+ * For multi-line string values (containing newlines), the first line is encoded
173
+ * on the template line, and subsequent lines are emitted as continuation lines
174
+ * with deeper indentation.
175
+ *
176
+ * @param record - The record object with field values
177
+ * @param overflowTemplates - Array of compiled overflow templates
178
+ * @returns Array of indented overflow line strings
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const templates = compileOverflowTemplates(['tagged {tags}', '~ {description}'])
183
+ * const record = { id: "1", title: "Dune", tags: ["classic"], description: null }
184
+ * encodeOverflowLines(record, templates)
185
+ * // → [' tagged [classic]']
186
+ * // Note: description is null, so its overflow line is omitted
187
+ *
188
+ * // Multi-line value:
189
+ * const record2 = { id: "1", description: "Line one\nLine two" }
190
+ * encodeOverflowLines(record2, compileOverflowTemplates(['~ {description}']))
191
+ * // → [' ~ Line one', ' Line two']
192
+ * ```
193
+ */
194
+ export declare const encodeOverflowLines: (record: Record<string, unknown>, overflowTemplates: ReadonlyArray<CompiledTemplate>) => ReadonlyArray<string>;
195
+ /**
196
+ * Result of decoding overflow lines for a record.
197
+ */
198
+ export interface DecodeOverflowResult {
199
+ /** The decoded field values from overflow lines */
200
+ readonly fields: Record<string, unknown>;
201
+ /** Number of lines consumed (including continuation lines) */
202
+ readonly linesConsumed: number;
203
+ }
204
+ /**
205
+ * Decodes overflow lines for a record using the configured overflow templates.
206
+ * Collects indented lines belonging to the record, tries each overflow template
207
+ * in order, skips on non-match, and captures field values on match.
208
+ *
209
+ * For each indented line:
210
+ * 1. Try matching against each overflow template (in order)
211
+ * 2. If a template matches, capture the field values and move to next line
212
+ * 3. If no template matches, check if it's a continuation line (deeper indentation)
213
+ * 4. Continuation lines are appended to the previous field's value with newline
214
+ *
215
+ * @param lines - Array of indented lines (already collected for this record)
216
+ * @param overflowTemplates - Array of compiled overflow templates
217
+ * @param baseIndent - The expected indentation level for overflow lines (default: 2)
218
+ * @returns The decoded field values and number of lines consumed
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const templates = compileOverflowTemplates(['tagged {tags}', '~ {description}'])
223
+ * const lines = [' tagged [sci-fi]', ' ~ A classic novel']
224
+ * const result = decodeOverflowLines(lines, templates)
225
+ * // → { fields: { tags: ['sci-fi'], description: 'A classic novel' }, linesConsumed: 2 }
226
+ * ```
227
+ */
228
+ export declare const decodeOverflowLines: (lines: ReadonlyArray<string>, overflowTemplates: ReadonlyArray<CompiledTemplate>, baseIndent?: number) => DecodeOverflowResult;
229
+ /**
230
+ * Result of scanning for the @prose directive in a document.
231
+ */
232
+ export interface ScanDirectiveResult {
233
+ /** Index of the last line before the directive (or -1 if no preamble) */
234
+ readonly preambleEnd: number;
235
+ /** Index of the line containing the @prose directive */
236
+ readonly directiveStart: number;
237
+ }
238
+ /**
239
+ * Scans a document for the @prose directive.
240
+ * The directive is a line starting with `@prose ` (note the trailing space).
241
+ *
242
+ * Rules:
243
+ * - Exactly one @prose directive must exist in the file
244
+ * - If no directive is found, throws an error
245
+ * - If multiple directives are found, throws an error
246
+ * - All lines before the directive are preamble
247
+ *
248
+ * @param lines - Array of lines from the document
249
+ * @returns The position information for preamble and directive
250
+ * @throws Error if no directive found or multiple directives found
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const lines = ['# My Books', '', '@prose #{id} {title}', '#1 Dune']
255
+ * const result = scanDirective(lines)
256
+ * // → { preambleEnd: 1, directiveStart: 2 }
257
+ *
258
+ * const linesNoPreable = ['@prose #{id} {title}', '#1 Dune']
259
+ * const result2 = scanDirective(linesNoPreable)
260
+ * // → { preambleEnd: -1, directiveStart: 0 }
261
+ * ```
262
+ */
263
+ export declare const scanDirective: (lines: ReadonlyArray<string>) => ScanDirectiveResult;
264
+ /**
265
+ * Result of parsing a directive block.
266
+ */
267
+ export interface DirectiveBlock {
268
+ /** The headline template (content after @prose) */
269
+ readonly headlineTemplate: string;
270
+ /** Overflow templates (indented lines immediately after @prose) */
271
+ readonly overflowTemplates: ReadonlyArray<string>;
272
+ /** Index of the first line after the directive block (body start) */
273
+ readonly bodyStart: number;
274
+ }
275
+ /**
276
+ * Parses a directive block from the document.
277
+ * Extracts the headline template from the @prose line and collects
278
+ * any indented overflow templates that immediately follow.
279
+ *
280
+ * The directive block structure:
281
+ * ```
282
+ * @prose #{id} "{title}" by {author} ← headline template
283
+ * tagged {tags} ← overflow template 1
284
+ * ~ {description} ← overflow template 2
285
+ * ← blank line or non-indented = end of block
286
+ * ```
287
+ *
288
+ * Overflow templates are lines that:
289
+ * - Immediately follow the @prose line (no blank lines between)
290
+ * - Are indented (start with whitespace)
291
+ *
292
+ * @param lines - Array of lines from the document
293
+ * @param directiveStart - Index of the @prose directive line
294
+ * @returns The parsed directive block with template strings and body start index
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * const lines = [
299
+ * '@prose #{id} "{title}"',
300
+ * ' tagged {tags}',
301
+ * ' ~ {description}',
302
+ * '',
303
+ * '#1 "Dune"',
304
+ * ]
305
+ * const result = parseDirectiveBlock(lines, 0)
306
+ * // → {
307
+ * // headlineTemplate: '#{id} "{title}"',
308
+ * // overflowTemplates: ['tagged {tags}', '~ {description}'],
309
+ * // bodyStart: 3
310
+ * // }
311
+ * ```
312
+ */
313
+ export declare const parseDirectiveBlock: (lines: ReadonlyArray<string>, directiveStart: number) => DirectiveBlock;
314
+ /**
315
+ * Represents a parsed entry from the body section of a prose document.
316
+ * Can be either a record (matched the headline template) or pass-through text.
317
+ */
318
+ export type ProseEntry = {
319
+ readonly type: "record";
320
+ /** The decoded headline fields */
321
+ readonly fields: Record<string, unknown>;
322
+ /** The raw headline line */
323
+ readonly headline: string;
324
+ /** Indented overflow lines belonging to this record */
325
+ readonly overflowLines: ReadonlyArray<string>;
326
+ } | {
327
+ readonly type: "passthrough";
328
+ /** Raw text lines that didn't match the template */
329
+ readonly lines: ReadonlyArray<string>;
330
+ };
331
+ /**
332
+ * Result of parsing the body section of a prose document.
333
+ */
334
+ export interface ParseBodyResult {
335
+ /** The parsed entries (interleaved records and pass-through text) */
336
+ readonly entries: ReadonlyArray<ProseEntry>;
337
+ }
338
+ /**
339
+ * Parses the body section of a prose document.
340
+ * Iterates lines after the directive block and classifies each as:
341
+ * - Record headline (matches the compiled template)
342
+ * - Indented overflow/continuation (part of the current record)
343
+ * - Pass-through text (doesn't match, preserved verbatim)
344
+ *
345
+ * @param lines - Array of lines from the document
346
+ * @param bodyStart - Index of the first line of the body (after directive block)
347
+ * @param headlineTemplate - The compiled headline template
348
+ * @returns The parsed body with interleaved records and pass-through text
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * const lines = [
353
+ * '@prose #{id} "{title}"',
354
+ * '',
355
+ * '## Science Fiction',
356
+ * '#1 "Dune"',
357
+ * ' tagged [classic]',
358
+ * '#2 "Neuromancer"',
359
+ * '',
360
+ * '## Fantasy',
361
+ * '#3 "The Hobbit"',
362
+ * ]
363
+ * const template = compileTemplate('#{id} "{title}"')
364
+ * const result = parseBody(lines, 1, template)
365
+ * // → {
366
+ * // entries: [
367
+ * // { type: "passthrough", lines: ["", "## Science Fiction"] },
368
+ * // { type: "record", fields: { id: "1", title: "Dune" }, headline: '#1 "Dune"', overflowLines: [" tagged [classic]"] },
369
+ * // { type: "record", fields: { id: "2", title: "Neuromancer" }, headline: '#2 "Neuromancer"', overflowLines: [] },
370
+ * // { type: "passthrough", lines: ["", "## Fantasy"] },
371
+ * // { type: "record", fields: { id: "3", title: "The Hobbit" }, headline: '#3 "The Hobbit"', overflowLines: [] },
372
+ * // ]
373
+ * // }
374
+ * ```
375
+ */
376
+ export declare const parseBody: (lines: ReadonlyArray<string>, bodyStart: number, headlineTemplate: CompiledTemplate) => ParseBodyResult;
377
+ /**
378
+ * Creates a prose format codec for human-readable, template-driven serialization.
379
+ *
380
+ * The prose format uses a `@prose` directive to define a sentence-like pattern
381
+ * mapping field names to positions within literal delimiter text. Records follow
382
+ * this pattern, producing human-readable lines.
383
+ *
384
+ * Templates use `{fieldName}` placeholders mixed with literal text:
385
+ * ```
386
+ * @prose #{id} "{title}" by {authorId} ({year}) — {genre}
387
+ * tagged {tags}
388
+ * ~ {description}
389
+ * ```
390
+ *
391
+ * The codec compiles templates at construction time and returns a standard
392
+ * FormatCodec with encode/decode functions.
393
+ *
394
+ * @param options - Codec configuration with headline and overflow templates
395
+ * @param options.template - The headline template with {fieldName} placeholders
396
+ * @param options.overflow - Optional array of overflow templates for additional fields
397
+ * @returns A FormatCodec for prose serialization
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * const codec = proseCodec({
402
+ * template: '#{id} "{title}" by {author}',
403
+ * overflow: ['tagged {tags}', '~ {description}'],
404
+ * })
405
+ *
406
+ * const layer = makeSerializerLayer([codec])
407
+ *
408
+ * // Encoded output:
409
+ * // @prose #{id} "{title}" by {author}
410
+ * // tagged {tags}
411
+ * // ~ {description}
412
+ * //
413
+ * // #1 "Dune" by Frank Herbert
414
+ * // tagged [sci-fi, classic]
415
+ * // ~ A masterpiece of science fiction
416
+ * ```
417
+ */
418
+ export declare const proseCodec: (options: ProseCodecOptions) => FormatCodec;
419
+ //# sourceMappingURL=prose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prose.d.ts","sourceRoot":"","sources":["../../../src/serializers/codecs/prose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,oBAAoB,CAAC;AAMrE;;;GAGG;AACH,MAAM,MAAM,YAAY,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,MAA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