@yaks/project 0.0.0-stage → 0.2.36

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/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts","./testing.ts"]},"name":"@yaks/project","version":"0.2.36","license":"Apache-2.0","description":"A portfolio: the projects work is filed under, the boards that are saved filters over it, the ventures being built, and where a project lands its source.","exports":{".":"./mod.ts","./vocab":"./vocab.ts","./graph":"./graph.ts","./tools":"./tools.ts","./views":"./views.ts"},"imports":{"@yaks/project":"./mod.ts","@yaks/project/vocab":"./vocab.ts","@yaks/project/graph":"./graph.ts","@yaks/project/tools":"./tools.ts","@yaks/project/views":"./views.ts"}}
package/graph.js ADDED
@@ -0,0 +1,14 @@
1
+ // The graph plugins this package contributes, exported as
2
+ // `@yaks/project/graph` — the entry point a server imports to install them.
3
+ // They include the check over a board's saved query, which is why this entry
4
+ // point needs the vocabulary that query is written against.
5
+ //
6
+ // The statuses a board may filter on are the ones the loaded vocabulary's
7
+ // ladder gives (@yaks/vocab's `status` keyword), so a server that also loads
8
+ // @yaks/session gets `wip` in the check by loading it, and one without leases
9
+ // knows only the three @yaks/task declares.
10
+ import { projects } from "./plugin.js";
11
+ /** The project work is filed under, the filing, and the board over it. */ export let plugins = (host)=>[
12
+ projects(host.vocab)
13
+ ];
14
+ //# sourceMappingURL=graph.js.map
package/graph.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sources":["./graph.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,4EAA4E;AAC5E,6EAA6E;AAC7E,4DAA4D;AAC5D,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,4CAA4C;AAI5C,SAAS,QAAQ,sBAAqB;AAEtC,wEAAwE,GACxE,OAAO,IAAI,UAAU,CACnB,OACa;IAAC,SAAS,KAAK,KAAK;GAAE,CAAA"}
package/graph.ts ADDED
@@ -0,0 +1,18 @@
1
+ // The graph plugins this package contributes, exported as
2
+ // `@yaks/project/graph` — the entry point a server imports to install them.
3
+ // They include the check over a board's saved query, which is why this entry
4
+ // point needs the vocabulary that query is written against.
5
+ //
6
+ // The statuses a board may filter on are the ones the loaded vocabulary's
7
+ // ladder gives (@yaks/vocab's `status` keyword), so a server that also loads
8
+ // @yaks/session gets `wip` in the check by loading it, and one without leases
9
+ // knows only the three @yaks/task declares.
10
+
11
+ import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
12
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
13
+ import { projects } from './plugin.js'
14
+
15
+ /** The project work is filed under, the filing, and the board over it. */
16
+ export let plugins = (
17
+ host: { vocab: Vocab },
18
+ ): Plugin[] => [projects(host.vocab)]
package/guard.js ADDED
@@ -0,0 +1,99 @@
1
+ // The `precondition` hook that refuses a board whose query would quietly match
2
+ // nothing.
3
+ //
4
+ // A board is its query — membership is never stored — and that is what makes
5
+ // this worth refusing over. An empty board looks exactly like a board whose
6
+ // filter is right and whose answer happens to be nothing, so a typo in a query
7
+ // is invisible forever: no error, no empty state explaining itself, just a
8
+ // board that is always blank. The query grammar and the vocabulary already know
9
+ // better, so the board is checked as it is written, while whoever typed it is
10
+ // still there.
11
+ //
12
+ // Two ways a query is wrong, both caught in one walk over its clauses:
13
+ //
14
+ // Routing `.task.staus=open` names no property. The vocabulary refuses it.
15
+ // Members `.task.status=complete` names no status. The status set refuses it.
16
+ //
17
+ // The second is what a closed set of statuses buys: `complete` and `completed`
18
+ // and `done` are all plausible, exactly one is a status, and a query naming
19
+ // either of the others is indistinguishable from a board with nothing on it.
20
+ //
21
+ // The empty query stays legal. It selects nothing on purpose — that is what a
22
+ // board nobody has written a filter for should show.
23
+ //
24
+ // Writing `task.status` itself needs no refusal here: it is declared
25
+ // `computed: true`, and @yaks/graph's `admit` phase drops a computed property
26
+ // before this hook ever sees the write.
27
+ //
28
+ // The hook runs at `precondition`, inside the transaction and before any row
29
+ // has changed, so a refusal rolls the whole write back: the batch
30
+ // passed to `graph.apply()` is committed entirely or not at all.
31
+ import { comps } from "@yaks/graph/bundle";
32
+ import { Refused } from "@yaks/graph/errors";
33
+ import { parse } from "@yaks/query";
34
+ import { BOARD } from "./comp.js";
35
+ // Every raw token a value contains: a scalar is one, a list is its items, a
36
+ // range is its ends. A time phrase is nobody's enum member and is left alone.
37
+ let tokens = (v)=>!v ? [] : v.kind == 'scalar' ? [
38
+ v.raw
39
+ ] : v.kind == 'list' ? v.items.flatMap(tokens) : v.kind == 'range' ? [
40
+ ...tokens(v.lo),
41
+ ...tokens(v.hi)
42
+ ] : [];
43
+ /**
44
+ * Returns why this query cannot stand as a board's filter, or `null` when it
45
+ * can: every predicate must route through the vocabulary, and every status it
46
+ * names must be one its component's ladder gives (@yaks/vocab's `status`
47
+ * keyword). The set is the vocabulary's, so a board in a graph that leases its
48
+ * tasks knows `wip` without @yaks/project being told about @yaks/session.
49
+ *
50
+ * ```ts
51
+ * import { unroutable } from '@yaks/project'
52
+ *
53
+ * // unroutable('.task.status=open', vocab) → null
54
+ * // unroutable('.task.status=complete', vocab) → 'no such status: complete — …'
55
+ * ```
56
+ */ export let unroutable = (query, vocab)=>{
57
+ try {
58
+ for (let c of parse(query).clauses){
59
+ if (c.kind != 'pred') continue;
60
+ let hops = vocab.aim(c.path.join('.'), c.op == '!' && c.path.length == 1);
61
+ let last = hops[hops.length - 1];
62
+ if (!last || last.prop != 'status' || !vocab.comp(last.comp)?.ladder) {
63
+ continue;
64
+ }
65
+ let known = vocab.prop(last.comp, 'status')?.values ?? [];
66
+ // An empty value is the absence form (`!task.status`), which names
67
+ // nothing.
68
+ for (let t of tokens(c.value).filter(Boolean)){
69
+ if (!known.includes(t)) {
70
+ return `no such status: ${t} — this board knows ${known.join(', ')}`;
71
+ }
72
+ }
73
+ }
74
+ return null;
75
+ } catch (e) {
76
+ return e instanceof Error ? e.message : String(e);
77
+ }
78
+ };
79
+ /**
80
+ * The `precondition` hook: refuses a board whose query does not route, or which
81
+ * names a status outside the closed set. Registered by
82
+ * {@link https://jsr.io/@yaks/project/doc/~/projects | projects}; exported on
83
+ * its own for a graph that wants the check without the rest of the plugin.
84
+ */ export let guarding = (vocab)=>(bundles)=>{
85
+ for (let b of bundles){
86
+ for (let [name, comp] of comps(b))checked(b, name, comp, vocab);
87
+ }
88
+ return bundles;
89
+ };
90
+ // Checks one component of one bundle. A `null` component is a deletion, which
91
+ // carries no query at all.
92
+ let checked = (b, name, comp, vocab)=>{
93
+ if (!comp || name != BOARD || comp.query == null) return;
94
+ let why = unroutable(String(comp.query), vocab);
95
+ if (why) {
96
+ throw new Refused(`board ${b.entity.eid} refused: ${why} — a board IS its query, so one ` + `that cannot be routed matches nothing and never says why`);
97
+ }
98
+ };
99
+ //# sourceMappingURL=guard.js.map
package/guard.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.js","sources":["./guard.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,WAAW;AACX,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,+EAA+E;AAC/E,2EAA2E;AAC3E,gFAAgF;AAChF,8EAA8E;AAC9E,eAAe;AACf,EAAE;AACF,uEAAuE;AACvE,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,EAAE;AACF,8EAA8E;AAC9E,qDAAqD;AACrD,EAAE;AACF,qEAAqE;AACrE,8EAA8E;AAC9E,wCAAwC;AACxC,EAAE;AACF,6EAA6E;AAC7E,kEAAkE;AAClE,iEAAiE;AAGjE,SAAS,KAAK,kCAAuC;AACrD,SAAS,OAAO,kCAAuC;AACvD,SAAS,KAAK,2BAA4C;AAE1D,SAAS,KAAK,oBAAmB;AAEjC,4EAA4E;AAC5E,8EAA8E;AAC9E,IAAI,SAAS,CAAC,IACZ,CAAC,IACG,EAAE,GACF,EAAE,IAAI,IAAI,WACV;IA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AC9E,2BAA2B;AAC3B,IAAI,UAAU,CACZ,GACA,MACA,MACA;EAEA,IAAI,CAAC,QAAQ,QAAQ,SAAS,KAAK,KAAK,IAAI,MAAM;EAClD,IAAI,MAAM,WAAW,OAAO,KAAK,KAAK,GAAG;EACzC,IAAI,KAAK;IACP,MAAM,IAAI,QACR,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,gCAAgC,CAAC,GACrE,CAAC,wDAAwD,CAAC;EAEhE;AACF"}
package/guard.ts ADDED
@@ -0,0 +1,119 @@
1
+ // The `precondition` hook that refuses a board whose query would quietly match
2
+ // nothing.
3
+ //
4
+ // A board is its query — membership is never stored — and that is what makes
5
+ // this worth refusing over. An empty board looks exactly like a board whose
6
+ // filter is right and whose answer happens to be nothing, so a typo in a query
7
+ // is invisible forever: no error, no empty state explaining itself, just a
8
+ // board that is always blank. The query grammar and the vocabulary already know
9
+ // better, so the board is checked as it is written, while whoever typed it is
10
+ // still there.
11
+ //
12
+ // Two ways a query is wrong, both caught in one walk over its clauses:
13
+ //
14
+ // Routing `.task.staus=open` names no property. The vocabulary refuses it.
15
+ // Members `.task.status=complete` names no status. The status set refuses it.
16
+ //
17
+ // The second is what a closed set of statuses buys: `complete` and `completed`
18
+ // and `done` are all plausible, exactly one is a status, and a query naming
19
+ // either of the others is indistinguishable from a board with nothing on it.
20
+ //
21
+ // The empty query stays legal. It selects nothing on purpose — that is what a
22
+ // board nobody has written a filter for should show.
23
+ //
24
+ // Writing `task.status` itself needs no refusal here: it is declared
25
+ // `computed: true`, and @yaks/graph's `admit` phase drops a computed property
26
+ // before this hook ever sees the write.
27
+ //
28
+ // The hook runs at `precondition`, inside the transaction and before any row
29
+ // has changed, so a refusal rolls the whole write back: the batch
30
+ // passed to `graph.apply()` is committed entirely or not at all.
31
+
32
+ import type { Bundle, Comp, Hook } from 'jsr:@yaks/graph@0.2.36'
33
+ import { comps } from '@yaks/graph/bundle'
34
+ import { Refused } from '@yaks/graph/errors'
35
+ import { parse, type Value } from '@yaks/query'
36
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
37
+ import { BOARD } from './comp.js'
38
+
39
+ // Every raw token a value contains: a scalar is one, a list is its items, a
40
+ // range is its ends. A time phrase is nobody's enum member and is left alone.
41
+ let tokens = (v: Value | null): string[] =>
42
+ !v
43
+ ? []
44
+ : v.kind == 'scalar'
45
+ ? [v.raw]
46
+ : v.kind == 'list'
47
+ ? v.items.flatMap(tokens)
48
+ : v.kind == 'range'
49
+ ? [...tokens(v.lo), ...tokens(v.hi)]
50
+ : []
51
+
52
+ /**
53
+ * Returns why this query cannot stand as a board's filter, or `null` when it
54
+ * can: every predicate must route through the vocabulary, and every status it
55
+ * names must be one its component's ladder gives (@yaks/vocab's `status`
56
+ * keyword). The set is the vocabulary's, so a board in a graph that leases its
57
+ * tasks knows `wip` without @yaks/project being told about @yaks/session.
58
+ *
59
+ * ```ts
60
+ * import { unroutable } from '@yaks/project'
61
+ *
62
+ * // unroutable('.task.status=open', vocab) → null
63
+ * // unroutable('.task.status=complete', vocab) → 'no such status: complete — …'
64
+ * ```
65
+ */
66
+ export let unroutable = (query: string, vocab: Vocab): string | null => {
67
+ try {
68
+ for (let c of parse(query).clauses) {
69
+ if (c.kind != 'pred') continue
70
+ let hops = vocab.aim(c.path.join('.'), c.op == '!' && c.path.length == 1)
71
+ let last = hops[hops.length - 1]
72
+ if (!last || last.prop != 'status' || !vocab.comp(last.comp)?.ladder) {
73
+ continue
74
+ }
75
+ let known = vocab.prop(last.comp, 'status')?.values ?? []
76
+ // An empty value is the absence form (`!task.status`), which names
77
+ // nothing.
78
+ for (let t of tokens(c.value).filter(Boolean)) {
79
+ if (!known.includes(t)) {
80
+ return `no such status: ${t} — this board knows ${known.join(', ')}`
81
+ }
82
+ }
83
+ }
84
+ return null
85
+ } catch (e) {
86
+ return e instanceof Error ? e.message : String(e)
87
+ }
88
+ }
89
+
90
+ /**
91
+ * The `precondition` hook: refuses a board whose query does not route, or which
92
+ * names a status outside the closed set. Registered by
93
+ * {@link https://jsr.io/@yaks/project/doc/~/projects | projects}; exported on
94
+ * its own for a graph that wants the check without the rest of the plugin.
95
+ */
96
+ export let guarding = (vocab: Vocab): Hook => (bundles) => {
97
+ for (let b of bundles) {
98
+ for (let [name, comp] of comps(b)) checked(b, name, comp, vocab)
99
+ }
100
+ return bundles
101
+ }
102
+
103
+ // Checks one component of one bundle. A `null` component is a deletion, which
104
+ // carries no query at all.
105
+ let checked = (
106
+ b: Bundle,
107
+ name: string,
108
+ comp: Comp | null,
109
+ vocab: Vocab,
110
+ ): void => {
111
+ if (!comp || name != BOARD || comp.query == null) return
112
+ let why = unroutable(String(comp.query), vocab)
113
+ if (why) {
114
+ throw new Refused(
115
+ `board ${b.entity.eid} refused: ${why} — a board IS its query, so one ` +
116
+ `that cannot be routed matches nothing and never says why`,
117
+ )
118
+ }
119
+ }
package/mod.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A portfolio. A `project` is what work is filed under — `filed{project,
3
+ * priority, domain, assignee}` is that filing, kept separate from being a task
4
+ * so that a task can have none. A `board` is a saved filter over the portfolio
5
+ * rather than a stored list of members, and the one piece of machinery here
6
+ * refuses a board whose query would quietly match nothing. A project filed
7
+ * under another project is its sub-project, so `.filed.project->P` is
8
+ * everything under P, and {@link lineage} reads the way up. A `venture` is a
9
+ * business being built, with a phase rather than a status.
10
+ *
11
+ * ```ts
12
+ * import { loadVocab } from '@yaks/vocab'
13
+ * import { edgeDoc, edgeKeywords } from '@yaks/edge'
14
+ * import { taskDoc } from '@yaks/task'
15
+ * import { projectDoc, projects } from '@yaks/project'
16
+ *
17
+ * let vocab = loadVocab([edgeDoc, taskDoc, projectDoc], [edgeKeywords])
18
+ * // let g = graph({ storage, vocab, plugins: [projects(vocab)] })
19
+ * ```
20
+ *
21
+ * @module
22
+ */ export * from "./comp.js";
23
+ export * from "./guard.js";
24
+ export * from "./plugin.js";
25
+ export * from "./tree.js";
26
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,0BAAyB;AACzB,2BAA0B;AAC1B,4BAA2B;AAC3B,0BAAyB"}
package/mod.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A portfolio. A `project` is what work is filed under — `filed{project,
3
+ * priority, domain, assignee}` is that filing, kept separate from being a task
4
+ * so that a task can have none. A `board` is a saved filter over the portfolio
5
+ * rather than a stored list of members, and the one piece of machinery here
6
+ * refuses a board whose query would quietly match nothing. A project filed
7
+ * under another project is its sub-project, so `.filed.project->P` is
8
+ * everything under P, and {@link lineage} reads the way up. A `venture` is a
9
+ * business being built, with a phase rather than a status.
10
+ *
11
+ * ```ts
12
+ * import { loadVocab } from '@yaks/vocab'
13
+ * import { edgeDoc, edgeKeywords } from '@yaks/edge'
14
+ * import { taskDoc } from '@yaks/task'
15
+ * import { projectDoc, projects } from '@yaks/project'
16
+ *
17
+ * let vocab = loadVocab([edgeDoc, taskDoc, projectDoc], [edgeKeywords])
18
+ * // let g = graph({ storage, vocab, plugins: [projects(vocab)] })
19
+ * ```
20
+ *
21
+ * @module
22
+ */
23
+ export * from './comp.js'
24
+ export * from './guard.js'
25
+ export * from './plugin.js'
26
+ export * from './tree.js'
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@yaks/project",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/project",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ },
11
+ "./vocab": {
12
+ "types": "./_dist/vocab.d.ts",
13
+ "default": "./vocab.js"
14
+ },
15
+ "./graph": {
16
+ "types": "./_dist/graph.d.ts",
17
+ "default": "./graph.js"
18
+ },
19
+ "./tools": {
20
+ "types": "./_dist/tools.d.ts",
21
+ "default": "./tools.js"
22
+ },
23
+ "./views": {
24
+ "types": "./_dist/views.d.ts",
25
+ "default": "./views.js"
26
+ }
27
+ },
28
+ "license": "Apache-2.0",
29
+ "dependencies": {
30
+ "@yaks/fp": "0.2.36",
31
+ "@yaks/graph": "0.2.36",
32
+ "@yaks/id": "0.2.36",
33
+ "@yaks/query": "0.2.36",
34
+ "@yaks/tools": "0.2.36",
35
+ "@yaks/vocab": "0.2.36"
36
+ },
37
+ "description": "A portfolio: the projects work is filed under, the boards that are saved filters over it, the ventures being built, and where a project lands its source.",
38
+ "repository": "https://github.com/yak-sh/yak.git"
39
+ }
package/plugin.js ADDED
@@ -0,0 +1,38 @@
1
+ // The package as a graph plugin: the portfolio's components, the check over a
2
+ // board's saved query, and the one that keeps projects a tree.
3
+ //
4
+ // It takes the loaded vocabulary as an argument because a board's query is
5
+ // checked against the schema, not against this package — a board filtering
6
+ // `.author=dana` is only valid if the graph has an author property, and only
7
+ // the loaded vocabulary knows whether it does. So a graph is built in two
8
+ // steps, the way @yaks/edge's is: load the documents, then pass the same
9
+ // vocabulary to the plugin.
10
+ import { after } from "@yaks/fp";
11
+ import { hook } from "@yaks/graph/plugin";
12
+ import { BOARD, FILED, projectDoc } from "./comp.js";
13
+ import { guarding } from "./guard.js";
14
+ import { nesting } from "./tree.js";
15
+ /**
16
+ * The portfolio plugin: the `project`, `filed`, `board` and `venture`
17
+ * components, and a `precondition` hook that refuses a board whose query would
18
+ * quietly match nothing, or a project filed under one already under it.
19
+ *
20
+ * A board's statuses are checked against the ladder the loaded vocabulary
21
+ * declares, so a server that loads leases gets `wip` without this package
22
+ * being told about them.
23
+ */ export let projects = (vocab)=>{
24
+ let boards = guarding(vocab);
25
+ return {
26
+ name: '@yaks/project',
27
+ vocab: [
28
+ projectDoc
29
+ ],
30
+ hooks: {
31
+ precondition: hook([
32
+ BOARD,
33
+ FILED
34
+ ], (b, tx)=>after(boards(b, tx), (b)=>nesting(b, tx)))
35
+ }
36
+ };
37
+ };
38
+ //# sourceMappingURL=plugin.js.map
package/plugin.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["./plugin.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+DAA+D;AAC/D,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,yEAAyE;AACzE,4BAA4B;AAE5B,SAAS,KAAK,wBAA6B;AAC3C,SAAS,IAAI,kCAAoD;AAEjE,SAAS,KAAK,EAAE,KAAK,EAAE,UAAU,oBAAmB;AACpD,SAAS,QAAQ,qBAAoB;AACrC,SAAS,OAAO,oBAAmB;AAEnC;;;;;;;;CAQC,GACD,OAAO,IAAI,WAAW,CAAC;EACrB,IAAI,SAAS,SAAS;EACtB,OAAO;IACL,MAAM;IACN,OAAO;MAAC;KAAW;IACnB,OAAO;MACL,cAAc,KACZ;QAAC;QAAO;OAAM,EACd,CAAC,GAAG,KAAO,MAAM,OAAO,GAAG,KAAK,CAAC,IAAM,QAAQ,GAAG;IAEtD;EACF;AACF,EAAC"}
package/plugin.ts ADDED
@@ -0,0 +1,39 @@
1
+ // The package as a graph plugin: the portfolio's components, the check over a
2
+ // board's saved query, and the one that keeps projects a tree.
3
+ //
4
+ // It takes the loaded vocabulary as an argument because a board's query is
5
+ // checked against the schema, not against this package — a board filtering
6
+ // `.author=dana` is only valid if the graph has an author property, and only
7
+ // the loaded vocabulary knows whether it does. So a graph is built in two
8
+ // steps, the way @yaks/edge's is: load the documents, then pass the same
9
+ // vocabulary to the plugin.
10
+
11
+ import { after } from '@yaks/fp'
12
+ import { hook, type Plugin } from '@yaks/graph/plugin'
13
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
14
+ import { BOARD, FILED, projectDoc } from './comp.js'
15
+ import { guarding } from './guard.js'
16
+ import { nesting } from './tree.js'
17
+
18
+ /**
19
+ * The portfolio plugin: the `project`, `filed`, `board` and `venture`
20
+ * components, and a `precondition` hook that refuses a board whose query would
21
+ * quietly match nothing, or a project filed under one already under it.
22
+ *
23
+ * A board's statuses are checked against the ladder the loaded vocabulary
24
+ * declares, so a server that loads leases gets `wip` without this package
25
+ * being told about them.
26
+ */
27
+ export let projects = (vocab: Vocab): Plugin => {
28
+ let boards = guarding(vocab)
29
+ return {
30
+ name: '@yaks/project',
31
+ vocab: [projectDoc],
32
+ hooks: {
33
+ precondition: hook(
34
+ [BOARD, FILED],
35
+ (b, tx) => after(boards(b, tx), (b) => nesting(b, tx)),
36
+ ),
37
+ },
38
+ }
39
+ }
package/tools.js ADDED
@@ -0,0 +1,105 @@
1
+ // The implementations of the tools declared with `tool: true` in
2
+ // ./vocab.json, exported as `@yaks/project/tools` — the entry point a server
3
+ // imports to register them. Both are checks: tools whose verb is `check`,
4
+ // which is all a "doctor" is (@yaks/tools ./check.ts).
5
+ //
6
+ // Two invariants, and both are about a portfolio quietly stopping being one:
7
+ //
8
+ // A board is its query. ./guard.ts refuses an unroutable query as it is
9
+ // written, while whoever typed it is still there — but that is not the only way
10
+ // a query stops routing. The vocabulary moves: a property is renamed, a status
11
+ // retires, a component this server used to load is gone. Every board written
12
+ // against the old declarations now matches nothing and reports no error, which
13
+ // is exactly the failure the precondition hook exists to prevent, arriving from
14
+ // the other direction.
15
+ //
16
+ // Governed work is under A project. `governed` is the keyword a component
17
+ // declares to mean that a project answers for the entities carrying it
18
+ // (@yaks/kernel): a task, a memory, a design. One that is filed under no
19
+ // project, and that no project reaches along a containment edge, is work
20
+ // nobody's portfolio can see — it is on no board, in nobody's queue, and
21
+ // nothing will ever report that it was dropped.
22
+ import { and, every, present } from "@yaks/query";
23
+ import { human } from "@yaks/id";
24
+ import { checked } from "@yaks/tools/check";
25
+ import { BOARD, FILED, PROJECT } from "./comp.js";
26
+ import { unroutable } from "./guard.js";
27
+ /** The containment relation tags assumed when configuration names none. */ let CONTAINS = [
28
+ 'contains'
29
+ ];
30
+ let comp = (b, name)=>b[name];
31
+ // The components a project answers for, read off the loaded vocabulary rather
32
+ // than listed here: a server that loads another governed component gets it
33
+ // checked without an edit to this file.
34
+ let governedIn = (v)=>v.all.filter((name)=>v.comp(name)?.keywords.governed === true);
35
+ // Everything a project can see: the projects themselves, whatever is filed
36
+ // under one, and whatever those reach along the containment edges. A cycle of
37
+ // orphans looks internally connected, so reachability is only meaningful from
38
+ // the project seed — which is the whole reason this is a walk and not a
39
+ // property read.
40
+ let reached = async (graph, through)=>{
41
+ let seeds = [
42
+ ...await graph.read(and(present(PROJECT))),
43
+ ...await graph.read(and(present(`${FILED}.project`)))
44
+ ];
45
+ // Only the edges a containment tag marks: reading every edge to keep these
46
+ // reads the whole edge table, more than one read may hold.
47
+ let links = (await Promise.all(through.map((tag)=>graph.read(and(present('edge'), present(tag)))))).flat();
48
+ let out = new Map();
49
+ for (let b of links){
50
+ let e = comp(b, 'edge');
51
+ if (!e?.from || !e?.to) continue;
52
+ out.set(String(e.from), [
53
+ ...out.get(String(e.from)) ?? [],
54
+ String(e.to)
55
+ ]);
56
+ }
57
+ let seen = new Set(seeds.map((b)=>b.entity.eid));
58
+ let front = [
59
+ ...seen
60
+ ];
61
+ while(front.length){
62
+ let here = front.pop();
63
+ for (let there of out.get(here) ?? []){
64
+ if (seen.has(there)) continue;
65
+ seen.add(there);
66
+ front.push(there);
67
+ }
68
+ }
69
+ return seen;
70
+ };
71
+ /** The implementations of the tools ./vocab.json declares. The loaded
72
+ * vocabulary is what a board's query routes through, and what declares which
73
+ * components are governed, so both checks are built against the components this
74
+ * graph actually has. */ export let runs = (host, options = {})=>({
75
+ board_check: async (call, graph)=>{
76
+ let id = human(host.vocab);
77
+ let found = (await graph.read(and(present(`${BOARD}.query`), every()))).flatMap((b)=>{
78
+ let query = String(comp(b, BOARD)?.query ?? '');
79
+ let why = query.trim() && unroutable(query, host.vocab);
80
+ return why ? [
81
+ {
82
+ level: 'fail',
83
+ text: `${id(b)} no longer routes (${why}): ${query}`
84
+ }
85
+ ] : [];
86
+ });
87
+ return checked(call.entity.eid, 'every saved board query still routes', found);
88
+ },
89
+ project_check: async (call, graph)=>{
90
+ let id = human(host.vocab);
91
+ let seen = await reached(graph, options.through ?? CONTAINS);
92
+ let found = [];
93
+ for (let word of governedIn(host.vocab)){
94
+ for (let b of (await graph.read(and(present(word), every())))){
95
+ if (seen.has(b.entity.eid)) continue;
96
+ found.push({
97
+ level: 'fail',
98
+ text: `${id(b)} (${word}) is under no project — nobody's portfolio ` + `holds it, so nothing will ever say it was dropped`
99
+ });
100
+ }
101
+ }
102
+ return checked(call.entity.eid, 'every governed entity is reachable from a project', found);
103
+ }
104
+ });
105
+ //# sourceMappingURL=tools.js.map
package/tools.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sources":["./tools.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,6EAA6E;AAC7E,0EAA0E;AAC1E,uDAAuD;AACvD,EAAE;AACF,6EAA6E;AAC7E,EAAE;AACF,wEAAwE;AACxE,gFAAgF;AAChF,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,uBAAuB;AACvB,EAAE;AACF,0EAA0E;AAC1E,uEAAuE;AACvE,yEAAyE;AACzE,yEAAyE;AACzE,yEAAyE;AACzE,gDAAgD;AAEhD,SAAS,GAAG,EAAE,KAAK,EAAE,OAAO,2BAAgC;AAC5D,SAAS,KAAK,wBAA6B;AAE3C,SAAS,OAAO,iCAAsC;AAItD,SAAS,KAAK,EAAE,KAAK,EAAE,OAAO,oBAAmB;AACjD,SAAS,UAAU,qBAAoB;AAWvC,yEAAyE,GACzE,IAAI,WAAW;EAAC;CAAW;AAE3B,IAAI,OAAO,CAAC,GAAW,OAAiB,CAAC,CAAC,KAAK;AAE/C,8EAA8E;AAC9E,2EAA2E;AAC3E,wCAAwC;AACxC,IAAI,aAAa,CAAC,IAChB,EAAE,GA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