@yaks/tools 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.
Files changed (138) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +870 -2
  3. package/_dist/access.d.ts +3 -0
  4. package/_dist/access.d.ts.map +1 -0
  5. package/_dist/app-view.d.ts +27 -0
  6. package/_dist/app-view.d.ts.map +1 -0
  7. package/_dist/args.d.ts +23 -0
  8. package/_dist/args.d.ts.map +1 -0
  9. package/_dist/check.d.ts +32 -0
  10. package/_dist/check.d.ts.map +1 -0
  11. package/_dist/declared.d.ts +66 -0
  12. package/_dist/declared.d.ts.map +1 -0
  13. package/_dist/display.d.ts +2 -0
  14. package/_dist/display.d.ts.map +1 -0
  15. package/_dist/errors.d.ts +46 -0
  16. package/_dist/errors.d.ts.map +1 -0
  17. package/_dist/fault.d.ts +4 -0
  18. package/_dist/fault.d.ts.map +1 -0
  19. package/_dist/invoke.d.ts +13 -0
  20. package/_dist/invoke.d.ts.map +1 -0
  21. package/_dist/mod.d.ts +31 -0
  22. package/_dist/mod.d.ts.map +1 -0
  23. package/_dist/outlast.d.ts +89 -0
  24. package/_dist/outlast.d.ts.map +1 -0
  25. package/_dist/persist.d.ts +5 -0
  26. package/_dist/persist.d.ts.map +1 -0
  27. package/_dist/read.d.ts +4 -0
  28. package/_dist/read.d.ts.map +1 -0
  29. package/_dist/readable.d.ts +59 -0
  30. package/_dist/readable.d.ts.map +1 -0
  31. package/_dist/registry.d.ts +53 -0
  32. package/_dist/registry.d.ts.map +1 -0
  33. package/_dist/result.d.ts +154 -0
  34. package/_dist/result.d.ts.map +1 -0
  35. package/_dist/routes.d.ts +11 -0
  36. package/_dist/routes.d.ts.map +1 -0
  37. package/_dist/runner.d.ts +161 -0
  38. package/_dist/runner.d.ts.map +1 -0
  39. package/_dist/said.d.ts +4 -0
  40. package/_dist/said.d.ts.map +1 -0
  41. package/_dist/schema.d.ts +76 -0
  42. package/_dist/schema.d.ts.map +1 -0
  43. package/_dist/state.d.ts +9 -0
  44. package/_dist/state.d.ts.map +1 -0
  45. package/_dist/title.d.ts +20 -0
  46. package/_dist/title.d.ts.map +1 -0
  47. package/_dist/value.d.ts +43 -0
  48. package/_dist/value.d.ts.map +1 -0
  49. package/_dist/views.d.ts +5 -0
  50. package/_dist/views.d.ts.map +1 -0
  51. package/_dist/vocab.d.ts +9 -0
  52. package/_dist/vocab.d.ts.map +1 -0
  53. package/_dist/watch.d.ts +28 -0
  54. package/_dist/watch.d.ts.map +1 -0
  55. package/access.js +3 -0
  56. package/access.js.map +1 -0
  57. package/access.ts +11 -0
  58. package/app-view.js +26 -0
  59. package/app-view.js.map +1 -0
  60. package/app-view.ts +41 -0
  61. package/args.js +136 -0
  62. package/args.js.map +1 -0
  63. package/args.ts +187 -0
  64. package/body.js +14 -0
  65. package/body.js.map +1 -0
  66. package/body.ts +15 -0
  67. package/check.js +67 -0
  68. package/check.js.map +1 -0
  69. package/check.ts +92 -0
  70. package/declared.js +529 -0
  71. package/declared.js.map +1 -0
  72. package/declared.ts +719 -0
  73. package/deno.json +1 -0
  74. package/display.js +21 -0
  75. package/display.js.map +1 -0
  76. package/display.ts +39 -0
  77. package/errors.js +99 -0
  78. package/errors.js.map +1 -0
  79. package/errors.ts +127 -0
  80. package/fault.js +17 -0
  81. package/fault.js.map +1 -0
  82. package/fault.ts +24 -0
  83. package/invoke.js +207 -0
  84. package/invoke.js.map +1 -0
  85. package/invoke.ts +210 -0
  86. package/mod.js +31 -0
  87. package/mod.js.map +1 -0
  88. package/mod.ts +78 -0
  89. package/outlast.js +416 -0
  90. package/outlast.js.map +1 -0
  91. package/outlast.ts +551 -0
  92. package/package.json +109 -4
  93. package/persist.js +18 -0
  94. package/persist.js.map +1 -0
  95. package/persist.ts +26 -0
  96. package/read.js +50 -0
  97. package/read.js.map +1 -0
  98. package/read.ts +58 -0
  99. package/readable.js +118 -0
  100. package/readable.js.map +1 -0
  101. package/readable.ts +134 -0
  102. package/registry.js +162 -0
  103. package/registry.js.map +1 -0
  104. package/registry.ts +207 -0
  105. package/result.js +497 -0
  106. package/result.js.map +1 -0
  107. package/result.ts +540 -0
  108. package/routes.js +46 -0
  109. package/routes.js.map +1 -0
  110. package/routes.ts +50 -0
  111. package/runner.js +748 -0
  112. package/runner.js.map +1 -0
  113. package/runner.ts +910 -0
  114. package/said.js +15 -0
  115. package/said.js.map +1 -0
  116. package/said.ts +12 -0
  117. package/schema.js +137 -0
  118. package/schema.js.map +1 -0
  119. package/schema.ts +134 -0
  120. package/state.js +69 -0
  121. package/state.js.map +1 -0
  122. package/state.ts +108 -0
  123. package/title.js +222 -0
  124. package/title.js.map +1 -0
  125. package/title.ts +257 -0
  126. package/value.js +57 -0
  127. package/value.js.map +1 -0
  128. package/value.ts +74 -0
  129. package/views.js +131 -0
  130. package/views.js.map +1 -0
  131. package/views.ts +125 -0
  132. package/vocab.js +22 -0
  133. package/vocab.js.map +1 -0
  134. package/vocab.json +268 -0
  135. package/vocab.ts +22 -0
  136. package/watch.js +64 -0
  137. package/watch.js.map +1 -0
  138. package/watch.ts +74 -0
package/title.js ADDED
@@ -0,0 +1,222 @@
1
+ // What a person reads in place of a tool's name. A tool's `title` is an
2
+ // imperative phrase ("Read or write app files"); a tool without one is its
3
+ // name in words ("graph_schema" is "Graph schema").
4
+ //
5
+ // A call reads from the person's side, as what is being done for them: its
6
+ // tool's `step` holds the two strings, the way a locale file holds them, one
7
+ // while it runs ("Texting %{person}…") and one once it answered ("Texted
8
+ // %{person}"). Each `%{name}` is filled in from the call's arguments and from
9
+ // what the view knows (the person it works for). A tool whose arguments choose
10
+ // what it does keeps a step for each under `by`: by argument, then by that
11
+ // argument's value ('' when left out). The first step whose names all fill in
12
+ // is the one said; with none, the title is said in the tense of the call, and
13
+ // a tool that says nothing of itself is "Use a tool".
14
+ /** How a call reads: while it runs, and once it answered. */ /** A tool's English name: its title, or its name in words. */ export let titleOf = (t)=>t.title?.trim() || (t.name ?? '').replace(/[_-]+/g, ' ').trim().replace(/^./, (c)=>c.toUpperCase());
15
+ // A step's words with each `%{name}` filled in, or null when a name has
16
+ // nothing to fill it.
17
+ let filled = (text, values)=>{
18
+ let missing = false;
19
+ let out = text.replace(/%\{(\w+)\}/g, (_, name)=>{
20
+ let v = values[name];
21
+ let said = typeof v == 'string' || typeof v == 'number' ? String(v).trim() : '';
22
+ if (!said) missing = true;
23
+ return said.length > 60 ? said.slice(0, 60) + '…' : said;
24
+ });
25
+ return missing ? null : out;
26
+ };
27
+ /** How one call reads to the person: the step its arguments chose, its
28
+ * tool's step, or its title in the tense of the call. */ export let stepOf = (t, args, known = {})=>{
29
+ let values = {
30
+ ...args,
31
+ ...known
32
+ };
33
+ let chosen = Object.entries(t.step?.by ?? {}).map(([arg, by])=>by[args?.[arg] == null ? '' : String(args[arg])]);
34
+ for (let s of [
35
+ ...chosen,
36
+ t.step
37
+ ]){
38
+ if (!s) continue;
39
+ let [running, answered] = [
40
+ filled(s.doing, values),
41
+ filled(s.done, values)
42
+ ];
43
+ if (running?.trim() && answered?.trim()) {
44
+ return {
45
+ doing: running,
46
+ done: answered
47
+ };
48
+ }
49
+ }
50
+ let title = titleOf(t) || 'Use a tool';
51
+ return {
52
+ doing: doing(title),
53
+ done: did(title)
54
+ };
55
+ };
56
+ // The past tense of the verbs whose past is not their base plus -ed.
57
+ let PAST = {
58
+ begin: 'began',
59
+ bring: 'brought',
60
+ build: 'built',
61
+ buy: 'bought',
62
+ choose: 'chose',
63
+ cut: 'cut',
64
+ do: 'did',
65
+ draw: 'drew',
66
+ find: 'found',
67
+ get: 'got',
68
+ give: 'gave',
69
+ hold: 'held',
70
+ keep: 'kept',
71
+ know: 'knew',
72
+ leave: 'left',
73
+ lend: 'lent',
74
+ let: 'let',
75
+ make: 'made',
76
+ pay: 'paid',
77
+ put: 'put',
78
+ read: 'read',
79
+ run: 'ran',
80
+ say: 'said',
81
+ see: 'saw',
82
+ sell: 'sold',
83
+ send: 'sent',
84
+ set: 'set',
85
+ spend: 'spent',
86
+ take: 'took',
87
+ tell: 'told',
88
+ think: 'thought',
89
+ write: 'wrote'
90
+ };
91
+ // The verbs that double their last letter before -ing and -ed.
92
+ let DOUBLE = new Set([
93
+ 'cut',
94
+ 'drop',
95
+ 'get',
96
+ 'let',
97
+ 'log',
98
+ 'plan',
99
+ 'put',
100
+ 'run',
101
+ 'set',
102
+ 'ship',
103
+ 'stop',
104
+ 'swap',
105
+ 'tag'
106
+ ]);
107
+ // The verbs a title may begin with. A title beginning with any other word is
108
+ // said as it is.
109
+ let VERBS = new Set([
110
+ ...Object.keys(PAST),
111
+ ...DOUBLE,
112
+ 'add',
113
+ 'answer',
114
+ 'apply',
115
+ 'archive',
116
+ 'arm',
117
+ 'ask',
118
+ 'attach',
119
+ 'call',
120
+ 'cancel',
121
+ 'change',
122
+ 'check',
123
+ 'claim',
124
+ 'close',
125
+ 'compact',
126
+ 'complete',
127
+ 'connect',
128
+ 'copy',
129
+ 'count',
130
+ 'create',
131
+ 'decide',
132
+ 'delete',
133
+ 'deploy',
134
+ 'describe',
135
+ 'detach',
136
+ 'download',
137
+ 'edit',
138
+ 'erase',
139
+ 'explain',
140
+ 'export',
141
+ 'fetch',
142
+ 'file',
143
+ 'fix',
144
+ 'grant',
145
+ 'import',
146
+ 'inspect',
147
+ 'install',
148
+ 'invite',
149
+ 'land',
150
+ 'link',
151
+ 'list',
152
+ 'load',
153
+ 'look',
154
+ 'mark',
155
+ 'merge',
156
+ 'move',
157
+ 'mute',
158
+ 'name',
159
+ 'note',
160
+ 'open',
161
+ 'peek',
162
+ 'post',
163
+ 'preview',
164
+ 'publish',
165
+ 'query',
166
+ 'recall',
167
+ 'record',
168
+ 'release',
169
+ 'remove',
170
+ 'rename',
171
+ 'reopen',
172
+ 'reply',
173
+ 'report',
174
+ 'reshare',
175
+ 'resolve',
176
+ 'restart',
177
+ 'restore',
178
+ 'retry',
179
+ 'revert',
180
+ 'review',
181
+ 'roll',
182
+ 'save',
183
+ 'search',
184
+ 'show',
185
+ 'sign',
186
+ 'start',
187
+ 'supply',
188
+ 'sync',
189
+ 'unarchive',
190
+ 'unpublish',
191
+ 'update',
192
+ 'upload',
193
+ 'use',
194
+ 'visualize',
195
+ 'wait',
196
+ 'watch',
197
+ 'wrap'
198
+ ]);
199
+ let stem = (verb)=>DOUBLE.has(verb) ? verb + verb.at(-1) : verb;
200
+ let ing = (verb)=>verb.endsWith('ie') ? verb.slice(0, -2) + 'ying' : verb.endsWith('e') && !verb.endsWith('ee') ? verb.slice(0, -1) + 'ing' : stem(verb) + 'ing';
201
+ let ed = (verb)=>PAST[verb] ?? (verb.endsWith('e') ? verb + 'd' : /[^aeiou]y$/.test(verb) ? verb.slice(0, -1) + 'ied' : stem(verb) + 'ed');
202
+ // The title with each of its leading verbs ("Read or write", "Rename, move or
203
+ // reshare") put in a tense; null when it does not begin with a verb.
204
+ let tensed = (title, tense)=>{
205
+ let words = title.split(' ');
206
+ let i = 0;
207
+ while(i < words.length){
208
+ let [, word, comma] = /^(.*?)(,?)$/.exec(words[i]);
209
+ let verb = word.toLowerCase();
210
+ if (!VERBS.has(verb)) break;
211
+ let said = tense(verb);
212
+ words[i] = (word[0] == verb[0] ? said : said[0].toUpperCase() + said.slice(1)) + comma;
213
+ i++;
214
+ if (comma) continue;
215
+ if (words[i] == 'or' || words[i] == 'and') i++;
216
+ else break;
217
+ }
218
+ return i ? words.join(' ') : null;
219
+ };
220
+ /** The call while it runs: "Listing app versions…". */ export let doing = (title)=>(tensed(title, ing) ?? title) + '…';
221
+ /** The call once it answered: "Listed app versions". */ export let did = (title)=>tensed(title, ed) ?? title;
222
+ //# sourceMappingURL=title.js.map
package/title.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"title.js","sources":["./title.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,2EAA2E;AAC3E,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,yEAAyE;AACzE,8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MACvC,OAAO;QAAE,OAAO;QAAS,MAAM;MAAS;IAC1C;EACF;EACA,IAAI,QAAQ,QAAQ,MAAM;EAC1B,OAAO;IAAE,OAAO,MAAM;IAAQ,MAAM,IAAI;EAAO;AACjD,EAAC;AAED,qEAAqE;AACrE,IAAI,OAA+B;EACjC,OAAO;EACP,OAAO;EACP,OAAO;EACP,KAAK;EACL,QAAQ;EACR,KAAK;EACL,IAAI;EACJ,MAAM;EACN,MAAM;EACN,KAAK;EACL,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,OAAO;EACP,MAAM;EACN,KAAK;EACL,MAAM;EACN,KAAK;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,KAAK;EACL,KAAK;EACL,MAAM;EACN,MAAM;EACN,KAAK;EACL,OAAO;EACP,MAAM;EACN,MAAM;EACN,OAAO;EACP,OAAO;AACT;AAEA,+DAA+D;AAC/D,IAAI,SAAS,IAAI,IAAI;EACnB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AAED,6EAA6E;AAC7E,iBAAiB;AACjB,IAAI,QAAQ,IAAI,IAAI;KACf,OAAO,IAAI,CAAC;KACZ;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AAED,IAAI,OAAO,CAAC,OAAiB,OAAO,GAAG,CAAC,QAAQ,OAAO,KAAK,E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0,0 +1,257 @@
1
+ // What a person reads in place of a tool's name. A tool's `title` is an
2
+ // imperative phrase ("Read or write app files"); a tool without one is its
3
+ // name in words ("graph_schema" is "Graph schema").
4
+ //
5
+ // A call reads from the person's side, as what is being done for them: its
6
+ // tool's `step` holds the two strings, the way a locale file holds them, one
7
+ // while it runs ("Texting %{person}…") and one once it answered ("Texted
8
+ // %{person}"). Each `%{name}` is filled in from the call's arguments and from
9
+ // what the view knows (the person it works for). A tool whose arguments choose
10
+ // what it does keeps a step for each under `by`: by argument, then by that
11
+ // argument's value ('' when left out). The first step whose names all fill in
12
+ // is the one said; with none, the title is said in the tense of the call, and
13
+ // a tool that says nothing of itself is "Use a tool".
14
+
15
+ /** How a call reads: while it runs, and once it answered. */
16
+ export type Step = { doing: string; done: string }
17
+
18
+ /** A tool's step, and under `by` the step of each thing its arguments choose. */
19
+ export type Steps = Step & { by?: Record<string, Record<string, Step>> }
20
+
21
+ /** A tool's English name: its title, or its name in words. */
22
+ export let titleOf = (
23
+ t: { name?: string | null; title?: string | null },
24
+ ): string =>
25
+ t.title?.trim() ||
26
+ (t.name ?? '').replace(/[_-]+/g, ' ').trim().replace(
27
+ /^./,
28
+ (c) => c.toUpperCase(),
29
+ )
30
+
31
+ // A step's words with each `%{name}` filled in, or null when a name has
32
+ // nothing to fill it.
33
+ let filled = (text: string, values: Record<string, unknown>) => {
34
+ let missing = false
35
+ let out = text.replace(/%\{(\w+)\}/g, (_, name: string) => {
36
+ let v = values[name]
37
+ let said = typeof v == 'string' || typeof v == 'number'
38
+ ? String(v).trim()
39
+ : ''
40
+ if (!said) missing = true
41
+ return said.length > 60 ? said.slice(0, 60) + '…' : said
42
+ })
43
+ return missing ? null : out
44
+ }
45
+
46
+ /** How one call reads to the person: the step its arguments chose, its
47
+ * tool's step, or its title in the tense of the call. */
48
+ export let stepOf = (
49
+ t: { name?: string | null; title?: string | null; step?: Steps | null },
50
+ args?: Record<string, unknown> | null,
51
+ known: Record<string, string> = {},
52
+ ): Step => {
53
+ let values = { ...args, ...known }
54
+ let chosen = Object.entries(t.step?.by ?? {}).map(([arg, by]) =>
55
+ by[args?.[arg] == null ? '' : String(args[arg])]
56
+ )
57
+ for (let s of [...chosen, t.step]) {
58
+ if (!s) continue
59
+ let [running, answered] = [filled(s.doing, values), filled(s.done, values)]
60
+ if (running?.trim() && answered?.trim()) {
61
+ return { doing: running, done: answered }
62
+ }
63
+ }
64
+ let title = titleOf(t) || 'Use a tool'
65
+ return { doing: doing(title), done: did(title) }
66
+ }
67
+
68
+ // The past tense of the verbs whose past is not their base plus -ed.
69
+ let PAST: Record<string, string> = {
70
+ begin: 'began',
71
+ bring: 'brought',
72
+ build: 'built',
73
+ buy: 'bought',
74
+ choose: 'chose',
75
+ cut: 'cut',
76
+ do: 'did',
77
+ draw: 'drew',
78
+ find: 'found',
79
+ get: 'got',
80
+ give: 'gave',
81
+ hold: 'held',
82
+ keep: 'kept',
83
+ know: 'knew',
84
+ leave: 'left',
85
+ lend: 'lent',
86
+ let: 'let',
87
+ make: 'made',
88
+ pay: 'paid',
89
+ put: 'put',
90
+ read: 'read',
91
+ run: 'ran',
92
+ say: 'said',
93
+ see: 'saw',
94
+ sell: 'sold',
95
+ send: 'sent',
96
+ set: 'set',
97
+ spend: 'spent',
98
+ take: 'took',
99
+ tell: 'told',
100
+ think: 'thought',
101
+ write: 'wrote',
102
+ }
103
+
104
+ // The verbs that double their last letter before -ing and -ed.
105
+ let DOUBLE = new Set([
106
+ 'cut',
107
+ 'drop',
108
+ 'get',
109
+ 'let',
110
+ 'log',
111
+ 'plan',
112
+ 'put',
113
+ 'run',
114
+ 'set',
115
+ 'ship',
116
+ 'stop',
117
+ 'swap',
118
+ 'tag',
119
+ ])
120
+
121
+ // The verbs a title may begin with. A title beginning with any other word is
122
+ // said as it is.
123
+ let VERBS = new Set([
124
+ ...Object.keys(PAST),
125
+ ...DOUBLE,
126
+ 'add',
127
+ 'answer',
128
+ 'apply',
129
+ 'archive',
130
+ 'arm',
131
+ 'ask',
132
+ 'attach',
133
+ 'call',
134
+ 'cancel',
135
+ 'change',
136
+ 'check',
137
+ 'claim',
138
+ 'close',
139
+ 'compact',
140
+ 'complete',
141
+ 'connect',
142
+ 'copy',
143
+ 'count',
144
+ 'create',
145
+ 'decide',
146
+ 'delete',
147
+ 'deploy',
148
+ 'describe',
149
+ 'detach',
150
+ 'download',
151
+ 'edit',
152
+ 'erase',
153
+ 'explain',
154
+ 'export',
155
+ 'fetch',
156
+ 'file',
157
+ 'fix',
158
+ 'grant',
159
+ 'import',
160
+ 'inspect',
161
+ 'install',
162
+ 'invite',
163
+ 'land',
164
+ 'link',
165
+ 'list',
166
+ 'load',
167
+ 'look',
168
+ 'mark',
169
+ 'merge',
170
+ 'move',
171
+ 'mute',
172
+ 'name',
173
+ 'note',
174
+ 'open',
175
+ 'peek',
176
+ 'post',
177
+ 'preview',
178
+ 'publish',
179
+ 'query',
180
+ 'recall',
181
+ 'record',
182
+ 'release',
183
+ 'remove',
184
+ 'rename',
185
+ 'reopen',
186
+ 'reply',
187
+ 'report',
188
+ 'reshare',
189
+ 'resolve',
190
+ 'restart',
191
+ 'restore',
192
+ 'retry',
193
+ 'revert',
194
+ 'review',
195
+ 'roll',
196
+ 'save',
197
+ 'search',
198
+ 'show',
199
+ 'sign',
200
+ 'start',
201
+ 'supply',
202
+ 'sync',
203
+ 'unarchive',
204
+ 'unpublish',
205
+ 'update',
206
+ 'upload',
207
+ 'use',
208
+ 'visualize',
209
+ 'wait',
210
+ 'watch',
211
+ 'wrap',
212
+ ])
213
+
214
+ let stem = (verb: string) => DOUBLE.has(verb) ? verb + verb.at(-1) : verb
215
+
216
+ let ing = (verb: string) =>
217
+ verb.endsWith('ie')
218
+ ? verb.slice(0, -2) + 'ying'
219
+ : verb.endsWith('e') && !verb.endsWith('ee')
220
+ ? verb.slice(0, -1) + 'ing'
221
+ : stem(verb) + 'ing'
222
+
223
+ let ed = (verb: string) =>
224
+ PAST[verb] ??
225
+ (verb.endsWith('e')
226
+ ? verb + 'd'
227
+ : /[^aeiou]y$/.test(verb)
228
+ ? verb.slice(0, -1) + 'ied'
229
+ : stem(verb) + 'ed')
230
+
231
+ // The title with each of its leading verbs ("Read or write", "Rename, move or
232
+ // reshare") put in a tense; null when it does not begin with a verb.
233
+ let tensed = (title: string, tense: (verb: string) => string) => {
234
+ let words = title.split(' ')
235
+ let i = 0
236
+ while (i < words.length) {
237
+ let [, word, comma] = /^(.*?)(,?)$/.exec(words[i])!
238
+ let verb = word.toLowerCase()
239
+ if (!VERBS.has(verb)) break
240
+ let said = tense(verb)
241
+ words[i] =
242
+ (word[0] == verb[0] ? said : said[0].toUpperCase() + said.slice(1)) +
243
+ comma
244
+ i++
245
+ if (comma) continue
246
+ if (words[i] == 'or' || words[i] == 'and') i++
247
+ else break
248
+ }
249
+ return i ? words.join(' ') : null
250
+ }
251
+
252
+ /** The call while it runs: "Listing app versions…". */
253
+ export let doing = (title: string): string =>
254
+ (tensed(title, ing) ?? title) + '…'
255
+
256
+ /** The call once it answered: "Listed app versions". */
257
+ export let did = (title: string): string => tensed(title, ed) ?? title
package/value.js ADDED
@@ -0,0 +1,57 @@
1
+ // Reading an answer as data. A tool answers words for a person and, where a
2
+ // program has something to read, the same answer as data in `output{value}`
3
+ // beside them. This file is that one read, importing nothing that runs, so a
4
+ // client that only reads answers (the CLI talking to a server, a probe) takes
5
+ // it without the runner and the vocabulary behind it (`@yaks/tools/value`).
6
+ /** Images a tool answered, for a door that displays them inline. */ export let imagesIn = (answer)=>answer.flatMap((b)=>{
7
+ let images = b.output?.images;
8
+ return Array.isArray(images) ? images.filter((v)=>!!v && typeof v == 'object' && typeof v.data == 'string' && typeof v.mime_type == 'string') : [];
9
+ });
10
+ /**
11
+ * A tool's answer that is a value: one bundle aimed at the call, carrying the
12
+ * value once, in `output{value}`. A door that sends text says it as
13
+ * {@link json}; one that sends data sends it as it is.
14
+ *
15
+ * ```ts
16
+ * import { assertEquals } from '@std/assert'
17
+ * assertEquals(valued({ entity: { eid: 'c1' } }, { n: 1 }), {
18
+ * entity: { eid: '$said' },
19
+ * output: { source: 'c1', value: { n: 1 } },
20
+ * })
21
+ * ```
22
+ */ export let valued = (call, value)=>({
23
+ entity: {
24
+ eid: '$said'
25
+ },
26
+ output: {
27
+ source: call.entity.eid,
28
+ value
29
+ }
30
+ });
31
+ /**
32
+ * A value as the text a door that sends text says: one line where it fits in
33
+ * 80 characters, indented JSON where it does not.
34
+ *
35
+ * ```ts
36
+ * import { assertEquals } from '@std/assert'
37
+ * assertEquals(json({ count: 2 }), '{"count":2}')
38
+ * assertEquals(json({ s: 'x'.repeat(80) }).split('\n').length, 3)
39
+ * ```
40
+ */ export let json = (value)=>{
41
+ let line = JSON.stringify(value) ?? 'null';
42
+ return line.length <= 80 ? line : JSON.stringify(value, null, 2);
43
+ };
44
+ /**
45
+ * The `output{value}` an answer carries: the same answer as data, beside the
46
+ * words a person reads. A caller that wants the answer's facts reads them here,
47
+ * never out of the words, which may carry more than the answer.
48
+ *
49
+ * ```ts
50
+ * import { assertEquals } from '@std/assert'
51
+ * let said = { entity: { eid: '$said' }, content: { body: 'a.txt' } }
52
+ * let files = { files: [{ path: 'a.txt' }] }
53
+ * assertEquals(valueIn([{ ...said, output: { value: files } }]), files)
54
+ * assertEquals(valueIn([said]), undefined)
55
+ * ```
56
+ */ export let valueIn = (answer)=>answer.map((b)=>b.output?.value).find((v)=>!!v && typeof v == 'object');
57
+ //# sourceMappingURL=value.js.map
package/value.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.js","sources":["./value.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAM5E,kEAAkE,GAClE,OAAO,IAAI,WAAW,CAAC,SACrB,OAAO,OAAO,CAAC,CAAC;IACd,IAAI,SAAU,EAAE,MAAM,EAAuB;IAC7C,OAAO,MAAM,OAAO,CAAC,UACjB,OAAO,MAAM,CAAC,CAAC,IACf,CAAC,CAAC,KAAK,OAAO,KAAK,YAAY,OAAO,EAAE,IAAI,IAAI,YAChD,OAAO,EAAE,SAAS,IAAI,YAEtB,EAAE;EACR,GAAE;AAEJ;;;;;;;;;;;;CAYC,GACD,OAAO,IAAI,SAAS,CAAC,MAAc,QAA2B,CAAC;IAC7D,QAAQ;MAAE,KAAK;IAAQ;IACvB,QAAQ;MAAE,QAAQ,KAAK,MAAM,CAAC,GAAG;MAAE;IAAM;EAC3C,CAAC,EAAC;AAEF;;;;;;;;;CASC,GACD,OAAO,IAAI,OAAO,CAAC;EACjB,IAAI,OAAO,KAAK,SAAS,CAAC,UAAU;EACpC,OAAO,KAAK,MAAM,IAAI,KAAK,OAAO,KAAK,SAAS,CAAC,OAAO,MAAM;AAChE,EAAC;AAED;;;;;;;;;;;;CAYC,GACD,OAAO,IAAI,UAAU,CACnB,SAEA,OACG,GAAG,CAAC,CAAC,IAAO,EAAE,MAAM,EAAuB,OAC3C,IAAI,CAAC,CAAC,IAAoC,CAAC,CAAC,KAAK,OAAO,KAAK,UAAS"}
package/value.ts ADDED
@@ -0,0 +1,74 @@
1
+ // Reading an answer as data. A tool answers words for a person and, where a
2
+ // program has something to read, the same answer as data in `output{value}`
3
+ // beside them. This file is that one read, importing nothing that runs, so a
4
+ // client that only reads answers (the CLI talking to a server, a probe) takes
5
+ // it without the runner and the vocabulary behind it (`@yaks/tools/value`).
6
+ import type { Bundle, Comp } from 'jsr:@yaks/graph@0.2.36'
7
+
8
+ /** An image answered beside a tool's text and structured value. */
9
+ export type Image = { data: string; mime_type: string }
10
+
11
+ /** Images a tool answered, for a door that displays them inline. */
12
+ export let imagesIn = (answer: Bundle[]): Image[] =>
13
+ answer.flatMap((b) => {
14
+ let images = (b.output as Comp | undefined)?.images
15
+ return Array.isArray(images)
16
+ ? images.filter((v): v is Image =>
17
+ !!v && typeof v == 'object' && typeof v.data == 'string' &&
18
+ typeof v.mime_type == 'string'
19
+ )
20
+ : []
21
+ })
22
+
23
+ /**
24
+ * A tool's answer that is a value: one bundle aimed at the call, carrying the
25
+ * value once, in `output{value}`. A door that sends text says it as
26
+ * {@link json}; one that sends data sends it as it is.
27
+ *
28
+ * ```ts
29
+ * import { assertEquals } from '@std/assert'
30
+ * assertEquals(valued({ entity: { eid: 'c1' } }, { n: 1 }), {
31
+ * entity: { eid: '$said' },
32
+ * output: { source: 'c1', value: { n: 1 } },
33
+ * })
34
+ * ```
35
+ */
36
+ export let valued = (call: Bundle, value: unknown): Bundle => ({
37
+ entity: { eid: '$said' },
38
+ output: { source: call.entity.eid, value },
39
+ })
40
+
41
+ /**
42
+ * A value as the text a door that sends text says: one line where it fits in
43
+ * 80 characters, indented JSON where it does not.
44
+ *
45
+ * ```ts
46
+ * import { assertEquals } from '@std/assert'
47
+ * assertEquals(json({ count: 2 }), '{"count":2}')
48
+ * assertEquals(json({ s: 'x'.repeat(80) }).split('\n').length, 3)
49
+ * ```
50
+ */
51
+ export let json = (value: unknown): string => {
52
+ let line = JSON.stringify(value) ?? 'null'
53
+ return line.length <= 80 ? line : JSON.stringify(value, null, 2)
54
+ }
55
+
56
+ /**
57
+ * The `output{value}` an answer carries: the same answer as data, beside the
58
+ * words a person reads. A caller that wants the answer's facts reads them here,
59
+ * never out of the words, which may carry more than the answer.
60
+ *
61
+ * ```ts
62
+ * import { assertEquals } from '@std/assert'
63
+ * let said = { entity: { eid: '$said' }, content: { body: 'a.txt' } }
64
+ * let files = { files: [{ path: 'a.txt' }] }
65
+ * assertEquals(valueIn([{ ...said, output: { value: files } }]), files)
66
+ * assertEquals(valueIn([said]), undefined)
67
+ * ```
68
+ */
69
+ export let valueIn = (
70
+ answer: Bundle[],
71
+ ): Record<string, unknown> | undefined =>
72
+ answer
73
+ .map((b) => (b.output as Comp | undefined)?.value)
74
+ .find((v): v is Record<string, unknown> => !!v && typeof v == 'object')