@owlmeans/server-planning 0.1.18-rc.21 → 0.1.18-rc.23

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 (313) hide show
  1. package/README.md +24 -17
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/server-planning/SKILL.md +28 -28
  4. package/build/actions/apply-schema-request.d.ts +8 -0
  5. package/build/actions/apply-schema-request.d.ts.map +1 -0
  6. package/build/actions/apply-schema-request.js +31 -0
  7. package/build/actions/apply-schema-request.js.map +1 -0
  8. package/build/actions/cards.d.ts +5 -3
  9. package/build/actions/cards.d.ts.map +1 -1
  10. package/build/actions/cards.js +1 -1
  11. package/build/actions/cards.js.map +1 -1
  12. package/build/actions/commit.d.ts +3 -3
  13. package/build/actions/commit.d.ts.map +1 -1
  14. package/build/actions/commit.js +5 -4
  15. package/build/actions/commit.js.map +1 -1
  16. package/build/actions/define-schemas.d.ts +13 -0
  17. package/build/actions/define-schemas.d.ts.map +1 -0
  18. package/build/actions/define-schemas.js +28 -0
  19. package/build/actions/define-schemas.js.map +1 -0
  20. package/build/actions/execute.d.ts +8 -28
  21. package/build/actions/execute.d.ts.map +1 -1
  22. package/build/actions/execute.js +17 -101
  23. package/build/actions/execute.js.map +1 -1
  24. package/build/actions/execution/types.d.ts +34 -0
  25. package/build/actions/execution/types.d.ts.map +1 -0
  26. package/build/actions/execution/types.js +2 -0
  27. package/build/actions/execution/types.js.map +1 -0
  28. package/build/actions/execution.d.ts +4 -0
  29. package/build/actions/execution.d.ts.map +1 -0
  30. package/build/actions/execution.js +79 -0
  31. package/build/actions/execution.js.map +1 -0
  32. package/build/actions/get-card.d.ts +6 -0
  33. package/build/actions/get-card.d.ts.map +1 -0
  34. package/build/actions/get-card.js +9 -0
  35. package/build/actions/get-card.js.map +1 -0
  36. package/build/actions/get-specification.d.ts +6 -0
  37. package/build/actions/get-specification.d.ts.map +1 -0
  38. package/build/actions/get-specification.js +9 -0
  39. package/build/actions/get-specification.js.map +1 -0
  40. package/build/actions/index.d.ts +12 -3
  41. package/build/actions/index.d.ts.map +1 -1
  42. package/build/actions/index.js +11 -3
  43. package/build/actions/index.js.map +1 -1
  44. package/build/actions/links.d.ts +3 -3
  45. package/build/actions/links.d.ts.map +1 -1
  46. package/build/actions/links.js +6 -5
  47. package/build/actions/links.js.map +1 -1
  48. package/build/actions/list-card-specifications.d.ts +6 -0
  49. package/build/actions/list-card-specifications.d.ts.map +1 -0
  50. package/build/actions/list-card-specifications.js +11 -0
  51. package/build/actions/list-card-specifications.js.map +1 -0
  52. package/build/actions/list-card-transitions.d.ts +6 -0
  53. package/build/actions/list-card-transitions.d.ts.map +1 -0
  54. package/build/actions/list-card-transitions.js +11 -0
  55. package/build/actions/list-card-transitions.js.map +1 -0
  56. package/build/actions/list-cards.d.ts +6 -0
  57. package/build/actions/list-cards.d.ts.map +1 -0
  58. package/build/actions/list-cards.js +10 -0
  59. package/build/actions/list-cards.js.map +1 -0
  60. package/build/actions/list-schemas.d.ts +13 -0
  61. package/build/actions/list-schemas.d.ts.map +1 -0
  62. package/build/actions/list-schemas.js +20 -0
  63. package/build/actions/list-schemas.js.map +1 -0
  64. package/build/actions/list-specification-revisions.d.ts +6 -0
  65. package/build/actions/list-specification-revisions.d.ts.map +1 -0
  66. package/build/actions/list-specification-revisions.js +10 -0
  67. package/build/actions/list-specification-revisions.js.map +1 -0
  68. package/build/actions/schemas.d.ts +5 -3
  69. package/build/actions/schemas.d.ts.map +1 -1
  70. package/build/actions/schemas.js.map +1 -1
  71. package/build/actions/specs.d.ts +4 -2
  72. package/build/actions/specs.d.ts.map +1 -1
  73. package/build/actions/specs.js.map +1 -1
  74. package/build/actions/summarize-cards.d.ts +6 -0
  75. package/build/actions/summarize-cards.d.ts.map +1 -0
  76. package/build/actions/summarize-cards.js +11 -0
  77. package/build/actions/summarize-cards.js.map +1 -0
  78. package/build/actions/transitions.d.ts +3 -3
  79. package/build/actions/transitions.d.ts.map +1 -1
  80. package/build/actions/transitions.js +4 -3
  81. package/build/actions/transitions.js.map +1 -1
  82. package/build/actions/types.d.ts +5 -3
  83. package/build/actions/types.d.ts.map +1 -1
  84. package/build/actions/watch.d.ts +2 -2
  85. package/build/actions/watch.d.ts.map +1 -1
  86. package/build/actions/watch.js +2 -2
  87. package/build/actions/watch.js.map +1 -1
  88. package/build/conformance/assert/types.d.ts +19 -0
  89. package/build/conformance/assert/types.d.ts.map +1 -0
  90. package/build/conformance/assert/types.js +2 -0
  91. package/build/conformance/assert/types.js.map +1 -0
  92. package/build/conformance/assert.d.ts +8 -13
  93. package/build/conformance/assert.d.ts.map +1 -1
  94. package/build/conformance/assert.js +41 -43
  95. package/build/conformance/assert.js.map +1 -1
  96. package/build/conformance/cases.d.ts.map +1 -1
  97. package/build/conformance/cases.js +86 -67
  98. package/build/conformance/cases.js.map +1 -1
  99. package/build/conformance/clock.d.ts +6 -0
  100. package/build/conformance/clock.d.ts.map +1 -0
  101. package/build/conformance/clock.js +12 -0
  102. package/build/conformance/clock.js.map +1 -0
  103. package/build/conformance/consts.d.ts +3 -1
  104. package/build/conformance/consts.d.ts.map +1 -1
  105. package/build/conformance/consts.js +84 -1
  106. package/build/conformance/consts.js.map +1 -1
  107. package/build/conformance/errors.d.ts +5 -0
  108. package/build/conformance/errors.d.ts.map +1 -0
  109. package/build/conformance/errors.js +8 -0
  110. package/build/conformance/errors.js.map +1 -0
  111. package/build/conformance/fixtures/types.d.ts +13 -0
  112. package/build/conformance/fixtures/types.d.ts.map +1 -0
  113. package/build/conformance/fixtures/types.js +2 -0
  114. package/build/conformance/fixtures/types.js.map +1 -0
  115. package/build/conformance/fixtures.d.ts +8 -8
  116. package/build/conformance/fixtures.d.ts.map +1 -1
  117. package/build/conformance/fixtures.js +24 -107
  118. package/build/conformance/fixtures.js.map +1 -1
  119. package/build/conformance/index.d.ts +3 -0
  120. package/build/conformance/index.d.ts.map +1 -1
  121. package/build/conformance/index.js +1 -0
  122. package/build/conformance/index.js.map +1 -1
  123. package/build/definitions.d.ts.map +1 -1
  124. package/build/definitions.js +9 -9
  125. package/build/definitions.js.map +1 -1
  126. package/build/executor/changes/types.d.ts +36 -0
  127. package/build/executor/changes/types.d.ts.map +1 -0
  128. package/build/executor/changes/types.js +2 -0
  129. package/build/executor/changes/types.js.map +1 -0
  130. package/build/executor/changes.d.ts +3 -30
  131. package/build/executor/changes.d.ts.map +1 -1
  132. package/build/executor/changes.js +42 -51
  133. package/build/executor/changes.js.map +1 -1
  134. package/build/executor/code/types.d.ts +17 -0
  135. package/build/executor/code/types.d.ts.map +1 -0
  136. package/build/executor/code/types.js +2 -0
  137. package/build/executor/code/types.js.map +1 -0
  138. package/build/executor/code.d.ts +3 -14
  139. package/build/executor/code.d.ts.map +1 -1
  140. package/build/executor/code.js +50 -54
  141. package/build/executor/code.js.map +1 -1
  142. package/build/executor/creator/types.d.ts +33 -0
  143. package/build/executor/creator/types.d.ts.map +1 -0
  144. package/build/executor/creator/types.js +2 -0
  145. package/build/executor/creator/types.js.map +1 -0
  146. package/build/executor/creator.d.ts +6 -25
  147. package/build/executor/creator.d.ts.map +1 -1
  148. package/build/executor/creator.js +26 -41
  149. package/build/executor/creator.js.map +1 -1
  150. package/build/executor/resolve/types.d.ts +30 -0
  151. package/build/executor/resolve/types.d.ts.map +1 -0
  152. package/build/executor/resolve/types.js +2 -0
  153. package/build/executor/resolve/types.js.map +1 -0
  154. package/build/executor/resolve.d.ts +4 -41
  155. package/build/executor/resolve.d.ts.map +1 -1
  156. package/build/executor/resolve.js +142 -157
  157. package/build/executor/resolve.js.map +1 -1
  158. package/build/executor/types.d.ts +0 -2
  159. package/build/executor/types.d.ts.map +1 -1
  160. package/build/executor/validate.d.ts +1 -1
  161. package/build/executor/validate.d.ts.map +1 -1
  162. package/build/executor/validate.js +16 -15
  163. package/build/executor/validate.js.map +1 -1
  164. package/build/executor.d.ts +4 -3
  165. package/build/executor.d.ts.map +1 -1
  166. package/build/executor.js +18 -17
  167. package/build/executor.js.map +1 -1
  168. package/build/facade.d.ts.map +1 -1
  169. package/build/facade.js +16 -16
  170. package/build/facade.js.map +1 -1
  171. package/build/helper.d.ts +1 -6
  172. package/build/helper.d.ts.map +1 -1
  173. package/build/helper.js +3 -8
  174. package/build/helper.js.map +1 -1
  175. package/build/projection.d.ts +2 -0
  176. package/build/projection.d.ts.map +1 -1
  177. package/build/projection.js +6 -4
  178. package/build/projection.js.map +1 -1
  179. package/build/queue/declare.d.ts +5 -0
  180. package/build/queue/declare.d.ts.map +1 -0
  181. package/build/queue/declare.js +5 -0
  182. package/build/queue/declare.js.map +1 -0
  183. package/build/queue/index.d.ts +1 -4
  184. package/build/queue/index.d.ts.map +1 -1
  185. package/build/queue/index.js +1 -4
  186. package/build/queue/index.js.map +1 -1
  187. package/build/store/composite.d.ts.map +1 -1
  188. package/build/store/composite.js +2 -2
  189. package/build/store/composite.js.map +1 -1
  190. package/build/store/fold/types.d.ts +43 -0
  191. package/build/store/fold/types.d.ts.map +1 -0
  192. package/build/store/fold/types.js +2 -0
  193. package/build/store/fold/types.js.map +1 -0
  194. package/build/store/fold.d.ts +7 -30
  195. package/build/store/fold.d.ts.map +1 -1
  196. package/build/store/fold.js +185 -203
  197. package/build/store/fold.js.map +1 -1
  198. package/build/store/index.d.ts +1 -0
  199. package/build/store/index.d.ts.map +1 -1
  200. package/build/store/index.js.map +1 -1
  201. package/build/store/memory.d.ts.map +1 -1
  202. package/build/store/memory.js +0 -0
  203. package/build/store/memory.js.map +1 -1
  204. package/build/store/types.local.d.ts +3 -1
  205. package/build/store/types.local.d.ts.map +1 -1
  206. package/build/types.d.ts +2 -1
  207. package/build/types.d.ts.map +1 -1
  208. package/build/utils/access/types.d.ts +30 -0
  209. package/build/utils/access/types.d.ts.map +1 -0
  210. package/build/utils/access/types.js +2 -0
  211. package/build/utils/access/types.js.map +1 -0
  212. package/build/utils/access.d.ts +4 -0
  213. package/build/utils/access.d.ts.map +1 -0
  214. package/build/utils/access.js +28 -0
  215. package/build/utils/access.js.map +1 -0
  216. package/build/utils/guard/types.d.ts +21 -0
  217. package/build/utils/guard/types.d.ts.map +1 -0
  218. package/build/utils/guard/types.js +2 -0
  219. package/build/utils/guard/types.js.map +1 -0
  220. package/build/utils/guard.d.ts +7 -10
  221. package/build/utils/guard.d.ts.map +1 -1
  222. package/build/utils/guard.js +33 -31
  223. package/build/utils/guard.js.map +1 -1
  224. package/build/utils/handler/types.d.ts +26 -0
  225. package/build/utils/handler/types.d.ts.map +1 -0
  226. package/build/utils/handler/types.js +2 -0
  227. package/build/utils/handler/types.js.map +1 -0
  228. package/build/utils/handler.d.ts +6 -0
  229. package/build/utils/handler.d.ts.map +1 -0
  230. package/build/utils/handler.js +21 -0
  231. package/build/utils/handler.js.map +1 -0
  232. package/build/utils/index.d.ts +8 -1
  233. package/build/utils/index.d.ts.map +1 -1
  234. package/build/utils/index.js +3 -0
  235. package/build/utils/index.js.map +1 -1
  236. package/build/utils/request/types.d.ts +23 -0
  237. package/build/utils/request/types.d.ts.map +1 -0
  238. package/build/utils/request/types.js +2 -0
  239. package/build/utils/request/types.js.map +1 -0
  240. package/build/utils/request.d.ts +4 -0
  241. package/build/utils/request.d.ts.map +1 -0
  242. package/build/utils/request.js +27 -0
  243. package/build/utils/request.js.map +1 -0
  244. package/build/utils/scope.d.ts +10 -43
  245. package/build/utils/scope.d.ts.map +1 -1
  246. package/build/utils/scope.js +21 -99
  247. package/build/utils/scope.js.map +1 -1
  248. package/package.json +18 -18
  249. package/src/actions/apply-schema-request.ts +35 -0
  250. package/src/actions/commit.ts +7 -5
  251. package/src/actions/define-schemas.ts +34 -0
  252. package/src/actions/execute.ts +30 -115
  253. package/src/actions/execution/types.ts +34 -0
  254. package/src/actions/execution.ts +96 -0
  255. package/src/actions/get-card.ts +14 -0
  256. package/src/actions/get-specification.ts +14 -0
  257. package/src/actions/index.ts +13 -3
  258. package/src/actions/links.ts +8 -6
  259. package/src/actions/list-card-specifications.ts +15 -0
  260. package/src/actions/list-card-transitions.ts +15 -0
  261. package/src/actions/list-cards.ts +14 -0
  262. package/src/actions/list-schemas.ts +29 -0
  263. package/src/actions/{specs.ts → list-specification-revisions.ts} +4 -11
  264. package/src/actions/summarize-cards.ts +15 -0
  265. package/src/actions/transitions.ts +6 -4
  266. package/src/actions/types.ts +4 -3
  267. package/src/actions/watch.ts +4 -3
  268. package/src/conformance/assert/types.ts +16 -0
  269. package/src/conformance/assert.ts +49 -41
  270. package/src/conformance/cases.ts +88 -67
  271. package/src/conformance/clock.ts +11 -0
  272. package/src/conformance/consts.ts +87 -1
  273. package/src/conformance/errors.ts +7 -0
  274. package/src/conformance/fixtures/types.ts +11 -0
  275. package/src/conformance/fixtures.ts +32 -107
  276. package/src/conformance/index.ts +3 -0
  277. package/src/definitions.ts +9 -9
  278. package/src/executor/changes/types.ts +38 -0
  279. package/src/executor/changes.ts +48 -63
  280. package/src/executor/code/types.ts +23 -0
  281. package/src/executor/code.ts +60 -61
  282. package/src/executor/creator/types.ts +33 -0
  283. package/src/executor/creator.ts +33 -41
  284. package/src/executor/resolve/types.ts +30 -0
  285. package/src/executor/resolve.ts +153 -167
  286. package/src/executor/types.ts +0 -3
  287. package/src/executor/validate.ts +17 -16
  288. package/src/executor.ts +20 -17
  289. package/src/facade.ts +16 -16
  290. package/src/helper.ts +3 -8
  291. package/src/projection.ts +8 -4
  292. package/src/queue/declare.ts +7 -0
  293. package/src/queue/index.ts +1 -8
  294. package/src/store/composite.ts +2 -2
  295. package/src/store/fold/types.ts +44 -0
  296. package/src/store/fold.ts +209 -212
  297. package/src/store/index.ts +1 -0
  298. package/src/store/memory.ts +0 -0
  299. package/src/store/types.local.ts +1 -1
  300. package/src/types.ts +1 -1
  301. package/src/utils/access/types.ts +30 -0
  302. package/src/utils/access.ts +33 -0
  303. package/src/utils/guard/types.ts +19 -0
  304. package/src/utils/guard.ts +41 -30
  305. package/src/utils/handler/types.ts +28 -0
  306. package/src/utils/handler.ts +35 -0
  307. package/src/utils/index.ts +9 -1
  308. package/src/utils/request/types.ts +23 -0
  309. package/src/utils/request.ts +40 -0
  310. package/src/utils/scope.ts +25 -108
  311. package/tests/creator.spec.ts +18 -18
  312. package/src/actions/cards.ts +0 -48
  313. package/src/actions/schemas.ts +0 -87
package/src/facade.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { criteriaOf, currentSpecification, isProject, isSpecification, linkWhereOf, listOptionsOf, modelOf, projectOf, PlanningUnsupported, specCriteriaOf, transitionWhereOf, WorkcardKind, WorkcardNotFound, type CommitEvent, type CommitSource, type PlanningFacade, type PlanningScope, type Relationship, type Specification, type Transition, type Workcard, type WorkcardModel, type WorkcardQuery } from '@owlmeans/planning'
1
+ import { cardHelper, modelOf, PlanningUnsupported, queryHelper, specificationHelper, WorkcardKind, WorkcardNotFound, type CommitEvent, type CommitSource, type PlanningFacade, type PlanningScope, type Relationship, type Specification, type Transition, type Workcard, type WorkcardModel, type WorkcardQuery } from '@owlmeans/planning'
2
2
  import type { Criteria } from '@owlmeans/resource'
3
3
  import { makeDefinitions } from './definitions.js'
4
4
  import { executeTransition } from './executor.js'
@@ -54,7 +54,7 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
54
54
  if (card == null || inProjects(card)) {
55
55
  return card
56
56
  }
57
- if (isSpecification(card) && card.parent != null) {
57
+ if (cardHelper.isSpecification(card) && card.parent != null) {
58
58
  const parent = mine(await reader().cards.get(card.parent, entityId))
59
59
  return parent != null && inProjects(parent) ? card : null
60
60
  }
@@ -82,7 +82,7 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
82
82
 
83
83
  /** A narrowed list's or count's criteria — `through` as {@link throughOf} resolved it. */
84
84
  const narrowed = async (query?: WorkcardQuery | null): Promise<Criteria<Workcard>> => {
85
- const where = criteriaOf(query, scope)
85
+ const where = queryHelper.criteriaOf(query, scope)
86
86
  return narrow(where, await throughOf(where, query?.parent))
87
87
  }
88
88
 
@@ -121,11 +121,11 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
121
121
 
122
122
  /** The project a card resolves its data-defined types in. */
123
123
  const projectFor = async (card: Workcard): Promise<string | undefined> => {
124
- if (isProject(card) || card.parent == null) {
125
- return projectOf(card)
124
+ if (cardHelper.isProject(card) || card.parent == null) {
125
+ return cardHelper.projectOf(card)
126
126
  }
127
127
  const parent = mine(await reader().cards.get(card.parent, entityId))
128
- return projectOf(card, parent)
128
+ return cardHelper.projectOf(card, parent)
129
129
  }
130
130
 
131
131
  const facade: PlanningFacade = {
@@ -144,13 +144,13 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
144
144
  return card
145
145
  },
146
146
 
147
- list: async query => await reader().cards.list(await narrowed(query), listOptionsOf(query)),
147
+ list: async query => await reader().cards.list(await narrowed(query), queryHelper.listOptionsOf(query)),
148
148
 
149
149
  count: async query => await reader().cards.count(await narrowed(query)),
150
150
 
151
151
  summary: async (parents, query) => parents.length === 0
152
152
  ? {}
153
- : await reader().cards.summary(parents, narrow(criteriaOf({ kind: query?.kind, type: query?.type }, scope))),
153
+ : await reader().cards.summary(parents, narrow(queryHelper.criteriaOf({ kind: query?.kind, type: query?.type }, scope))),
154
154
  },
155
155
 
156
156
  specifications: {
@@ -162,8 +162,8 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
162
162
  if (specs != null) {
163
163
  return mine(await specs.current(parent, category, entityId))
164
164
  }
165
- const listed = await reader().cards.list(specCriteriaOf(parent, { category }, scope) as never, { size: 0 })
166
- return currentSpecification(listed.items, category)
165
+ const listed = await reader().cards.list(queryHelper.specCriteriaOf(parent, { category }, scope) as never, { size: 0 })
166
+ return specificationHelper.currentSpecification(listed.items, category)
167
167
  },
168
168
 
169
169
  list: async (parent, query) => {
@@ -174,12 +174,12 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
174
174
  if (specs != null) {
175
175
  return await specs.list(parent, entityId, query)
176
176
  }
177
- return await reader().cards.list(specCriteriaOf(parent, query, scope) as never, listOptionsOf(query) as never) as never
177
+ return await reader().cards.list(queryHelper.specCriteriaOf(parent, query, scope) as never, queryHelper.listOptionsOf(query) as never) as never
178
178
  },
179
179
 
180
180
  get: async id => {
181
181
  const card = await facade.cards.load(id)
182
- if (card == null || !isSpecification(card)) {
182
+ if (card == null || !cardHelper.isSpecification(card)) {
183
183
  throw new WorkcardNotFound(id)
184
184
  }
185
185
  return card as Specification
@@ -202,9 +202,9 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
202
202
  return { items: [], total: 0 }
203
203
  }
204
204
  if (projects == null) {
205
- return await links.list(linkWhereOf(query, scope), listOptionsOf(query))
205
+ return await links.list(queryHelper.linkWhereOf(query, scope), queryHelper.listOptionsOf(query))
206
206
  }
207
- const listed = await links.list({ ...linkWhereOf(query, scope), project: projects }, listOptionsOf(query))
207
+ const listed = await links.list({ ...queryHelper.linkWhereOf(query, scope), project: projects }, queryHelper.listOptionsOf(query))
208
208
  // A store that ignores `project` must still not leak an edge filed under another project.
209
209
  const items = listed.items.filter((link: Relationship) => projectVisible(link.project))
210
210
  return items.length === listed.items.length ? listed : { ...listed, items, total: listed.total - (listed.items.length - items.length) }
@@ -226,13 +226,13 @@ export const makeStoreFacade = (runtime: PlanningRuntime, scope: PlanningScope):
226
226
  return { items: [], total: 0 }
227
227
  }
228
228
  if (projects == null) {
229
- return await transitions.list(transitionWhereOf(query, scope), listOptionsOf(query))
229
+ return await transitions.list(queryHelper.transitionWhereOf(query, scope), queryHelper.listOptionsOf(query))
230
230
  }
231
231
  if (query.project != null && !projects.includes(query.project)) {
232
232
  return { items: [], total: 0 }
233
233
  }
234
234
  const listed = await transitions.list(
235
- { ...transitionWhereOf(query, scope), project: query.project ?? projects }, listOptionsOf(query)
235
+ { ...queryHelper.transitionWhereOf(query, scope), project: query.project ?? projects }, queryHelper.listOptionsOf(query)
236
236
  )
237
237
  const items = listed.items.filter((transition: Transition) => projectVisible(transition.project))
238
238
  return items.length === listed.items.length ? listed : { ...listed, items, total: listed.total - (listed.items.length - items.length) }
package/src/helper.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  watchCommits,
9
9
  } from './actions/index.js'
10
10
  import type { PlanningHandlerOptions } from './types.js'
11
- import { planningServiceOf, scopeOf } from './utils/index.js'
11
+ import { planningHandlerOf } from './utils/handler.js'
12
12
 
13
13
  /**
14
14
  * Bind this package's handlers to a tree declared by `makePlanningProtocols` — one binding per
@@ -36,13 +36,8 @@ export const servePlanningEntrypoints = (protocols: PlanningProtocols, opts?: Pl
36
36
  bind(protocols.commit.events, watchCommits(protocols.commit.events, opts)),
37
37
  ]
38
38
 
39
- /**
40
- * The facade a hand-written handler works through: the request's entity and subject, plus `extra`
41
- * (a `channel`) — never an entity from the request body.
42
- *
43
- * @throws {AuthorizationError} when the request carries no organization
44
- */
39
+ /** @deprecated compat:factory-refactor — use `planningHandlerOf(ctx).planningFor(…)` */
45
40
  export const planningFor = (
46
41
  ctx: BasicContext<BasicConfig>, req: AbstractRequest, extra?: Partial<PlanningScope>,
47
42
  opts?: Pick<PlanningHandlerOptions, 'service'>
48
- ): PlanningFacade => planningServiceOf(ctx, opts).for(scopeOf(req, extra))
43
+ ): PlanningFacade => planningHandlerOf(ctx).planningFor(req, extra, opts)
package/src/projection.ts CHANGED
@@ -3,7 +3,7 @@ import { PLANNING_SERVICE, type PlanningService, type PlanningStore } from '@owl
3
3
  import { PLANNING_PROJECT_JOB, PLANNING_PROJECTION_QUEUE } from './queue/consts.js'
4
4
  import type { ProjectionRequest } from './queue/types.js'
5
5
  import type { JobProcessor, QueueHooks } from '@owlmeans/queue'
6
- import { failPending, foldPending } from './store/fold.js'
6
+ import { foldHelper } from './store/fold.js'
7
7
  import type { PlanningHostService, ProjectionOptions } from './types.js'
8
8
  import type { CommitHub, FoldResult } from './store/types.js'
9
9
 
@@ -30,7 +30,7 @@ export const makeProjectionProcessor = (
30
30
  const store = storeOf(service, opts)
31
31
  const publish = publisherOf(store, opts)
32
32
 
33
- return await foldPending(store, job.data.cardId, job.data.entityId, {
33
+ return await foldHelper.foldPending(store, job.data.cardId, job.data.entityId, {
34
34
  touch: job.touch,
35
35
  onCommitted: async event => { await service.committed(event) },
36
36
  ...(publish != null ? { publish } : {}),
@@ -42,7 +42,7 @@ export const makeProjectionProcessor = (
42
42
  * failed event is published — otherwise `execute({ wait: true })` and `commits.wait` hang to their
43
43
  * timeout. Merge it into the queue driver's hooks.
44
44
  */
45
- export const planningQueueHooks = (ctx: BasicContext<BasicConfig>, opts?: ProjectionOptions): QueueHooks => ({
45
+ export const makePlanningQueueHooks = (ctx: BasicContext<BasicConfig>, opts?: ProjectionOptions): QueueHooks => ({
46
46
  onJobDead: async (job, reason) => {
47
47
  if (job.queue !== PLANNING_PROJECTION_QUEUE || job.name !== PLANNING_PROJECT_JOB) {
48
48
  return
@@ -50,6 +50,10 @@ export const planningQueueHooks = (ctx: BasicContext<BasicConfig>, opts?: Projec
50
50
  const request = job.data as ProjectionRequest
51
51
  const store = storeOf(serviceOf(ctx, opts), opts)
52
52
  const publish = publisherOf(store, opts)
53
- await failPending(store, request.cardId, request.entityId, reason, publish != null ? { publish } : {})
53
+ await foldHelper.failPending(store, request.cardId, request.entityId, reason, publish != null ? { publish } : {})
54
54
  },
55
55
  })
56
+
57
+ /** @deprecated compat:factory-refactor — use `makePlanningQueueHooks(…)` */
58
+ export const planningQueueHooks = (ctx: BasicContext<BasicConfig>, opts?: ProjectionOptions): QueueHooks =>
59
+ makePlanningQueueHooks(ctx, opts)
@@ -0,0 +1,7 @@
1
+ import { declareQueue, type Config } from '@owlmeans/queue'
2
+ import { PLANNING_PROJECT_JOB, PLANNING_PROJECTION_QUEUE } from './consts.js'
3
+ import type { PlanningQueueOptions } from './types.js'
4
+
5
+ /** Declare the shared projection address; each process separately chooses whether to listen. */
6
+ export const declarePlanningQueue = <C extends Config>(cfg: C, opts?: PlanningQueueOptions): C =>
7
+ declareQueue(cfg, PLANNING_PROJECTION_QUEUE, [PLANNING_PROJECT_JOB], opts)
@@ -1,10 +1,3 @@
1
- import { declareQueue, type Config } from '@owlmeans/queue'
2
- import { PLANNING_PROJECT_JOB, PLANNING_PROJECTION_QUEUE } from './consts.js'
3
- import type { PlanningQueueOptions } from './types.js'
4
-
5
- /** Declare the shared projection address; each process separately chooses whether to listen. */
6
- export const declarePlanningQueue = <C extends Config>(cfg: C, opts?: PlanningQueueOptions): C =>
7
- declareQueue(cfg, PLANNING_PROJECTION_QUEUE, [PLANNING_PROJECT_JOB], opts)
8
-
1
+ export { declarePlanningQueue } from './declare.js'
9
2
  export { PLANNING_PROJECTION_QUEUE, PLANNING_PROJECT_JOB } from './consts.js'
10
3
  export type { PlanningQueueOptions, ProjectionRequest } from './types.js'
@@ -3,9 +3,9 @@ import type {
3
3
  CommitSource, PlanningStore, ProjectionStore, Relationship, RelationshipStore, SpecificationStore,
4
4
  TransitionStore, Unsubscribe, Workcard,
5
5
  } from '@owlmeans/planning'
6
- import { applyQuery } from '@owlmeans/resource'
7
6
  import type { Criteria, ListResult } from '@owlmeans/resource'
8
7
  import type { CommitHub, StoreRoute } from './types.js'
8
+ import { recordQueryHelper } from '@owlmeans/resource'
9
9
 
10
10
  const firstOf = async <S, T>(
11
11
  stores: S[], read: (store: S) => Promise<T | null | undefined> | undefined
@@ -122,7 +122,7 @@ export const makeCompositeStore = (routes: StoreRoute[], fallback: PlanningStore
122
122
  list: async (where, opts) => {
123
123
  const results = await Promise.all(linked.map(store => store.links!.list(where, { size: 0 })))
124
124
  const items = results.flatMap((result: ListResult<Relationship>) => result.items)
125
- return applyQuery(items, undefined, opts)
125
+ return recordQueryHelper.applyQuery(items, undefined, opts)
126
126
  },
127
127
  put: link => (fallback.links ?? linked[0].links!).put(link),
128
128
  drop: where => sum(linked, store => store.links!.drop(where)),
@@ -0,0 +1,44 @@
1
+ import type { CommitEvent, CommitState, PlanningStore, SpecificationRevision, Transition, Workcard } from '@owlmeans/planning'
2
+ import type { FoldOptions, FoldResult } from '../types.js'
3
+
4
+ /** The projection body every store reuses: the fold of a card's pending log, and what it publishes. */
5
+ export interface FoldHelper {
6
+ /** The event a settled transition publishes. `record` is in-process only — strip it before a bus. */
7
+ commitEventOf: (
8
+ transition: Transition, state: CommitState, at: string, extra?: { error?: string, record?: Workcard | null }
9
+ ) => CommitEvent
10
+ /**
11
+ * Fold every pending transition of one card — the projection body every store reuses.
12
+ *
13
+ * Transitions are read in `seq` order past the card's own `seq`, and only `pending` ones are
14
+ * applied, each with `applyHelper.applyTransition` and nothing else. Per transition: write the
15
+ * record (a `delete` drops it, a project `delete` purges everything under it), fold its
16
+ * relationships, mark it `committed`, `publish` the event, then run `onCommitted` — so the `after`
17
+ * chain runs in THIS process, exactly once per committed transition. A transition that cannot be
18
+ * folded is marked `failed` with the reason and a failed event is published, and the fold goes PAST
19
+ * it: the card's `seq` advances to the failed transition with every other value as it was, so the
20
+ * next transition applies normally. Nothing is removed from the log. A create that fails leaves no
21
+ * card to advance, so what follows it fails too; a store that refuses the advancing write itself
22
+ * stops the fold there and reports `followUp`, leaving the rest pending for a retry.
23
+ *
24
+ * The caller owns single flight: two folds of one card running at once would both publish. A
25
+ * transactional store passes `unit`, which wraps each transition's writes (a savepoint), so a write
26
+ * the database refuses is undone whole before the fold marks the transition failed.
27
+ *
28
+ * @throws {PlanningUnsupported} for a store without a transition log
29
+ */
30
+ foldPending: (store: PlanningStore, cardId: string, entityId: string, opts?: FoldOptions) => Promise<FoldResult>
31
+ /**
32
+ * Mark every pending transition of a card `failed` and publish a failed event for each — what a
33
+ * queued store does when its projection job is dead, or waiters hang until their timeout.
34
+ */
35
+ failPending: (
36
+ store: PlanningStore, cardId: string, entityId: string, reason: string, opts?: Pick<FoldOptions, 'publish' | 'now'>
37
+ ) => Promise<number>
38
+ /**
39
+ * A specification's history, replayed from its log: one entry per create and per committed
40
+ * content change, newest first. The fold is `applyHelper.applyTransition` itself, so an entry's
41
+ * `body` is the body AT that revision even when the transition changed only `ref`.
42
+ */
43
+ revisionsFromLog: (log: Transition[], limit?: number) => SpecificationRevision[]
44
+ }