@owlmeans/server-planning 0.1.18-rc.0
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 +150 -0
- package/agent-meta/manifest.json +16 -0
- package/agent-meta/skills/server-planning/SKILL.md +203 -0
- package/build/actions/cards.d.ts +16 -0
- package/build/actions/cards.d.ts.map +1 -0
- package/build/actions/cards.js +32 -0
- package/build/actions/cards.js.map +1 -0
- package/build/actions/commit.d.ts +14 -0
- package/build/actions/commit.d.ts.map +1 -0
- package/build/actions/commit.js +48 -0
- package/build/actions/commit.js.map +1 -0
- package/build/actions/execute.d.ts +13 -0
- package/build/actions/execute.d.ts.map +1 -0
- package/build/actions/execute.js +35 -0
- package/build/actions/execute.js.map +1 -0
- package/build/actions/index.d.ts +9 -0
- package/build/actions/index.d.ts.map +1 -0
- package/build/actions/index.js +9 -0
- package/build/actions/index.js.map +1 -0
- package/build/actions/links.d.ts +5 -0
- package/build/actions/links.d.ts.map +1 -0
- package/build/actions/links.js +8 -0
- package/build/actions/links.js.map +1 -0
- package/build/actions/schemas.d.ts +6 -0
- package/build/actions/schemas.d.ts.map +1 -0
- package/build/actions/schemas.js +9 -0
- package/build/actions/schemas.js.map +1 -0
- package/build/actions/specs.d.ts +10 -0
- package/build/actions/specs.d.ts.map +1 -0
- package/build/actions/specs.js +14 -0
- package/build/actions/specs.js.map +1 -0
- package/build/actions/transitions.d.ts +6 -0
- package/build/actions/transitions.d.ts.map +1 -0
- package/build/actions/transitions.js +8 -0
- package/build/actions/transitions.js.map +1 -0
- package/build/actions/watch.d.ts +12 -0
- package/build/actions/watch.d.ts.map +1 -0
- package/build/actions/watch.js +45 -0
- package/build/actions/watch.js.map +1 -0
- package/build/consts.d.ts +18 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +19 -0
- package/build/consts.js.map +1 -0
- package/build/executor/changes.d.ts +31 -0
- package/build/executor/changes.d.ts.map +1 -0
- package/build/executor/changes.js +55 -0
- package/build/executor/changes.js.map +1 -0
- package/build/executor/code.d.ts +15 -0
- package/build/executor/code.d.ts.map +1 -0
- package/build/executor/code.js +59 -0
- package/build/executor/code.js.map +1 -0
- package/build/executor/receipt.d.ts +12 -0
- package/build/executor/receipt.d.ts.map +1 -0
- package/build/executor/receipt.js +56 -0
- package/build/executor/receipt.js.map +1 -0
- package/build/executor/resolve.d.ts +35 -0
- package/build/executor/resolve.d.ts.map +1 -0
- package/build/executor/resolve.js +136 -0
- package/build/executor/resolve.js.map +1 -0
- package/build/executor/validate.d.ts +13 -0
- package/build/executor/validate.d.ts.map +1 -0
- package/build/executor/validate.js +222 -0
- package/build/executor/validate.js.map +1 -0
- package/build/executor.d.ts +15 -0
- package/build/executor.d.ts.map +1 -0
- package/build/executor.js +113 -0
- package/build/executor.js.map +1 -0
- package/build/facade.d.ts +12 -0
- package/build/facade.d.ts.map +1 -0
- package/build/facade.js +131 -0
- package/build/facade.js.map +1 -0
- package/build/helper.d.ts +18 -0
- package/build/helper.d.ts.map +1 -0
- package/build/helper.js +32 -0
- package/build/helper.js.map +1 -0
- package/build/index.d.ts +13 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +11 -0
- package/build/index.js.map +1 -0
- package/build/projection.d.ts +28 -0
- package/build/projection.d.ts.map +1 -0
- package/build/projection.js +40 -0
- package/build/projection.js.map +1 -0
- package/build/registry.d.ts +30 -0
- package/build/registry.d.ts.map +1 -0
- package/build/registry.js +103 -0
- package/build/registry.js.map +1 -0
- package/build/service.d.ts +40 -0
- package/build/service.d.ts.map +1 -0
- package/build/service.js +109 -0
- package/build/service.js.map +1 -0
- package/build/store/commits.d.ts +15 -0
- package/build/store/commits.d.ts.map +1 -0
- package/build/store/commits.js +147 -0
- package/build/store/commits.js.map +1 -0
- package/build/store/composite.d.ts +12 -0
- package/build/store/composite.d.ts.map +1 -0
- package/build/store/composite.js +150 -0
- package/build/store/composite.js.map +1 -0
- package/build/store/fold.d.ts +39 -0
- package/build/store/fold.d.ts.map +1 -0
- package/build/store/fold.js +220 -0
- package/build/store/fold.js.map +1 -0
- package/build/store/index.d.ts +6 -0
- package/build/store/index.d.ts.map +1 -0
- package/build/store/index.js +5 -0
- package/build/store/index.js.map +1 -0
- package/build/store/memory.d.ts +19 -0
- package/build/store/memory.d.ts.map +1 -0
- package/build/store/memory.js +0 -0
- package/build/store/memory.js.map +1 -0
- package/build/store/types.d.ts +82 -0
- package/build/store/types.d.ts.map +1 -0
- package/build/store/types.js +2 -0
- package/build/store/types.js.map +1 -0
- package/build/types.d.ts +46 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/build/utils/guard.d.ts +19 -0
- package/build/utils/guard.d.ts.map +1 -0
- package/build/utils/guard.js +35 -0
- package/build/utils/guard.js.map +1 -0
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +3 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/scope.d.ts +20 -0
- package/build/utils/scope.d.ts.map +1 -0
- package/build/utils/scope.js +36 -0
- package/build/utils/scope.js.map +1 -0
- package/package.json +66 -0
- package/src/actions/cards.ts +52 -0
- package/src/actions/commit.ts +55 -0
- package/src/actions/execute.ts +47 -0
- package/src/actions/index.ts +8 -0
- package/src/actions/links.ts +14 -0
- package/src/actions/schemas.ts +15 -0
- package/src/actions/specs.ts +23 -0
- package/src/actions/transitions.ts +14 -0
- package/src/actions/watch.ts +52 -0
- package/src/consts.ts +22 -0
- package/src/executor/changes.ts +78 -0
- package/src/executor/code.ts +83 -0
- package/src/executor/receipt.ts +66 -0
- package/src/executor/resolve.ts +174 -0
- package/src/executor/validate.ts +253 -0
- package/src/executor.ts +149 -0
- package/src/facade.ts +162 -0
- package/src/helper.ts +44 -0
- package/src/index.ts +13 -0
- package/src/projection.ts +65 -0
- package/src/registry.ts +143 -0
- package/src/service.ts +157 -0
- package/src/store/commits.ts +174 -0
- package/src/store/composite.ts +171 -0
- package/src/store/fold.ts +257 -0
- package/src/store/index.ts +6 -0
- package/src/store/memory.ts +0 -0
- package/src/store/types.ts +94 -0
- package/src/types.ts +48 -0
- package/src/utils/guard.ts +40 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/scope.ts +51 -0
- package/tests/commits.spec.ts +78 -0
- package/tests/context.ts +198 -0
- package/tests/entrypoints.spec.ts +72 -0
- package/tests/executor.spec.ts +69 -0
- package/tests/memory-store.spec.ts +84 -0
- package/tests/plugins.spec.ts +86 -0
- package/tests/specifications.spec.ts +61 -0
- package/tests/tsconfig.json +17 -0
- package/tests/validation.spec.ts +62 -0
- package/tsconfig.json +16 -0
package/build/facade.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { criteriaOf, currentSpecification, isSpecification, linkWhereOf, listOptionsOf, modelOf, PlanningUnsupported, specCriteriaOf, transitionWhereOf, WorkcardKind, WorkcardNotFound, } from '@owlmeans/planning';
|
|
2
|
+
import { executeTransition } from './executor.js';
|
|
3
|
+
/**
|
|
4
|
+
* The scoped facade over the service's stores.
|
|
5
|
+
*
|
|
6
|
+
* Every read carries the scope's `entityId` into the store and re-checks it on what comes back, so
|
|
7
|
+
* a card of another entity is simply absent — `load` answers `null`, `get` throws
|
|
8
|
+
* `WorkcardNotFound`, exactly as for an id that never existed. Reads go through the composite
|
|
9
|
+
* store (the default store plus the stores plugins own); writes go through the executor.
|
|
10
|
+
*/
|
|
11
|
+
export const makeStoreFacade = (runtime, scope) => {
|
|
12
|
+
const entityId = scope.entityId;
|
|
13
|
+
const reader = () => runtime.reader();
|
|
14
|
+
const mine = (record) => record != null && record.entityId === entityId ? record : null;
|
|
15
|
+
const commitSource = () => {
|
|
16
|
+
const commits = reader().commits;
|
|
17
|
+
if (commits == null) {
|
|
18
|
+
throw new PlanningUnsupported('commits');
|
|
19
|
+
}
|
|
20
|
+
return commits;
|
|
21
|
+
};
|
|
22
|
+
/** The transition is this entity's — its row, or the remembered commit of a purged one. */
|
|
23
|
+
const assertTransition = async (transition) => {
|
|
24
|
+
const row = await reader().transitions?.get(transition);
|
|
25
|
+
if (row != null) {
|
|
26
|
+
if (row.entityId !== entityId) {
|
|
27
|
+
throw new WorkcardNotFound(`transition:${transition}`);
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const recalled = reader().commits?.recall?.(transition);
|
|
32
|
+
if (recalled == null || recalled.entityId !== entityId) {
|
|
33
|
+
throw new WorkcardNotFound(`transition:${transition}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const facade = {
|
|
37
|
+
scope: Object.freeze({ ...scope }),
|
|
38
|
+
schemas: runtime.service().schemas,
|
|
39
|
+
cards: {
|
|
40
|
+
load: async (id) => mine(await reader().cards.get(id, entityId)),
|
|
41
|
+
get: async (id) => {
|
|
42
|
+
const card = await facade.cards.load(id);
|
|
43
|
+
if (card == null) {
|
|
44
|
+
throw new WorkcardNotFound(id);
|
|
45
|
+
}
|
|
46
|
+
return card;
|
|
47
|
+
},
|
|
48
|
+
list: async (query) => await reader().cards.list(criteriaOf(query, scope), listOptionsOf(query)),
|
|
49
|
+
count: async (query) => await reader().cards.count(criteriaOf(query, scope)),
|
|
50
|
+
summary: async (parents, query) => parents.length === 0
|
|
51
|
+
? {}
|
|
52
|
+
: await reader().cards.summary(parents, criteriaOf({ kind: query?.kind, type: query?.type }, scope)),
|
|
53
|
+
},
|
|
54
|
+
specifications: {
|
|
55
|
+
current: async (parent, category) => {
|
|
56
|
+
const specs = reader().specs;
|
|
57
|
+
if (specs != null) {
|
|
58
|
+
return mine(await specs.current(parent, category, entityId));
|
|
59
|
+
}
|
|
60
|
+
const listed = await reader().cards.list(specCriteriaOf(parent, { category }, scope), { size: 0 });
|
|
61
|
+
return currentSpecification(listed.items, category);
|
|
62
|
+
},
|
|
63
|
+
list: async (parent, query) => {
|
|
64
|
+
const specs = reader().specs;
|
|
65
|
+
if (specs != null) {
|
|
66
|
+
return await specs.list(parent, entityId, query);
|
|
67
|
+
}
|
|
68
|
+
return await reader().cards.list(specCriteriaOf(parent, query, scope), listOptionsOf(query));
|
|
69
|
+
},
|
|
70
|
+
get: async (id) => {
|
|
71
|
+
const card = await facade.cards.load(id);
|
|
72
|
+
if (card == null || !isSpecification(card)) {
|
|
73
|
+
throw new WorkcardNotFound(id);
|
|
74
|
+
}
|
|
75
|
+
return card;
|
|
76
|
+
},
|
|
77
|
+
revisions: async (id, limit) => {
|
|
78
|
+
await facade.specifications.get(id);
|
|
79
|
+
const specs = reader().specs;
|
|
80
|
+
if (specs == null) {
|
|
81
|
+
throw new PlanningUnsupported('revisions');
|
|
82
|
+
}
|
|
83
|
+
return await specs.revisions(id, entityId, limit);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
relationships: {
|
|
87
|
+
list: async (query) => {
|
|
88
|
+
const links = reader().links;
|
|
89
|
+
return links == null
|
|
90
|
+
? { items: [], total: 0 }
|
|
91
|
+
: await links.list(linkWhereOf(query, scope), listOptionsOf(query));
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
transitions: {
|
|
95
|
+
get: async (id) => {
|
|
96
|
+
const transition = mine(await reader().transitions?.get(id));
|
|
97
|
+
if (transition == null) {
|
|
98
|
+
throw new WorkcardNotFound(`transition:${id}`);
|
|
99
|
+
}
|
|
100
|
+
return transition;
|
|
101
|
+
},
|
|
102
|
+
list: async (query) => {
|
|
103
|
+
const transitions = reader().transitions;
|
|
104
|
+
return transitions == null
|
|
105
|
+
? { items: [], total: 0 }
|
|
106
|
+
: await transitions.list(transitionWhereOf(query, scope), listOptionsOf(query));
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
commits: {
|
|
110
|
+
status: async (transition) => {
|
|
111
|
+
await assertTransition(transition);
|
|
112
|
+
return await commitSource().status(transition);
|
|
113
|
+
},
|
|
114
|
+
subscribe: (listener, filter) => commitSource().subscribe(listener, { ...filter, entityId }),
|
|
115
|
+
wait: async (transition, opts) => {
|
|
116
|
+
await assertTransition(transition);
|
|
117
|
+
return await commitSource().wait(transition, opts);
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
execute: async (exec, opts) => await executeTransition(runtime, facade, exec, opts),
|
|
121
|
+
model: async (card) => {
|
|
122
|
+
const record = typeof card === 'string' ? await facade.cards.get(card) : card;
|
|
123
|
+
if (record.entityId !== entityId) {
|
|
124
|
+
throw new WorkcardNotFound(record.id ?? WorkcardKind.Card);
|
|
125
|
+
}
|
|
126
|
+
return modelOf(record, facade);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
return facade;
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=facade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facade.js","sourceRoot":"","sources":["../src/facade.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAAE,oBAAoB,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EACtF,mBAAmB,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,GACvF,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAIjD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAwB,EAAE,KAAoB,EAAkB,EAAE;IAChG,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;IAC/B,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAA;IACrC,MAAM,IAAI,GAAG,CAAiC,MAA4B,EAAY,EAAE,CACtF,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;IAEhE,MAAM,YAAY,GAAG,GAAiB,EAAE;QACtC,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAA;QAChC,IAAI,OAAO,IAAI,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AS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC;YAE5F,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE;gBAC/B,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAA;gBAClC,OAAO,MAAM,YAAY,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;YACpD,CAAC;SACF;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC;QAEnF,KAAK,EAAE,KAAK,EAAiC,IAAgB,EAA6B,EAAE;YAC1F,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAM,CAAC,CAAC,CAAC,IAAI,CAAA;YAClF,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACjC,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,IAAI,YAAY,CAAC,IAAI,CAAC,CAAA;YAC5D,CAAC;YACD,OAAO,OAAO,CAAI,MAAM,EAAE,MAAM,CAAC,CAAA;QACnC,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context';
|
|
2
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint';
|
|
3
|
+
import type { PlanningFacade, PlanningProtocols, PlanningScope } from '@owlmeans/planning';
|
|
4
|
+
import type { PlanningHandlerOptions } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Bind this package's handlers to a tree declared by `makePlanningProtocols` — one binding per
|
|
7
|
+
* protocol, the base included. Pass the tree itself, never a flattened list; an application that
|
|
8
|
+
* wants its own handler for one leaf binds that protocol afterwards.
|
|
9
|
+
*/
|
|
10
|
+
export declare const servePlanningEntrypoints: (protocols: PlanningProtocols, opts?: PlanningHandlerOptions) => import("@owlmeans/server-entrypoint").ServerProtocolEntrypoint<import("@owlmeans/entrypoint").EntrypointProtocolDeclaration>[];
|
|
11
|
+
/**
|
|
12
|
+
* The facade a hand-written handler works through: the request's entity and subject, plus `extra`
|
|
13
|
+
* (a `channel`) — never an entity from the request body.
|
|
14
|
+
*
|
|
15
|
+
* @throws {AuthorizationError} when the request carries no organization
|
|
16
|
+
*/
|
|
17
|
+
export declare const planningFor: (ctx: BasicContext<BasicConfig>, req: AbstractRequest, extra?: Partial<PlanningScope>, opts?: Pick<PlanningHandlerOptions, 'service'>) => PlanningFacade;
|
|
18
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAO1F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAGxD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,cAAe,iBAAiB,SAAS,sBAAsB,mIAenG,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QACjB,YAAY,CAAC,WAAW,CAAC,OAAO,eAAe,UAAU,OAAO,CAAC,aAAa,CAAC,SAC7E,IAAI,CAAC,sBAAsB,EAAE,SAAS,CAAC,KAC7C,cAAuE,CAAA"}
|
package/build/helper.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { bind } from '@owlmeans/server-entrypoint';
|
|
2
|
+
import { executePlanning, getCard, getCommit, getSpecification, getTransition, listCardSpecifications, listCardTransitions, listCards, listLinks, listSchemas, listSpecificationRevisions, summarizeCards, watchCommits, } from './actions/index.js';
|
|
3
|
+
import { planningServiceOf, scopeOf } from './utils/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Bind this package's handlers to a tree declared by `makePlanningProtocols` — one binding per
|
|
6
|
+
* protocol, the base included. Pass the tree itself, never a flattened list; an application that
|
|
7
|
+
* wants its own handler for one leaf binds that protocol afterwards.
|
|
8
|
+
*/
|
|
9
|
+
export const servePlanningEntrypoints = (protocols, opts) => [
|
|
10
|
+
bind(protocols.base),
|
|
11
|
+
bind(protocols.schema.list, listSchemas(protocols.schema.list, opts)),
|
|
12
|
+
bind(protocols.card.list, listCards(protocols.card.list, opts)),
|
|
13
|
+
bind(protocols.card.summary, summarizeCards(protocols.card.summary, opts)),
|
|
14
|
+
bind(protocols.card.get, getCard(protocols.card.get, opts)),
|
|
15
|
+
bind(protocols.card.transitions, listCardTransitions(protocols.card.transitions, opts)),
|
|
16
|
+
bind(protocols.card.specifications, listCardSpecifications(protocols.card.specifications, opts)),
|
|
17
|
+
bind(protocols.spec.get, getSpecification(protocols.spec.get, opts)),
|
|
18
|
+
bind(protocols.spec.revisions, listSpecificationRevisions(protocols.spec.revisions, opts)),
|
|
19
|
+
bind(protocols.link.list, listLinks(protocols.link.list, opts)),
|
|
20
|
+
bind(protocols.transition.get, getTransition(protocols.transition.get, opts)),
|
|
21
|
+
bind(protocols.execute, executePlanning(protocols.execute, opts)),
|
|
22
|
+
bind(protocols.commit.get, getCommit(protocols.commit.get, opts)),
|
|
23
|
+
bind(protocols.commit.events, watchCommits(protocols.commit.events, opts)),
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* The facade a hand-written handler works through: the request's entity and subject, plus `extra`
|
|
27
|
+
* (a `channel`) — never an entity from the request body.
|
|
28
|
+
*
|
|
29
|
+
* @throws {AuthorizationError} when the request carries no organization
|
|
30
|
+
*/
|
|
31
|
+
export const planningFor = (ctx, req, extra, opts) => planningServiceOf(ctx, opts).for(scopeOf(req, extra));
|
|
32
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAClD,OAAO,EACL,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAE,sBAAsB,EAC5F,mBAAmB,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,0BAA0B,EAAE,cAAc,EAClG,YAAY,GACb,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAA4B,EAAE,IAA6B,EAAE,EAAE,CAAC;IACvG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IACpB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC1E,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3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AAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type * from './types.js';
|
|
2
|
+
export type * from './store/types.js';
|
|
3
|
+
export * from './consts.js';
|
|
4
|
+
export * from './service.js';
|
|
5
|
+
export * from './registry.js';
|
|
6
|
+
export * from './facade.js';
|
|
7
|
+
export * from './executor.js';
|
|
8
|
+
export * from './helper.js';
|
|
9
|
+
export * from './projection.js';
|
|
10
|
+
export * from './actions/index.js';
|
|
11
|
+
export * from './utils/index.js';
|
|
12
|
+
export * from './store/index.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,kBAAkB,CAAA;AAErC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './consts.js';
|
|
2
|
+
export * from './service.js';
|
|
3
|
+
export * from './registry.js';
|
|
4
|
+
export * from './facade.js';
|
|
5
|
+
export * from './executor.js';
|
|
6
|
+
export * from './helper.js';
|
|
7
|
+
export * from './projection.js';
|
|
8
|
+
export * from './actions/index.js';
|
|
9
|
+
export * from './utils/index.js';
|
|
10
|
+
export * from './store/index.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context';
|
|
2
|
+
import type { CommitEvent, PlanningService, PlanningStore } from '@owlmeans/planning';
|
|
3
|
+
import type { ProjectionRequest } from '@owlmeans/planning/queue';
|
|
4
|
+
import type { JobProcessor, QueueHooks } from '@owlmeans/queue';
|
|
5
|
+
import type { FoldResult } from './store/types.js';
|
|
6
|
+
export interface ProjectionOptions {
|
|
7
|
+
/** The planning service alias. */
|
|
8
|
+
service?: string;
|
|
9
|
+
/** The store the queue folds — the service's default store when omitted. */
|
|
10
|
+
store?: (service: PlanningService) => PlanningStore;
|
|
11
|
+
/** Where events go — the store's commit hub `publish` when it has one. */
|
|
12
|
+
publish?: (event: CommitEvent) => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The body of a projection job: fold one card with the service's `committed` as the commit
|
|
16
|
+
* listener, so the `after` chain runs in the process that took the job.
|
|
17
|
+
*
|
|
18
|
+
* Register it only where the process listens to `PLANNING_PROJECTION_QUEUE`; a durable store adds
|
|
19
|
+
* its own admission and release around it.
|
|
20
|
+
*/
|
|
21
|
+
export declare const makeProjectionProcessor: (ctx: BasicContext<BasicConfig>, opts?: ProjectionOptions) => JobProcessor<ProjectionRequest, FoldResult>;
|
|
22
|
+
/**
|
|
23
|
+
* `onJobDead` for the projection queue: every pending transition of the card is marked failed and a
|
|
24
|
+
* failed event is published — otherwise `execute({ wait: true })` and `commits.wait` hang to their
|
|
25
|
+
* timeout. Merge it into the queue driver's hooks.
|
|
26
|
+
*/
|
|
27
|
+
export declare const planningQueueHooks: (ctx: BasicContext<BasicConfig>, opts?: ProjectionOptions) => QueueHooks;
|
|
28
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAErF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG/D,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7D,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,aAAa,CAAA;IACnD,0EAA0E;IAC1E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAChD;AAWD;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,QAC7B,YAAY,CAAC,WAAW,CAAC,SAAS,iBAAiB,KACvD,YAAY,CAAC,iBAAiB,EAAE,UAAU,CAU5C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QAAS,YAAY,CAAC,WAAW,CAAC,SAAS,iBAAiB,KAAG,UAU5F,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PLANNING_SERVICE } from '@owlmeans/planning';
|
|
2
|
+
import { PLANNING_PROJECT_JOB, PLANNING_PROJECTION_QUEUE } from '@owlmeans/planning/queue';
|
|
3
|
+
import { failPending, foldPending } from './store/fold.js';
|
|
4
|
+
const serviceOf = (ctx, opts) => ctx.service(opts?.service ?? PLANNING_SERVICE);
|
|
5
|
+
const storeOf = (service, opts) => opts?.store?.(service) ?? service.store();
|
|
6
|
+
const publisherOf = (store, opts) => opts?.publish ?? store.commits?.publish;
|
|
7
|
+
/**
|
|
8
|
+
* The body of a projection job: fold one card with the service's `committed` as the commit
|
|
9
|
+
* listener, so the `after` chain runs in the process that took the job.
|
|
10
|
+
*
|
|
11
|
+
* Register it only where the process listens to `PLANNING_PROJECTION_QUEUE`; a durable store adds
|
|
12
|
+
* its own admission and release around it.
|
|
13
|
+
*/
|
|
14
|
+
export const makeProjectionProcessor = (ctx, opts) => async (job) => {
|
|
15
|
+
const service = serviceOf(ctx, opts);
|
|
16
|
+
const store = storeOf(service, opts);
|
|
17
|
+
const publish = publisherOf(store, opts);
|
|
18
|
+
return await foldPending(store, job.data.cardId, job.data.entityId, {
|
|
19
|
+
touch: job.touch,
|
|
20
|
+
onCommitted: async (event) => { await service.committed(event); },
|
|
21
|
+
...(publish != null ? { publish } : {}),
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* `onJobDead` for the projection queue: every pending transition of the card is marked failed and a
|
|
26
|
+
* failed event is published — otherwise `execute({ wait: true })` and `commits.wait` hang to their
|
|
27
|
+
* timeout. Merge it into the queue driver's hooks.
|
|
28
|
+
*/
|
|
29
|
+
export const planningQueueHooks = (ctx, opts) => ({
|
|
30
|
+
onJobDead: async (job, reason) => {
|
|
31
|
+
if (job.queue !== PLANNING_PROJECTION_QUEUE || job.name !== PLANNING_PROJECT_JOB) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const request = job.data;
|
|
35
|
+
const store = storeOf(serviceOf(ctx, opts), opts);
|
|
36
|
+
const publish = publisherOf(store, opts);
|
|
37
|
+
await failPending(store, request.cardId, request.entityId, reason, publish != null ? { publish } : {});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAA;AAG1F,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAa1D,MAAM,SAAS,GAAG,CAAC,GAA8B,EAAE,IAAwB,EAAmB,EAAE,CAC9F,GAAG,CAAC,OAAO,CAAsB,IAAI,EAAE,OAAO,IAAI,gBAAgB,CAAC,CAAA;AAErE,MAAM,OAAO,GAAG,CAAC,OAAwB,EAAE,IAAwB,EAAiB,EAAE,CACpF,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAA;AAE3C,MAAM,WAAW,GAAG,CAAC,KAAoB,EAAE,IAAwB,EAAE,EAAE,CACrE,IAAI,EAAE,OAAO,IAAK,KAAK,CAAC,OAA0C,EAAE,OAAO,CAAA;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,GAA8B,EAAE,IAAwB,EACX,EAAE,CAAC,KAAK,EAAC,GAAG,EAAC,EAAE;IAC5D,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IACpC,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAExC,OAAO,MAAM,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;QAClE,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,WAAW,EAAE,KAAK,EAAC,KAAK,EAAC,EAAE,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC;QAC9D,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAA8B,EAAE,IAAwB,EAAc,EAAE,CAAC,CAAC;IAC3G,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;QAC/B,IAAI,GAAG,CAAC,KAAK,KAAK,yBAAyB,IAAI,GAAG,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;YACjF,OAAM;QACR,CAAC;QACD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAyB,CAAA;QAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACxC,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IACxG,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context';
|
|
2
|
+
import type { CommitEvent, PlanningExecContext, PlanningHookContext, PlanningPlugin, PlanningSchemaRegistry, PlanningStore, TransitionExecution, WorkcardDraft } from '@owlmeans/planning';
|
|
3
|
+
import type { StoreRoute } from './store/types.js';
|
|
4
|
+
export interface PluginRegistry {
|
|
5
|
+
/** Register, or replace the plugin of the same `name`. Its schemas are contributed now. */
|
|
6
|
+
use: (plugin: PlanningPlugin) => void;
|
|
7
|
+
/** Every plugin, `order` ascending (registration order among equals). */
|
|
8
|
+
plugins: () => PlanningPlugin[];
|
|
9
|
+
/** The owning plugins that supply a store, in plugin order, each store resolved once. */
|
|
10
|
+
routes: (ctx?: BasicContext<BasicConfig>) => StoreRoute[];
|
|
11
|
+
/** The first owning plugin's store for a type, else `fallback`. */
|
|
12
|
+
storeFor: (type: string | undefined, fallback: PlanningStore, ctx?: BasicContext<BasicConfig>) => PlanningStore;
|
|
13
|
+
/** The first plugin answering a code wins. */
|
|
14
|
+
mintCode: (draft: WorkcardDraft, taken: (code: string) => Promise<boolean>, contextOf: (plugin: PlanningPlugin) => PlanningExecContext) => Promise<string | undefined>;
|
|
15
|
+
/** The `before` chain; answers the execution the chain left. */
|
|
16
|
+
before: (exec: TransitionExecution, contextOf: (plugin: PlanningPlugin) => PlanningExecContext) => Promise<TransitionExecution>;
|
|
17
|
+
/** The `after` chain; a failing hook is logged and the chain goes on. */
|
|
18
|
+
after: (event: CommitEvent, contextOf: (plugin: PlanningPlugin) => PlanningHookContext) => Promise<void>;
|
|
19
|
+
/** Bumps on every `use` — what a cached composite store is keyed by. */
|
|
20
|
+
version: () => number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The plugin chain of one planning service.
|
|
24
|
+
*
|
|
25
|
+
* Ordering is `order ?? DEFAULT_PLUGIN_ORDER` ascending, lower first; a plugin registered under a
|
|
26
|
+
* name already present replaces it in place. A store factory is resolved once per plugin object and
|
|
27
|
+
* handed to `onStore` (the service binds its `committed` there).
|
|
28
|
+
*/
|
|
29
|
+
export declare const makePluginRegistry: (schemas: PlanningSchemaRegistry, onStore?: (store: PlanningStore) => void) => PluginRegistry;
|
|
30
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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AAM,EAAE,cAAc,KAAK,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxG,wEAAwE;IACxE,OAAO,EAAE,MAAM,MAAM,CAAA;CACtB;AAID;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,YACpB,sBAAsB,YAAY,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,KACxE,cAmGF,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ResilientError } from '@owlmeans/error';
|
|
2
|
+
import { DEFAULT_PLUGIN_ORDER, PlanningRefused } from '@owlmeans/planning';
|
|
3
|
+
const messageOf = (error) => error instanceof Error ? error.message : `${error}`;
|
|
4
|
+
/**
|
|
5
|
+
* The plugin chain of one planning service.
|
|
6
|
+
*
|
|
7
|
+
* Ordering is `order ?? DEFAULT_PLUGIN_ORDER` ascending, lower first; a plugin registered under a
|
|
8
|
+
* name already present replaces it in place. A store factory is resolved once per plugin object and
|
|
9
|
+
* handed to `onStore` (the service binds its `committed` there).
|
|
10
|
+
*/
|
|
11
|
+
export const makePluginRegistry = (schemas, onStore) => {
|
|
12
|
+
const registered = [];
|
|
13
|
+
const stores = new WeakMap();
|
|
14
|
+
let version = 0;
|
|
15
|
+
const ordered = () => registered
|
|
16
|
+
.map((plugin, index) => ({ plugin, index }))
|
|
17
|
+
.sort((left, right) => (left.plugin.order ?? DEFAULT_PLUGIN_ORDER) - (right.plugin.order ?? DEFAULT_PLUGIN_ORDER)
|
|
18
|
+
|| left.index - right.index)
|
|
19
|
+
.map(entry => entry.plugin);
|
|
20
|
+
const storeOf = (plugin, ctx) => {
|
|
21
|
+
if (plugin.store == null) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
let store = stores.get(plugin);
|
|
25
|
+
if (store == null) {
|
|
26
|
+
store = typeof plugin.store === 'function' ? plugin.store(ctx) : plugin.store;
|
|
27
|
+
stores.set(plugin, store);
|
|
28
|
+
onStore?.(store);
|
|
29
|
+
}
|
|
30
|
+
return store;
|
|
31
|
+
};
|
|
32
|
+
const registry = {
|
|
33
|
+
use: plugin => {
|
|
34
|
+
const at = registered.findIndex(entry => entry.name === plugin.name);
|
|
35
|
+
if (at < 0) {
|
|
36
|
+
registered.push(plugin);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
registered[at] = plugin;
|
|
40
|
+
}
|
|
41
|
+
plugin.schemas?.flows?.forEach(schemas.registerFlow);
|
|
42
|
+
plugin.schemas?.types?.forEach(schemas.registerType);
|
|
43
|
+
version++;
|
|
44
|
+
},
|
|
45
|
+
plugins: ordered,
|
|
46
|
+
routes: ctx => ordered()
|
|
47
|
+
.filter(plugin => plugin.owns != null && plugin.store != null)
|
|
48
|
+
.map(plugin => ({ owns: plugin.owns, store: storeOf(plugin, ctx) })),
|
|
49
|
+
storeFor: (type, fallback, ctx) => {
|
|
50
|
+
if (type == null) {
|
|
51
|
+
return fallback;
|
|
52
|
+
}
|
|
53
|
+
const owner = ordered().find(plugin => plugin.store != null && plugin.owns?.(type) === true);
|
|
54
|
+
return owner == null ? fallback : storeOf(owner, ctx);
|
|
55
|
+
},
|
|
56
|
+
mintCode: async (draft, taken, contextOf) => {
|
|
57
|
+
for (const plugin of ordered()) {
|
|
58
|
+
if (plugin.mintCode == null) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const code = await plugin.mintCode(draft, taken, contextOf(plugin));
|
|
62
|
+
if (code != null) {
|
|
63
|
+
return code;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
},
|
|
68
|
+
before: async (exec, contextOf) => {
|
|
69
|
+
let current = exec;
|
|
70
|
+
for (const plugin of ordered()) {
|
|
71
|
+
if (plugin.before == null) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
current = await plugin.before(current, contextOf(plugin)) ?? current;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof ResilientError) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
throw new PlanningRefused(`${plugin.name}:${messageOf(error)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return current;
|
|
85
|
+
},
|
|
86
|
+
after: async (event, contextOf) => {
|
|
87
|
+
for (const plugin of ordered()) {
|
|
88
|
+
if (plugin.after == null) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await plugin.after(event, contextOf(plugin));
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error(`planning: after hook of ${plugin.name} failed on ${event.transition}:`, error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
version: () => version,
|
|
100
|
+
};
|
|
101
|
+
return registry;
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AA8B1E,MAAM,SAAS,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAA;AAEjG;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAA+B,EAAE,OAAwC,EACzD,EAAE;IAClB,MAAM,UAAU,GAAqB,EAAE,CAAA;IACvC,MAAM,MAAM,GAAG,IAAI,OAAO,EAAiC,CAAA;IAC3D,IAAI,OAAO,GAAG,CAAC,CAAA;IAEf,MAAM,OAAO,GAAG,GAAqB,EAAE,CAAC,UAAU;SAC/C,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,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AC,CAAA;gBAC9C,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,2BAA2B,MAAM,CAAC,IAAI,cAAc,KAAK,CAAC,UAAU,GAAG,EAAE,KAAK,CAAC,CAAA;gBAC/F,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO;KACvB,CAAA;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context';
|
|
2
|
+
import type { PlanningService, PlanningStore, WithPlanningService } from '@owlmeans/planning';
|
|
3
|
+
import type { PluginRegistry } from './registry.js';
|
|
4
|
+
import type { PlanningHostService, PlanningServiceOptions } from './types.js';
|
|
5
|
+
export type PlanningServiceApi = Pick<PlanningService, 'use' | 'plugins' | 'schemas' | 'store' | 'for' | 'committed'>;
|
|
6
|
+
/** What the facade and the executor reach the service through. */
|
|
7
|
+
export interface PlanningRuntime {
|
|
8
|
+
service: () => PlanningService;
|
|
9
|
+
registry: PluginRegistry;
|
|
10
|
+
options: PlanningServiceOptions;
|
|
11
|
+
context: () => BasicContext<BasicConfig> | undefined;
|
|
12
|
+
/** The composite store reads and commits go through. */
|
|
13
|
+
reader: () => PlanningStore;
|
|
14
|
+
/** Every distinct store: the default one first, then each plugin's. */
|
|
15
|
+
stores: () => PlanningStore[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The service body, without context registration — spread it into a specialised service; `self`
|
|
19
|
+
* is late-bound for exactly that case.
|
|
20
|
+
*
|
|
21
|
+
* A store receives the service's `committed` through its `bind` the first time the service resolves
|
|
22
|
+
* it, so the store that folds runs the `after` chain in its own process.
|
|
23
|
+
*/
|
|
24
|
+
export declare const planningServiceApi: (options: PlanningServiceOptions, self: () => PlanningService) => PlanningServiceApi & {
|
|
25
|
+
runtime: PlanningRuntime;
|
|
26
|
+
};
|
|
27
|
+
export declare const makePlanningService: (options?: PlanningServiceOptions, alias?: string) => PlanningHostService;
|
|
28
|
+
/**
|
|
29
|
+
* Register the planning service and `context.planning()`.
|
|
30
|
+
*
|
|
31
|
+
* The default store's commits and every plugin store's run this service's `after` chain in the
|
|
32
|
+
* process that folds them; `hooks: false` makes this process fold without running it.
|
|
33
|
+
*/
|
|
34
|
+
export declare const appendPlanningService: <C extends BasicConfig, T extends BasicContext<C>>(ctx: T, options?: PlanningServiceOptions, alias?: string) => T & WithPlanningService;
|
|
35
|
+
/**
|
|
36
|
+
* The planning service on a context, registering one with defaults when there is none — the
|
|
37
|
+
* `ensureRouterService` shape. A plugin package calls it before `use`, from `makeContext`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const ensurePlanningService: (ctx: BasicContext<any>, alias?: string) => PlanningService;
|
|
40
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAc,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAIzG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAE7E,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,eAAe,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,WAAW,CAAC,CAAA;AAErH,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,eAAe,CAAA;IAC9B,QAAQ,EAAE,cAAc,CAAA;IACxB,OAAO,EAAE,sBAAsB,CAAA;IAC/B,OAAO,EAAE,MAAM,YAAY,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;IACpD,wDAAwD;IACxD,MAAM,EAAE,MAAM,aAAa,CAAA;IAC3B,uEAAuE;IACvE,MAAM,EAAE,MAAM,aAAa,EAAE,CAAA;CAC9B;AAKD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,YACpB,sBAAsB,QAAQ,MAAM,eAAe,KAC3D,kBAAkB,GAAG;IAAE,OAAO,EAAE,eAAe,CAAA;CA0EjD,CAAA;AAED,eAAO,MAAM,mBAAmB,aACrB,sBAAsB,UAAc,MAAM,KAClD,mBAMF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,OAC/E,CAAC,YAAW,sBAAsB,UAAc,MAAM,KAC1D,CAAC,GAAG,mBAON,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAC3B,YAAY,CAAC,GAAG,CAAC,UAAS,MAAM,KACpC,eAQF,CAAA"}
|
package/build/service.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { createLazyService } from '@owlmeans/context';
|
|
2
|
+
import { makeSchemaRegistry, PlanningError } from '@owlmeans/planning';
|
|
3
|
+
import { DEFAULT_ALIAS } from './consts.js';
|
|
4
|
+
import { makeStoreFacade } from './facade.js';
|
|
5
|
+
import { makePluginRegistry } from './registry.js';
|
|
6
|
+
import { makeCompositeStore } from './store/composite.js';
|
|
7
|
+
import { makeMemoryPlanningStore } from './store/memory.js';
|
|
8
|
+
const contextOf = (service) => service.ctx;
|
|
9
|
+
/**
|
|
10
|
+
* The service body, without context registration — spread it into a specialised service; `self`
|
|
11
|
+
* is late-bound for exactly that case.
|
|
12
|
+
*
|
|
13
|
+
* A store receives the service's `committed` through its `bind` the first time the service resolves
|
|
14
|
+
* it, so the store that folds runs the `after` chain in its own process.
|
|
15
|
+
*/
|
|
16
|
+
export const planningServiceApi = (options, self) => {
|
|
17
|
+
const schemas = makeSchemaRegistry(options.schemas);
|
|
18
|
+
const bound = new WeakSet();
|
|
19
|
+
const bind = (store) => {
|
|
20
|
+
if (bound.has(store)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
bound.add(store);
|
|
24
|
+
store.bind?.(async (event) => { await self().committed(event); });
|
|
25
|
+
};
|
|
26
|
+
const registry = makePluginRegistry(schemas, bind);
|
|
27
|
+
const fallback = options.store ?? makeMemoryPlanningStore({ ids: options.ids, now: options.now });
|
|
28
|
+
bind(fallback);
|
|
29
|
+
let reader;
|
|
30
|
+
const runtime = {
|
|
31
|
+
service: self,
|
|
32
|
+
registry,
|
|
33
|
+
options,
|
|
34
|
+
context: () => contextOf(self()),
|
|
35
|
+
reader: () => {
|
|
36
|
+
if (reader == null || reader.version !== registry.version()) {
|
|
37
|
+
reader = { version: registry.version(), store: makeCompositeStore(registry.routes(runtime.context()), fallback) };
|
|
38
|
+
}
|
|
39
|
+
return reader.store;
|
|
40
|
+
},
|
|
41
|
+
stores: () => [...new Set([fallback, ...registry.routes(runtime.context()).map(route => route.store)])],
|
|
42
|
+
};
|
|
43
|
+
options.plugins?.forEach(registry.use);
|
|
44
|
+
return {
|
|
45
|
+
runtime,
|
|
46
|
+
schemas,
|
|
47
|
+
use: plugin => registry.use(plugin),
|
|
48
|
+
plugins: () => registry.plugins(),
|
|
49
|
+
store: type => registry.storeFor(type, fallback, runtime.context()),
|
|
50
|
+
for: scope => {
|
|
51
|
+
if (scope?.entityId == null || scope.entityId === '') {
|
|
52
|
+
throw new PlanningError('malformed:scope-without-entity');
|
|
53
|
+
}
|
|
54
|
+
return makeStoreFacade(runtime, scope);
|
|
55
|
+
},
|
|
56
|
+
committed: async (event) => {
|
|
57
|
+
if (options.hooks === false || !registry.plugins().some(plugin => plugin.after != null)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const store = self().store(event.type);
|
|
61
|
+
let transition;
|
|
62
|
+
try {
|
|
63
|
+
transition = await store.transitions?.get(event.transition) ?? undefined;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
transition = undefined;
|
|
67
|
+
}
|
|
68
|
+
const context = runtime.context();
|
|
69
|
+
// The hook acts as this process's service, never as whoever wrote the transition.
|
|
70
|
+
const facade = self().for({
|
|
71
|
+
entityId: event.entityId,
|
|
72
|
+
...(context?.cfg?.service != null ? { service: context.cfg.service } : {}),
|
|
73
|
+
});
|
|
74
|
+
await registry.after(event, plugin => ({
|
|
75
|
+
context, schemas, store, plugin, facade, ...(transition != null ? { transition } : {}),
|
|
76
|
+
}));
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export const makePlanningService = (options = {}, alias = DEFAULT_ALIAS) => {
|
|
81
|
+
const service = createLazyService(alias, planningServiceApi(options, () => service));
|
|
82
|
+
return service;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Register the planning service and `context.planning()`.
|
|
86
|
+
*
|
|
87
|
+
* The default store's commits and every plugin store's run this service's `after` chain in the
|
|
88
|
+
* process that folds them; `hooks: false` makes this process fold without running it.
|
|
89
|
+
*/
|
|
90
|
+
export const appendPlanningService = (ctx, options = {}, alias = DEFAULT_ALIAS) => {
|
|
91
|
+
const context = ctx;
|
|
92
|
+
context.registerService(makePlanningService(options, alias));
|
|
93
|
+
context.planning = () => context.service(alias);
|
|
94
|
+
return context;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The planning service on a context, registering one with defaults when there is none — the
|
|
98
|
+
* `ensureRouterService` shape. A plugin package calls it before `use`, from `makeContext`.
|
|
99
|
+
*/
|
|
100
|
+
export const ensurePlanningService = (ctx, alias = DEFAULT_ALIAS) => {
|
|
101
|
+
if (!ctx.hasService(alias)) {
|
|
102
|
+
appendPlanningService(ctx, {}, alias);
|
|
103
|
+
}
|
|
104
|
+
else if (ctx.planning == null && alias === DEFAULT_ALIAS) {
|
|
105
|
+
ctx.planning = () => ctx.service(alias);
|
|
106
|
+
}
|
|
107
|
+
return ctx.service(alias);
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAkB3D,MAAM,SAAS,GAAG,CAAC,OAAwB,EAAyC,EAAE,CACnF,OAAwC,CAAC,GAA4C,CAAA;AAExF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAA+B,EAAE,IAA2B,EACT,EAAE;IACrD,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,MAAM,KAAK,GAAG,IAAI,OAAO,EAAiB,CAAA;IAC1C,MAAM,IAAI,GAAG,CAAC,KAAoB,EAAQ,EAAE;QAC1C,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,OAAM;QACR,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CACf;QAAC,KAA+B,CAAC,IAAI,EAAE,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IAC5F,CAAC,CAAA;IAED,MAAM,QAAQ,GAAG,kBAAkB,C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