effect-app 4.0.0-beta.99 → 4.0.1

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 (391) hide show
  1. package/CHANGELOG.md +2042 -0
  2. package/dist/Array.d.ts +1 -17
  3. package/dist/Array.d.ts.map +1 -1
  4. package/dist/Array.js +3 -27
  5. package/dist/Chunk.d.ts +3 -27
  6. package/dist/Chunk.d.ts.map +1 -1
  7. package/dist/Chunk.js +4 -39
  8. package/dist/Config/SecretURL.d.ts +3 -1
  9. package/dist/Config/SecretURL.d.ts.map +1 -1
  10. package/dist/Config/SecretURL.js +3 -6
  11. package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
  12. package/dist/Config/internal/configSecretURL.js +2 -2
  13. package/dist/Config.d.ts +0 -5
  14. package/dist/Config.d.ts.map +1 -1
  15. package/dist/Config.js +7 -5
  16. package/dist/ConfigProvider.d.ts +0 -37
  17. package/dist/ConfigProvider.d.ts.map +1 -1
  18. package/dist/ConfigProvider.js +5 -41
  19. package/dist/Context.d.ts +6 -4
  20. package/dist/Context.d.ts.map +1 -1
  21. package/dist/Context.js +4 -3
  22. package/dist/DataDependencies.d.ts +136 -0
  23. package/dist/DataDependencies.d.ts.map +1 -0
  24. package/dist/DataDependencies.js +112 -0
  25. package/dist/DateTime.d.ts +33 -0
  26. package/dist/DateTime.d.ts.map +1 -0
  27. package/dist/DateTime.js +18 -0
  28. package/dist/Effect.d.ts +3 -14
  29. package/dist/Effect.d.ts.map +1 -1
  30. package/dist/Effect.js +8 -26
  31. package/dist/Emailer.d.ts +51 -0
  32. package/dist/Emailer.d.ts.map +1 -0
  33. package/dist/Emailer.js +7 -0
  34. package/dist/Function.d.ts +0 -4
  35. package/dist/Function.d.ts.map +1 -1
  36. package/dist/Function.js +1 -7
  37. package/dist/Layer.d.ts +6 -3
  38. package/dist/Layer.d.ts.map +1 -1
  39. package/dist/Layer.js +3 -2
  40. package/dist/Model/Repository/Registry.d.ts +22 -0
  41. package/dist/Model/Repository/Registry.d.ts.map +1 -0
  42. package/dist/Model/Repository/Registry.js +18 -0
  43. package/dist/Model/Repository/dependency.d.ts +6 -0
  44. package/dist/Model/Repository/dependency.d.ts.map +1 -0
  45. package/dist/Model/Repository/dependency.js +29 -0
  46. package/dist/Model/Repository/ext.d.ts +60 -0
  47. package/dist/Model/Repository/ext.d.ts.map +1 -0
  48. package/dist/Model/Repository/ext.js +124 -0
  49. package/dist/Model/Repository/internal/internal.d.ts +68 -0
  50. package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
  51. package/dist/Model/Repository/internal/internal.js +610 -0
  52. package/dist/Model/Repository/legacy.d.ts +21 -0
  53. package/dist/Model/Repository/legacy.d.ts.map +1 -0
  54. package/dist/Model/Repository/legacy.js +2 -0
  55. package/dist/Model/Repository/makeRepo.d.ts +71 -0
  56. package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
  57. package/dist/Model/Repository/makeRepo.js +30 -0
  58. package/dist/Model/Repository/service.d.ts +121 -0
  59. package/dist/Model/Repository/service.d.ts.map +1 -0
  60. package/dist/Model/Repository/service.js +2 -0
  61. package/dist/Model/Repository/validation.d.ts +72 -0
  62. package/dist/Model/Repository/validation.d.ts.map +1 -0
  63. package/dist/Model/Repository/validation.js +39 -0
  64. package/dist/Model/Repository.d.ts +8 -0
  65. package/dist/Model/Repository.d.ts.map +1 -0
  66. package/dist/Model/Repository.js +8 -0
  67. package/dist/Model/dsl.d.ts +34 -0
  68. package/dist/Model/dsl.d.ts.map +1 -0
  69. package/dist/Model/dsl.js +45 -0
  70. package/dist/Model/filter/filterApi.d.ts +30 -0
  71. package/dist/Model/filter/filterApi.d.ts.map +1 -0
  72. package/dist/Model/filter/filterApi.js +2 -0
  73. package/dist/Model/filter/types/errors.d.ts +29 -0
  74. package/dist/Model/filter/types/errors.d.ts.map +1 -0
  75. package/dist/Model/filter/types/errors.js +2 -0
  76. package/dist/Model/filter/types/fields.d.ts +15 -0
  77. package/dist/Model/filter/types/fields.d.ts.map +1 -0
  78. package/dist/Model/filter/types/fields.js +2 -0
  79. package/dist/Model/filter/types/path/common.d.ts +316 -0
  80. package/dist/Model/filter/types/path/common.d.ts.map +1 -0
  81. package/dist/Model/filter/types/path/common.js +2 -0
  82. package/dist/Model/filter/types/path/eager.d.ts +94 -0
  83. package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
  84. package/dist/Model/filter/types/path/eager.js +36 -0
  85. package/dist/Model/filter/types/path/index.d.ts +4 -0
  86. package/dist/Model/filter/types/path/index.d.ts.map +1 -0
  87. package/dist/Model/filter/types/path/index.js +3 -0
  88. package/dist/Model/filter/types/utils.d.ts +79 -0
  89. package/dist/Model/filter/types/utils.d.ts.map +1 -0
  90. package/dist/Model/filter/types/utils.js +2 -0
  91. package/dist/Model/filter/types/validator.d.ts +30 -0
  92. package/dist/Model/filter/types/validator.d.ts.map +1 -0
  93. package/dist/Model/filter/types/validator.js +2 -0
  94. package/dist/Model/filter/types.d.ts +5 -0
  95. package/dist/Model/filter/types.d.ts.map +1 -0
  96. package/dist/Model/filter/types.js +7 -0
  97. package/dist/Model/query/dsl.d.ts +630 -0
  98. package/dist/Model/query/dsl.d.ts.map +1 -0
  99. package/dist/Model/query/dsl.js +376 -0
  100. package/dist/Model/query/new-kid-interpreter.d.ts +132 -0
  101. package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
  102. package/dist/Model/query/new-kid-interpreter.js +369 -0
  103. package/dist/Model/query.d.ts +15 -0
  104. package/dist/Model/query.d.ts.map +1 -0
  105. package/dist/Model/query.js +3 -0
  106. package/dist/Model.d.ts +6 -0
  107. package/dist/Model.d.ts.map +1 -0
  108. package/dist/Model.js +6 -0
  109. package/dist/NonEmptySet.d.ts +3 -1
  110. package/dist/NonEmptySet.d.ts.map +1 -1
  111. package/dist/NonEmptySet.js +2 -2
  112. package/dist/Option.d.ts +1 -2
  113. package/dist/Option.d.ts.map +1 -1
  114. package/dist/Option.js +3 -7
  115. package/dist/Pure.d.ts +9 -7
  116. package/dist/Pure.d.ts.map +1 -1
  117. package/dist/Pure.js +20 -17
  118. package/dist/QueueMaker.d.ts +11 -0
  119. package/dist/QueueMaker.d.ts.map +1 -0
  120. package/dist/QueueMaker.js +11 -0
  121. package/dist/RequestContext.d.ts +87 -0
  122. package/dist/RequestContext.d.ts.map +1 -0
  123. package/dist/RequestContext.js +45 -0
  124. package/dist/RequestScopedDependencies.d.ts +21 -0
  125. package/dist/RequestScopedDependencies.d.ts.map +1 -0
  126. package/dist/RequestScopedDependencies.js +16 -0
  127. package/dist/Schema/Class.d.ts +163 -16
  128. package/dist/Schema/Class.d.ts.map +1 -1
  129. package/dist/Schema/Class.js +193 -21
  130. package/dist/Schema/FastCheck.d.ts.map +1 -1
  131. package/dist/Schema/SchemaParser.d.ts +5 -0
  132. package/dist/Schema/SchemaParser.d.ts.map +1 -0
  133. package/dist/Schema/SchemaParser.js +6 -0
  134. package/dist/Schema/SpecialJsonSchema.d.ts +15 -2
  135. package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -1
  136. package/dist/Schema/SpecialJsonSchema.js +70 -12
  137. package/dist/Schema/SpecialOpenApi.d.ts +1 -1
  138. package/dist/Schema/SpecialOpenApi.js +3 -3
  139. package/dist/Schema/brand.d.ts +5 -5
  140. package/dist/Schema/brand.d.ts.map +1 -1
  141. package/dist/Schema/brand.js +6 -4
  142. package/dist/Schema/email.d.ts.map +1 -1
  143. package/dist/Schema/email.js +8 -5
  144. package/dist/Schema/ext.d.ts +279 -75
  145. package/dist/Schema/ext.d.ts.map +1 -1
  146. package/dist/Schema/ext.js +330 -72
  147. package/dist/Schema/moreStrings.d.ts +82 -48
  148. package/dist/Schema/moreStrings.d.ts.map +1 -1
  149. package/dist/Schema/moreStrings.js +85 -51
  150. package/dist/Schema/numbers.d.ts +33 -21
  151. package/dist/Schema/numbers.d.ts.map +1 -1
  152. package/dist/Schema/numbers.js +64 -12
  153. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  154. package/dist/Schema/phoneNumber.js +6 -6
  155. package/dist/Schema/schema.d.ts +1 -1
  156. package/dist/Schema/schema.d.ts.map +1 -1
  157. package/dist/Schema/schema.js +2 -2
  158. package/dist/Schema/strings.d.ts +18 -4
  159. package/dist/Schema/strings.d.ts.map +1 -1
  160. package/dist/Schema/strings.js +1 -5
  161. package/dist/Schema.d.ts +224 -7
  162. package/dist/Schema.d.ts.map +1 -1
  163. package/dist/Schema.js +190 -24
  164. package/dist/SchemaAST.d.ts +2 -0
  165. package/dist/SchemaAST.d.ts.map +1 -0
  166. package/dist/SchemaAST.js +2 -0
  167. package/dist/Set.d.ts +4 -1
  168. package/dist/Set.d.ts.map +1 -1
  169. package/dist/Set.js +8 -6
  170. package/dist/Store.d.ts +215 -0
  171. package/dist/Store.d.ts.map +1 -0
  172. package/dist/Store.js +113 -0
  173. package/dist/_ext/Array.d.ts +1 -1
  174. package/dist/_ext/Array.d.ts.map +1 -1
  175. package/dist/_ext/Array.js +4 -2
  176. package/dist/_ext/ord.ext.d.ts +2 -1
  177. package/dist/_ext/ord.ext.d.ts.map +1 -1
  178. package/dist/_ext/ord.ext.js +2 -2
  179. package/dist/builtin.d.ts +2 -14
  180. package/dist/builtin.d.ts.map +1 -1
  181. package/dist/builtin.js +1 -1
  182. package/dist/client/InvalidationKeys.d.ts +30 -0
  183. package/dist/client/InvalidationKeys.d.ts.map +1 -0
  184. package/dist/client/InvalidationKeys.js +37 -0
  185. package/dist/client/apiClientFactory.d.ts +13 -8
  186. package/dist/client/apiClientFactory.d.ts.map +1 -1
  187. package/dist/client/apiClientFactory.js +154 -34
  188. package/dist/client/clientFor.d.ts +48 -13
  189. package/dist/client/clientFor.d.ts.map +1 -1
  190. package/dist/client/clientFor.js +9 -1
  191. package/dist/client/errors.d.ts +74 -28
  192. package/dist/client/errors.d.ts.map +1 -1
  193. package/dist/client/errors.js +41 -10
  194. package/dist/client/makeClient.d.ts +487 -32
  195. package/dist/client/makeClient.d.ts.map +1 -1
  196. package/dist/client/makeClient.js +47 -21
  197. package/dist/client.d.ts +2 -0
  198. package/dist/client.d.ts.map +1 -1
  199. package/dist/client.js +3 -1
  200. package/dist/faker.d.ts.map +1 -1
  201. package/dist/http/Request.d.ts +2 -2
  202. package/dist/http/Request.d.ts.map +1 -1
  203. package/dist/http/Request.js +2 -2
  204. package/dist/http/internal/lib.d.ts +12 -12
  205. package/dist/http/internal/lib.d.ts.map +1 -1
  206. package/dist/http/internal/lib.js +13 -13
  207. package/dist/ids.d.ts +32 -14
  208. package/dist/ids.d.ts.map +1 -1
  209. package/dist/ids.js +38 -7
  210. package/dist/index.d.ts +3 -0
  211. package/dist/index.d.ts.map +1 -1
  212. package/dist/index.js +5 -1
  213. package/dist/middleware.d.ts +12 -6
  214. package/dist/middleware.d.ts.map +1 -1
  215. package/dist/middleware.js +13 -7
  216. package/dist/migration/nativeEffect.d.ts +21 -0
  217. package/dist/migration/nativeEffect.d.ts.map +1 -0
  218. package/dist/migration/nativeEffect.js +598 -0
  219. package/dist/rpc/Invalidation.d.ts +1124 -0
  220. package/dist/rpc/Invalidation.d.ts.map +1 -0
  221. package/dist/rpc/Invalidation.js +178 -0
  222. package/dist/rpc/MiddlewareMaker.d.ts +10 -7
  223. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  224. package/dist/rpc/MiddlewareMaker.js +57 -37
  225. package/dist/rpc/RpcContextMap.d.ts +2 -2
  226. package/dist/rpc/RpcContextMap.d.ts.map +1 -1
  227. package/dist/rpc/RpcMiddleware.d.ts +13 -10
  228. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  229. package/dist/rpc/RpcMiddleware.js +2 -2
  230. package/dist/rpc.d.ts +1 -1
  231. package/dist/rpc.d.ts.map +1 -1
  232. package/dist/rpc.js +2 -2
  233. package/dist/runtime.d.ts +19 -0
  234. package/dist/runtime.d.ts.map +1 -0
  235. package/dist/runtime.js +40 -0
  236. package/dist/setupRequest.d.ts +20 -0
  237. package/dist/setupRequest.d.ts.map +1 -0
  238. package/dist/setupRequest.js +72 -0
  239. package/dist/toast.d.ts +51 -0
  240. package/dist/toast.d.ts.map +1 -0
  241. package/dist/toast.js +34 -0
  242. package/dist/transform.d.ts +1 -1
  243. package/dist/transform.d.ts.map +1 -1
  244. package/dist/transform.js +4 -5
  245. package/dist/utils/effectify.d.ts +1 -1
  246. package/dist/utils/effectify.d.ts.map +1 -1
  247. package/dist/utils/effectify.js +2 -2
  248. package/dist/utils/extend.d.ts +6 -1
  249. package/dist/utils/extend.d.ts.map +1 -1
  250. package/dist/utils/extend.js +24 -6
  251. package/dist/utils/gen.d.ts +4 -4
  252. package/dist/utils/gen.d.ts.map +1 -1
  253. package/dist/utils/logLevel.d.ts +2 -2
  254. package/dist/utils/logLevel.d.ts.map +1 -1
  255. package/dist/utils/logger.d.ts +2 -1
  256. package/dist/utils/logger.d.ts.map +1 -1
  257. package/dist/utils/logger.js +2 -2
  258. package/dist/utils.d.ts +34 -45
  259. package/dist/utils.d.ts.map +1 -1
  260. package/dist/utils.js +33 -49
  261. package/dist/validation/validators.d.ts.map +1 -1
  262. package/dist/validation.d.ts.map +1 -1
  263. package/dist/withToast.d.ts +30 -0
  264. package/dist/withToast.d.ts.map +1 -0
  265. package/dist/withToast.js +64 -0
  266. package/package.json +25 -266
  267. package/src/Array.ts +7 -39
  268. package/src/Chunk.ts +6 -55
  269. package/src/Config/SecretURL.ts +6 -3
  270. package/src/Config/internal/configSecretURL.ts +2 -2
  271. package/src/Config.ts +6 -13
  272. package/src/ConfigProvider.ts +4 -47
  273. package/src/Context.ts +9 -8
  274. package/src/DataDependencies.ts +171 -0
  275. package/src/DateTime.ts +473 -0
  276. package/src/Effect.ts +10 -32
  277. package/src/Emailer.ts +51 -0
  278. package/src/Function.ts +0 -7
  279. package/src/Inputify.type.ts +1 -1
  280. package/src/Layer.ts +8 -5
  281. package/src/Model/Repository/Registry.ts +35 -0
  282. package/src/Model/Repository/dependency.ts +32 -0
  283. package/src/Model/Repository/ext.ts +374 -0
  284. package/src/Model/Repository/internal/internal.ts +987 -0
  285. package/src/Model/Repository/legacy.ts +29 -0
  286. package/src/Model/Repository/makeRepo.ts +168 -0
  287. package/src/Model/Repository/service.ts +676 -0
  288. package/src/Model/Repository/validation.ts +38 -0
  289. package/src/Model/Repository.ts +7 -0
  290. package/src/Model/dsl.ts +130 -0
  291. package/src/Model/filter/filterApi.ts +78 -0
  292. package/src/Model/filter/types/errors.ts +47 -0
  293. package/src/Model/filter/types/fields.ts +50 -0
  294. package/src/Model/filter/types/path/common.ts +404 -0
  295. package/src/Model/filter/types/path/eager.ts +329 -0
  296. package/src/Model/filter/types/path/index.ts +4 -0
  297. package/src/Model/filter/types/utils.ts +128 -0
  298. package/src/Model/filter/types/validator.ts +46 -0
  299. package/src/Model/filter/types.ts +6 -0
  300. package/src/Model/query/dsl.ts +3092 -0
  301. package/src/Model/query/new-kid-interpreter.ts +531 -0
  302. package/src/Model/query.ts +13 -0
  303. package/src/Model.ts +5 -0
  304. package/src/NonEmptySet.ts +6 -4
  305. package/src/Option.ts +3 -8
  306. package/src/Pure.ts +20 -17
  307. package/src/QueueMaker.ts +11 -0
  308. package/src/RequestContext.ts +48 -0
  309. package/src/RequestScopedDependencies.ts +45 -0
  310. package/src/Schema/Class.ts +550 -56
  311. package/src/Schema/SchemaParser.ts +12 -0
  312. package/src/Schema/SpecialJsonSchema.ts +75 -7
  313. package/src/Schema/SpecialOpenApi.ts +5 -5
  314. package/src/Schema/brand.ts +27 -12
  315. package/src/Schema/email.ts +9 -7
  316. package/src/Schema/ext.ts +405 -95
  317. package/src/Schema/moreStrings.ts +213 -88
  318. package/src/Schema/numbers.ts +107 -29
  319. package/src/Schema/phoneNumber.ts +8 -9
  320. package/src/Schema/schema.ts +1 -1
  321. package/src/Schema/strings.ts +23 -14
  322. package/src/Schema.ts +403 -46
  323. package/src/SchemaAST.ts +1 -0
  324. package/src/Set.ts +10 -5
  325. package/src/Store.ts +325 -0
  326. package/src/_ext/Array.ts +4 -2
  327. package/src/_ext/ord.ext.ts +2 -1
  328. package/src/builtin-json.d.ts +24 -0
  329. package/src/builtin.ts +16 -21
  330. package/src/client/InvalidationKeys.ts +55 -0
  331. package/src/client/apiClientFactory.ts +295 -129
  332. package/src/client/clientFor.ts +101 -33
  333. package/src/client/errors.ts +66 -20
  334. package/src/client/makeClient.ts +519 -60
  335. package/src/client.ts +6 -4
  336. package/src/http/Request.ts +4 -4
  337. package/src/http/internal/lib.ts +12 -12
  338. package/src/http.ts +1 -1
  339. package/src/ids.ts +45 -8
  340. package/src/index.ts +20 -16
  341. package/src/middleware.ts +12 -8
  342. package/src/migration/nativeEffect.ts +645 -0
  343. package/src/rpc/Invalidation.ts +278 -0
  344. package/src/rpc/MiddlewareMaker.ts +86 -79
  345. package/src/rpc/README.md +2 -2
  346. package/src/rpc/RpcContextMap.ts +4 -4
  347. package/src/rpc/RpcMiddleware.ts +18 -13
  348. package/src/rpc.ts +4 -4
  349. package/src/runtime.ts +57 -0
  350. package/src/setupRequest.ts +138 -0
  351. package/src/toast.ts +54 -0
  352. package/src/transform.ts +4 -4
  353. package/src/utils/effectify.ts +1 -1
  354. package/src/utils/extend.ts +24 -5
  355. package/src/utils/gen.ts +7 -7
  356. package/src/utils/logLevel.ts +1 -1
  357. package/src/utils/logger.ts +3 -2
  358. package/src/utils.ts +85 -175
  359. package/src/validation.ts +2 -2
  360. package/src/withToast.ts +133 -0
  361. package/test/dateTimeLocal.test.ts +55 -0
  362. package/test/dist/dateTimeLocal.test.d.ts.map +1 -0
  363. package/test/dist/nativeEffectMigration.test.d.ts.map +1 -0
  364. package/test/dist/rpc.test.d.ts.map +1 -1
  365. package/test/dist/rpcMiddlewareContext.test.d.ts.map +1 -0
  366. package/test/moreStrings.test.ts +55 -10
  367. package/test/nativeEffectMigration.test.ts +77 -0
  368. package/test/rpc.test.ts +28 -11
  369. package/test/rpcMiddlewareContext.test.ts +63 -0
  370. package/test/schema.test.ts +318 -55
  371. package/test/secretURL.test.ts +4 -1
  372. package/test/special.test.ts +663 -131
  373. package/test/utils.test.ts +5 -5
  374. package/tsconfig.base.json +6 -4
  375. package/tsconfig.json +9 -1
  376. package/tsconfig.src.json +29 -29
  377. package/tsconfig.test.json +2 -2
  378. package/dist/Operations.d.ts +0 -124
  379. package/dist/Operations.d.ts.map +0 -1
  380. package/dist/Operations.js +0 -29
  381. package/dist/_ext/date.d.ts +0 -15
  382. package/dist/_ext/date.d.ts.map +0 -1
  383. package/dist/_ext/date.js +0 -16
  384. package/dist/_ext/misc.d.ts +0 -14
  385. package/dist/_ext/misc.d.ts.map +0 -1
  386. package/dist/_ext/misc.js +0 -17
  387. package/eslint.config.mjs +0 -26
  388. package/src/Operations.ts +0 -55
  389. package/src/_ext/date.ts +0 -27
  390. package/src/_ext/misc.ts +0 -46
  391. package/tsconfig.json.bak +0 -12
@@ -0,0 +1,531 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ import { identity } from "effect/Function"
4
+ import * as Array from "../../Array.ts"
5
+ import * as Option from "../../Option.ts"
6
+ import * as S from "../../Schema.ts"
7
+ import * as SchemaAST from "../../SchemaAST.ts"
8
+ import { dropUndefinedT } from "../../utils.ts"
9
+ import type { FilterResult } from "../filter/filterApi.ts"
10
+ import type { FieldValues } from "../filter/types.ts"
11
+ import type { FieldPath } from "../filter/types/path/eager.ts"
12
+ import { make, type Q, type QAll } from "../query/dsl.ts"
13
+
14
+ export type AggregateIrExpression =
15
+ | { readonly _tag: "agg-count" }
16
+ | { readonly _tag: "agg-count-when"; readonly filter: readonly FilterResult[] }
17
+ | { readonly _tag: "agg-sum"; readonly field: string }
18
+ | { readonly _tag: "agg-min"; readonly field: string }
19
+ | { readonly _tag: "agg-max"; readonly field: string }
20
+
21
+ export type AggregateIrItem =
22
+ | AggregateIrExpression
23
+ | { readonly _tag: "agg-field"; readonly path: string }
24
+
25
+ export type ComputedProjectionMathIrExpression =
26
+ | {
27
+ readonly _tag: "field"
28
+ readonly field: string
29
+ }
30
+ | {
31
+ readonly _tag: "mul"
32
+ readonly left: ComputedProjectionMathIrExpression
33
+ readonly right: ComputedProjectionMathIrExpression
34
+ }
35
+
36
+ export type ComputedProjectionIrExpression =
37
+ | {
38
+ readonly _tag: "relation-count"
39
+ readonly path: string
40
+ readonly filter: readonly FilterResult[]
41
+ }
42
+ | {
43
+ readonly _tag: "relation-any"
44
+ readonly path: string
45
+ readonly filter: readonly FilterResult[]
46
+ }
47
+ | {
48
+ readonly _tag: "relation-every"
49
+ readonly path: string
50
+ readonly filter: readonly FilterResult[]
51
+ }
52
+ | {
53
+ readonly _tag: "relation-distinct-count"
54
+ readonly path: string
55
+ readonly field: string
56
+ readonly filter: readonly FilterResult[]
57
+ }
58
+ | {
59
+ readonly _tag: "relation-sum"
60
+ readonly path: string
61
+ readonly field: string
62
+ readonly filter: readonly FilterResult[]
63
+ }
64
+ | {
65
+ readonly _tag: "relation-sum-expr"
66
+ readonly path: string
67
+ readonly expression: ComputedProjectionMathIrExpression
68
+ readonly filter: readonly FilterResult[]
69
+ }
70
+ | {
71
+ readonly _tag: "relation-sum-expr-by"
72
+ readonly path: string
73
+ readonly expression: ComputedProjectionMathIrExpression
74
+ readonly unit: string
75
+ readonly filter: readonly FilterResult[]
76
+ }
77
+ | {
78
+ readonly _tag: "relation-sum-expr-normalized"
79
+ readonly path: string
80
+ readonly expression: ComputedProjectionMathIrExpression
81
+ readonly unit: string
82
+ readonly toBase: string
83
+ readonly factors: Readonly<Record<string, number>>
84
+ readonly filter: readonly FilterResult[]
85
+ }
86
+ | {
87
+ readonly _tag: "relation-collect"
88
+ readonly path: string
89
+ readonly field: string
90
+ readonly distinct: boolean
91
+ readonly filter: readonly FilterResult[]
92
+ }
93
+ | {
94
+ readonly _tag: "relation-collect-fields"
95
+ readonly path: string
96
+ readonly fields: readonly string[]
97
+ readonly distinct: boolean
98
+ readonly filter: readonly FilterResult[]
99
+ }
100
+ | {
101
+ readonly _tag: "relation-length"
102
+ readonly path: string
103
+ }
104
+
105
+ type SelectItem<TFieldValues extends FieldValues> =
106
+ | keyof TFieldValues
107
+ | { key: string; subKeys: string[] }
108
+ | {
109
+ key: string
110
+ computed: ComputedProjectionIrExpression
111
+ }
112
+
113
+ const isArraySelect = <TFieldValues extends FieldValues>(
114
+ item: SelectItem<TFieldValues>
115
+ ): item is { key: string; subKeys: string[] } => typeof item === "object" && item !== null && "subKeys" in item
116
+
117
+ const mergeArraySelect = <TFieldValues extends FieldValues>(
118
+ select: SelectItem<TFieldValues>[],
119
+ arraySelect: { key: string; subKeys: string[] }
120
+ ) => {
121
+ const subKeys = [...new Set(arraySelect.subKeys)]
122
+ const existing = select.find(
123
+ (item): item is { key: string; subKeys: string[] } => isArraySelect(item) && item.key === arraySelect.key
124
+ )
125
+
126
+ if (existing) {
127
+ const existingIndex = select.indexOf(existing)
128
+ select[existingIndex] = {
129
+ key: arraySelect.key,
130
+ subKeys: [...new Set([...existing.subKeys, ...subKeys])]
131
+ }
132
+ } else {
133
+ select.push({ key: arraySelect.key, subKeys })
134
+ }
135
+
136
+ const scalarIndex = select.findIndex((item) => item === arraySelect.key)
137
+ if (scalarIndex >= 0) {
138
+ select.splice(scalarIndex, 1)
139
+ }
140
+ }
141
+
142
+ type Result<TFieldValues extends FieldValues, A = TFieldValues, R = never> = {
143
+ filter: FilterResult[]
144
+ schema: S.Codec<A, TFieldValues, R> | undefined
145
+ limit: number | undefined
146
+ skip: number | undefined
147
+ order: { key: FieldPath<TFieldValues>; direction: "ASC" | "DESC" }[]
148
+ ttype: "one" | "many" | "count" | undefined
149
+ mode: "collect" | "project" | "transform" | "aggregate" | undefined
150
+ computed: Record<string, ComputedProjectionIrExpression> | undefined
151
+ aggregateMap: Record<string, AggregateIrItem> | undefined
152
+ }
153
+
154
+ const interpret = <
155
+ TFieldValues extends FieldValues,
156
+ TFieldValuesRefined extends TFieldValues = TFieldValues,
157
+ A = TFieldValues,
158
+ R = never
159
+ >(_: QAll<TFieldValues, TFieldValuesRefined, A, R>) => {
160
+ const a = _ as Q<TFieldValues>
161
+
162
+ const data: Result<TFieldValues, any, any> = {
163
+ filter: [],
164
+ schema: undefined,
165
+ limit: undefined,
166
+ skip: undefined,
167
+ order: [],
168
+ ttype: undefined,
169
+ mode: undefined,
170
+ computed: undefined,
171
+ aggregateMap: undefined
172
+ }
173
+
174
+ const upd = (
175
+ v: Result<TFieldValues, any, any>
176
+ ) => {
177
+ data.filter.push(...v.filter)
178
+ data.order.push(...v.order)
179
+ if (v.limit !== undefined) data.limit = v.limit
180
+ if (v.skip !== undefined) data.skip = v.skip
181
+ if (v.ttype !== undefined) data.ttype = v.ttype
182
+ if (v.schema !== undefined) data.schema = v.schema
183
+ if (v.mode !== undefined) data.mode = v.mode
184
+ if (v.computed !== undefined) data.computed = v.computed
185
+ if (v.aggregateMap !== undefined) data.aggregateMap = v.aggregateMap
186
+ }
187
+
188
+ const applyPath = (path: string) => (_: FilterResult): FilterResult =>
189
+ _.t === "where" || _.t === "and" || _.t === "or"
190
+ ? { ..._, path: `${path}.-1.${_.path}` }
191
+ : { ..._, result: _.result.map(applyPath(path)) }
192
+
193
+ switch (a._tag) {
194
+ case "value":
195
+ break
196
+ case "where": {
197
+ const { current, operation, relation, subPath } = a
198
+ upd(interpret(current))
199
+ if (typeof operation === "function") {
200
+ data.filter.push(
201
+ {
202
+ t: "where-scope",
203
+ result: interpret(operation(make())).filter.map(subPath ? applyPath(subPath) : identity),
204
+ relation
205
+ }
206
+ )
207
+ } else {
208
+ data.filter.push(
209
+ {
210
+ t: "where",
211
+ path: operation[0],
212
+ op: operation.length === 2 ? "eq" : operation[1],
213
+ value: operation.length === 2 ? operation[1] : operation[2]
214
+ }
215
+ )
216
+ }
217
+ break
218
+ }
219
+ case "and": {
220
+ const { current, operation, relation } = a
221
+ upd(interpret(current))
222
+ if (typeof operation === "function") {
223
+ data.filter.push(
224
+ { t: "and-scope", result: interpret(operation(make())).filter, relation }
225
+ )
226
+ } else {
227
+ data.filter.push(
228
+ {
229
+ t: "and",
230
+ path: operation[0],
231
+ op: operation.length === 2 ? "eq" : operation[1],
232
+ value: operation.length === 2 ? operation[1] : operation[2]
233
+ }
234
+ )
235
+ }
236
+ break
237
+ }
238
+ case "or": {
239
+ const { current, operation, relation } = a
240
+ upd(interpret(current))
241
+ if (typeof operation === "function") {
242
+ data.filter.push(
243
+ { t: "or-scope", result: interpret(operation(make())).filter, relation }
244
+ )
245
+ } else {
246
+ data.filter.push(
247
+ {
248
+ t: "or",
249
+ path: operation[0],
250
+ op: operation.length === 2 ? "eq" : operation[1],
251
+ value: operation.length === 2 ? operation[1] : operation[2]
252
+ }
253
+ )
254
+ }
255
+ break
256
+ }
257
+ case "one": {
258
+ upd(interpret(a.current))
259
+ data.limit = 1
260
+ data.ttype = "one"
261
+ break
262
+ }
263
+ case "count": {
264
+ upd(interpret(a.current))
265
+ data.ttype = "count"
266
+ data.schema = S.Struct({ id: S.String }) as any
267
+ break
268
+ }
269
+ case "order": {
270
+ upd(interpret(a.current))
271
+ data.order.push({ key: a.field, direction: a.direction })
272
+ break
273
+ }
274
+ case "page": {
275
+ upd(interpret(a.current))
276
+ data.limit = a.take
277
+ data.skip = a.skip
278
+ break
279
+ }
280
+ case "project": {
281
+ upd(interpret(a.current))
282
+ if (a.mode === "aggregate" && a.aggregateMap) {
283
+ data.schema = a.schema
284
+ data.mode = "aggregate"
285
+ data.aggregateMap = Object.fromEntries(
286
+ Object.entries(a.aggregateMap).map(([key, expression]) => {
287
+ switch (expression._tag) {
288
+ case "agg-field":
289
+ return [key, { _tag: "agg-field" as const, path: expression.path }]
290
+ case "agg-count":
291
+ return [key, { _tag: "agg-count" as const }]
292
+ case "agg-count-when": {
293
+ const filter = interpret(expression.operation(make())).filter
294
+ return [key, { _tag: "agg-count-when" as const, filter }]
295
+ }
296
+ case "agg-sum":
297
+ return [key, { _tag: "agg-sum" as const, field: expression.field }]
298
+ case "agg-min":
299
+ return [key, { _tag: "agg-min" as const, field: expression.field }]
300
+ case "agg-max":
301
+ return [key, { _tag: "agg-max" as const, field: expression.field }]
302
+ }
303
+ })
304
+ )
305
+ break
306
+ }
307
+ if (a.computed && a.mode === "transform") {
308
+ throw new Error("Computed projections require mode 'project' or 'collect', not 'transform'")
309
+ }
310
+ data.schema = a.schema
311
+ data.mode = a.computed
312
+ ? a.mode === "collect" ? "collect" : "project"
313
+ : a.mode
314
+ data.computed = a.computed
315
+ ? Object.fromEntries(
316
+ Object.entries(a.computed).map(([key, expression]) => {
317
+ const e = expression
318
+ const op = "operation" in e ? e.operation : undefined
319
+ const filter = op ? interpret(op(make())).filter.map(applyPath(e.path)) : []
320
+ switch (e._tag) {
321
+ case "relation-count":
322
+ case "relation-any":
323
+ case "relation-every":
324
+ return [key, { _tag: e._tag, path: e.path, filter }]
325
+ case "relation-distinct-count":
326
+ case "relation-sum":
327
+ return [
328
+ key,
329
+ { _tag: e._tag, path: e.path, field: e.field, filter }
330
+ ]
331
+ case "relation-sum-expr":
332
+ return [
333
+ key,
334
+ { _tag: e._tag, path: e.path, expression: e.expression, filter }
335
+ ]
336
+ case "relation-sum-expr-by":
337
+ return [
338
+ key,
339
+ {
340
+ _tag: e._tag,
341
+ path: e.path,
342
+ expression: e.expression,
343
+ unit: e.unit,
344
+ filter
345
+ }
346
+ ]
347
+ case "relation-sum-expr-normalized":
348
+ return [
349
+ key,
350
+ {
351
+ _tag: e._tag,
352
+ path: e.path,
353
+ expression: e.expression,
354
+ unit: e.unit,
355
+ toBase: e.toBase,
356
+ factors: e.factors,
357
+ filter
358
+ }
359
+ ]
360
+ case "relation-collect":
361
+ return [
362
+ key,
363
+ {
364
+ _tag: e._tag,
365
+ path: e.path,
366
+ field: e.field,
367
+ distinct: e.distinct,
368
+ filter
369
+ }
370
+ ]
371
+ case "relation-collect-fields":
372
+ return [
373
+ key,
374
+ {
375
+ _tag: e._tag,
376
+ path: e.path,
377
+ fields: e.fields,
378
+ distinct: e.distinct,
379
+ filter
380
+ }
381
+ ]
382
+ case "relation-length":
383
+ return [key, { _tag: e._tag, path: e.path }]
384
+ }
385
+ })
386
+ )
387
+ : undefined
388
+ break
389
+ }
390
+ }
391
+
392
+ return data
393
+ }
394
+
395
+ const walkTransformation = (t: S.AST.AST): S.AST.AST => {
396
+ if (S.AST.isDeclaration(t) && t.typeParameters.length > 0) {
397
+ return walkTransformation(t.typeParameters[0]!)
398
+ }
399
+ return t
400
+ }
401
+
402
+ const objectAsts = (ast: S.AST.AST): readonly S.AST.Objects[] => {
403
+ const t = walkTransformation(ast)
404
+ if (S.AST.isObjects(t)) {
405
+ return [t]
406
+ }
407
+ if (S.AST.isUnion(t)) {
408
+ return t.types.flatMap(objectAsts)
409
+ }
410
+ return []
411
+ }
412
+
413
+ const objectKeys = (ast: S.AST.AST): readonly string[] => [
414
+ ...new Set(objectAsts(ast).flatMap((object) => object.propertySignatures.map((_) => _.name as string)))
415
+ ]
416
+
417
+ export const toFilter = <
418
+ TFieldValues extends FieldValues,
419
+ A,
420
+ R,
421
+ TFieldValuesRefined extends TFieldValues = TFieldValues
422
+ >(
423
+ q: QAll<TFieldValues, TFieldValuesRefined, A, R>,
424
+ baseSchema?: S.Schema<unknown>
425
+ ) => {
426
+ // TODO: Native interpreter for each db adapter, instead of the intermediate "new-kid" format
427
+ const a = interpret(q)
428
+
429
+ // Aggregate mode: build select entirely from aggregateMap (no schema-driven field list)
430
+ if (a.mode === "aggregate" && a.aggregateMap) {
431
+ const aggSelect = Object.entries(a.aggregateMap).map(([key, item]) => {
432
+ if (item._tag === "agg-field") {
433
+ return { key, path: item.path }
434
+ }
435
+ return { key, aggregate: item }
436
+ })
437
+ return dropUndefinedT({
438
+ t: null as unknown as TFieldValues,
439
+ limit: a.limit,
440
+ skip: a.skip,
441
+ select: Option.getOrUndefined(Option.liftPredicate(Array.isReadonlyArrayNonEmpty)(aggSelect)) as any,
442
+ schema: a.schema,
443
+ computed: undefined,
444
+ order: Option.getOrUndefined(Option.liftPredicate(Array.isReadonlyArrayNonEmpty)(a.order)),
445
+ ttype: a.ttype,
446
+ mode: "aggregate" as const,
447
+ filter: a.filter.length ? a.filter : undefined
448
+ })
449
+ }
450
+
451
+ const schema = a.schema
452
+ let select: SelectItem<TFieldValues>[] = []
453
+ // TODO: support more complex (nested) schemas?
454
+ if (schema) {
455
+ const t = walkTransformation(SchemaAST.toEncoded(schema.ast))
456
+ const objects = [...objectAsts(t)]
457
+ if (Array.isArrayNonEmpty(objects)) {
458
+ select = [...objectKeys(t)]
459
+ for (const prop of objects.flatMap((_) => _.propertySignatures)) {
460
+ if (S.AST.isArrays(prop.type)) {
461
+ // make sure we only select when there are actually type literals in the tuple...
462
+ // otherwise we might be dealing with strings etc.
463
+ // TODO; be more strict, can't support arrays with unions that have non TypeLiteral members etc..
464
+ const arraySelect = {
465
+ key: prop.name as string,
466
+ subKeys: Array.flatMap(
467
+ prop.type.rest,
468
+ (x) => {
469
+ return objectKeys(x)
470
+ }
471
+ )
472
+ }
473
+ if (arraySelect.subKeys.length > 0) {
474
+ mergeArraySelect(select, arraySelect)
475
+ }
476
+ }
477
+ }
478
+ }
479
+ }
480
+ const computed = a.computed
481
+ const getSelectKey = (_: (typeof select)[number]) => {
482
+ if (typeof _ === "string") {
483
+ return _
484
+ }
485
+ if (typeof _ === "object" && _ !== null && "key" in _) {
486
+ return _.key
487
+ }
488
+ return String(_)
489
+ }
490
+ const schemaKeys = select.map(getSelectKey)
491
+ const nonEncodedSchemaKeys = (() => {
492
+ if (!baseSchema) {
493
+ return [] as string[]
494
+ }
495
+ const encoded = walkTransformation(SchemaAST.toEncoded(baseSchema.ast))
496
+ const encodedKeys = objectKeys(encoded)
497
+ return schemaKeys.filter((key) => !encodedKeys.includes(key))
498
+ })()
499
+ const missingComputedKeys = nonEncodedSchemaKeys.filter((key) => !(computed && key in computed))
500
+
501
+ if (Array.isArrayNonEmpty(missingComputedKeys)) {
502
+ throw new Error(`Missing computed projections for schema keys: ${missingComputedKeys.join(", ")}`)
503
+ }
504
+
505
+ if (computed) {
506
+ const computedKeys = Object.keys(computed)
507
+ const extraComputedKeys = computedKeys.filter((key) => !schemaKeys.includes(key))
508
+ if (Array.isArrayNonEmpty(extraComputedKeys)) {
509
+ throw new Error(`Computed projection keys must exist in projection schema: ${extraComputedKeys.join(", ")}`)
510
+ }
511
+ select = select.filter((_) => {
512
+ const key = getSelectKey(_)
513
+ return !(key in computed)
514
+ })
515
+ select.push(...Object.entries(computed).map(([key, expression]) => ({ key, computed: expression })))
516
+ }
517
+ return dropUndefinedT({
518
+ t: null as unknown as TFieldValues,
519
+ limit: a.limit,
520
+ skip: a.skip,
521
+ select: Option.getOrUndefined(Option.liftPredicate(Array.isReadonlyArrayNonEmpty)(select)),
522
+ schema,
523
+ computed,
524
+ order: Option.getOrUndefined(Option.liftPredicate(Array.isReadonlyArrayNonEmpty)(a.order)),
525
+ ttype: a.ttype,
526
+ mode: a.mode ?? "transform",
527
+ filter: a.filter.length
528
+ ? a.filter
529
+ : undefined
530
+ })
531
+ }
@@ -0,0 +1,13 @@
1
+ export * from "./query/dsl.ts"
2
+ export * from "./query/new-kid-interpreter.ts"
3
+
4
+ export interface RawQuery<Encoded, Out> {
5
+ cosmos: (vals: { name: string }) => {
6
+ query: string
7
+ parameters: {
8
+ name: string
9
+ value: any
10
+ }[]
11
+ }
12
+ memory: (t: readonly Encoded[]) => readonly Out[]
13
+ }
package/src/Model.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./Model/dsl.ts"
2
+ export * as Q from "./Model/query.ts"
3
+ export { makeRepo } from "./Model/Repository.ts"
4
+ export { repositoryDependency } from "./Model/Repository.ts"
5
+ export { type RegisteredRepository, RepositoryRegistry, RepositoryRegistryLive } from "./Model/Repository.ts"
@@ -1,7 +1,9 @@
1
- import { type Equivalence, Option, type Order } from "effect"
2
1
  import type { NonEmptyReadonlyArray } from "effect/Array"
3
- import { flow, pipe } from "./Function.js"
4
- import { filter_, filterMap, filterMap_, fromArray as fromArrayOriginal, insert as insertOriginal, insert_ as insert_Original, map, map_, reduce, reduce_, remove, remove_, type Set, toArray as toArrayOriginal } from "./Set.js"
2
+ import type * as Equivalence from "effect/Equivalence"
3
+ import * as Option from "effect/Option"
4
+ import type * as Order from "effect/Order"
5
+ import { flow, pipe } from "./Function.ts"
6
+ import { filter_, filterMap, filterMap_, fromArray as fromArrayOriginal, insert as insertOriginal, insert_ as insert_Original, map, map_, reduce, reduce_, remove, remove_, type Set, toArray as toArrayOriginal } from "./Set.ts"
5
7
 
6
8
  export interface NonEmptyBrand {
7
9
  readonly NonEmpty: unique symbol
@@ -87,4 +89,4 @@ export function fromSet<A>(set: Set<A>) {
87
89
  }
88
90
 
89
91
  // TODO
90
- export * from "./Set.js"
92
+ export * from "./Set.ts"
package/src/Option.ts CHANGED
@@ -2,22 +2,17 @@
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
3
  /* eslint-disable @typescript-eslint/no-unsafe-return */
4
4
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
- import { getOrUndefined as value, type Some } from "effect/Option"
5
+ // eslint-disable-next-line import/no-unassigned-import
6
+ import "./builtin.ts"
7
+ import { type Some } from "effect/Option"
6
8
  import * as Option from "effect/Option"
7
9
 
8
10
  export * from "effect/Option"
9
11
 
10
- export const getOrUndefined = value
11
-
12
12
  export function omitableToNullable<T>(om: Option.Option<T> | undefined) {
13
13
  return om ?? Option.fromNullishOr(om)
14
14
  }
15
15
 
16
- export const toBool = Option.match({
17
- onNone: () => false,
18
- onSome: () => true
19
- })
20
-
21
16
  export const fromBool = (b: boolean) => (b ? Option.some(true) : Option.none())
22
17
 
23
18
  /**