@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.
- package/README.md +24 -17
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-planning/SKILL.md +28 -28
- package/build/actions/apply-schema-request.d.ts +8 -0
- package/build/actions/apply-schema-request.d.ts.map +1 -0
- package/build/actions/apply-schema-request.js +31 -0
- package/build/actions/apply-schema-request.js.map +1 -0
- package/build/actions/cards.d.ts +5 -3
- package/build/actions/cards.d.ts.map +1 -1
- package/build/actions/cards.js +1 -1
- package/build/actions/cards.js.map +1 -1
- package/build/actions/commit.d.ts +3 -3
- package/build/actions/commit.d.ts.map +1 -1
- package/build/actions/commit.js +5 -4
- package/build/actions/commit.js.map +1 -1
- package/build/actions/define-schemas.d.ts +13 -0
- package/build/actions/define-schemas.d.ts.map +1 -0
- package/build/actions/define-schemas.js +28 -0
- package/build/actions/define-schemas.js.map +1 -0
- package/build/actions/execute.d.ts +8 -28
- package/build/actions/execute.d.ts.map +1 -1
- package/build/actions/execute.js +17 -101
- package/build/actions/execute.js.map +1 -1
- package/build/actions/execution/types.d.ts +34 -0
- package/build/actions/execution/types.d.ts.map +1 -0
- package/build/actions/execution/types.js +2 -0
- package/build/actions/execution/types.js.map +1 -0
- package/build/actions/execution.d.ts +4 -0
- package/build/actions/execution.d.ts.map +1 -0
- package/build/actions/execution.js +79 -0
- package/build/actions/execution.js.map +1 -0
- package/build/actions/get-card.d.ts +6 -0
- package/build/actions/get-card.d.ts.map +1 -0
- package/build/actions/get-card.js +9 -0
- package/build/actions/get-card.js.map +1 -0
- package/build/actions/get-specification.d.ts +6 -0
- package/build/actions/get-specification.d.ts.map +1 -0
- package/build/actions/get-specification.js +9 -0
- package/build/actions/get-specification.js.map +1 -0
- package/build/actions/index.d.ts +12 -3
- package/build/actions/index.d.ts.map +1 -1
- package/build/actions/index.js +11 -3
- package/build/actions/index.js.map +1 -1
- package/build/actions/links.d.ts +3 -3
- package/build/actions/links.d.ts.map +1 -1
- package/build/actions/links.js +6 -5
- package/build/actions/links.js.map +1 -1
- package/build/actions/list-card-specifications.d.ts +6 -0
- package/build/actions/list-card-specifications.d.ts.map +1 -0
- package/build/actions/list-card-specifications.js +11 -0
- package/build/actions/list-card-specifications.js.map +1 -0
- package/build/actions/list-card-transitions.d.ts +6 -0
- package/build/actions/list-card-transitions.d.ts.map +1 -0
- package/build/actions/list-card-transitions.js +11 -0
- package/build/actions/list-card-transitions.js.map +1 -0
- package/build/actions/list-cards.d.ts +6 -0
- package/build/actions/list-cards.d.ts.map +1 -0
- package/build/actions/list-cards.js +10 -0
- package/build/actions/list-cards.js.map +1 -0
- package/build/actions/list-schemas.d.ts +13 -0
- package/build/actions/list-schemas.d.ts.map +1 -0
- package/build/actions/list-schemas.js +20 -0
- package/build/actions/list-schemas.js.map +1 -0
- package/build/actions/list-specification-revisions.d.ts +6 -0
- package/build/actions/list-specification-revisions.d.ts.map +1 -0
- package/build/actions/list-specification-revisions.js +10 -0
- package/build/actions/list-specification-revisions.js.map +1 -0
- package/build/actions/schemas.d.ts +5 -3
- package/build/actions/schemas.d.ts.map +1 -1
- package/build/actions/schemas.js.map +1 -1
- package/build/actions/specs.d.ts +4 -2
- package/build/actions/specs.d.ts.map +1 -1
- package/build/actions/specs.js.map +1 -1
- package/build/actions/summarize-cards.d.ts +6 -0
- package/build/actions/summarize-cards.d.ts.map +1 -0
- package/build/actions/summarize-cards.js +11 -0
- package/build/actions/summarize-cards.js.map +1 -0
- package/build/actions/transitions.d.ts +3 -3
- package/build/actions/transitions.d.ts.map +1 -1
- package/build/actions/transitions.js +4 -3
- package/build/actions/transitions.js.map +1 -1
- package/build/actions/types.d.ts +5 -3
- package/build/actions/types.d.ts.map +1 -1
- package/build/actions/watch.d.ts +2 -2
- package/build/actions/watch.d.ts.map +1 -1
- package/build/actions/watch.js +2 -2
- package/build/actions/watch.js.map +1 -1
- package/build/conformance/assert/types.d.ts +19 -0
- package/build/conformance/assert/types.d.ts.map +1 -0
- package/build/conformance/assert/types.js +2 -0
- package/build/conformance/assert/types.js.map +1 -0
- package/build/conformance/assert.d.ts +8 -13
- package/build/conformance/assert.d.ts.map +1 -1
- package/build/conformance/assert.js +41 -43
- package/build/conformance/assert.js.map +1 -1
- package/build/conformance/cases.d.ts.map +1 -1
- package/build/conformance/cases.js +86 -67
- package/build/conformance/cases.js.map +1 -1
- package/build/conformance/clock.d.ts +6 -0
- package/build/conformance/clock.d.ts.map +1 -0
- package/build/conformance/clock.js +12 -0
- package/build/conformance/clock.js.map +1 -0
- package/build/conformance/consts.d.ts +3 -1
- package/build/conformance/consts.d.ts.map +1 -1
- package/build/conformance/consts.js +84 -1
- package/build/conformance/consts.js.map +1 -1
- package/build/conformance/errors.d.ts +5 -0
- package/build/conformance/errors.d.ts.map +1 -0
- package/build/conformance/errors.js +8 -0
- package/build/conformance/errors.js.map +1 -0
- package/build/conformance/fixtures/types.d.ts +13 -0
- package/build/conformance/fixtures/types.d.ts.map +1 -0
- package/build/conformance/fixtures/types.js +2 -0
- package/build/conformance/fixtures/types.js.map +1 -0
- package/build/conformance/fixtures.d.ts +8 -8
- package/build/conformance/fixtures.d.ts.map +1 -1
- package/build/conformance/fixtures.js +24 -107
- package/build/conformance/fixtures.js.map +1 -1
- package/build/conformance/index.d.ts +3 -0
- package/build/conformance/index.d.ts.map +1 -1
- package/build/conformance/index.js +1 -0
- package/build/conformance/index.js.map +1 -1
- package/build/definitions.d.ts.map +1 -1
- package/build/definitions.js +9 -9
- package/build/definitions.js.map +1 -1
- package/build/executor/changes/types.d.ts +36 -0
- package/build/executor/changes/types.d.ts.map +1 -0
- package/build/executor/changes/types.js +2 -0
- package/build/executor/changes/types.js.map +1 -0
- package/build/executor/changes.d.ts +3 -30
- package/build/executor/changes.d.ts.map +1 -1
- package/build/executor/changes.js +42 -51
- package/build/executor/changes.js.map +1 -1
- package/build/executor/code/types.d.ts +17 -0
- package/build/executor/code/types.d.ts.map +1 -0
- package/build/executor/code/types.js +2 -0
- package/build/executor/code/types.js.map +1 -0
- package/build/executor/code.d.ts +3 -14
- package/build/executor/code.d.ts.map +1 -1
- package/build/executor/code.js +50 -54
- package/build/executor/code.js.map +1 -1
- package/build/executor/creator/types.d.ts +33 -0
- package/build/executor/creator/types.d.ts.map +1 -0
- package/build/executor/creator/types.js +2 -0
- package/build/executor/creator/types.js.map +1 -0
- package/build/executor/creator.d.ts +6 -25
- package/build/executor/creator.d.ts.map +1 -1
- package/build/executor/creator.js +26 -41
- package/build/executor/creator.js.map +1 -1
- package/build/executor/resolve/types.d.ts +30 -0
- package/build/executor/resolve/types.d.ts.map +1 -0
- package/build/executor/resolve/types.js +2 -0
- package/build/executor/resolve/types.js.map +1 -0
- package/build/executor/resolve.d.ts +4 -41
- package/build/executor/resolve.d.ts.map +1 -1
- package/build/executor/resolve.js +142 -157
- package/build/executor/resolve.js.map +1 -1
- package/build/executor/types.d.ts +0 -2
- package/build/executor/types.d.ts.map +1 -1
- package/build/executor/validate.d.ts +1 -1
- package/build/executor/validate.d.ts.map +1 -1
- package/build/executor/validate.js +16 -15
- package/build/executor/validate.js.map +1 -1
- package/build/executor.d.ts +4 -3
- package/build/executor.d.ts.map +1 -1
- package/build/executor.js +18 -17
- package/build/executor.js.map +1 -1
- package/build/facade.d.ts.map +1 -1
- package/build/facade.js +16 -16
- package/build/facade.js.map +1 -1
- package/build/helper.d.ts +1 -6
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +3 -8
- package/build/helper.js.map +1 -1
- package/build/projection.d.ts +2 -0
- package/build/projection.d.ts.map +1 -1
- package/build/projection.js +6 -4
- package/build/projection.js.map +1 -1
- package/build/queue/declare.d.ts +5 -0
- package/build/queue/declare.d.ts.map +1 -0
- package/build/queue/declare.js +5 -0
- package/build/queue/declare.js.map +1 -0
- package/build/queue/index.d.ts +1 -4
- package/build/queue/index.d.ts.map +1 -1
- package/build/queue/index.js +1 -4
- package/build/queue/index.js.map +1 -1
- package/build/store/composite.d.ts.map +1 -1
- package/build/store/composite.js +2 -2
- package/build/store/composite.js.map +1 -1
- package/build/store/fold/types.d.ts +43 -0
- package/build/store/fold/types.d.ts.map +1 -0
- package/build/store/fold/types.js +2 -0
- package/build/store/fold/types.js.map +1 -0
- package/build/store/fold.d.ts +7 -30
- package/build/store/fold.d.ts.map +1 -1
- package/build/store/fold.js +185 -203
- package/build/store/fold.js.map +1 -1
- package/build/store/index.d.ts +1 -0
- package/build/store/index.d.ts.map +1 -1
- package/build/store/index.js.map +1 -1
- package/build/store/memory.d.ts.map +1 -1
- package/build/store/memory.js +0 -0
- package/build/store/memory.js.map +1 -1
- package/build/store/types.local.d.ts +3 -1
- package/build/store/types.local.d.ts.map +1 -1
- package/build/types.d.ts +2 -1
- package/build/types.d.ts.map +1 -1
- package/build/utils/access/types.d.ts +30 -0
- package/build/utils/access/types.d.ts.map +1 -0
- package/build/utils/access/types.js +2 -0
- package/build/utils/access/types.js.map +1 -0
- package/build/utils/access.d.ts +4 -0
- package/build/utils/access.d.ts.map +1 -0
- package/build/utils/access.js +28 -0
- package/build/utils/access.js.map +1 -0
- package/build/utils/guard/types.d.ts +21 -0
- package/build/utils/guard/types.d.ts.map +1 -0
- package/build/utils/guard/types.js +2 -0
- package/build/utils/guard/types.js.map +1 -0
- package/build/utils/guard.d.ts +7 -10
- package/build/utils/guard.d.ts.map +1 -1
- package/build/utils/guard.js +33 -31
- package/build/utils/guard.js.map +1 -1
- package/build/utils/handler/types.d.ts +26 -0
- package/build/utils/handler/types.d.ts.map +1 -0
- package/build/utils/handler/types.js +2 -0
- package/build/utils/handler/types.js.map +1 -0
- package/build/utils/handler.d.ts +6 -0
- package/build/utils/handler.d.ts.map +1 -0
- package/build/utils/handler.js +21 -0
- package/build/utils/handler.js.map +1 -0
- package/build/utils/index.d.ts +8 -1
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +3 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/request/types.d.ts +23 -0
- package/build/utils/request/types.d.ts.map +1 -0
- package/build/utils/request/types.js +2 -0
- package/build/utils/request/types.js.map +1 -0
- package/build/utils/request.d.ts +4 -0
- package/build/utils/request.d.ts.map +1 -0
- package/build/utils/request.js +27 -0
- package/build/utils/request.js.map +1 -0
- package/build/utils/scope.d.ts +10 -43
- package/build/utils/scope.d.ts.map +1 -1
- package/build/utils/scope.js +21 -99
- package/build/utils/scope.js.map +1 -1
- package/package.json +18 -18
- package/src/actions/apply-schema-request.ts +35 -0
- package/src/actions/commit.ts +7 -5
- package/src/actions/define-schemas.ts +34 -0
- package/src/actions/execute.ts +30 -115
- package/src/actions/execution/types.ts +34 -0
- package/src/actions/execution.ts +96 -0
- package/src/actions/get-card.ts +14 -0
- package/src/actions/get-specification.ts +14 -0
- package/src/actions/index.ts +13 -3
- package/src/actions/links.ts +8 -6
- package/src/actions/list-card-specifications.ts +15 -0
- package/src/actions/list-card-transitions.ts +15 -0
- package/src/actions/list-cards.ts +14 -0
- package/src/actions/list-schemas.ts +29 -0
- package/src/actions/{specs.ts → list-specification-revisions.ts} +4 -11
- package/src/actions/summarize-cards.ts +15 -0
- package/src/actions/transitions.ts +6 -4
- package/src/actions/types.ts +4 -3
- package/src/actions/watch.ts +4 -3
- package/src/conformance/assert/types.ts +16 -0
- package/src/conformance/assert.ts +49 -41
- package/src/conformance/cases.ts +88 -67
- package/src/conformance/clock.ts +11 -0
- package/src/conformance/consts.ts +87 -1
- package/src/conformance/errors.ts +7 -0
- package/src/conformance/fixtures/types.ts +11 -0
- package/src/conformance/fixtures.ts +32 -107
- package/src/conformance/index.ts +3 -0
- package/src/definitions.ts +9 -9
- package/src/executor/changes/types.ts +38 -0
- package/src/executor/changes.ts +48 -63
- package/src/executor/code/types.ts +23 -0
- package/src/executor/code.ts +60 -61
- package/src/executor/creator/types.ts +33 -0
- package/src/executor/creator.ts +33 -41
- package/src/executor/resolve/types.ts +30 -0
- package/src/executor/resolve.ts +153 -167
- package/src/executor/types.ts +0 -3
- package/src/executor/validate.ts +17 -16
- package/src/executor.ts +20 -17
- package/src/facade.ts +16 -16
- package/src/helper.ts +3 -8
- package/src/projection.ts +8 -4
- package/src/queue/declare.ts +7 -0
- package/src/queue/index.ts +1 -8
- package/src/store/composite.ts +2 -2
- package/src/store/fold/types.ts +44 -0
- package/src/store/fold.ts +209 -212
- package/src/store/index.ts +1 -0
- package/src/store/memory.ts +0 -0
- package/src/store/types.local.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/access/types.ts +30 -0
- package/src/utils/access.ts +33 -0
- package/src/utils/guard/types.ts +19 -0
- package/src/utils/guard.ts +41 -30
- package/src/utils/handler/types.ts +28 -0
- package/src/utils/handler.ts +35 -0
- package/src/utils/index.ts +9 -1
- package/src/utils/request/types.ts +23 -0
- package/src/utils/request.ts +40 -0
- package/src/utils/scope.ts +25 -108
- package/tests/creator.spec.ts +18 -18
- package/src/actions/cards.ts +0 -48
- package/src/actions/schemas.ts +0 -87
package/src/facade.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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 =>
|
|
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 {
|
|
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
|
|
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)
|
package/src/queue/index.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
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'
|
package/src/store/composite.ts
CHANGED
|
@@ -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
|
+
}
|