@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 @@
1
+ {"version":3,"file":"migration-runner.d.ts","sourceRoot":"","sources":["../../src/migrations/migration-runner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EACX,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,KAAK,EAGX,YAAY,EAEZ,SAAS,EACT,MAAM,sBAAsB,CAAC;AAM9B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,GACzB,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,aAAa,MAAM,EACnB,eAAe,MAAM,EACrB,YAAY,aAAa,CAAC,SAAS,CAAC,EACpC,gBAAgB,MAAM,KACpB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,CAwCvD,CAAC;AAMF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,yBAAyB,GACrC,gBAAgB,MAAM,EACtB,SAAS,MAAM,EACf,YAAY,aAAa,CAAC,SAAS,CAAC,KAClC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CA6GpC,CAAC;AAMF;;GAEG;AACH,KAAK,KAAK,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AACrC,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAErE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAC5B,QAAQ,cAAc,EACtB,YAAY,SAAS,KACnB,MAAM,CAAC,MAAM,CACf,YAAY,EACZ,cAAc,GAAG,YAAY,GAAG,kBAAkB,GAAG,sBAAsB,EAC3E,cAAc,GAAG,kBAAkB,CAmHjC,CAAC"}
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Migration Runner
3
+ *
4
+ * Core migration logic: validate migration registries, run migrations,
5
+ * and preview migrations via dry-run.
6
+ */
7
+ import { Effect } from "effect";
8
+ import { MigrationError } from "../errors/migration-errors.js";
9
+ import { SerializerRegistry } from "../serializers/serializer-service.js";
10
+ import { StorageAdapter } from "../storage/storage-service.js";
11
+ // ============================================================================
12
+ // Migration Execution
13
+ // ============================================================================
14
+ /**
15
+ * Run migrations to transform data from one version to another.
16
+ *
17
+ * Filters migrations to only those applicable for the version transition,
18
+ * then runs each transform in order, piping the output of one to the input
19
+ * of the next.
20
+ *
21
+ * @param data - The raw entity map to migrate
22
+ * @param fileVersion - The version of the data (from file's _version, or 0 if absent)
23
+ * @param targetVersion - The target schema version from collection config
24
+ * @param migrations - The full migration registry for this collection
25
+ * @param collectionName - Name of the collection (for error messages)
26
+ * @returns Effect<Record<string, unknown>, MigrationError> - the migrated data
27
+ */
28
+ export const runMigrations = (data, fileVersion, targetVersion, migrations, collectionName) => {
29
+ // If already at target version, no migrations needed
30
+ if (fileVersion >= targetVersion) {
31
+ return Effect.succeed(data);
32
+ }
33
+ // Filter to migrations that apply: from >= fileVersion and to <= targetVersion
34
+ // Then sort by `from` to ensure correct execution order
35
+ const applicableMigrations = migrations
36
+ .filter((m) => m.from >= fileVersion && m.to <= targetVersion)
37
+ .sort((a, b) => a.from - b.from);
38
+ // Run a single migration step, catching any thrown exceptions
39
+ const runStep = (currentData, migration, stepIndex) => Effect.try({
40
+ try: () => migration.transform(currentData),
41
+ catch: (error) => new MigrationError({
42
+ collection: collectionName,
43
+ fromVersion: migration.from,
44
+ toVersion: migration.to,
45
+ step: stepIndex,
46
+ reason: "transform-failed",
47
+ message: `Migration ${migration.from}→${migration.to} failed: ${error instanceof Error ? error.message : String(error)}`,
48
+ }),
49
+ });
50
+ // Chain all migrations using reduce
51
+ return applicableMigrations.reduce((acc, migration, stepIndex) => acc.pipe(Effect.flatMap((d) => runStep(d, migration, stepIndex))), Effect.succeed(data));
52
+ };
53
+ // ============================================================================
54
+ // Migration Registry Validation
55
+ // ============================================================================
56
+ /**
57
+ * Validate that a migration registry forms a valid, contiguous chain.
58
+ *
59
+ * Validation rules:
60
+ * - Migrations must form a contiguous chain (no gaps in `from`/`to`)
61
+ * - Each migration's `to` must equal `from + 1`
62
+ * - No duplicate `from` values
63
+ * - The last migration's `to` must equal the collection's `version`
64
+ * - Version 0 with no migrations is valid
65
+ * - Version > 0 with empty migrations is invalid
66
+ *
67
+ * @param collectionName - Name of the collection (for error messages)
68
+ * @param version - Target schema version from collection config
69
+ * @param migrations - Array of migrations to validate
70
+ * @returns Effect<void, MigrationError> - succeeds if valid, fails with MigrationError if invalid
71
+ */
72
+ export const validateMigrationRegistry = (collectionName, version, migrations) => {
73
+ // Version 0 with no migrations is valid (no migrations needed)
74
+ if (version === 0 && migrations.length === 0) {
75
+ return Effect.void;
76
+ }
77
+ // Version > 0 with empty migrations is invalid (no path from 0 to current)
78
+ if (version > 0 && migrations.length === 0) {
79
+ return Effect.fail(new MigrationError({
80
+ collection: collectionName,
81
+ fromVersion: 0,
82
+ toVersion: version,
83
+ step: -1,
84
+ reason: "empty-registry",
85
+ message: `Collection "${collectionName}" has version ${version} but no migrations defined. Cannot migrate from version 0 to ${version}.`,
86
+ }));
87
+ }
88
+ // Check each migration's to === from + 1
89
+ for (let i = 0; i < migrations.length; i++) {
90
+ const migration = migrations[i];
91
+ if (migration.to !== migration.from + 1) {
92
+ return Effect.fail(new MigrationError({
93
+ collection: collectionName,
94
+ fromVersion: migration.from,
95
+ toVersion: migration.to,
96
+ step: i,
97
+ reason: "invalid-increment",
98
+ message: `Migration at index ${i} has from=${migration.from} and to=${migration.to}, but to must equal from + 1.`,
99
+ }));
100
+ }
101
+ }
102
+ // Check for duplicate `from` values
103
+ const fromValues = new Set();
104
+ for (let i = 0; i < migrations.length; i++) {
105
+ const migration = migrations[i];
106
+ if (fromValues.has(migration.from)) {
107
+ return Effect.fail(new MigrationError({
108
+ collection: collectionName,
109
+ fromVersion: migration.from,
110
+ toVersion: migration.to,
111
+ step: i,
112
+ reason: "duplicate-from",
113
+ message: `Duplicate migration from version ${migration.from}. Each version can only have one migration.`,
114
+ }));
115
+ }
116
+ fromValues.add(migration.from);
117
+ }
118
+ // Sort migrations by `from` to check for contiguous chain
119
+ const sortedMigrations = [...migrations].sort((a, b) => a.from - b.from);
120
+ // Check that first migration starts from version 0
121
+ // (data without _version is treated as version 0, so we need a path from 0)
122
+ const firstMigration = sortedMigrations[0];
123
+ if (firstMigration.from !== 0) {
124
+ return Effect.fail(new MigrationError({
125
+ collection: collectionName,
126
+ fromVersion: 0,
127
+ toVersion: firstMigration.from,
128
+ step: -1,
129
+ reason: "missing-start",
130
+ message: `First migration starts at version ${firstMigration.from}, but must start at version 0. No path from version 0 to ${firstMigration.from}.`,
131
+ }));
132
+ }
133
+ // Check for contiguous chain (no gaps)
134
+ for (let i = 1; i < sortedMigrations.length; i++) {
135
+ const prev = sortedMigrations[i - 1];
136
+ const curr = sortedMigrations[i];
137
+ if (curr.from !== prev.to) {
138
+ return Effect.fail(new MigrationError({
139
+ collection: collectionName,
140
+ fromVersion: prev.to,
141
+ toVersion: curr.from,
142
+ step: -1,
143
+ reason: "gap-in-chain",
144
+ message: `Gap in migration chain: no migration from version ${prev.to} to ${curr.from}.`,
145
+ }));
146
+ }
147
+ }
148
+ // Check that last migration's `to` matches the version
149
+ const lastMigration = sortedMigrations[sortedMigrations.length - 1];
150
+ if (lastMigration.to !== version) {
151
+ return Effect.fail(new MigrationError({
152
+ collection: collectionName,
153
+ fromVersion: lastMigration.from,
154
+ toVersion: lastMigration.to,
155
+ step: -1,
156
+ reason: "version-mismatch",
157
+ message: `Last migration goes to version ${lastMigration.to}, but collection version is ${version}.`,
158
+ }));
159
+ }
160
+ return Effect.void;
161
+ };
162
+ /**
163
+ * Preview which files need migration and what transforms would apply.
164
+ *
165
+ * For each versioned collection with a file path:
166
+ * - Read the file and extract `_version`
167
+ * - Compare to config `version`
168
+ * - List which migrations would apply (without running transforms)
169
+ * - Report status
170
+ *
171
+ * No transforms are executed. No files are written.
172
+ *
173
+ * @param config - The database configuration
174
+ * @param _stateRefs - State refs (unused, but kept for API consistency)
175
+ * @returns Effect<DryRunResult, MigrationError | StorageError | SerializationError | UnsupportedFormatError>
176
+ */
177
+ export const dryRunMigrations = (config, _stateRefs) => Effect.gen(function* () {
178
+ const storage = yield* StorageAdapter;
179
+ const serializer = yield* SerializerRegistry;
180
+ const collectionResults = [];
181
+ for (const collectionName of Object.keys(config)) {
182
+ const collectionConfig = config[collectionName];
183
+ // Skip unversioned collections
184
+ if (collectionConfig.version === undefined) {
185
+ continue;
186
+ }
187
+ const targetVersion = collectionConfig.version;
188
+ const filePath = collectionConfig.file;
189
+ // Skip collections without a file path
190
+ if (!filePath) {
191
+ continue;
192
+ }
193
+ // Check if file exists
194
+ const fileExists = yield* storage.exists(filePath);
195
+ if (!fileExists) {
196
+ // File doesn't exist - report as no-file
197
+ collectionResults.push({
198
+ name: collectionName,
199
+ filePath,
200
+ currentVersion: 0,
201
+ targetVersion,
202
+ migrationsToApply: [],
203
+ status: "no-file",
204
+ });
205
+ continue;
206
+ }
207
+ // Read and deserialize the file to extract _version
208
+ const raw = yield* storage.read(filePath);
209
+ // Extract file extension for deserializer
210
+ const extMatch = filePath.match(/\.([^.]+)$/);
211
+ const ext = extMatch ? extMatch[1] : "json";
212
+ const parsed = yield* serializer.deserialize(raw, ext);
213
+ // Check if parsed is an object
214
+ if (typeof parsed !== "object" ||
215
+ parsed === null ||
216
+ Array.isArray(parsed)) {
217
+ return yield* Effect.fail(new MigrationError({
218
+ collection: collectionName,
219
+ fromVersion: 0,
220
+ toVersion: targetVersion,
221
+ step: -1,
222
+ reason: "invalid-file-format",
223
+ message: `File '${filePath}' does not contain a valid object`,
224
+ }));
225
+ }
226
+ // Extract _version from file (default 0 if absent)
227
+ const fileVersion = typeof parsed._version === "number"
228
+ ? parsed._version
229
+ : 0;
230
+ // Determine status and migrations to apply
231
+ let status;
232
+ let migrationsToApply = [];
233
+ if (fileVersion > targetVersion) {
234
+ // File version ahead of config - cannot migrate
235
+ status = "ahead";
236
+ }
237
+ else if (fileVersion === targetVersion) {
238
+ // Already at target version
239
+ status = "up-to-date";
240
+ }
241
+ else {
242
+ // File version < target version - needs migration
243
+ status = "needs-migration";
244
+ // Filter applicable migrations
245
+ const migrations = collectionConfig.migrations ?? [];
246
+ migrationsToApply = migrations
247
+ .filter((m) => m.from >= fileVersion && m.to <= targetVersion)
248
+ .sort((a, b) => a.from - b.from)
249
+ .map((m) => {
250
+ const result = {
251
+ from: m.from,
252
+ to: m.to,
253
+ };
254
+ if (m.description !== undefined) {
255
+ return { ...result, description: m.description };
256
+ }
257
+ return result;
258
+ });
259
+ }
260
+ collectionResults.push({
261
+ name: collectionName,
262
+ filePath,
263
+ currentVersion: fileVersion,
264
+ targetVersion,
265
+ migrationsToApply,
266
+ status,
267
+ });
268
+ }
269
+ return { collections: collectionResults };
270
+ });
271
+ //# sourceMappingURL=migration-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-runner.js","sourceRoot":"","sources":["../../src/migrations/migration-runner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAM/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,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version to the next.
3
+ *
4
+ * Migrations are pure synchronous functions that operate on raw deserialized
5
+ * data (plain objects) before schema decoding. This is necessary because the
6
+ * old data doesn't conform to the new schema.
7
+ */
8
+ export interface Migration {
9
+ /**
10
+ * Source version (the version being migrated from).
11
+ */
12
+ readonly from: number;
13
+ /**
14
+ * Target version (must be `from + 1`).
15
+ */
16
+ readonly to: number;
17
+ /**
18
+ * Transform function that converts the entity map from the source
19
+ * version to the target version.
20
+ *
21
+ * Receives the entire entity map (all entities keyed by ID) and returns
22
+ * the transformed map. This allows cross-entity transformations.
23
+ */
24
+ readonly transform: (data: Record<string, unknown>) => Record<string, unknown>;
25
+ /**
26
+ * Optional human-readable description of what this migration does.
27
+ * Used in dry-run output.
28
+ */
29
+ readonly description?: string;
30
+ }
31
+ /**
32
+ * Status of a collection in a dry-run result.
33
+ */
34
+ export type DryRunStatus = "up-to-date" | "needs-migration" | "ahead" | "no-file";
35
+ /**
36
+ * Information about a single migration that would be applied.
37
+ */
38
+ export interface DryRunMigration {
39
+ readonly from: number;
40
+ readonly to: number;
41
+ readonly description?: string;
42
+ }
43
+ /**
44
+ * Status of a single collection in a dry-run result.
45
+ */
46
+ export interface DryRunCollectionResult {
47
+ readonly name: string;
48
+ readonly filePath: string;
49
+ readonly currentVersion: number;
50
+ readonly targetVersion: number;
51
+ readonly migrationsToApply: ReadonlyArray<DryRunMigration>;
52
+ readonly status: DryRunStatus;
53
+ }
54
+ /**
55
+ * Result of a dry-run migration check.
56
+ *
57
+ * Contains status for each versioned collection, showing which migrations
58
+ * would be applied without actually executing any transforms or writing files.
59
+ */
60
+ export interface DryRunResult {
61
+ readonly collections: ReadonlyArray<DryRunCollectionResult>;
62
+ }
63
+ //# sourceMappingURL=migration-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-types.d.ts","sourceRoot":"","sources":["../../src/migrations/migration-types.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACzB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,CACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B;AAMD;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB,YAAY,GACZ,iBAAiB,GACjB,OAAO,GACP,SAAS,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;CAC5D"}
@@ -0,0 +1,5 @@
1
+ // ============================================================================
2
+ // Migration Types
3
+ // ============================================================================
4
+ export {};
5
+ //# sourceMappingURL=migration-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-types.js","sourceRoot":"","sources":["../../src/migrations/migration-types.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Effect-based create operations with relationship support.
3
+ *
4
+ * Uses Ref<ReadonlyMap> for atomic state mutation, Effect Schema for validation,
5
+ * and typed errors. Supports $connect, $create, and $connectOrCreate operations
6
+ * for both ref (single) and inverse (many) relationship types.
7
+ */
8
+ import { Effect, PubSub, Ref, type Schema } from "effect";
9
+ import { ForeignKeyError, type OperationError, ValidationError } from "../../errors/crud-errors.js";
10
+ import type { ComputedFieldsConfig } from "../../types/computed-types.js";
11
+ import type { CreateWithRelationshipsInput } from "../../types/crud-relationship-types.js";
12
+ import type { ChangeEvent } from "../../types/reactive-types.js";
13
+ import type { RelationshipDef } from "../../types/types.js";
14
+ type HasId = {
15
+ readonly id: string;
16
+ };
17
+ type RelationshipConfig = {
18
+ readonly type: "ref" | "inverse";
19
+ readonly target?: string;
20
+ readonly __targetCollection?: string;
21
+ readonly foreignKey?: string;
22
+ };
23
+ type CollectionConfig = {
24
+ readonly schema: Schema.Schema<HasId, unknown>;
25
+ readonly relationships: Record<string, RelationshipConfig>;
26
+ };
27
+ type DatabaseConfig = Record<string, CollectionConfig>;
28
+ /**
29
+ * Create a single entity with relationship support.
30
+ *
31
+ * Steps:
32
+ * 1. Strip computed field keys from input (they are derived, not stored)
33
+ * 2. Parse relationship operations from input
34
+ * 3. Generate parent ID early for use in inverse relationships
35
+ * 4. Process $create: create nested entities in target collections
36
+ * 5. Process $connectOrCreate: find or create target entities
37
+ * 6. Process $connect: resolve target entity IDs
38
+ * 7. Set foreign keys from resolved relationships
39
+ * 8. Validate and create the parent entity
40
+ * 9. Update inverse relationship foreign keys on connected entities
41
+ */
42
+ export declare const createWithRelationships: <T extends HasId, I = T>(collectionName: string, schema: Schema.Schema<T, I>, relationships: Record<string, RelationshipConfig>, ref: Ref.Ref<ReadonlyMap<string, T>>, stateRefs: Record<string, Ref.Ref<ReadonlyMap<string, HasId>>>, dbConfig: DatabaseConfig, computed?: ComputedFieldsConfig<unknown>, changePubSub?: PubSub.PubSub<ChangeEvent>) => (input: CreateWithRelationshipsInput<T, Record<string, RelationshipDef>>) => Effect.Effect<T, ValidationError | ForeignKeyError | OperationError>;
43
+ export {};
44
+ //# sourceMappingURL=create-with-relationships.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-with-relationships.d.ts","sourceRoot":"","sources":["../../../src/operations/crud/create-with-relationships.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EACN,eAAe,EACf,KAAK,cAAc,EACnB,eAAe,EACf,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAEX,4BAA4B,EAG5B,MAAM,wCAAwC,CAAC;AAGhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAS5D,KAAK,KAAK,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC,KAAK,kBAAkB,GAAG;IACzB,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CA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