effect-app 4.0.0-beta.33 → 4.0.0-beta.331

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