@opensaas/stack-core 0.44.0-alpha.5 → 0.44.0-alpha.7

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 (402) hide show
  1. package/CHANGELOG.md +1051 -0
  2. package/dist/.build-hash +1 -1
  3. package/dist/access/actor.d.ts +56 -0
  4. package/dist/access/actor.d.ts.map +1 -0
  5. package/dist/access/actor.js +66 -0
  6. package/dist/access/actor.js.map +1 -0
  7. package/dist/access/decide-advertisement.d.ts +55 -0
  8. package/dist/access/decide-advertisement.d.ts.map +1 -0
  9. package/dist/access/decide-advertisement.js +125 -0
  10. package/dist/access/decide-advertisement.js.map +1 -0
  11. package/dist/access/declared-dependencies.d.ts +4 -89
  12. package/dist/access/declared-dependencies.d.ts.map +1 -1
  13. package/dist/access/declared-dependencies.js +14 -84
  14. package/dist/access/declared-dependencies.js.map +1 -1
  15. package/dist/access/depth-limits.d.ts +2 -0
  16. package/dist/access/depth-limits.d.ts.map +1 -1
  17. package/dist/access/depth-limits.js +2 -0
  18. package/dist/access/depth-limits.js.map +1 -1
  19. package/dist/access/engine.d.ts +1 -24
  20. package/dist/access/engine.d.ts.map +1 -1
  21. package/dist/access/engine.js +0 -35
  22. package/dist/access/engine.js.map +1 -1
  23. package/dist/access/field-access.d.ts +43 -19
  24. package/dist/access/field-access.d.ts.map +1 -1
  25. package/dist/access/field-access.js +206 -185
  26. package/dist/access/field-access.js.map +1 -1
  27. package/dist/access/index.d.ts +5 -6
  28. package/dist/access/index.d.ts.map +1 -1
  29. package/dist/access/index.js +6 -7
  30. package/dist/access/index.js.map +1 -1
  31. package/dist/access/rule-item.d.ts +42 -0
  32. package/dist/access/rule-item.d.ts.map +1 -0
  33. package/dist/access/rule-item.js +215 -0
  34. package/dist/access/rule-item.js.map +1 -0
  35. package/dist/access/session-vocabulary.d.ts +124 -0
  36. package/dist/access/session-vocabulary.d.ts.map +1 -0
  37. package/dist/access/session-vocabulary.js +366 -0
  38. package/dist/access/session-vocabulary.js.map +1 -0
  39. package/dist/access/transaction-registry.d.ts +6 -0
  40. package/dist/access/transaction-registry.d.ts.map +1 -1
  41. package/dist/access/transaction-registry.js +19 -2
  42. package/dist/access/transaction-registry.js.map +1 -1
  43. package/dist/access/types.d.ts +66 -0
  44. package/dist/access/types.d.ts.map +1 -1
  45. package/dist/access/vocabulary-filter-specs.d.ts +17 -0
  46. package/dist/access/vocabulary-filter-specs.d.ts.map +1 -0
  47. package/dist/access/vocabulary-filter-specs.js +27 -0
  48. package/dist/access/vocabulary-filter-specs.js.map +1 -0
  49. package/dist/client-safe.d.ts +8 -0
  50. package/dist/client-safe.d.ts.map +1 -0
  51. package/dist/client-safe.js +8 -0
  52. package/dist/client-safe.js.map +1 -0
  53. package/dist/config/field-kind.d.ts +7 -21
  54. package/dist/config/field-kind.d.ts.map +1 -1
  55. package/dist/config/field-kind.js +8 -5
  56. package/dist/config/field-kind.js.map +1 -1
  57. package/dist/config/has-access-gate.d.ts +20 -0
  58. package/dist/config/has-access-gate.d.ts.map +1 -0
  59. package/dist/config/has-access-gate.js +26 -0
  60. package/dist/config/has-access-gate.js.map +1 -0
  61. package/dist/config/index.d.ts +1 -1
  62. package/dist/config/index.d.ts.map +1 -1
  63. package/dist/config/index.js +8 -2
  64. package/dist/config/index.js.map +1 -1
  65. package/dist/config/list-view-keys.d.ts +5 -0
  66. package/dist/config/list-view-keys.d.ts.map +1 -0
  67. package/dist/config/list-view-keys.js +18 -0
  68. package/dist/config/list-view-keys.js.map +1 -0
  69. package/dist/config/mcp-default-tools.d.ts +3 -0
  70. package/dist/config/mcp-default-tools.d.ts.map +1 -0
  71. package/dist/config/mcp-default-tools.js +14 -0
  72. package/dist/config/mcp-default-tools.js.map +1 -0
  73. package/dist/config/mcp-tool-names.d.ts +2 -0
  74. package/dist/config/mcp-tool-names.d.ts.map +1 -1
  75. package/dist/config/mcp-tool-names.js +17 -5
  76. package/dist/config/mcp-tool-names.js.map +1 -1
  77. package/dist/config/nav-count.d.ts +8 -16
  78. package/dist/config/nav-count.d.ts.map +1 -1
  79. package/dist/config/nav-count.js +20 -32
  80. package/dist/config/nav-count.js.map +1 -1
  81. package/dist/config/plugin-engine.d.ts.map +1 -1
  82. package/dist/config/plugin-engine.js +6 -0
  83. package/dist/config/plugin-engine.js.map +1 -1
  84. package/dist/config/preset-views.d.ts +22 -0
  85. package/dist/config/preset-views.d.ts.map +1 -0
  86. package/dist/config/preset-views.js +46 -0
  87. package/dist/config/preset-views.js.map +1 -0
  88. package/dist/config/row-action-availability.d.ts +4 -0
  89. package/dist/config/row-action-availability.d.ts.map +1 -0
  90. package/dist/config/row-action-availability.js +20 -0
  91. package/dist/config/row-action-availability.js.map +1 -0
  92. package/dist/config/types.d.ts +409 -34
  93. package/dist/config/types.d.ts.map +1 -1
  94. package/dist/context/engine-context.d.ts +2 -0
  95. package/dist/context/engine-context.d.ts.map +1 -1
  96. package/dist/context/engine-context.js +8 -0
  97. package/dist/context/engine-context.js.map +1 -1
  98. package/dist/context/hook-pipeline.d.ts +6 -1
  99. package/dist/context/hook-pipeline.d.ts.map +1 -1
  100. package/dist/context/hook-pipeline.js +6 -4
  101. package/dist/context/hook-pipeline.js.map +1 -1
  102. package/dist/context/index.d.ts +10 -1
  103. package/dist/context/index.d.ts.map +1 -1
  104. package/dist/context/index.js +217 -94
  105. package/dist/context/index.js.map +1 -1
  106. package/dist/context/junction.d.ts +28 -21
  107. package/dist/context/junction.d.ts.map +1 -1
  108. package/dist/context/junction.js +74 -69
  109. package/dist/context/junction.js.map +1 -1
  110. package/dist/context/plugin-field-write.d.ts.map +1 -1
  111. package/dist/context/plugin-field-write.js +19 -25
  112. package/dist/context/plugin-field-write.js.map +1 -1
  113. package/dist/context/process-lifetime.d.ts +8 -0
  114. package/dist/context/process-lifetime.d.ts.map +1 -0
  115. package/dist/context/process-lifetime.js +14 -0
  116. package/dist/context/process-lifetime.js.map +1 -0
  117. package/dist/context/relationship-input.d.ts +2 -15
  118. package/dist/context/relationship-input.d.ts.map +1 -1
  119. package/dist/context/relationship-input.js +44 -85
  120. package/dist/context/relationship-input.js.map +1 -1
  121. package/dist/context/transaction-boundary.d.ts +3 -2
  122. package/dist/context/transaction-boundary.d.ts.map +1 -1
  123. package/dist/context/transaction-boundary.js +17 -2
  124. package/dist/context/transaction-boundary.js.map +1 -1
  125. package/dist/context/write-pipeline.d.ts +5 -19
  126. package/dist/context/write-pipeline.d.ts.map +1 -1
  127. package/dist/context/write-pipeline.js +54 -92
  128. package/dist/context/write-pipeline.js.map +1 -1
  129. package/dist/context/write-target.d.ts +52 -0
  130. package/dist/context/write-target.d.ts.map +1 -0
  131. package/dist/context/write-target.js +118 -0
  132. package/dist/context/write-target.js.map +1 -0
  133. package/dist/contract/dependencies.d.ts +24 -10
  134. package/dist/contract/dependencies.d.ts.map +1 -1
  135. package/dist/contract/dependencies.js +120 -80
  136. package/dist/contract/dependencies.js.map +1 -1
  137. package/dist/contract/derive.d.ts +6 -11
  138. package/dist/contract/derive.d.ts.map +1 -1
  139. package/dist/contract/derive.js +256 -211
  140. package/dist/contract/derive.js.map +1 -1
  141. package/dist/contract/fixtures/contract-configs.d.ts +5 -0
  142. package/dist/contract/fixtures/contract-configs.d.ts.map +1 -1
  143. package/dist/contract/fixtures/contract-configs.js +21 -0
  144. package/dist/contract/fixtures/contract-configs.js.map +1 -1
  145. package/dist/contract/id-boundary.js +1 -1
  146. package/dist/contract/id-boundary.js.map +1 -1
  147. package/dist/contract/prisma.js +2 -2
  148. package/dist/contract/prisma.js.map +1 -1
  149. package/dist/contract/strategy.d.ts +13 -0
  150. package/dist/contract/strategy.d.ts.map +1 -0
  151. package/dist/contract/strategy.js +38 -0
  152. package/dist/contract/strategy.js.map +1 -0
  153. package/dist/db/client-alias.d.ts +12 -0
  154. package/dist/db/client-alias.d.ts.map +1 -0
  155. package/dist/db/client-alias.js +8 -0
  156. package/dist/db/client-alias.js.map +1 -0
  157. package/dist/extend.d.ts +2 -2
  158. package/dist/extend.d.ts.map +1 -1
  159. package/dist/extend.js.map +1 -1
  160. package/dist/fields/index.d.ts +12 -14
  161. package/dist/fields/index.d.ts.map +1 -1
  162. package/dist/fields/index.js +217 -67
  163. package/dist/fields/index.js.map +1 -1
  164. package/dist/filter/collect.d.ts +43 -25
  165. package/dist/filter/collect.d.ts.map +1 -1
  166. package/dist/filter/collect.js +107 -38
  167. package/dist/filter/collect.js.map +1 -1
  168. package/dist/filter/index.d.ts +7 -5
  169. package/dist/filter/index.d.ts.map +1 -1
  170. package/dist/filter/index.js +6 -14
  171. package/dist/filter/index.js.map +1 -1
  172. package/dist/filter/map.d.ts +112 -20
  173. package/dist/filter/map.d.ts.map +1 -1
  174. package/dist/filter/map.js +271 -52
  175. package/dist/filter/map.js.map +1 -1
  176. package/dist/filter/parse.d.ts +70 -26
  177. package/dist/filter/parse.d.ts.map +1 -1
  178. package/dist/filter/parse.js +212 -79
  179. package/dist/filter/parse.js.map +1 -1
  180. package/dist/filter/record-id.d.ts +19 -0
  181. package/dist/filter/record-id.d.ts.map +1 -0
  182. package/dist/filter/record-id.js +37 -0
  183. package/dist/filter/record-id.js.map +1 -0
  184. package/dist/filter/serialize.d.ts +45 -19
  185. package/dist/filter/serialize.d.ts.map +1 -1
  186. package/dist/filter/serialize.js +146 -50
  187. package/dist/filter/serialize.js.map +1 -1
  188. package/dist/filter/types.d.ts +132 -21
  189. package/dist/filter/types.d.ts.map +1 -1
  190. package/dist/filter/types.js +2 -11
  191. package/dist/filter/types.js.map +1 -1
  192. package/dist/hooks/index.d.ts +6 -3
  193. package/dist/hooks/index.d.ts.map +1 -1
  194. package/dist/hooks/index.js +38 -8
  195. package/dist/hooks/index.js.map +1 -1
  196. package/dist/index.d.ts +10 -9
  197. package/dist/index.d.ts.map +1 -1
  198. package/dist/index.js +5 -5
  199. package/dist/index.js.map +1 -1
  200. package/dist/internal.d.ts +11 -2
  201. package/dist/internal.d.ts.map +1 -1
  202. package/dist/internal.js +8 -8
  203. package/dist/internal.js.map +1 -1
  204. package/dist/lib/database-errors.d.ts +2 -1
  205. package/dist/lib/database-errors.d.ts.map +1 -1
  206. package/dist/lib/database-errors.js +5 -4
  207. package/dist/lib/database-errors.js.map +1 -1
  208. package/dist/mcp/advertise.d.ts +5 -13
  209. package/dist/mcp/advertise.d.ts.map +1 -1
  210. package/dist/mcp/advertise.js +7 -22
  211. package/dist/mcp/advertise.js.map +1 -1
  212. package/dist/mcp/arguments.d.ts.map +1 -1
  213. package/dist/mcp/arguments.js +8 -11
  214. package/dist/mcp/arguments.js.map +1 -1
  215. package/dist/mcp/field-schema.d.ts +4 -15
  216. package/dist/mcp/field-schema.d.ts.map +1 -1
  217. package/dist/mcp/field-schema.js +50 -69
  218. package/dist/mcp/field-schema.js.map +1 -1
  219. package/dist/mcp/handler.d.ts +111 -18
  220. package/dist/mcp/handler.d.ts.map +1 -1
  221. package/dist/mcp/handler.js +231 -87
  222. package/dist/mcp/handler.js.map +1 -1
  223. package/dist/mcp/index.d.ts +2 -1
  224. package/dist/mcp/index.d.ts.map +1 -1
  225. package/dist/mcp/index.js +1 -1
  226. package/dist/mcp/index.js.map +1 -1
  227. package/dist/mcp/procedure-tools.d.ts +63 -0
  228. package/dist/mcp/procedure-tools.d.ts.map +1 -0
  229. package/dist/mcp/procedure-tools.js +139 -0
  230. package/dist/mcp/procedure-tools.js.map +1 -0
  231. package/dist/mcp/projection.d.ts +6 -5
  232. package/dist/mcp/projection.d.ts.map +1 -1
  233. package/dist/mcp/projection.js +33 -38
  234. package/dist/mcp/projection.js.map +1 -1
  235. package/dist/mcp/reachability.d.ts +13 -0
  236. package/dist/mcp/reachability.d.ts.map +1 -0
  237. package/dist/mcp/reachability.js +51 -0
  238. package/dist/mcp/reachability.js.map +1 -0
  239. package/dist/mcp/relation-member.d.ts +15 -0
  240. package/dist/mcp/relation-member.d.ts.map +1 -0
  241. package/dist/mcp/relation-member.js +50 -0
  242. package/dist/mcp/relation-member.js.map +1 -0
  243. package/dist/mcp/types.d.ts +12 -0
  244. package/dist/mcp/types.d.ts.map +1 -1
  245. package/dist/mcp/where-id-boundary.d.ts.map +1 -1
  246. package/dist/mcp/where-id-boundary.js +12 -24
  247. package/dist/mcp/where-id-boundary.js.map +1 -1
  248. package/dist/mcp/where-reachability.d.ts +10 -0
  249. package/dist/mcp/where-reachability.d.ts.map +1 -0
  250. package/dist/mcp/where-reachability.js +88 -0
  251. package/dist/mcp/where-reachability.js.map +1 -0
  252. package/dist/members/claims.d.ts +71 -0
  253. package/dist/members/claims.d.ts.map +1 -0
  254. package/dist/members/claims.js +199 -0
  255. package/dist/members/claims.js.map +1 -0
  256. package/dist/members/list-members.d.ts +87 -0
  257. package/dist/members/list-members.d.ts.map +1 -0
  258. package/dist/members/list-members.js +250 -0
  259. package/dist/members/list-members.js.map +1 -0
  260. package/dist/procedures/client.d.ts +163 -0
  261. package/dist/procedures/client.d.ts.map +1 -0
  262. package/dist/procedures/client.js +152 -0
  263. package/dist/procedures/client.js.map +1 -0
  264. package/dist/procedures/codes.d.ts +23 -0
  265. package/dist/procedures/codes.d.ts.map +1 -0
  266. package/dist/procedures/codes.js +46 -0
  267. package/dist/procedures/codes.js.map +1 -0
  268. package/dist/procedures/context-face.d.ts +4 -0
  269. package/dist/procedures/context-face.d.ts.map +1 -0
  270. package/dist/procedures/context-face.js +31 -0
  271. package/dist/procedures/context-face.js.map +1 -0
  272. package/dist/procedures/failures.d.ts +31 -0
  273. package/dist/procedures/failures.d.ts.map +1 -0
  274. package/dist/procedures/failures.js +51 -0
  275. package/dist/procedures/failures.js.map +1 -0
  276. package/dist/procedures/http.d.ts +114 -0
  277. package/dist/procedures/http.d.ts.map +1 -0
  278. package/dist/procedures/http.js +224 -0
  279. package/dist/procedures/http.js.map +1 -0
  280. package/dist/procedures/index.d.ts +7 -0
  281. package/dist/procedures/index.d.ts.map +1 -0
  282. package/dist/procedures/index.js +11 -0
  283. package/dist/procedures/index.js.map +1 -0
  284. package/dist/procedures/procedure.d.ts +204 -0
  285. package/dist/procedures/procedure.d.ts.map +1 -0
  286. package/dist/procedures/procedure.js +123 -0
  287. package/dist/procedures/procedure.js.map +1 -0
  288. package/dist/procedures/result.d.ts +42 -0
  289. package/dist/procedures/result.d.ts.map +1 -0
  290. package/dist/procedures/result.js +51 -0
  291. package/dist/procedures/result.js.map +1 -0
  292. package/dist/procedures/run.d.ts +36 -0
  293. package/dist/procedures/run.d.ts.map +1 -0
  294. package/dist/procedures/run.js +76 -0
  295. package/dist/procedures/run.js.map +1 -0
  296. package/dist/procedures/server.d.ts +131 -0
  297. package/dist/procedures/server.d.ts.map +1 -0
  298. package/dist/procedures/server.js +115 -0
  299. package/dist/procedures/server.js.map +1 -0
  300. package/dist/procedures/validate.d.ts +60 -0
  301. package/dist/procedures/validate.d.ts.map +1 -0
  302. package/dist/procedures/validate.js +254 -0
  303. package/dist/procedures/validate.js.map +1 -0
  304. package/dist/procedures/web-session.d.ts +12 -0
  305. package/dist/procedures/web-session.d.ts.map +1 -0
  306. package/dist/procedures/web-session.js +35 -0
  307. package/dist/procedures/web-session.js.map +1 -0
  308. package/dist/query/relationship-options.d.ts +8 -0
  309. package/dist/query/relationship-options.d.ts.map +1 -1
  310. package/dist/query/relationship-options.js +18 -4
  311. package/dist/query/relationship-options.js.map +1 -1
  312. package/dist/secured/binding.d.ts +84 -0
  313. package/dist/secured/binding.d.ts.map +1 -0
  314. package/dist/secured/binding.js +52 -0
  315. package/dist/secured/binding.js.map +1 -0
  316. package/dist/secured/declared-branch.d.ts +11 -0
  317. package/dist/secured/declared-branch.d.ts.map +1 -0
  318. package/dist/secured/declared-branch.js +17 -0
  319. package/dist/secured/declared-branch.js.map +1 -0
  320. package/dist/secured/field-visibility.d.ts +56 -0
  321. package/dist/secured/field-visibility.d.ts.map +1 -0
  322. package/dist/secured/field-visibility.js +624 -0
  323. package/dist/secured/field-visibility.js.map +1 -0
  324. package/dist/secured/include.d.ts +77 -37
  325. package/dist/secured/include.d.ts.map +1 -1
  326. package/dist/secured/include.js +228 -122
  327. package/dist/secured/include.js.map +1 -1
  328. package/dist/secured/lock.d.ts +8 -2
  329. package/dist/secured/lock.d.ts.map +1 -1
  330. package/dist/secured/lock.js +44 -15
  331. package/dist/secured/lock.js.map +1 -1
  332. package/dist/secured/lower.d.ts.map +1 -1
  333. package/dist/secured/lower.js +15 -4
  334. package/dist/secured/lower.js.map +1 -1
  335. package/dist/secured/read.d.ts +13 -52
  336. package/dist/secured/read.d.ts.map +1 -1
  337. package/dist/secured/read.js +88 -614
  338. package/dist/secured/read.js.map +1 -1
  339. package/dist/secured/select.d.ts +0 -24
  340. package/dist/secured/select.d.ts.map +1 -1
  341. package/dist/secured/select.js +60 -153
  342. package/dist/secured/select.js.map +1 -1
  343. package/dist/secured/vocabulary.d.ts +13 -1
  344. package/dist/secured/vocabulary.d.ts.map +1 -1
  345. package/dist/secured/vocabulary.js +173 -83
  346. package/dist/secured/vocabulary.js.map +1 -1
  347. package/dist/testing/untyped-rule.d.ts +8 -0
  348. package/dist/testing/untyped-rule.d.ts.map +1 -0
  349. package/dist/testing/untyped-rule.js +4 -0
  350. package/dist/testing/untyped-rule.js.map +1 -0
  351. package/dist/types/index.d.ts +1 -1
  352. package/dist/types/index.d.ts.map +1 -1
  353. package/dist/types/rows.d.ts +18 -1
  354. package/dist/types/rows.d.ts.map +1 -1
  355. package/dist/validation/config-refusal.d.ts +3 -1
  356. package/dist/validation/config-refusal.d.ts.map +1 -1
  357. package/dist/validation/database-config.d.ts +1 -15
  358. package/dist/validation/database-config.d.ts.map +1 -1
  359. package/dist/validation/database-config.js +32 -1
  360. package/dist/validation/database-config.js.map +1 -1
  361. package/dist/validation/default-value.d.ts.map +1 -1
  362. package/dist/validation/default-value.js +3 -8
  363. package/dist/validation/default-value.js.map +1 -1
  364. package/dist/validation/extension-packs.d.ts.map +1 -1
  365. package/dist/validation/extension-packs.js +1 -0
  366. package/dist/validation/extension-packs.js.map +1 -1
  367. package/dist/validation/field-config.d.ts +3 -2
  368. package/dist/validation/field-config.d.ts.map +1 -1
  369. package/dist/validation/field-config.js +3 -1
  370. package/dist/validation/field-config.js.map +1 -1
  371. package/dist/validation/field-names.d.ts +2 -1
  372. package/dist/validation/field-names.d.ts.map +1 -1
  373. package/dist/validation/field-names.js +76 -63
  374. package/dist/validation/field-names.js.map +1 -1
  375. package/dist/validation/identifier-names.d.ts +1 -0
  376. package/dist/validation/identifier-names.d.ts.map +1 -1
  377. package/dist/validation/identifier-names.js +17 -9
  378. package/dist/validation/identifier-names.js.map +1 -1
  379. package/dist/validation/needs-closure.d.ts +30 -14
  380. package/dist/validation/needs-closure.d.ts.map +1 -1
  381. package/dist/validation/needs-closure.js +184 -31
  382. package/dist/validation/needs-closure.js.map +1 -1
  383. package/dist/validation/relations.d.ts.map +1 -1
  384. package/dist/validation/relations.js +11 -0
  385. package/dist/validation/relations.js.map +1 -1
  386. package/dist/validation/schema.d.ts +4 -3
  387. package/dist/validation/schema.d.ts.map +1 -1
  388. package/dist/validation/schema.js +8 -6
  389. package/dist/validation/schema.js.map +1 -1
  390. package/package.json +26 -10
  391. package/dist/access/field-visibility.d.ts +0 -58
  392. package/dist/access/field-visibility.d.ts.map +0 -1
  393. package/dist/access/field-visibility.js +0 -383
  394. package/dist/access/field-visibility.js.map +0 -1
  395. package/dist/access/query-validation.d.ts +0 -30
  396. package/dist/access/query-validation.d.ts.map +0 -1
  397. package/dist/access/query-validation.js +0 -49
  398. package/dist/access/query-validation.js.map +0 -1
  399. package/dist/access/system-fields.d.ts +0 -2
  400. package/dist/access/system-fields.d.ts.map +0 -1
  401. package/dist/access/system-fields.js +0 -7
  402. package/dist/access/system-fields.js.map +0 -1
@@ -1,25 +1,117 @@
1
- import type { FilterCondition, FilterSpec, FilterToken } from './types.js';
1
+ import type { FilterCondition, FilterFieldSuggestion, FilterOperator, FilterQuery, FilterSpec, FilterToken, FilterTokenOperator } from './types.js';
2
+ /** What {@link isFieldConditionToken} needs to know about a field. */
3
+ export type FilterFieldCapabilities = Pick<FilterFieldSuggestion, 'operators' | 'canBeEmpty'>;
2
4
  /**
3
- * Map parsed {@link FilterToken}s to a single Prisma `where` fragment, given the
4
- * fields' {@link FilterSpec}s (ADR-0017).
5
+ * Whether a {@link FilterToken} was written with no characters at all (`role:`,
6
+ * `""`, `a:,`, or no values). Such a token is incomplete input and filters
7
+ * nothing (#1509). An `empty` token (`field:!`) carries no values and is not one.
8
+ */
9
+ export declare function isEmptyFilterToken(token: FilterToken): boolean;
10
+ /**
11
+ * Whether a field whose Filter spec declares `operators` takes an inclusive
12
+ * `range` token: it compares both ways, with `gte` and `lte`.
13
+ */
14
+ export declare function supportsFilterRange(operators: readonly FilterOperator[]): boolean;
15
+ /**
16
+ * The token operators a field whose Filter spec declares `operators` accepts
17
+ * on its values: its own, and `range` when it {@link supportsFilterRange}.
18
+ */
19
+ export declare function filterTokenOperators(operators: readonly FilterOperator[]): FilterTokenOperator[];
20
+ /**
21
+ * The token a field whose Filter spec declares `operators` actually maps: a
22
+ * `range` token (`field:a..b`) on a field that does not
23
+ * {@link supportsFilterRange} keeps the meaning it had before ranges existed,
24
+ * `eq` on its literal `a..b`, negated or not. Any other token is returned as
25
+ * it is.
26
+ */
27
+ export declare function effectiveFilterToken(token: FilterToken, operators: readonly FilterOperator[]): FilterToken;
28
+ /**
29
+ * Whether a {@link FilterToken} is a field condition the engine maps through
30
+ * its field's Filter spec: not empty, and naming a field that, as `fieldFor`
31
+ * reports it, supports the token's operator, or can be empty for an `empty`
32
+ * token. A `range` token needs exactly two non-empty bounds, and on a field
33
+ * that takes no range it is that field's `eq` on the literal `a..b` (see
34
+ * {@link effectiveFilterToken}). Negation and several values are composed
35
+ * around the field's own condition, so neither decides this. Any other token
36
+ * is searched as free text.
37
+ */
38
+ export declare function isFieldConditionToken(token: FilterToken, fieldFor: (field: string) => FilterFieldCapabilities | undefined): token is FilterToken & {
39
+ field: string;
40
+ };
41
+ /**
42
+ * The one free-text word a {@link FilterToken} is searched as when it cannot
43
+ * map to a field condition, and the text the Filter builder's chip shows for it.
44
+ *
45
+ * - A positive field token searches its values, written as one comma list
46
+ * with the field name dropped: `nosuchfield:Findable` is `Findable`, and
47
+ * `status:draft,bogus` is `draft,bogus`. A positive `range` token searches
48
+ * its literal `a..b`.
49
+ * - A negated token, or a `field:!`, searches its whole serialised literal
50
+ * (`-secret:x`), so a token that cannot map is never negated.
51
+ * - A bare word searches its own text.
52
+ */
53
+ export declare function filterTokenFreeTextWord(token: FilterToken): string;
54
+ export declare const FILTER_MAX_ENTRIES = 200;
55
+ export declare class FilterTooLongError extends Error {
56
+ constructor();
57
+ }
58
+ /**
59
+ * Map a parsed {@link FilterQuery} to a single Where fragment, given the
60
+ * fields' {@link FilterSpec}s (ADR-0017, ADR-0083).
5
61
  *
6
62
  * Pure — no DB/Prisma imports. This is the unit-tested half of the filter seam.
7
- * Tokens combine with implicit AND. An empty-value token (`role:` or a bare
8
- * `""`) is a deliberate no-op — incomplete input expresses no constraint, so it
9
- * contributes nothing and is never handed to a free-text field (#1509). A
10
- * token with a value degrades to free text (never an error) when its field is
11
- * unknown, has no spec, uses an unsupported operator, or maps to `null`. Bare
12
- * words (and degraded tokens) are OR-matched across every free-text field, and
13
- * each such word is ANDed with the rest — so `beta gamma` requires both. A word
14
- * that reaches this stage but cannot be matched against any free-text field —
15
- * because the list has none, or because every free-text field's own mapping
16
- * rejects it — narrows the chain to {@link NEVER_MATCHES} instead of being
17
- * dropped: a condition that cannot be honoured must never widen the result set
18
- * (#1356).
19
- *
20
- * @param tokens Parsed tokens from {@link parseFilterQuery}.
21
- * @param specs Field-name → Filter spec (from {@link collectFilterSpecs}).
22
- * @returns A Prisma `where` fragment, or `undefined` when nothing filters.
63
+ * Terms combine with implicit AND. An empty token is a deliberate no-op —
64
+ * incomplete input expresses no constraint, so it contributes nothing and is
65
+ * never handed to a free-text field (#1509), and an empty value inside a list
66
+ * (`a:x,`) is skipped the same way.
67
+ *
68
+ * The engine composes around each field's own `toCondition`:
69
+ *
70
+ * - `field:a,b` ORs the field's condition once per value.
71
+ * - `-field:value` is `NOT` of that condition, ORed with the field's `empty`
72
+ * condition when it states one, so "is not" keeps the rows with no value.
73
+ * A spec stating a `negation` says `NOT` alone already does, and gets no `OR`.
74
+ * - `field:!` is the field's `empty` condition and `-field:!` its `NOT`.
75
+ * - `field:a..b` ANDs the field's own `gte` on `a` and `lte` on `b`, on any
76
+ * field comparing both ways, and `-field:a..b` is `NOT` of that, composed
77
+ * like any other negation. On a field that takes no range it is that
78
+ * field's `eq` on the literal `a..b`, as it was before ranges existed
79
+ * ({@link effectiveFilterToken}).
80
+ * - An unquoted `#id` value on a field whose spec has `toIdCondition` maps
81
+ * through it instead, matching exactly that related record, so
82
+ * `field:#a,#b` matches either and `-field:#id` excludes it. An id the
83
+ * related list cannot hold makes the token free text.
84
+ *
85
+ * A token that cannot map in any part (an unknown or unreadable field, an
86
+ * unsupported operator, a value the field rejects, any one value of a list, or
87
+ * `field:!` on a field that cannot be empty, or either bound of a range) is
88
+ * searched as one free-text word,
89
+ * {@link filterTokenFreeTextWord}, which is also what the Filter builder's chip
90
+ * shows. A positive token searches its values with the field name dropped
91
+ * (`status:draft,bogus` searches `draft,bogus`); a negated one searches its
92
+ * whole literal (`-secret:x`) and is never negated, because `NOT` of free text
93
+ * would turn a field the session cannot read into a filter. A free-text token
94
+ * is read as its serialised form reads back, so a structured one with several
95
+ * values is the words its URL holds. A `range` token is read the same way, so
96
+ * one whose bounds cannot be written `a..b` is the literal `"a..b"` its URL
97
+ * holds.
98
+ *
99
+ * An OR group, `(a OR b)`, is the `OR` of its tokens, each mapped exactly as
100
+ * it would be on its own and negated by the same rules. A token in a group
101
+ * that cannot map stays in place as its free-text alternative, never dropped,
102
+ * so it can only add rows the free-text search finds; an empty token in a
103
+ * group is skipped, and a group of nothing but empty tokens filters nothing.
104
+ *
105
+ * Bare words (and degraded tokens) are OR-matched across every free-text
106
+ * field, and each such word is ANDed with the rest — so `beta gamma` requires
107
+ * both. A word that cannot be matched against any free-text field — because
108
+ * the list has none, or because every free-text field's own mapping rejects
109
+ * it — narrows the chain to {@link NEVER_MATCHES} instead of being dropped: a
110
+ * condition that cannot be honoured must never widen the result set (#1356).
111
+ *
112
+ * @param query The structured query from {@link parseFilterQuery}.
113
+ * @param specs Field-name → Filter spec (from {@link collectFilterSpecs}).
114
+ * @returns A Where fragment, or `undefined` when nothing filters.
23
115
  */
24
- export declare function buildFilterWhere(tokens: FilterToken[], specs: Record<string, FilterSpec>): FilterCondition | undefined;
116
+ export declare function buildFilterWhere(query: FilterQuery, specs: Record<string, FilterSpec>): FilterCondition | undefined;
25
117
  //# sourceMappingURL=map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/filter/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAe1E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EAAE,EACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAChC,eAAe,GAAG,SAAS,CAoD7B"}
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/filter/map.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,WAAW,EAEX,UAAU,EAEV,WAAW,EACX,mBAAmB,EACpB,MAAM,YAAY,CAAA;AAenB,sEAAsE;AACtE,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,qBAAqB,EAAE,WAAW,GAAG,YAAY,CAAC,CAAA;AAE7F;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAE9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,GAAG,OAAO,CAEjF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,GAAG,mBAAmB,EAAE,CAEhG;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,SAAS,cAAc,EAAE,GACnC,WAAW,CAIb;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,uBAAuB,GAAG,SAAS,GAC/D,KAAK,IAAI,WAAW,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAQ1C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAOlE;AAED,eAAO,MAAM,kBAAkB,MAAM,CAAA;AAErC,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,cAGC;CACF;AAgFD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAChC,eAAe,GAAG,SAAS,CAmE7B"}
@@ -1,3 +1,6 @@
1
+ import { filterQueryTokens, parseFilterQuery } from './parse.js';
2
+ import { filterValueRecordId } from './record-id.js';
3
+ import { serializeFilterQuery, serializeFilterToken } from './serialize.js';
1
4
  /**
2
5
  * A Where fragment an `AND` chain can carry that never matches a row. `NOT`
3
6
  * on an empty predicate: the empty predicate resolves to the vacuous,
@@ -11,73 +14,289 @@
11
14
  */
12
15
  const NEVER_MATCHES = { NOT: {} };
13
16
  /**
14
- * Map parsed {@link FilterToken}s to a single Prisma `where` fragment, given the
15
- * fields' {@link FilterSpec}s (ADR-0017).
17
+ * Whether a {@link FilterToken} was written with no characters at all (`role:`,
18
+ * `""`, `a:,`, or no values). Such a token is incomplete input and filters
19
+ * nothing (#1509). An `empty` token (`field:!`) carries no values and is not one.
20
+ */
21
+ export function isEmptyFilterToken(token) {
22
+ return token.operator !== 'empty' && token.values.every((value) => value.text === '');
23
+ }
24
+ /**
25
+ * Whether a field whose Filter spec declares `operators` takes an inclusive
26
+ * `range` token: it compares both ways, with `gte` and `lte`.
27
+ */
28
+ export function supportsFilterRange(operators) {
29
+ return operators.includes('gte') && operators.includes('lte');
30
+ }
31
+ /**
32
+ * The token operators a field whose Filter spec declares `operators` accepts
33
+ * on its values: its own, and `range` when it {@link supportsFilterRange}.
34
+ */
35
+ export function filterTokenOperators(operators) {
36
+ return supportsFilterRange(operators) ? [...operators, 'range'] : [...operators];
37
+ }
38
+ /**
39
+ * The token a field whose Filter spec declares `operators` actually maps: a
40
+ * `range` token (`field:a..b`) on a field that does not
41
+ * {@link supportsFilterRange} keeps the meaning it had before ranges existed,
42
+ * `eq` on its literal `a..b`, negated or not. Any other token is returned as
43
+ * it is.
44
+ */
45
+ export function effectiveFilterToken(token, operators) {
46
+ if (token.operator !== 'range' || supportsFilterRange(operators))
47
+ return token;
48
+ const text = token.values.map((value) => value.text).join('..');
49
+ return { ...token, operator: 'eq', values: [{ text, quoted: false }] };
50
+ }
51
+ /**
52
+ * Whether a {@link FilterToken} is a field condition the engine maps through
53
+ * its field's Filter spec: not empty, and naming a field that, as `fieldFor`
54
+ * reports it, supports the token's operator, or can be empty for an `empty`
55
+ * token. A `range` token needs exactly two non-empty bounds, and on a field
56
+ * that takes no range it is that field's `eq` on the literal `a..b` (see
57
+ * {@link effectiveFilterToken}). Negation and several values are composed
58
+ * around the field's own condition, so neither decides this. Any other token
59
+ * is searched as free text.
60
+ */
61
+ export function isFieldConditionToken(token, fieldFor) {
62
+ if (token.field === null || isEmptyFilterToken(token))
63
+ return false;
64
+ const capabilities = fieldFor(token.field);
65
+ if (!capabilities)
66
+ return false;
67
+ if (token.operator === 'empty')
68
+ return capabilities.canBeEmpty === true;
69
+ if (token.operator !== 'range')
70
+ return capabilities.operators.includes(token.operator);
71
+ if (token.values.length !== 2 || token.values.some((value) => value.text === ''))
72
+ return false;
73
+ return supportsFilterRange(capabilities.operators) || capabilities.operators.includes('eq');
74
+ }
75
+ /**
76
+ * The one free-text word a {@link FilterToken} is searched as when it cannot
77
+ * map to a field condition, and the text the Filter builder's chip shows for it.
78
+ *
79
+ * - A positive field token searches its values, written as one comma list
80
+ * with the field name dropped: `nosuchfield:Findable` is `Findable`, and
81
+ * `status:draft,bogus` is `draft,bogus`. A positive `range` token searches
82
+ * its literal `a..b`.
83
+ * - A negated token, or a `field:!`, searches its whole serialised literal
84
+ * (`-secret:x`), so a token that cannot map is never negated.
85
+ * - A bare word searches its own text.
86
+ */
87
+ export function filterTokenFreeTextWord(token) {
88
+ if (token.negated || token.operator === 'empty')
89
+ return serializeFilterToken(token);
90
+ if (token.operator === 'range')
91
+ return token.values.map((value) => value.text).join('..');
92
+ return token.values
93
+ .map((value) => value.text)
94
+ .filter((text) => text !== '')
95
+ .join(',');
96
+ }
97
+ export const FILTER_MAX_ENTRIES = 200;
98
+ export class FilterTooLongError extends Error {
99
+ constructor() {
100
+ super('The search is too long to run. Remove some of its words or values.');
101
+ this.name = 'FilterTooLongError';
102
+ }
103
+ }
104
+ const QUANTIFIERS = new Set(['some', 'every', 'none']);
105
+ function countEntries(condition) {
106
+ if (Array.isArray(condition))
107
+ return condition.reduce((sum, item) => sum + countEntries(item), 0);
108
+ if (typeof condition !== 'object' || condition === null)
109
+ return 0;
110
+ return Object.entries(condition).reduce((sum, [key, value]) => {
111
+ if (key === 'AND' || key === 'OR' || key === 'NOT')
112
+ return sum + 1 + countEntries(value);
113
+ if (typeof value !== 'object' || value === null)
114
+ return sum + 1;
115
+ return (sum +
116
+ 1 +
117
+ Object.entries(value).reduce((inner, [quantifier, nested]) => QUANTIFIERS.has(quantifier) ? inner + 1 + countEntries(nested) : inner, 0));
118
+ }, 0);
119
+ }
120
+ function hasNul(text) {
121
+ return text.includes('\u0000');
122
+ }
123
+ function anyOf(conditions) {
124
+ return conditions.length === 1 ? conditions[0] : { OR: conditions };
125
+ }
126
+ function rangeCondition(token, spec) {
127
+ if (token.values.length !== 2)
128
+ return null;
129
+ const [low, high] = token.values;
130
+ if (low.text === '' || high.text === '')
131
+ return null;
132
+ if (hasNul(low.text) || hasNul(high.text))
133
+ return null;
134
+ const lower = spec.toCondition('gte', low.text);
135
+ const upper = lower === null ? null : spec.toCondition('lte', high.text);
136
+ return lower === null || upper === null ? null : { AND: [lower, upper] };
137
+ }
138
+ function valuesCondition(token, operator, spec) {
139
+ const conditions = [];
140
+ for (const value of token.values) {
141
+ if (value.text === '')
142
+ continue;
143
+ if (hasNul(value.text))
144
+ return null;
145
+ const recordId = operator === 'eq' ? filterValueRecordId(value) : null;
146
+ const condition = recordId !== null && spec.toIdCondition
147
+ ? spec.toIdCondition(recordId)
148
+ : spec.toCondition(operator, value.text);
149
+ if (condition === null)
150
+ return null;
151
+ conditions.push(condition);
152
+ }
153
+ return conditions.length === 0 ? null : anyOf(conditions);
154
+ }
155
+ function fieldCondition(written, spec) {
156
+ const token = effectiveFilterToken(written, spec.operators);
157
+ if (token.operator === 'empty') {
158
+ if (spec.empty === undefined)
159
+ return null;
160
+ return token.negated ? { NOT: spec.empty } : spec.empty;
161
+ }
162
+ const matched = token.operator === 'range'
163
+ ? rangeCondition(token, spec)
164
+ : spec.operators.includes(token.operator)
165
+ ? valuesCondition(token, token.operator, spec)
166
+ : null;
167
+ if (matched === null)
168
+ return null;
169
+ if (!token.negated)
170
+ return matched;
171
+ const excluded = { NOT: matched };
172
+ return spec.empty === undefined || spec.negation !== undefined
173
+ ? excluded
174
+ : { OR: [excluded, spec.empty] };
175
+ }
176
+ /**
177
+ * Map a parsed {@link FilterQuery} to a single Where fragment, given the
178
+ * fields' {@link FilterSpec}s (ADR-0017, ADR-0083).
16
179
  *
17
180
  * Pure — no DB/Prisma imports. This is the unit-tested half of the filter seam.
18
- * Tokens combine with implicit AND. An empty-value token (`role:` or a bare
19
- * `""`) is a deliberate no-op — incomplete input expresses no constraint, so it
20
- * contributes nothing and is never handed to a free-text field (#1509). A
21
- * token with a value degrades to free text (never an error) when its field is
22
- * unknown, has no spec, uses an unsupported operator, or maps to `null`. Bare
23
- * words (and degraded tokens) are OR-matched across every free-text field, and
24
- * each such word is ANDed with the rest — so `beta gamma` requires both. A word
25
- * that reaches this stage but cannot be matched against any free-text field —
26
- * because the list has none, or because every free-text field's own mapping
27
- * rejects it — narrows the chain to {@link NEVER_MATCHES} instead of being
28
- * dropped: a condition that cannot be honoured must never widen the result set
29
- * (#1356).
181
+ * Terms combine with implicit AND. An empty token is a deliberate no-op —
182
+ * incomplete input expresses no constraint, so it contributes nothing and is
183
+ * never handed to a free-text field (#1509), and an empty value inside a list
184
+ * (`a:x,`) is skipped the same way.
185
+ *
186
+ * The engine composes around each field's own `toCondition`:
187
+ *
188
+ * - `field:a,b` ORs the field's condition once per value.
189
+ * - `-field:value` is `NOT` of that condition, ORed with the field's `empty`
190
+ * condition when it states one, so "is not" keeps the rows with no value.
191
+ * A spec stating a `negation` says `NOT` alone already does, and gets no `OR`.
192
+ * - `field:!` is the field's `empty` condition and `-field:!` its `NOT`.
193
+ * - `field:a..b` ANDs the field's own `gte` on `a` and `lte` on `b`, on any
194
+ * field comparing both ways, and `-field:a..b` is `NOT` of that, composed
195
+ * like any other negation. On a field that takes no range it is that
196
+ * field's `eq` on the literal `a..b`, as it was before ranges existed
197
+ * ({@link effectiveFilterToken}).
198
+ * - An unquoted `#id` value on a field whose spec has `toIdCondition` maps
199
+ * through it instead, matching exactly that related record, so
200
+ * `field:#a,#b` matches either and `-field:#id` excludes it. An id the
201
+ * related list cannot hold makes the token free text.
202
+ *
203
+ * A token that cannot map in any part (an unknown or unreadable field, an
204
+ * unsupported operator, a value the field rejects, any one value of a list, or
205
+ * `field:!` on a field that cannot be empty, or either bound of a range) is
206
+ * searched as one free-text word,
207
+ * {@link filterTokenFreeTextWord}, which is also what the Filter builder's chip
208
+ * shows. A positive token searches its values with the field name dropped
209
+ * (`status:draft,bogus` searches `draft,bogus`); a negated one searches its
210
+ * whole literal (`-secret:x`) and is never negated, because `NOT` of free text
211
+ * would turn a field the session cannot read into a filter. A free-text token
212
+ * is read as its serialised form reads back, so a structured one with several
213
+ * values is the words its URL holds. A `range` token is read the same way, so
214
+ * one whose bounds cannot be written `a..b` is the literal `"a..b"` its URL
215
+ * holds.
216
+ *
217
+ * An OR group, `(a OR b)`, is the `OR` of its tokens, each mapped exactly as
218
+ * it would be on its own and negated by the same rules. A token in a group
219
+ * that cannot map stays in place as its free-text alternative, never dropped,
220
+ * so it can only add rows the free-text search finds; an empty token in a
221
+ * group is skipped, and a group of nothing but empty tokens filters nothing.
30
222
  *
31
- * @param tokens Parsed tokens from {@link parseFilterQuery}.
32
- * @param specs Field-name → Filter spec (from {@link collectFilterSpecs}).
33
- * @returns A Prisma `where` fragment, or `undefined` when nothing filters.
223
+ * Bare words (and degraded tokens) are OR-matched across every free-text
224
+ * field, and each such word is ANDed with the rest — so `beta gamma` requires
225
+ * both. A word that cannot be matched against any free-text field — because
226
+ * the list has none, or because every free-text field's own mapping rejects
227
+ * it — narrows the chain to {@link NEVER_MATCHES} instead of being dropped: a
228
+ * condition that cannot be honoured must never widen the result set (#1356).
229
+ *
230
+ * @param query The structured query from {@link parseFilterQuery}.
231
+ * @param specs Field-name → Filter spec (from {@link collectFilterSpecs}).
232
+ * @returns A Where fragment, or `undefined` when nothing filters.
34
233
  */
35
- export function buildFilterWhere(tokens, specs) {
36
- const andConditions = [];
37
- const freeTextWords = [];
234
+ export function buildFilterWhere(query, specs) {
235
+ const fieldConditions = [];
236
+ const textConditions = [];
38
237
  const freeTextFields = Object.keys(specs).filter((field) => specs[field].freeText);
39
- for (const token of tokens) {
238
+ const specFor = (field) => Object.hasOwn(specs, field) ? specs[field] : undefined;
239
+ const freeText = (word) => {
240
+ if (hasNul(word))
241
+ return NEVER_MATCHES;
242
+ const conditions = freeTextFields
243
+ .map((field) => specs[field].toCondition('eq', word))
244
+ .filter((condition) => condition !== null);
245
+ return conditions.length > 0 ? anyOf(conditions) : NEVER_MATCHES;
246
+ };
247
+ const tokenCondition = (token) => {
248
+ const spec = token.field === null ? undefined : specFor(token.field);
249
+ return spec === undefined ? null : fieldCondition(token, spec);
250
+ };
251
+ const groupCondition = (term) => {
252
+ const alternatives = term.tokens
253
+ .filter((token) => !isEmptyFilterToken(token))
254
+ .map((token) => tokenCondition(token) ?? freeText(filterTokenFreeTextWord(token)));
255
+ return alternatives.length === 0 ? null : anyOf(alternatives);
256
+ };
257
+ const addToken = (token) => {
40
258
  // An empty value is incomplete input, not a constraint the engine failed
41
259
  // to honour: `role:` (or a bare `""`) says nothing to filter on, so it is
42
260
  // inert by design rather than narrowed away (#1509). This must be checked
43
- // before a token ever reaches `freeTextWords` — an empty value degrading
44
- // through the free-text path would call `toCondition('eq', '')`, and a
45
- // `contains`-style mapping over `''` matches every row, not none. That is
46
- // the opposite of #1356's narrow-on-failure rule, which only ever applies
47
- // to a token that DOES carry a value the system cannot compile.
48
- if (token.value === '')
49
- continue;
50
- if (token.field === null) {
51
- freeTextWords.push(token.value);
52
- continue;
261
+ // before a token ever reaches the free-text path — an empty value there
262
+ // would call `toCondition('eq', '')`, and a `contains`-style mapping over
263
+ // `''` matches every row, not none. That is the opposite of #1356's
264
+ // narrow-on-failure rule, which only ever applies to a token that DOES
265
+ // carry a value the system cannot compile.
266
+ if (isEmptyFilterToken(token))
267
+ return;
268
+ const condition = tokenCondition(token);
269
+ if (condition !== null)
270
+ fieldConditions.push(condition);
271
+ else
272
+ textConditions.push(freeText(filterTokenFreeTextWord(token)));
273
+ };
274
+ const addTerm = (term) => {
275
+ if (term.kind === 'token') {
276
+ addToken(term);
277
+ return;
53
278
  }
54
- const spec = Object.hasOwn(specs, token.field) ? specs[token.field] : undefined;
55
- if (!spec || !spec.operators.includes(token.operator)) {
56
- freeTextWords.push(token.value);
57
- continue;
279
+ const condition = groupCondition(term);
280
+ if (condition !== null)
281
+ fieldConditions.push(condition);
282
+ };
283
+ for (const term of query.terms) {
284
+ if (term.kind === 'group' || term.operator === 'range') {
285
+ parseFilterQuery(serializeFilterQuery({ terms: [term] })).terms.forEach(addTerm);
58
286
  }
59
- const condition = spec.toCondition(token.operator, token.value);
60
- if (condition === null) {
61
- freeTextWords.push(token.value);
62
- continue;
63
- }
64
- andConditions.push(condition);
65
- }
66
- for (const word of freeTextWords) {
67
- const orConditions = freeTextFields
68
- .map((field) => specs[field].toCondition('eq', word))
69
- .filter((condition) => condition !== null);
70
- if (orConditions.length > 0) {
71
- andConditions.push(orConditions.length === 1 ? orConditions[0] : { OR: orConditions });
287
+ else if (term.field === null) {
288
+ filterQueryTokens(parseFilterQuery(serializeFilterToken(term))).forEach(addToken);
72
289
  }
73
290
  else {
74
- andConditions.push(NEVER_MATCHES);
291
+ addToken(term);
75
292
  }
76
293
  }
294
+ const andConditions = [...fieldConditions, ...textConditions];
77
295
  if (andConditions.length === 0)
78
296
  return undefined;
79
- if (andConditions.length === 1)
80
- return andConditions[0];
81
- return { AND: andConditions };
297
+ const built = andConditions.length === 1 ? andConditions[0] : { AND: andConditions };
298
+ if (countEntries(built) > FILTER_MAX_ENTRIES)
299
+ throw new FilterTooLongError();
300
+ return built;
82
301
  }
83
302
  //# sourceMappingURL=map.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/filter/map.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,aAAa,GAAoB,EAAE,GAAG,EAAE,EAAE,EAAE,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAqB,EACrB,KAAiC;IAEjC,MAAM,aAAa,GAAsB,EAAE,CAAA;IAC3C,MAAM,aAAa,GAAa,EAAE,CAAA;IAElC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC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AAS,CAAA;IAChD,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa,EAAE,CAAA;IACpF,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,kBAAkB;QAAE,MAAM,IAAI,kBAAkB,EAAE,CAAA;IAC5E,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -1,33 +1,77 @@
1
- import type { FilterToken } from './types.js';
1
+ import type { FilterGroup, FilterOperator, FilterQuery, FilterTerm, FilterToken } from './types.js';
2
+ /** The keyword joining the tokens of an OR group: `(a OR b)`. */
3
+ export declare const FILTER_GROUP_KEYWORD = "OR";
2
4
  /**
3
- * Parse a filter query string into {@link FilterToken}s (ADR-0017 grammar).
4
- *
5
- * Pure and field-agnostic: it recognises the *syntax* (field prefix, comparison
6
- * operator, quoted value, bare word) but never validates field names or values
7
- * — that is the mapping step's job, where unknown/unmappable tokens degrade to
8
- * free text. This parser therefore never throws; malformed input simply parses
9
- * as bare free-text words.
5
+ * The prefix each {@link FilterOperator} is written with after `field:`: none
6
+ * for `eq`, and `>`, `>=`, `<`, `<=` for the comparisons.
7
+ */
8
+ export declare const FILTER_OPERATOR_PREFIXES: Readonly<Record<FilterOperator, string>>;
9
+ /**
10
+ * Every comparison prefix and its operator, longest prefix first, so a reader
11
+ * matching them in order takes `>=` before `>`.
12
+ */
13
+ export declare const FILTER_COMPARISON_PREFIXES: ReadonlyArray<readonly [string, FilterOperator]>;
14
+ export declare function isFilterWhitespace(ch: string): boolean;
15
+ /**
16
+ * The length of the field prefix (`name:`) at `start` in `text`, or `0` when
17
+ * there is none. A `word:` followed by `//` is a URL scheme, not a field.
18
+ */
19
+ export declare function fieldPrefixLength(text: string, start?: number): number;
20
+ /**
21
+ * The two bounds of an unquoted single value written as an inclusive range
22
+ * (`a..b`), split at its first `..`, or `null` when it is not one: a bound is
23
+ * missing, or the value holds a comma.
24
+ */
25
+ export declare function splitRangeValue(value: string): [string, string] | null;
26
+ export interface FilterRead<T> {
27
+ value: T;
28
+ end: number;
29
+ }
30
+ export declare function readFilterGroup(query: string, start: number): FilterRead<FilterGroup> | null;
31
+ /**
32
+ * Parse a filter query string into a structured {@link FilterQuery}
33
+ * (ADR-0017, ADR-0083). Never throws: input it cannot read as syntax parses as
34
+ * bare free-text words.
10
35
  *
11
- * Grammar:
12
- * - `field:value` → a field token with the `eq` operator.
13
- * - `field:>value`, `field:>=value`, `field:<value`, `field:<=value` →
14
- * comparison operators.
15
- * - `field:"multi word"` / bare `"multi word"` → quoted values keep spaces.
16
- * - anything else (`beta`, `>5`) → a bare free-text token (`field: null`).
36
+ * - `field:value` is a field token with the `eq` operator, and `field:>value`,
37
+ * `field:>=value`, `field:<value`, `field:<=value` are comparisons.
38
+ * - `field:a,b` carries several values, and `field:!` is the `empty` operator.
39
+ * - `field:a..b` is an inclusive `range` token whose two values are its
40
+ * bounds, split at the first `..`. A quoted value is never a range, and
41
+ * neither is a list: `field:a..b,c` is `eq` on `a..b` and `c`.
42
+ * - A leading `-` followed by more of the token negates it: `-field:value`.
43
+ * A `-` on its own is a free-text word.
44
+ * - `(a OR b)` is an OR group of the tokens `a` and `b`: `(` directly before
45
+ * the first token, the uppercase keyword `OR` between tokens, and `)`
46
+ * directly after the last. No member may hold an unquoted parenthesis of its
47
+ * own. Anything else, such as a lowercase `or`, a nested, inner or
48
+ * unmatched parenthesis (`(a OR f(x) y)`), or a group of one token, reads as
49
+ * it would without the group: literal words.
50
+ * - A value in double quotes keeps its spaces and commas and is literal:
51
+ * `"status:draft"` and `"OR"` are free-text words and `field:"!"` the text
52
+ * `!`. Inside quotes, `\"` is a quote and `\\` a backslash; any other
53
+ * backslash is itself.
54
+ * - Anything else (`beta`, `>5`, `http://x`) is a free-text word (`field: null`),
55
+ * whose commas are ordinary characters.
17
56
  *
18
- * A `word:` is *not* treated as a field prefix when the colon is immediately
19
- * followed by `//` (a URL scheme like `http://x` or `https://…`); the whole
20
- * token stays free text so a pasted URL is searched verbatim rather than
21
- * mangled into `{ field: 'http', value: '//x' }`.
57
+ * Validating fields and values is the engine's job, where a token that cannot
58
+ * map degrades to free text. {@link serializeFilterQuery} is the inverse.
22
59
  *
23
60
  * @example
24
- * parseFilterQuery('role:Editor orders:>5 name:"Ada Lovelace" beta')
25
- * // [
26
- * // { field: 'role', operator: 'eq', value: 'Editor', raw: 'role:Editor' },
27
- * // { field: 'orders', operator: 'gt', value: '5', raw: 'orders:>5' },
28
- * // { field: 'name', operator: 'eq', value: 'Ada Lovelace', raw: 'name:"Ada Lovelace"' },
29
- * // { field: null, operator: 'eq', value: 'beta', raw: 'beta' },
30
- * // ]
61
+ * parseFilterQuery('-role:Editor (status:draft OR author:#42) name:"Ada Lovelace" beta')
62
+ * // { terms: [
63
+ * // { kind: 'token', field: 'role', operator: 'eq', negated: true, values: [{ text: 'Editor', quoted: false }] },
64
+ * // { kind: 'group', tokens: [
65
+ * // { kind: 'token', field: 'status', operator: 'eq', negated: false, values: [{ text: 'draft', quoted: false }] },
66
+ * // { kind: 'token', field: 'author', operator: 'eq', negated: false, values: [{ text: '#42', quoted: false }] },
67
+ * // ] },
68
+ * // { kind: 'token', field: 'name', operator: 'eq', negated: false, values: [{ text: 'Ada Lovelace', quoted: true }] },
69
+ * // { kind: 'token', field: null, operator: 'eq', negated: false, values: [{ text: 'beta', quoted: false }] },
70
+ * // ] }
31
71
  */
32
- export declare function parseFilterQuery(query: string): FilterToken[];
72
+ export declare function parseFilterQuery(query: string): FilterQuery;
73
+ /** The tokens of one {@link FilterTerm}: the token itself, or a group's tokens. */
74
+ export declare function filterTermTokens(term: FilterTerm): FilterToken[];
75
+ /** Every token of a {@link FilterQuery}, with its groups flattened, in order. */
76
+ export declare function filterQueryTokens(query: FilterQuery): FilterToken[];
33
77
  //# sourceMappingURL=parse.d.ts.map