@yaks/task 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/DecisionForm.js +118 -0
- package/DecisionForm.js.map +1 -0
- package/DecisionForm.ts +211 -0
- package/LICENSE +202 -0
- package/README.md +389 -2
- package/_dist/DecisionForm.d.ts +25 -0
- package/_dist/DecisionForm.d.ts.map +1 -0
- package/_dist/comp.d.ts +20 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/decision.d.ts +41 -0
- package/_dist/decision.d.ts.map +1 -0
- package/_dist/deps.d.ts +58 -0
- package/_dist/deps.d.ts.map +1 -0
- package/_dist/graph.d.ts +3 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/mod.d.ts +71 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/plugin.d.ts +28 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/text.d.ts +5 -0
- package/_dist/text.d.ts.map +1 -0
- package/_dist/tools.d.ts +20 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/views.d.ts +6 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/words.d.ts +28 -0
- package/_dist/words.d.ts.map +1 -0
- package/comp.js +66 -0
- package/comp.js.map +1 -0
- package/comp.ts +77 -0
- package/decision.js +156 -0
- package/decision.js.map +1 -0
- package/decision.ts +174 -0
- package/deno.json +1 -0
- package/deps.js +127 -0
- package/deps.js.map +1 -0
- package/deps.ts +163 -0
- package/graph.js +9 -0
- package/graph.js.map +1 -0
- package/graph.ts +10 -0
- package/inspect.js +131 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +144 -0
- package/mod.js +71 -0
- package/mod.js.map +1 -0
- package/mod.ts +83 -0
- package/package.json +53 -4
- package/plugin.js +46 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +40 -0
- package/text.js +22 -0
- package/text.js.map +1 -0
- package/text.ts +30 -0
- package/tools.js +303 -0
- package/tools.js.map +1 -0
- package/tools.ts +282 -0
- package/views.js +35 -0
- package/views.js.map +1 -0
- package/views.ts +39 -0
- package/vocab.js +18 -0
- package/vocab.js.map +1 -0
- package/vocab.json +860 -0
- package/vocab.ts +20 -0
- package/words.js +46 -0
- package/words.js.map +1 -0
- package/words.ts +57 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Plugin } from "@yaks/graph/plugin";
|
|
2
|
+
/**
|
|
3
|
+
* The task plugin: the `task`, `cancelled` and `blocked` components and the
|
|
4
|
+
* `requires` and `contains` relations. A task is done when it wears
|
|
5
|
+
* @yaks/kernel's `completed`, so a graph of tasks loads the kernel beside it.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
9
|
+
* import { graph } from '@yaks/graph'
|
|
10
|
+
* import { ram } from '@yaks/ram'
|
|
11
|
+
* import { kernel, kernelDoc, kernelKeywords } from '@yaks/kernel'
|
|
12
|
+
* import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
|
|
13
|
+
* import { taskDoc, tasks } from '@yaks/task'
|
|
14
|
+
*
|
|
15
|
+
* let vocab = loadVocab([kernelDoc, edgeDoc, taskDoc], [
|
|
16
|
+
* kernelKeywords,
|
|
17
|
+
* edgeKeywords,
|
|
18
|
+
* ])
|
|
19
|
+
* let plugins = [kernel(), edges(vocab), tasks()]
|
|
20
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The status itself is not stored and not written. `task` declares it as a
|
|
24
|
+
* ladder of marks in the vocabulary (@yaks/vocab's `status` keyword), and
|
|
25
|
+
* every store reads it from there. A graph that leases its tasks adds a rung
|
|
26
|
+
* where it declares the lease, as @yaks/session reads a held claim as `wip`.
|
|
27
|
+
*/ export declare let tasks: () => Plugin;
|
|
28
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sources":["../plugin.ts"],"names":[],"mappings":"AAKA,SAAe,KAAK,MAAM,kCAAuC;AAIjE;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,YAAI,aAAY,OAIrB"}
|
package/_dist/text.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sources":["../text.ts"],"names":[],"mappings":"AAeA,qEAAqE,GACrE,OAAO,YAAI,WACT,OAAO,MAAM,EACb,OAAO,MAAM;EACV,OAAO,MAAM;EAAE,MAAM,MAAM;EAU/B"}
|
package/_dist/tools.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Comp } from "@yaks/graph";
|
|
2
|
+
import { type Runs } from "@yaks/graph/tools";
|
|
3
|
+
import { type Line } from "@yaks/query";
|
|
4
|
+
/**
|
|
5
|
+
* A status, as the marks that mean it. Nothing writes `task.status` — it is
|
|
6
|
+
* computed from these — so moving a task means adding one mark and removing
|
|
7
|
+
* the other, which is why finishing something records when and by whom instead
|
|
8
|
+
* of overwriting a value.
|
|
9
|
+
*/ export declare let marked: Record<string, Record<string, Comp | null>>;
|
|
10
|
+
/**
|
|
11
|
+
* The query a listing runs, with `.task` always part of it.
|
|
12
|
+
*
|
|
13
|
+
* The default is `.task.status=open,wip`. A caller's own query is passed
|
|
14
|
+
* through as typed and narrowed to tasks as a whole (`.a|.b` lists the tasks
|
|
15
|
+
* that are either), and every task comes back whole (`*`): a listing shows
|
|
16
|
+
* tasks, not the words it matched.
|
|
17
|
+
*/ export declare let listing: (query?: unknown, limit?: unknown) => Line;
|
|
18
|
+
/** The implementations behind ./vocab.json. Scalar changes are data; partial
|
|
19
|
+
* text changes read through the graph and keep the shared compiler's guard. */ export declare let runs: () => Runs;
|
|
20
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAkBA,cAAsB,IAAI,2BAAuC;AAGjE,SAA4B,KAAK,IAAI,iCAAqD;AAE1F,SAAkB,KAAK,IAAI,2BAA6C;AA0BxE;;;;;CAKC,GACD,OAAO,YAAI,QAAQ,OAAO,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,IAAI,GAK3D;AAED;;;;;;;CAOC,GAGD,OAAO,YAAI,UAAW,QAAQ,OAAO,EAAE,QAAQ,OAAO,KAAG,KAMrD;AA+KJ;6EAC6E,GAC7E,OAAO,YAAI,YAAW,KA0BpB"}
|
package/_dist/views.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { View } from "@yaks/inspect";
|
|
2
|
+
import { type Registry } from "@yaks/render";
|
|
3
|
+
/** `Status` for a task: `open`, `done`, `cancelled`, or a rung another package
|
|
4
|
+
* adds. */ export declare let views: Registry;
|
|
5
|
+
export declare let inspectViews: () => Promise<View[]>;
|
|
6
|
+
//# sourceMappingURL=views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAcA,cAAc,IAAI,6BAAkC;AACpD,SAAiB,KAAK,QAAQ,4BAAiC;AAQ/D;SACS,GACT,OAAO,YAAI,OAAO,SAShB;AAGF,OAAO,YAAI,oBAAmB,QAAQ,QACc"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
import { taskDoc } from "./comp.js";
|
|
3
|
+
export { taskDoc };
|
|
4
|
+
/** What this package is: its manifest's description, the one place it is
|
|
5
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
6
|
+
/** Every document this plugin declares. */ export declare let docs: VocabDoc[];
|
|
7
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAQA,cAAc,QAAQ,2BAAgC;AACtD,SAAS,OAAO,oBAAmB;AAGnC,SAAS,OAAO,GAAE;AAElB;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAsB"}
|
package/_dist/words.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Vocab } from "@yaks/vocab";
|
|
2
|
+
/**
|
|
3
|
+
* A task's status, read off the bundle through the ladder the vocabulary
|
|
4
|
+
* declares: the first rung it wears, else the status its store read, else
|
|
5
|
+
* `open`. An entity that is not a task has none, and reads `null`.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { assertEquals } from '@std/assert'
|
|
9
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
10
|
+
* import { kernelDoc, kernelKeywords } from '@yaks/kernel'
|
|
11
|
+
* import { statusOf, taskDoc } from '@yaks/task'
|
|
12
|
+
*
|
|
13
|
+
* let v = loadVocab([kernelDoc, taskDoc], [kernelKeywords])
|
|
14
|
+
* let task = { entity: { eid: 't1' }, task: {} }
|
|
15
|
+
* assertEquals(statusOf(v, task), 'open')
|
|
16
|
+
* assertEquals(statusOf(v, { ...task, completed: {} }), 'done')
|
|
17
|
+
* assertEquals(statusOf(v, { ...task, completed: {}, cancelled: {} }), 'cancelled')
|
|
18
|
+
* assertEquals(statusOf(v, { entity: { eid: 'x' }, completed: {} }), null)
|
|
19
|
+
* ```
|
|
20
|
+
*/ export declare let statusOf: (v: Vocab, b: Record<string, unknown>) => string | null;
|
|
21
|
+
/** What {@link statusOf} reads of a task: `task` and the mark on each rung of
|
|
22
|
+
* the ladder the vocabulary declares. A read naming only these answers the
|
|
23
|
+
* status without the rest the task wears. */ export declare let statusComps: (v: Vocab) => string[];
|
|
24
|
+
/** Does this status mean the work is over: finished, or called off? An open
|
|
25
|
+
* task has not settled, and neither has one somebody is on (`wip`). This is
|
|
26
|
+
* what {@link https://jsr.io/@yaks/task/doc/~/openDeps | openDeps} counts by
|
|
27
|
+
* its absence. */ export declare let settled: (status?: string | null) => boolean;
|
|
28
|
+
//# sourceMappingURL=words.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"words.d.ts","sources":["../words.ts"],"names":[],"mappings":"AAgBA,cAAc,KAAK,2BAAgC;AAGnD;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,YAAI,WACT,GAAG,OACH,GAAG,OAAO,MAAM,EAAE,OAAO,MACxB,MAAM,GAAG,IAAI,CAAsB;AAEtC;;2CAE2C,GAC3C,OAAO,YAAI,cAAe,GAAG,UAAQ,MAAM,GAG1C;AAED;;;gBAGgB,GAChB,OAAO,YAAI,UAAW,SAAS,MAAM,GAAG,IAAI,KAAG,OAAO,CACX"}
|
package/comp.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The components this package ships, as one vocabulary document to load beside
|
|
2
|
+
// your own.
|
|
3
|
+
//
|
|
4
|
+
// task{} a to-do item, with a computed status
|
|
5
|
+
// started{at, by, via} somebody said they are on it
|
|
6
|
+
// blocked{on} something outside is in the way
|
|
7
|
+
// requires / contains the two relations between tasks
|
|
8
|
+
//
|
|
9
|
+
// What a task is filed under — `project`, `filed`, the `board` that is a saved
|
|
10
|
+
// filter over the filing — belongs to @yaks/project: a task with nothing filed
|
|
11
|
+
// is still a task, and a portfolio is a different idea from a to-do item.
|
|
12
|
+
//
|
|
13
|
+
// Four things are worth explaining about the shapes, because each is a decision
|
|
14
|
+
// somebody would otherwise make differently.
|
|
15
|
+
//
|
|
16
|
+
// Status is not stored. `task` declares it with the `status` keyword: a ladder
|
|
17
|
+
// over the `cancelled`, `completed` and `started` marks (`completed` and `cancelled` are
|
|
18
|
+
// @yaks/kernel's shared marks), which gives it a computed `task.status`
|
|
19
|
+
// that is readable and filterable, and that no writer sets. Finishing a task
|
|
20
|
+
// means writing a fact with a time and an author rather than overwriting a
|
|
21
|
+
// value. Both evaluators read the one declaration, so `.task.status=done` selects
|
|
22
|
+
// the same tasks in a database and in a page, and a package that adds a rung
|
|
23
|
+
// (@yaks/session's held `claim`, also `wip`) widens the set where it declares
|
|
24
|
+
// the rung. `started` is how a person says "I'm on it", having no claim to hold.
|
|
25
|
+
//
|
|
26
|
+
// The two relations are `requires` and `contains`, as @yaks/edge reads them: a
|
|
27
|
+
// component that an edge entity carries beside `edge{from, to}`. Neither has
|
|
28
|
+
// any properties — the link itself is the whole of what they mean.
|
|
29
|
+
//
|
|
30
|
+
// Blocked is A component, not A status. `blocked{on}` records that something
|
|
31
|
+
// outside the graph is in the way — waiting on a vendor, on a decision, on a
|
|
32
|
+
// person. It is deliberately not a rung on the status ladder: a blocked task is
|
|
33
|
+
// still open work, and rolling it into the status would hide it from every
|
|
34
|
+
// open-work query exactly when somebody needs to see it. Unfinished `requires`
|
|
35
|
+
// children are not blocking either; they are ordinary work, counted and shown,
|
|
36
|
+
// never an alarm.
|
|
37
|
+
//
|
|
38
|
+
// The marks outlive the people. `cancelled.by` is `death: keep`, as the
|
|
39
|
+
// kernel's `completed.by` is — deleting the person who finished a task does not
|
|
40
|
+
// unfinish it. The reference stands as history.
|
|
41
|
+
//
|
|
42
|
+
// The document itself is `./vocab.json` — plain JSON Schema, readable by
|
|
43
|
+
// anything that reads JSON. This file re-exports it under the name callers
|
|
44
|
+
// import, and keeps the prose about why it is shaped the way it is.
|
|
45
|
+
import doc from './vocab.json' with {
|
|
46
|
+
type: 'json'
|
|
47
|
+
};
|
|
48
|
+
/** The component that makes an entity a task. */ export let TASK = 'task';
|
|
49
|
+
/** The mark on a task that was called off. */ export let CANCELLED = 'cancelled';
|
|
50
|
+
/** The component recording that something outside the graph is in the way. */ export let BLOCKED = 'blocked';
|
|
51
|
+
/** The relation from a task to work it waits for. */ export let REQUIRES = 'requires';
|
|
52
|
+
/** The relation from a task to work that is part of it. */ export let CONTAINS = 'contains';
|
|
53
|
+
/**
|
|
54
|
+
* The task vocabulary, to load beside your own:
|
|
55
|
+
* `loadVocab([taskDoc, ...mine], [edgeKeywords, ...])`. It declares nothing
|
|
56
|
+
* about what a person or a document is — bring your own `doc` (or
|
|
57
|
+
* {@link https://jsr.io/@yaks/doc | @yaks/doc}'s), and whatever else your tasks
|
|
58
|
+
* carry.
|
|
59
|
+
*
|
|
60
|
+
* `requires` and `contains` are declared through
|
|
61
|
+
* {@link https://jsr.io/@yaks/edge | @yaks/edge}'s `edge` keyword, so an
|
|
62
|
+
* edge entity carrying one of them states that link. Register `edgeKeywords`
|
|
63
|
+
* when you load, or the loader will carry the declaration with nobody reading
|
|
64
|
+
* it.
|
|
65
|
+
*/ export let taskDoc = doc;
|
|
66
|
+
//# sourceMappingURL=comp.js.map
|
package/comp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comp.js","sources":["./comp.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,YAAY;AACZ,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,sEAAsE;AACtE,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,0EAA0E;AAC1E,EAAE;AACF,gFAAgF;AAChF,6CAA6C;AAC7C,EAAE;AACF,+EAA+E;AAC/E,yFAAyF;AACzF,wEAAwE;AACxE,6EAA6E;AAC7E,2EAA2E;AAC3E,kFAAkF;AAClF,6EAA6E;AAC7E,8EAA8E;AAC9E,iFAAiF;AACjF,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,mEAAmE;AACnE,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,gFAAgF;AAChF,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,kBAAkB;AAClB,EAAE;AACF,wEAAwE;AACxE,gFAAgF;AAChF,gDAAgD;AAChD,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,oEAAoE;AAGpE,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD,+CAA+C,GAC/C,OAAO,IAAI,OAAO,OAAM;AAExB,4CAA4C,GAC5C,OAAO,IAAI,YAAY,YAAW;AAElC,4EAA4E,GAC5E,OAAO,IAAI,UAAU,UAAS;AAE9B,mDAAmD,GACnD,OAAO,IAAI,WAAW,WAAU;AAEhC,yDAAyD,GACzD,OAAO,IAAI,WAAW,WAAU;AAEhC;;;;;;;;;;;;CAYC,GACD,OAAO,IAAI,UAAoB,IAAG"}
|
package/comp.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The components this package ships, as one vocabulary document to load beside
|
|
2
|
+
// your own.
|
|
3
|
+
//
|
|
4
|
+
// task{} a to-do item, with a computed status
|
|
5
|
+
// started{at, by, via} somebody said they are on it
|
|
6
|
+
// blocked{on} something outside is in the way
|
|
7
|
+
// requires / contains the two relations between tasks
|
|
8
|
+
//
|
|
9
|
+
// What a task is filed under — `project`, `filed`, the `board` that is a saved
|
|
10
|
+
// filter over the filing — belongs to @yaks/project: a task with nothing filed
|
|
11
|
+
// is still a task, and a portfolio is a different idea from a to-do item.
|
|
12
|
+
//
|
|
13
|
+
// Four things are worth explaining about the shapes, because each is a decision
|
|
14
|
+
// somebody would otherwise make differently.
|
|
15
|
+
//
|
|
16
|
+
// Status is not stored. `task` declares it with the `status` keyword: a ladder
|
|
17
|
+
// over the `cancelled`, `completed` and `started` marks (`completed` and `cancelled` are
|
|
18
|
+
// @yaks/kernel's shared marks), which gives it a computed `task.status`
|
|
19
|
+
// that is readable and filterable, and that no writer sets. Finishing a task
|
|
20
|
+
// means writing a fact with a time and an author rather than overwriting a
|
|
21
|
+
// value. Both evaluators read the one declaration, so `.task.status=done` selects
|
|
22
|
+
// the same tasks in a database and in a page, and a package that adds a rung
|
|
23
|
+
// (@yaks/session's held `claim`, also `wip`) widens the set where it declares
|
|
24
|
+
// the rung. `started` is how a person says "I'm on it", having no claim to hold.
|
|
25
|
+
//
|
|
26
|
+
// The two relations are `requires` and `contains`, as @yaks/edge reads them: a
|
|
27
|
+
// component that an edge entity carries beside `edge{from, to}`. Neither has
|
|
28
|
+
// any properties — the link itself is the whole of what they mean.
|
|
29
|
+
//
|
|
30
|
+
// Blocked is A component, not A status. `blocked{on}` records that something
|
|
31
|
+
// outside the graph is in the way — waiting on a vendor, on a decision, on a
|
|
32
|
+
// person. It is deliberately not a rung on the status ladder: a blocked task is
|
|
33
|
+
// still open work, and rolling it into the status would hide it from every
|
|
34
|
+
// open-work query exactly when somebody needs to see it. Unfinished `requires`
|
|
35
|
+
// children are not blocking either; they are ordinary work, counted and shown,
|
|
36
|
+
// never an alarm.
|
|
37
|
+
//
|
|
38
|
+
// The marks outlive the people. `cancelled.by` is `death: keep`, as the
|
|
39
|
+
// kernel's `completed.by` is — deleting the person who finished a task does not
|
|
40
|
+
// unfinish it. The reference stands as history.
|
|
41
|
+
//
|
|
42
|
+
// The document itself is `./vocab.json` — plain JSON Schema, readable by
|
|
43
|
+
// anything that reads JSON. This file re-exports it under the name callers
|
|
44
|
+
// import, and keeps the prose about why it is shaped the way it is.
|
|
45
|
+
|
|
46
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
47
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
48
|
+
|
|
49
|
+
/** The component that makes an entity a task. */
|
|
50
|
+
export let TASK = 'task'
|
|
51
|
+
|
|
52
|
+
/** The mark on a task that was called off. */
|
|
53
|
+
export let CANCELLED = 'cancelled'
|
|
54
|
+
|
|
55
|
+
/** The component recording that something outside the graph is in the way. */
|
|
56
|
+
export let BLOCKED = 'blocked'
|
|
57
|
+
|
|
58
|
+
/** The relation from a task to work it waits for. */
|
|
59
|
+
export let REQUIRES = 'requires'
|
|
60
|
+
|
|
61
|
+
/** The relation from a task to work that is part of it. */
|
|
62
|
+
export let CONTAINS = 'contains'
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The task vocabulary, to load beside your own:
|
|
66
|
+
* `loadVocab([taskDoc, ...mine], [edgeKeywords, ...])`. It declares nothing
|
|
67
|
+
* about what a person or a document is — bring your own `doc` (or
|
|
68
|
+
* {@link https://jsr.io/@yaks/doc | @yaks/doc}'s), and whatever else your tasks
|
|
69
|
+
* carry.
|
|
70
|
+
*
|
|
71
|
+
* `requires` and `contains` are declared through
|
|
72
|
+
* {@link https://jsr.io/@yaks/edge | @yaks/edge}'s `edge` keyword, so an
|
|
73
|
+
* edge entity carrying one of them states that link. Register `edgeKeywords`
|
|
74
|
+
* when you load, or the loader will carry the declaration with nobody reading
|
|
75
|
+
* it.
|
|
76
|
+
*/
|
|
77
|
+
export let taskDoc: VocabDoc = doc
|
package/decision.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/** Questions and answers: pure values, checked at the graph's write boundary. */ import { after } from "@yaks/fp";
|
|
2
|
+
import { Refused } from "@yaks/graph/errors";
|
|
3
|
+
import { line } from "@yaks/query";
|
|
4
|
+
/** The query for a decision's `shows` edges. */ export let showing = (eid)=>line`.edge.from=${eid}&.shows`;
|
|
5
|
+
/** Each choice's shown entities, from the decision's `shows` edges. */ export let shown = (edges)=>{
|
|
6
|
+
let out = new Map();
|
|
7
|
+
let sorted = [
|
|
8
|
+
...edges
|
|
9
|
+
].sort((a, b)=>Number(a.edge?.ord ?? 0) - Number(b.edge?.ord ?? 0));
|
|
10
|
+
for (let b of sorted){
|
|
11
|
+
let choice = b.shows?.choice;
|
|
12
|
+
let to = b.edge?.to;
|
|
13
|
+
if (choice == null || to == null) continue;
|
|
14
|
+
out.set(String(choice), [
|
|
15
|
+
...out.get(String(choice)) ?? [],
|
|
16
|
+
String(to)
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
};
|
|
21
|
+
/** The `shows` edges a new decision writes, one for each choice that shows
|
|
22
|
+
* an entity, ordered as the choices are. */ export let shows = (from, choices)=>choices.flatMap((c, i)=>c.shows ? [
|
|
23
|
+
{
|
|
24
|
+
entity: {
|
|
25
|
+
eid: `$shows-${i}`
|
|
26
|
+
},
|
|
27
|
+
edge: {
|
|
28
|
+
from,
|
|
29
|
+
to: c.shows,
|
|
30
|
+
ord: i
|
|
31
|
+
},
|
|
32
|
+
shows: {
|
|
33
|
+
choice: c.label
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
] : []);
|
|
37
|
+
/** The query for the decisions waiting on `person`: assigned to them, and
|
|
38
|
+
* neither answered nor cancelled. */ export let waiting = (person)=>line`.decision .filed.assignee=${person} !decided !cancelled`;
|
|
39
|
+
/**
|
|
40
|
+
* The decisions in `rows` as one line each: its id (`id`, the eid where it
|
|
41
|
+
* gives none), its question and its choices' labels, the recommended one
|
|
42
|
+
* marked.
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { asked } from '@yaks/task'
|
|
46
|
+
* import { equal } from '@yaks/testing'
|
|
47
|
+
*
|
|
48
|
+
* let row = {
|
|
49
|
+
* entity: { eid: 'e1' },
|
|
50
|
+
* decision: {
|
|
51
|
+
* question: 'Which cover?',
|
|
52
|
+
* choices: [{ label: 'Gothic' }, { label: 'Plain' }],
|
|
53
|
+
* recommended: 'Plain',
|
|
54
|
+
* },
|
|
55
|
+
* }
|
|
56
|
+
* equal(asked([row], () => 'T-4'), '- T-4: Which cover? "Gothic", "Plain" (recommended)')
|
|
57
|
+
* equal(asked([]), '')
|
|
58
|
+
* ```
|
|
59
|
+
*/ export let asked = (rows, id = ()=>undefined)=>rows.map((b)=>{
|
|
60
|
+
let d = b.decision;
|
|
61
|
+
let labels = d.choices.map((c)=>JSON.stringify(c.label) + (c.label == d.recommended ? ' (recommended)' : ''));
|
|
62
|
+
return `- ${id(b.entity.eid) ?? b.entity.eid}: ${d.question} ${labels.join(', ')}`;
|
|
63
|
+
}).join('\n');
|
|
64
|
+
/** The answer a door writes, optionally recording another person's words. */ export let answer = (eid, choice, by)=>[
|
|
65
|
+
{
|
|
66
|
+
entity: {
|
|
67
|
+
eid
|
|
68
|
+
},
|
|
69
|
+
decided: {
|
|
70
|
+
choice
|
|
71
|
+
},
|
|
72
|
+
...by ? {
|
|
73
|
+
$decider: by
|
|
74
|
+
} : {}
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
/** A stale answer attempt can read the decision's settled state. */ export let DECISION_SETTLED = 'This decision is already answered or cancelled';
|
|
78
|
+
/** Refuses a decision that is not whole: a store composing only this
|
|
79
|
+
* package's vocabulary runs no {@link deciding}, so decision_new checks the
|
|
80
|
+
* ask it builds too. */ export let check = (b)=>{
|
|
81
|
+
let d = b.decision;
|
|
82
|
+
if (b.task == null) throw new Refused('A decision must be a task');
|
|
83
|
+
if (!d.question?.trim()) throw new Refused('A decision needs a question');
|
|
84
|
+
if (!Array.isArray(d.choices) || d.choices.length < 2 || d.choices.length > 4) {
|
|
85
|
+
throw new Refused('Offer two to four choices');
|
|
86
|
+
}
|
|
87
|
+
let labels = d.choices.map((c)=>c.label?.trim());
|
|
88
|
+
if (labels.some((l)=>!l) || new Set(labels).size != labels.length) {
|
|
89
|
+
throw new Refused('Choice labels must be nonempty and distinct');
|
|
90
|
+
}
|
|
91
|
+
if (d.choices.some((c)=>!c.description?.trim())) {
|
|
92
|
+
throw new Refused('Each choice needs a description');
|
|
93
|
+
}
|
|
94
|
+
if (!d.choices.some((c)=>c.label == d.recommended)) {
|
|
95
|
+
let labels = d.choices.map((c)=>JSON.stringify(c.label)).join(', ');
|
|
96
|
+
throw new Refused(`Recommend one of the choices by its label: ${labels}`, {
|
|
97
|
+
comp: 'decision',
|
|
98
|
+
prop: 'recommended'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (b.decided && !b.decided.choice?.toString().trim()) {
|
|
102
|
+
throw new Refused('Answer a decision with a choice');
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/** Validate the merged decision, including partial edits and direct graph writes. */ export let deciding = (bundles, tx)=>{
|
|
106
|
+
let touched = bundles.filter((b)=>'decision' in b || 'decided' in b || 'task' in b);
|
|
107
|
+
if (!touched.length) return bundles;
|
|
108
|
+
return after(tx.get(touched.map((b)=>b.entity.eid)), (rows)=>{
|
|
109
|
+
let held = new Map(rows.map((b)=>[
|
|
110
|
+
b.entity.eid,
|
|
111
|
+
b
|
|
112
|
+
]));
|
|
113
|
+
let normalized = new Map();
|
|
114
|
+
for (let b of touched){
|
|
115
|
+
let old = held.get(b.entity.eid);
|
|
116
|
+
let next = {
|
|
117
|
+
...old,
|
|
118
|
+
...b
|
|
119
|
+
};
|
|
120
|
+
if (b.decision && old?.decision) {
|
|
121
|
+
next.decision = {
|
|
122
|
+
...old.decision,
|
|
123
|
+
...b.decision
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (!next.decision) {
|
|
127
|
+
if (b.decided?.choice != null) {
|
|
128
|
+
throw new Refused('Only a decision can be answered with a choice');
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (b.decided != null && (old?.decided || next.cancelled)) {
|
|
133
|
+
throw new Refused(DECISION_SETTLED, {
|
|
134
|
+
eid: b.entity.eid,
|
|
135
|
+
comp: 'decided',
|
|
136
|
+
prop: 'choice'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
check(next);
|
|
140
|
+
let choice = b.decided?.choice;
|
|
141
|
+
if (typeof choice == 'string' && choice != choice.trim()) {
|
|
142
|
+
next.decided = {
|
|
143
|
+
...b.decided,
|
|
144
|
+
choice: choice.trim()
|
|
145
|
+
};
|
|
146
|
+
normalized.set(b, {
|
|
147
|
+
...b,
|
|
148
|
+
decided: next.decided
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
held.set(b.entity.eid, next);
|
|
152
|
+
}
|
|
153
|
+
return bundles.map((b)=>normalized.get(b) ?? b);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=decision.js.map
|
package/decision.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,KAAK,QAAQ,EAAE;QAClB,IAAI,AAAC,EAAE,OAAO,EAAW,UAAU,MAAM;UACvC,MAAM,IAAI,QAAQ;QACpB;QACA;MACF;MACA,IAAI,EAAE,OAAO,IAAI,QAAQ,CAAC,KAAK,WAAW,KAAK,SAAS,GAAG;QACzD,MAAM,IAAI,QAAQ,kBAAkB;UAClC,KAAK,EAAE,MAAM,CAAC,GAAG;UACjB,MAAM;UACN,MAAM;QACR;MACF;MACA,MAAM;MACN,IAAI,SAAU,EAAE,OAAO,EAAuB;MAC9C,IAAI,OAAO,UAAU,YAAY,UAAU,OAAO,IAAI,IAAI;QACxD,KAAK,OAAO,GAAG;UAAE,GAAG,EAAE,OAAO;UAAU,QAAQ,OAAO,IAAI;QAAG;QAC7D,WAAW,GAAG,CAAC,GAAG;UAAE,GAAG,CAAC;UAAE,SAAS,KAAK,OAAO;QAAC;MAClD;MACA,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE;IACzB;IACA,OAAO,QAAQ,GAAG,CAAC,CAAC,IAAM,WAAW,GAAG,CAAC,MAAM;EACjD;AACF,EAAC"}
|
package/decision.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/** Questions and answers: pure values, checked at the graph's write boundary. */
|
|
2
|
+
import { after } from '@yaks/fp'
|
|
3
|
+
import type { Bundle, Comp, Hook } from 'jsr:@yaks/graph@0.2.36'
|
|
4
|
+
import { Refused } from '@yaks/graph/errors'
|
|
5
|
+
import { type Built, line } from '@yaks/query'
|
|
6
|
+
|
|
7
|
+
/** A label and a line saying what choosing it means. */
|
|
8
|
+
export type Choice = { label: string; description: string }
|
|
9
|
+
/** The ask, read whole by every door. */
|
|
10
|
+
export type Decision = {
|
|
11
|
+
question: string
|
|
12
|
+
choices: Choice[]
|
|
13
|
+
recommended: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** What each choice presents, by label, in the order the decision shows them:
|
|
17
|
+
* read from its `shows` edges (`edge{from, to, ord}` + `shows{choice}`). */
|
|
18
|
+
export type Shown = Map<string, string[]>
|
|
19
|
+
|
|
20
|
+
/** The query for a decision's `shows` edges. */
|
|
21
|
+
export let showing = (eid: string): Built => line`.edge.from=${eid}&.shows`
|
|
22
|
+
|
|
23
|
+
/** Each choice's shown entities, from the decision's `shows` edges. */
|
|
24
|
+
export let shown = (edges: Bundle[]): Shown => {
|
|
25
|
+
let out: Shown = new Map()
|
|
26
|
+
let sorted = [...edges].sort((a, b) =>
|
|
27
|
+
Number((a.edge as Comp)?.ord ?? 0) - Number((b.edge as Comp)?.ord ?? 0)
|
|
28
|
+
)
|
|
29
|
+
for (let b of sorted) {
|
|
30
|
+
let choice = (b.shows as Comp | undefined)?.choice
|
|
31
|
+
let to = (b.edge as Comp | undefined)?.to
|
|
32
|
+
if (choice == null || to == null) continue
|
|
33
|
+
out.set(String(choice), [...out.get(String(choice)) ?? [], String(to)])
|
|
34
|
+
}
|
|
35
|
+
return out
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The `shows` edges a new decision writes, one for each choice that shows
|
|
39
|
+
* an entity, ordered as the choices are. */
|
|
40
|
+
export let shows = (
|
|
41
|
+
from: string,
|
|
42
|
+
choices: (Choice & { shows?: string })[],
|
|
43
|
+
): Bundle[] =>
|
|
44
|
+
choices.flatMap((c, i) =>
|
|
45
|
+
c.shows
|
|
46
|
+
? [{
|
|
47
|
+
entity: { eid: `$shows-${i}` },
|
|
48
|
+
edge: { from, to: c.shows, ord: i },
|
|
49
|
+
shows: { choice: c.label },
|
|
50
|
+
}]
|
|
51
|
+
: []
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
/** The query for the decisions waiting on `person`: assigned to them, and
|
|
55
|
+
* neither answered nor cancelled. */
|
|
56
|
+
export let waiting = (person: string): Built =>
|
|
57
|
+
line`.decision .filed.assignee=${person} !decided !cancelled`
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The decisions in `rows` as one line each: its id (`id`, the eid where it
|
|
61
|
+
* gives none), its question and its choices' labels, the recommended one
|
|
62
|
+
* marked.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { asked } from '@yaks/task'
|
|
66
|
+
* import { equal } from '@yaks/testing'
|
|
67
|
+
*
|
|
68
|
+
* let row = {
|
|
69
|
+
* entity: { eid: 'e1' },
|
|
70
|
+
* decision: {
|
|
71
|
+
* question: 'Which cover?',
|
|
72
|
+
* choices: [{ label: 'Gothic' }, { label: 'Plain' }],
|
|
73
|
+
* recommended: 'Plain',
|
|
74
|
+
* },
|
|
75
|
+
* }
|
|
76
|
+
* equal(asked([row], () => 'T-4'), '- T-4: Which cover? "Gothic", "Plain" (recommended)')
|
|
77
|
+
* equal(asked([]), '')
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export let asked = (
|
|
81
|
+
rows: Bundle[],
|
|
82
|
+
id: (eid: string) => string | undefined = () => undefined,
|
|
83
|
+
): string =>
|
|
84
|
+
rows.map((b) => {
|
|
85
|
+
let d = b.decision as Decision
|
|
86
|
+
let labels = d.choices.map((c) =>
|
|
87
|
+
JSON.stringify(c.label) +
|
|
88
|
+
(c.label == d.recommended ? ' (recommended)' : '')
|
|
89
|
+
)
|
|
90
|
+
return `- ${id(b.entity.eid) ?? b.entity.eid}: ${d.question} ${
|
|
91
|
+
labels.join(', ')
|
|
92
|
+
}`
|
|
93
|
+
}).join('\n')
|
|
94
|
+
|
|
95
|
+
/** The answer a door writes, optionally recording another person's words. */
|
|
96
|
+
export let answer = (eid: string, choice: string, by?: string): Bundle[] => [{
|
|
97
|
+
entity: { eid },
|
|
98
|
+
decided: { choice },
|
|
99
|
+
...(by ? { $decider: by } : {}),
|
|
100
|
+
}]
|
|
101
|
+
|
|
102
|
+
/** A stale answer attempt can read the decision's settled state. */
|
|
103
|
+
export let DECISION_SETTLED = 'This decision is already answered or cancelled'
|
|
104
|
+
|
|
105
|
+
/** Refuses a decision that is not whole: a store composing only this
|
|
106
|
+
* package's vocabulary runs no {@link deciding}, so decision_new checks the
|
|
107
|
+
* ask it builds too. */
|
|
108
|
+
export let check = (b: Bundle): void => {
|
|
109
|
+
let d = b.decision as Decision
|
|
110
|
+
if (b.task == null) throw new Refused('A decision must be a task')
|
|
111
|
+
if (!d.question?.trim()) throw new Refused('A decision needs a question')
|
|
112
|
+
if (
|
|
113
|
+
!Array.isArray(d.choices) || d.choices.length < 2 || d.choices.length > 4
|
|
114
|
+
) {
|
|
115
|
+
throw new Refused('Offer two to four choices')
|
|
116
|
+
}
|
|
117
|
+
let labels = d.choices.map((c) => c.label?.trim())
|
|
118
|
+
if (labels.some((l) => !l) || new Set(labels).size != labels.length) {
|
|
119
|
+
throw new Refused('Choice labels must be nonempty and distinct')
|
|
120
|
+
}
|
|
121
|
+
if (d.choices.some((c) => !c.description?.trim())) {
|
|
122
|
+
throw new Refused('Each choice needs a description')
|
|
123
|
+
}
|
|
124
|
+
if (!d.choices.some((c) => c.label == d.recommended)) {
|
|
125
|
+
let labels = d.choices.map((c) => JSON.stringify(c.label)).join(', ')
|
|
126
|
+
throw new Refused(`Recommend one of the choices by its label: ${labels}`, {
|
|
127
|
+
comp: 'decision',
|
|
128
|
+
prop: 'recommended',
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
if (b.decided && !(b.decided as Comp).choice?.toString().trim()) {
|
|
132
|
+
throw new Refused('Answer a decision with a choice')
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Validate the merged decision, including partial edits and direct graph writes. */
|
|
137
|
+
export let deciding: Hook = (bundles, tx) => {
|
|
138
|
+
let touched = bundles.filter((b) =>
|
|
139
|
+
'decision' in b || 'decided' in b || 'task' in b
|
|
140
|
+
)
|
|
141
|
+
if (!touched.length) return bundles
|
|
142
|
+
return after(tx.get(touched.map((b) => b.entity.eid)), (rows) => {
|
|
143
|
+
let held = new Map(rows.map((b) => [b.entity.eid, b]))
|
|
144
|
+
let normalized = new Map<Bundle, Bundle>()
|
|
145
|
+
for (let b of touched) {
|
|
146
|
+
let old = held.get(b.entity.eid)
|
|
147
|
+
let next = { ...old, ...b }
|
|
148
|
+
if (b.decision && old?.decision) {
|
|
149
|
+
next.decision = { ...old.decision as Comp, ...b.decision as Comp }
|
|
150
|
+
}
|
|
151
|
+
if (!next.decision) {
|
|
152
|
+
if ((b.decided as Comp)?.choice != null) {
|
|
153
|
+
throw new Refused('Only a decision can be answered with a choice')
|
|
154
|
+
}
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
if (b.decided != null && (old?.decided || next.cancelled)) {
|
|
158
|
+
throw new Refused(DECISION_SETTLED, {
|
|
159
|
+
eid: b.entity.eid,
|
|
160
|
+
comp: 'decided',
|
|
161
|
+
prop: 'choice',
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
check(next)
|
|
165
|
+
let choice = (b.decided as Comp | undefined)?.choice
|
|
166
|
+
if (typeof choice == 'string' && choice != choice.trim()) {
|
|
167
|
+
next.decided = { ...b.decided as Comp, choice: choice.trim() }
|
|
168
|
+
normalized.set(b, { ...b, decided: next.decided })
|
|
169
|
+
}
|
|
170
|
+
held.set(b.entity.eid, next)
|
|
171
|
+
}
|
|
172
|
+
return bundles.map((b) => normalized.get(b) ?? b)
|
|
173
|
+
})
|
|
174
|
+
}
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts","./testing.ts"]},"name":"@yaks/task","version":"0.2.36","license":"Apache-2.0","description":"Task components for a graph: a status computed from marks instead of stored, dependency counts, and completion attribution.","exports":{".":"./mod.ts","./vocab":"./vocab.ts","./graph":"./graph.ts","./tools":"./tools.ts","./text":"./text.ts","./form":"./DecisionForm.ts","./views":"./views.ts"},"imports":{"@yaks/task":"./mod.ts","@yaks/task/vocab":"./vocab.ts","@yaks/task/graph":"./graph.ts","@yaks/task/tools":"./tools.ts","@yaks/task/text":"./text.ts","@yaks/task/form":"./DecisionForm.ts","@yaks/task/views":"./views.ts"}}
|