@kurvball/rehearse 0.0.0-stage → 1.2.1

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 (266) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -2
  3. package/dist/affected/affected.d.ts +22 -0
  4. package/dist/affected/affected.js +162 -0
  5. package/dist/affected/index.d.ts +1 -0
  6. package/dist/affected/index.js +1 -0
  7. package/dist/args.d.ts +12 -0
  8. package/dist/args.js +42 -0
  9. package/dist/cli.d.ts +4 -0
  10. package/dist/cli.js +100 -0
  11. package/dist/commands/check.d.ts +2 -0
  12. package/dist/commands/check.js +42 -0
  13. package/dist/commands/clean.d.ts +2 -0
  14. package/dist/commands/clean.js +37 -0
  15. package/dist/commands/command.d.ts +29 -0
  16. package/dist/commands/command.js +29 -0
  17. package/dist/commands/compare.d.ts +4 -0
  18. package/dist/commands/compare.js +84 -0
  19. package/dist/commands/drive.d.ts +2 -0
  20. package/dist/commands/drive.js +244 -0
  21. package/dist/commands/index.d.ts +3 -0
  22. package/dist/commands/index.js +32 -0
  23. package/dist/commands/init.d.ts +2 -0
  24. package/dist/commands/init.js +19 -0
  25. package/dist/commands/list.d.ts +2 -0
  26. package/dist/commands/list.js +69 -0
  27. package/dist/commands/open.d.ts +2 -0
  28. package/dist/commands/open.js +60 -0
  29. package/dist/commands/people.d.ts +2 -0
  30. package/dist/commands/people.js +49 -0
  31. package/dist/commands/run.d.ts +4 -0
  32. package/dist/commands/run.js +82 -0
  33. package/dist/commands/services.d.ts +28 -0
  34. package/dist/commands/services.js +51 -0
  35. package/dist/commands/stage.d.ts +7 -0
  36. package/dist/commands/stage.js +49 -0
  37. package/dist/commands/up.d.ts +3 -0
  38. package/dist/commands/up.js +77 -0
  39. package/dist/commands/validate.d.ts +2 -0
  40. package/dist/commands/validate.js +35 -0
  41. package/dist/commands/worlds.d.ts +2 -0
  42. package/dist/commands/worlds.js +15 -0
  43. package/dist/compare/announce.d.ts +6 -0
  44. package/dist/compare/announce.js +27 -0
  45. package/dist/compare/compare.d.ts +82 -0
  46. package/dist/compare/compare.js +310 -0
  47. package/dist/compare/diff.d.ts +15 -0
  48. package/dist/compare/diff.js +105 -0
  49. package/dist/compare/index.d.ts +4 -0
  50. package/dist/compare/index.js +4 -0
  51. package/dist/compare/setaside.d.ts +29 -0
  52. package/dist/compare/setaside.js +121 -0
  53. package/dist/compare/verdict.d.ts +21 -0
  54. package/dist/compare/verdict.js +30 -0
  55. package/dist/drive/aria.d.ts +8 -0
  56. package/dist/drive/aria.js +12 -0
  57. package/dist/drive/browser.d.ts +34 -0
  58. package/dist/drive/browser.js +216 -0
  59. package/dist/drive/daemon.d.ts +1 -0
  60. package/dist/drive/daemon.js +171 -0
  61. package/dist/drive/grammar.d.ts +93 -0
  62. package/dist/drive/grammar.js +303 -0
  63. package/dist/drive/index.d.ts +4 -0
  64. package/dist/drive/index.js +4 -0
  65. package/dist/drive/names.d.ts +24 -0
  66. package/dist/drive/names.js +97 -0
  67. package/dist/drive/state.d.ts +13 -0
  68. package/dist/drive/state.js +28 -0
  69. package/dist/errors.d.ts +26 -0
  70. package/dist/errors.js +32 -0
  71. package/dist/exec.d.ts +16 -0
  72. package/dist/exec.js +43 -0
  73. package/dist/git/checkout.d.ts +11 -0
  74. package/dist/git/checkout.js +84 -0
  75. package/dist/git/git.d.ts +7 -0
  76. package/dist/git/git.js +27 -0
  77. package/dist/git/index.d.ts +2 -0
  78. package/dist/git/index.js +2 -0
  79. package/dist/index.d.ts +18 -0
  80. package/dist/index.js +15 -0
  81. package/dist/kinds/all.d.ts +4 -0
  82. package/dist/kinds/all.js +4 -0
  83. package/dist/kinds/call/check.d.ts +29 -0
  84. package/dist/kinds/call/check.js +187 -0
  85. package/dist/kinds/call/definition.d.ts +16 -0
  86. package/dist/kinds/call/definition.js +33 -0
  87. package/dist/kinds/call/hurl.d.ts +65 -0
  88. package/dist/kinds/call/hurl.js +333 -0
  89. package/dist/kinds/call/kind.d.ts +8 -0
  90. package/dist/kinds/call/kind.js +122 -0
  91. package/dist/kinds/call/send.d.ts +32 -0
  92. package/dist/kinds/call/send.js +152 -0
  93. package/dist/kinds/call/words.d.ts +22 -0
  94. package/dist/kinds/call/words.js +24 -0
  95. package/dist/kinds/file/kind.d.ts +44 -0
  96. package/dist/kinds/file/kind.js +331 -0
  97. package/dist/kinds/file/layouts.d.ts +14 -0
  98. package/dist/kinds/file/layouts.js +103 -0
  99. package/dist/kinds/flow/kind.d.ts +21 -0
  100. package/dist/kinds/flow/kind.js +401 -0
  101. package/dist/kinds/flow/literal.d.ts +8 -0
  102. package/dist/kinds/flow/literal.js +148 -0
  103. package/dist/kinds/index.d.ts +10 -0
  104. package/dist/kinds/index.js +8 -0
  105. package/dist/kinds/kind.d.ts +57 -0
  106. package/dist/kinds/kind.js +21 -0
  107. package/dist/kinds/piece/canvas.d.ts +18 -0
  108. package/dist/kinds/piece/canvas.js +165 -0
  109. package/dist/kinds/piece/conventions.d.ts +12 -0
  110. package/dist/kinds/piece/conventions.js +101 -0
  111. package/dist/kinds/piece/csf.d.ts +10 -0
  112. package/dist/kinds/piece/csf.js +304 -0
  113. package/dist/kinds/piece/kind.d.ts +12 -0
  114. package/dist/kinds/piece/kind.js +297 -0
  115. package/dist/kinds/piece/server.d.ts +23 -0
  116. package/dist/kinds/piece/server.js +236 -0
  117. package/dist/manifest/fill.d.ts +4 -0
  118. package/dist/manifest/fill.js +7 -0
  119. package/dist/manifest/index.d.ts +5 -0
  120. package/dist/manifest/index.js +5 -0
  121. package/dist/manifest/init.d.ts +1 -0
  122. package/dist/manifest/init.js +47 -0
  123. package/dist/manifest/load.d.ts +7 -0
  124. package/dist/manifest/load.js +244 -0
  125. package/dist/manifest/types.d.ts +253 -0
  126. package/dist/manifest/types.js +7 -0
  127. package/dist/manifest/yaml.d.ts +5 -0
  128. package/dist/manifest/yaml.js +47 -0
  129. package/dist/people/index.d.ts +1 -0
  130. package/dist/people/index.js +1 -0
  131. package/dist/people/people.d.ts +39 -0
  132. package/dist/people/people.js +139 -0
  133. package/dist/run/cache.d.ts +20 -0
  134. package/dist/run/cache.js +98 -0
  135. package/dist/run/index.d.ts +4 -0
  136. package/dist/run/index.js +3 -0
  137. package/dist/run/observation.d.ts +27 -0
  138. package/dist/run/observation.js +1 -0
  139. package/dist/run/session.d.ts +32 -0
  140. package/dist/run/session.js +258 -0
  141. package/dist/run/vars.d.ts +3 -0
  142. package/dist/run/vars.js +13 -0
  143. package/dist/scenarios/area.d.ts +6 -0
  144. package/dist/scenarios/area.js +37 -0
  145. package/dist/scenarios/files.d.ts +9 -0
  146. package/dist/scenarios/files.js +26 -0
  147. package/dist/scenarios/glob.d.ts +6 -0
  148. package/dist/scenarios/glob.js +106 -0
  149. package/dist/scenarios/index.d.ts +4 -0
  150. package/dist/scenarios/index.js +4 -0
  151. package/dist/scenarios/read.d.ts +18 -0
  152. package/dist/scenarios/read.js +54 -0
  153. package/dist/scenarios/scenario.d.ts +34 -0
  154. package/dist/scenarios/scenario.js +10 -0
  155. package/dist/schema.d.ts +14 -0
  156. package/dist/schema.js +122 -0
  157. package/dist/services/index.d.ts +2 -0
  158. package/dist/services/index.js +2 -0
  159. package/dist/services/registry.d.ts +23 -0
  160. package/dist/services/registry.js +49 -0
  161. package/dist/services/service.d.ts +22 -0
  162. package/dist/services/service.js +284 -0
  163. package/dist/stage/api.d.ts +28 -0
  164. package/dist/stage/api.js +206 -0
  165. package/dist/stage/client/client/api.js +11 -0
  166. package/dist/stage/client/client/index.js +1 -0
  167. package/dist/stage/client/features/canvas/call.js +65 -0
  168. package/dist/stage/client/features/canvas/context.js +1 -0
  169. package/dist/stage/client/features/canvas/file.js +36 -0
  170. package/dist/stage/client/features/canvas/flow.js +59 -0
  171. package/dist/stage/client/features/canvas/index.js +1 -0
  172. package/dist/stage/client/features/canvas/observed.js +8 -0
  173. package/dist/stage/client/features/canvas/parts.js +24 -0
  174. package/dist/stage/client/features/canvas/piece.js +31 -0
  175. package/dist/stage/client/features/canvas/reach.js +6 -0
  176. package/dist/stage/client/features/canvas/views.js +16 -0
  177. package/dist/stage/client/features/list/index.js +1 -0
  178. package/dist/stage/client/features/list/list.js +53 -0
  179. package/dist/stage/client/features/list/reach.js +10 -0
  180. package/dist/stage/client/features/scenario/heading.js +14 -0
  181. package/dist/stage/client/features/scenario/index.js +1 -0
  182. package/dist/stage/client/features/scenario/reach.js +9 -0
  183. package/dist/stage/client/features/scenario/scenario.js +145 -0
  184. package/dist/stage/client/features/try/index.js +1 -0
  185. package/dist/stage/client/features/try/reach.js +12 -0
  186. package/dist/stage/client/features/try/try.js +65 -0
  187. package/dist/stage/client/index.html +16 -0
  188. package/dist/stage/client/main.js +24 -0
  189. package/dist/stage/client/primitives/busy.js +6 -0
  190. package/dist/stage/client/primitives/focus.js +21 -0
  191. package/dist/stage/client/primitives/h.js +25 -0
  192. package/dist/stage/client/primitives/index.js +6 -0
  193. package/dist/stage/client/primitives/keyed.js +16 -0
  194. package/dist/stage/client/primitives/say.js +6 -0
  195. package/dist/stage/client/primitives/state.js +21 -0
  196. package/dist/stage/client/primitives/types.js +1 -0
  197. package/dist/stage/client/primitives/verdicts.js +8 -0
  198. package/dist/stage/client/stage.css +652 -0
  199. package/dist/stage/compared.d.ts +20 -0
  200. package/dist/stage/compared.js +58 -0
  201. package/dist/stage/files.d.ts +4 -0
  202. package/dist/stage/files.js +59 -0
  203. package/dist/stage/guard.d.ts +3 -0
  204. package/dist/stage/guard.js +20 -0
  205. package/dist/stage/http.d.ts +12 -0
  206. package/dist/stage/http.js +34 -0
  207. package/dist/stage/index.d.ts +1 -0
  208. package/dist/stage/index.js +1 -0
  209. package/dist/stage/sending.d.ts +18 -0
  210. package/dist/stage/sending.js +66 -0
  211. package/dist/stage/server.d.ts +31 -0
  212. package/dist/stage/server.js +250 -0
  213. package/dist/version.d.ts +2 -0
  214. package/dist/version.js +5 -0
  215. package/dist/worlds/define.d.ts +16 -0
  216. package/dist/worlds/define.js +45 -0
  217. package/dist/worlds/index.d.ts +2 -0
  218. package/dist/worlds/index.js +2 -0
  219. package/dist/worlds/worlds.d.ts +15 -0
  220. package/dist/worlds/worlds.js +46 -0
  221. package/llms.txt +46 -0
  222. package/package.json +84 -3
  223. package/schema/v1/announce.schema.json +28 -0
  224. package/schema/v1/check.schema.json +67 -0
  225. package/schema/v1/clean.schema.json +19 -0
  226. package/schema/v1/common.schema.json +210 -0
  227. package/schema/v1/comparison.schema.json +298 -0
  228. package/schema/v1/dependents.schema.json +30 -0
  229. package/schema/v1/drive.schema.json +112 -0
  230. package/schema/v1/error.schema.json +26 -0
  231. package/schema/v1/file-scenario.schema.json +175 -0
  232. package/schema/v1/flow.schema.json +216 -0
  233. package/schema/v1/init.schema.json +20 -0
  234. package/schema/v1/list.schema.json +70 -0
  235. package/schema/v1/manifest.schema.json +430 -0
  236. package/schema/v1/observation.schema.json +388 -0
  237. package/schema/v1/open.schema.json +14 -0
  238. package/schema/v1/people.schema.json +88 -0
  239. package/schema/v1/samples/announce.yaml +5 -0
  240. package/schema/v1/samples/check.json +13 -0
  241. package/schema/v1/samples/clean.json +1 -0
  242. package/schema/v1/samples/comparison.json +83 -0
  243. package/schema/v1/samples/dependents.json +7 -0
  244. package/schema/v1/samples/drive.json +10 -0
  245. package/schema/v1/samples/error.json +10 -0
  246. package/schema/v1/samples/file-scenario.yaml +13 -0
  247. package/schema/v1/samples/flow.yaml +13 -0
  248. package/schema/v1/samples/init.json +1 -0
  249. package/schema/v1/samples/list.json +24 -0
  250. package/schema/v1/samples/manifest.yaml +55 -0
  251. package/schema/v1/samples/observation.json +49 -0
  252. package/schema/v1/samples/open.json +6 -0
  253. package/schema/v1/samples/people.json +11 -0
  254. package/schema/v1/samples/services.json +27 -0
  255. package/schema/v1/samples/stage.json +6 -0
  256. package/schema/v1/samples/try.json +13 -0
  257. package/schema/v1/samples/up.json +16 -0
  258. package/schema/v1/samples/validate.json +7 -0
  259. package/schema/v1/samples/worlds.json +21 -0
  260. package/schema/v1/services.schema.json +72 -0
  261. package/schema/v1/stage.schema.json +14 -0
  262. package/schema/v1/try.schema.json +56 -0
  263. package/schema/v1/up.schema.json +55 -0
  264. package/schema/v1/validate.schema.json +40 -0
  265. package/schema/v1/worlds.schema.json +33 -0
  266. package/skill/rehearse/SKILL.md +148 -0
@@ -0,0 +1,26 @@
1
+ import path from 'node:path';
2
+ import { KIND_BLOCK } from '../manifest/index.js';
3
+ import { findFiles, toPosix } from './glob.js';
4
+ export function filesOf(m, kind, checkout) {
5
+ const out = new Map();
6
+ for (const entry of m.scenarios[KIND_BLOCK[kind]].paths) {
7
+ const root = entry.from === 'manifest' ? m.dir : checkout;
8
+ for (const file of findFiles(root, [entry.glob])) {
9
+ const abs = path.resolve(root, file);
10
+ const rel = toPosix(entry.from === 'manifest' ? path.relative(m.dir, abs) : file);
11
+ const id = `${entry.from}:${rel}`;
12
+ const known = out.get(id);
13
+ if (known)
14
+ known.covers.push(...entry.covers);
15
+ else
16
+ out.set(id, {
17
+ kind,
18
+ file: rel.startsWith('.') ? rel : entry.from === 'manifest' ? `./${rel}` : rel,
19
+ abs,
20
+ from: entry.from,
21
+ covers: [...entry.covers],
22
+ });
23
+ }
24
+ }
25
+ return [...out.values()].sort((a, b) => a.file.localeCompare(b.file));
26
+ }
@@ -0,0 +1,6 @@
1
+ export declare const NEVER_WALKED: Set<string>;
2
+ export declare function globToRegExp(glob: string): RegExp;
3
+ export declare function globRoot(glob: string): string;
4
+ export declare const toPosix: (p: string) => string;
5
+ export declare function findFiles(root: string, globs: readonly string[], limit?: number): string[];
6
+ export declare const matches: (file: string, globs: readonly string[]) => boolean;
@@ -0,0 +1,106 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ export const NEVER_WALKED = new Set([
4
+ 'node_modules',
5
+ '.git',
6
+ 'dist',
7
+ 'out',
8
+ 'build',
9
+ 'target',
10
+ '.rehearse',
11
+ 'coverage',
12
+ '.turbo',
13
+ '.next',
14
+ '.astro',
15
+ '__pycache__',
16
+ '.venv',
17
+ ]);
18
+ const escape = (c) => c.replace(/[.+^$()|\\]/g, '\\$&');
19
+ export function globToRegExp(glob) {
20
+ let out = '';
21
+ let i = 0;
22
+ let braces = 0;
23
+ while (i < glob.length) {
24
+ const c = glob[i];
25
+ if (c === '*') {
26
+ if (glob[i + 1] === '*') {
27
+ const slashAfter = glob[i + 2] === '/';
28
+ out += slashAfter ? '(?:.*/)?' : '.*';
29
+ i += slashAfter ? 3 : 2;
30
+ continue;
31
+ }
32
+ out += '[^/]*';
33
+ }
34
+ else if (c === '?')
35
+ out += '[^/]';
36
+ else if (c === '{') {
37
+ braces += 1;
38
+ out += '(?:';
39
+ }
40
+ else if (c === '}' && braces > 0) {
41
+ braces -= 1;
42
+ out += ')';
43
+ }
44
+ else if (c === ',' && braces > 0)
45
+ out += '|';
46
+ else if (c === '[') {
47
+ const end = glob.indexOf(']', i + 1);
48
+ if (end < 0)
49
+ out += '\\[';
50
+ else {
51
+ out += `[${glob
52
+ .slice(i + 1, end)
53
+ .replace(/^!/, '^')
54
+ .replace(/\\/g, '\\\\')}]`;
55
+ i = end;
56
+ }
57
+ }
58
+ else
59
+ out += escape(c);
60
+ i += 1;
61
+ }
62
+ return new RegExp(`^${out}$`);
63
+ }
64
+ export function globRoot(glob) {
65
+ const parts = glob.split('/');
66
+ const fixed = [];
67
+ for (const part of parts.slice(0, -1)) {
68
+ if (/[*?{[]/.test(part))
69
+ break;
70
+ fixed.push(part);
71
+ }
72
+ return fixed.join('/');
73
+ }
74
+ export const toPosix = (p) => p.split(path.sep).join('/');
75
+ export function findFiles(root, globs, limit = 20_000) {
76
+ const found = new Set();
77
+ for (const glob of globs) {
78
+ const clean = glob.replace(/^\.\//, '');
79
+ const re = globToRegExp(clean);
80
+ const start = globRoot(clean);
81
+ const walk = (relative) => {
82
+ if (found.size >= limit)
83
+ return;
84
+ let entries;
85
+ try {
86
+ entries = readdirSync(path.join(root, relative), { withFileTypes: true });
87
+ }
88
+ catch {
89
+ return;
90
+ }
91
+ for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
92
+ const child = relative ? `${relative}/${entry.name}` : entry.name;
93
+ if (entry.isDirectory()) {
94
+ if (NEVER_WALKED.has(entry.name))
95
+ continue;
96
+ walk(child);
97
+ }
98
+ else if (entry.isFile() && re.test(child))
99
+ found.add(child);
100
+ }
101
+ };
102
+ walk(start);
103
+ }
104
+ return [...found].sort();
105
+ }
106
+ export const matches = (file, globs) => globs.some((g) => globToRegExp(g.replace(/^\.\//, '')).test(file));
@@ -0,0 +1,4 @@
1
+ export { packageDirOf, packageNameOf } from './area.ts';
2
+ export { findFiles, globRoot, globToRegExp, matches, toPosix } from './glob.ts';
3
+ export { readScenarios, registerReader } from './read.ts';
4
+ export { refOf, type Refused, type Scenario, type ScenarioRef } from './scenario.ts';
@@ -0,0 +1,4 @@
1
+ export { packageDirOf, packageNameOf } from './area.js';
2
+ export { findFiles, globRoot, globToRegExp, matches, toPosix } from './glob.js';
3
+ export { readScenarios, registerReader } from './read.js';
4
+ export { refOf } from './scenario.js';
@@ -0,0 +1,18 @@
1
+ import { type Kind, type Manifest } from '../manifest/index.ts';
2
+ import { type ScenarioFile } from './files.ts';
3
+ import type { Refused, Scenario } from './scenario.ts';
4
+ export interface KindReader {
5
+ kind: Kind;
6
+ read(file: ScenarioFile, text: string, ctx: ReadContext): Scenario[];
7
+ }
8
+ export interface ReadContext {
9
+ manifest: Manifest;
10
+ checkout: string;
11
+ area: string;
12
+ }
13
+ export declare function registerReader(reader: KindReader): void;
14
+ export interface Read {
15
+ scenarios: Scenario[];
16
+ refused: Refused[];
17
+ }
18
+ export declare function readScenarios(m: Manifest, checkout: string, kinds?: readonly Kind[]): Promise<Read>;
@@ -0,0 +1,54 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { KINDS } from '../manifest/index.js';
3
+ import { filesOf } from './files.js';
4
+ import { areaOf } from './area.js';
5
+ const readers = new Map();
6
+ export function registerReader(reader) {
7
+ readers.set(reader.kind, reader);
8
+ }
9
+ export async function readScenarios(m, checkout, kinds = KINDS) {
10
+ await (await import('../kinds/index.js')).loadKinds();
11
+ const out = { scenarios: [], refused: [] };
12
+ for (const kind of kinds) {
13
+ const reader = readers.get(kind);
14
+ for (const f of filesOf(m, kind, checkout)) {
15
+ if (!reader) {
16
+ out.refused.push({ file: f.file, says: `Rehearse has no reader for ${kind} scenarios yet.` });
17
+ continue;
18
+ }
19
+ let text;
20
+ try {
21
+ text = readFileSync(f.abs, 'utf8');
22
+ }
23
+ catch (error) {
24
+ out.refused.push({ file: f.file, says: `Rehearse can't read it: ${error.message}` });
25
+ continue;
26
+ }
27
+ try {
28
+ out.scenarios.push(...reader.read(f, text, { manifest: m, checkout, area: areaOf(m, checkout, f) }));
29
+ }
30
+ catch (error) {
31
+ const e = error;
32
+ out.refused.push({
33
+ file: f.file,
34
+ ...(e.line !== undefined && { line: e.line }),
35
+ says: e.says ?? e.message ?? String(error),
36
+ });
37
+ }
38
+ }
39
+ }
40
+ const seen = new Map();
41
+ for (const s of out.scenarios) {
42
+ const twice = seen.get(s.id);
43
+ if (twice)
44
+ out.refused.push({
45
+ file: s.file,
46
+ ...(s.line !== null && { line: s.line }),
47
+ says: `Two scenarios have the id “${s.id}”.`,
48
+ });
49
+ else
50
+ seen.set(s.id, s);
51
+ }
52
+ out.scenarios = [...seen.values()];
53
+ return out;
54
+ }
@@ -0,0 +1,34 @@
1
+ import type { Kind } from '../manifest/index.ts';
2
+ export interface Scenario {
3
+ id: string;
4
+ kind: Kind;
5
+ name: string;
6
+ file: string;
7
+ abs: string;
8
+ line: number | null;
9
+ from: 'checkout' | 'manifest';
10
+ area: string;
11
+ definition: string;
12
+ context?: string;
13
+ world: string | null;
14
+ person: string | null;
15
+ service: string | null;
16
+ covers: string[];
17
+ spec: unknown;
18
+ }
19
+ export interface Refused {
20
+ file: string;
21
+ line?: number;
22
+ says: string;
23
+ }
24
+ export interface ScenarioRef {
25
+ id: string;
26
+ kind: Kind;
27
+ name: string;
28
+ file: string;
29
+ line?: number;
30
+ area: string;
31
+ from: 'checkout' | 'manifest';
32
+ definition: string;
33
+ }
34
+ export declare const refOf: (s: Scenario) => ScenarioRef;
@@ -0,0 +1,10 @@
1
+ export const refOf = (s) => ({
2
+ id: s.id,
3
+ kind: s.kind,
4
+ name: s.name,
5
+ file: s.file,
6
+ ...(s.line !== null && { line: s.line }),
7
+ area: s.area,
8
+ from: s.from,
9
+ definition: s.definition,
10
+ });
@@ -0,0 +1,14 @@
1
+ import { type ErrorObject, type ValidateFunction } from 'ajv/dist/2020.js';
2
+ export declare const SCHEMA_DIR: string;
3
+ export declare const SCHEMAS: readonly ['manifest', 'flow', 'file-scenario', 'announce', 'services', 'people', 'worlds', 'list', 'observation', 'comparison', 'drive', 'open', 'stage', 'try', 'error', 'dependents', 'check', 'init', 'validate', 'up', 'clean'];
4
+ export type SchemaName = (typeof SCHEMAS)[number];
5
+ export declare const schemaId: (name: SchemaName | 'common') => string;
6
+ export declare function validatorOf(name: SchemaName): ValidateFunction;
7
+ export interface Invalid {
8
+ at: string[];
9
+ key?: string;
10
+ says: string;
11
+ }
12
+ export declare const placeOf: (at: readonly string[]) => string;
13
+ export declare function explain(errors: readonly ErrorObject[]): Invalid[];
14
+ export declare function validate(name: SchemaName, value: unknown): Invalid[];
package/dist/schema.js ADDED
@@ -0,0 +1,122 @@
1
+ import { readdirSync, readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { Ajv2020 } from 'ajv/dist/2020.js';
4
+ import { PACKAGE_ROOT } from './version.js';
5
+ export const SCHEMA_DIR = path.join(PACKAGE_ROOT, 'schema', 'v1');
6
+ export const SCHEMAS = [
7
+ 'manifest',
8
+ 'flow',
9
+ 'file-scenario',
10
+ 'announce',
11
+ 'services',
12
+ 'people',
13
+ 'worlds',
14
+ 'list',
15
+ 'observation',
16
+ 'comparison',
17
+ 'drive',
18
+ 'open',
19
+ 'stage',
20
+ 'try',
21
+ 'error',
22
+ 'dependents',
23
+ 'check',
24
+ 'init',
25
+ 'validate',
26
+ 'up',
27
+ 'clean',
28
+ ];
29
+ const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
30
+ let ajv = null;
31
+ const compiled = new Map();
32
+ function load() {
33
+ if (ajv)
34
+ return ajv;
35
+ const made = new Ajv2020({ allErrors: true, strict: false, allowUnionTypes: true });
36
+ made.addFormat('date-time', ISO);
37
+ for (const file of readdirSync(SCHEMA_DIR).filter((f) => f.endsWith('.schema.json')))
38
+ made.addSchema(JSON.parse(readFileSync(path.join(SCHEMA_DIR, file), 'utf8')));
39
+ ajv = made;
40
+ return made;
41
+ }
42
+ export const schemaId = (name) => `https://rehearse.kurvball.ca/schema/v1/${name}.schema.json`;
43
+ export function validatorOf(name) {
44
+ const known = compiled.get(name);
45
+ if (known)
46
+ return known;
47
+ const v = load().getSchema(schemaId(name));
48
+ if (!v)
49
+ throw new Error(`Rehearse has no schema named ${name}.`);
50
+ compiled.set(name, v);
51
+ return v;
52
+ }
53
+ const segments = (pointer) => pointer
54
+ .split('/')
55
+ .slice(1)
56
+ .map((s) => s.replace(/~1/g, '/').replace(/~0/g, '~'));
57
+ export const placeOf = (at) => at.length === 0
58
+ ? 'the top'
59
+ : at
60
+ .map((s) => (/^\d+$/.test(s) ? `[${s}]` : s))
61
+ .join('.')
62
+ .replace(/\.\[/g, '[');
63
+ function words(e) {
64
+ const at = segments(e.instancePath);
65
+ const where = placeOf(at);
66
+ const p = e.params;
67
+ switch (e.keyword) {
68
+ case 'additionalProperties':
69
+ return `${where} has no field “${String(p.additionalProperty)}”.`;
70
+ case 'required':
71
+ return `${where} needs “${String(p.missingProperty)}”.`;
72
+ case 'type':
73
+ return `${where} should be ${String(p.type).split(',').join(' or ')}.`;
74
+ case 'enum':
75
+ return `${where} should be one of ${p.allowedValues.map((v) => JSON.stringify(v)).join(', ')}.`;
76
+ case 'const':
77
+ return `${where} should be ${JSON.stringify(p.allowedValue)}.`;
78
+ case 'pattern':
79
+ return `${where} doesn't have the form it needs (${String(p.pattern)}).`;
80
+ case 'propertyNames':
81
+ return `${where} has a name that can't be used: “${String(p.propertyName)}”.`;
82
+ case 'minItems':
83
+ return `${where} needs at least ${String(p.limit)}.`;
84
+ case 'minLength':
85
+ return `${where} can't be empty.`;
86
+ case 'minProperties':
87
+ return `${where} needs at least one field.`;
88
+ case 'maxProperties':
89
+ return `${where} takes only one of its fields.`;
90
+ default:
91
+ return `${where} ${e.message ?? 'is not valid'}.`;
92
+ }
93
+ }
94
+ const depthOf = (e) => segments(e.instancePath).length;
95
+ const namesAField = (e) => e.keyword === 'additionalProperties' || e.keyword === 'required';
96
+ const isShapeMismatch = (e) => e.keyword === 'type';
97
+ const worthSayingFirst = (e) => depthOf(e) * 10 + (namesAField(e) ? 5 : 0) - (isShapeMismatch(e) ? 3 : 0);
98
+ export function explain(errors) {
99
+ const useful = errors.filter((e) => !['oneOf', 'anyOf', 'if', 'not', '$ref'].includes(e.keyword));
100
+ const pool = useful.length ? useful : [...errors];
101
+ const sorted = [...pool].sort((a, b) => worthSayingFirst(b) - worthSayingFirst(a));
102
+ const seen = new Set();
103
+ const out = [];
104
+ for (const e of sorted) {
105
+ const said = words(e);
106
+ if (seen.has(said))
107
+ continue;
108
+ seen.add(said);
109
+ const p = e.params;
110
+ const key = e.keyword === 'additionalProperties'
111
+ ? String(p.additionalProperty)
112
+ : e.keyword === 'propertyNames'
113
+ ? String(p.propertyName)
114
+ : undefined;
115
+ out.push({ at: segments(e.instancePath), says: said, ...(key !== undefined && { key }) });
116
+ }
117
+ return out;
118
+ }
119
+ export function validate(name, value) {
120
+ const v = validatorOf(name);
121
+ return v(value) ? [] : explain(v.errors ?? []);
122
+ }
@@ -0,0 +1,2 @@
1
+ export { alive, runningServices, stateDir, type Running } from './registry.ts';
2
+ export { bringDown, bringUp, downStartedHere, freePort, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.ts';
@@ -0,0 +1,2 @@
1
+ export { alive, runningServices, stateDir } from './registry.js';
2
+ export { bringDown, bringUp, downStartedHere, freePort, liveServices, makeRoom, release, restart, restartable, standinsFor, } from './service.js';
@@ -0,0 +1,23 @@
1
+ export interface Running {
2
+ name: string;
3
+ checkout: string;
4
+ pid: number;
5
+ port: number | null;
6
+ url: string | null;
7
+ since: string;
8
+ down: string | null;
9
+ scratch: string | null;
10
+ standins: string[];
11
+ up?: string;
12
+ env?: Record<string, string>;
13
+ world?: string | null;
14
+ daemon?: boolean;
15
+ starting?: boolean;
16
+ }
17
+ export declare const stateDir: (manifestDir: string) => string;
18
+ export declare const checkoutKey: (checkout: string) => string;
19
+ export declare const alive: (pid: number) => boolean;
20
+ export declare function remember(manifestDir: string, r: Running): void;
21
+ export declare function forget(manifestDir: string, name: string, checkout: string): void;
22
+ export declare function runningServices(manifestDir: string): Running[];
23
+ export declare const runningOf: (manifestDir: string, name: string, checkout: string) => Running | null;
@@ -0,0 +1,49 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ export const stateDir = (manifestDir) => path.join(manifestDir, '.rehearse');
5
+ const registryDir = (manifestDir) => path.join(stateDir(manifestDir), 'services');
6
+ export const checkoutKey = (checkout) => createHash('sha256').update(path.resolve(checkout)).digest('hex').slice(0, 10);
7
+ const fileOf = (manifestDir, name, checkout) => path.join(registryDir(manifestDir), `${name}@${checkoutKey(checkout)}.json`);
8
+ export const alive = (pid) => {
9
+ try {
10
+ process.kill(pid, 0);
11
+ return true;
12
+ }
13
+ catch (error) {
14
+ return error.code === 'EPERM';
15
+ }
16
+ };
17
+ export function remember(manifestDir, r) {
18
+ mkdirSync(registryDir(manifestDir), { recursive: true });
19
+ writeFileSync(fileOf(manifestDir, r.name, r.checkout), `${JSON.stringify(r, null, 2)}\n`);
20
+ }
21
+ export function forget(manifestDir, name, checkout) {
22
+ rmSync(fileOf(manifestDir, name, checkout), { force: true });
23
+ }
24
+ const daemonOrStoppableByItsDown = (r) => !r.starting && (Boolean(r.daemon) || r.down !== null);
25
+ export function runningServices(manifestDir) {
26
+ let files;
27
+ try {
28
+ files = readdirSync(registryDir(manifestDir)).filter((f) => f.endsWith('.json'));
29
+ }
30
+ catch {
31
+ return [];
32
+ }
33
+ const out = [];
34
+ for (const f of files) {
35
+ const file = path.join(registryDir(manifestDir), f);
36
+ try {
37
+ const r = JSON.parse(readFileSync(file, 'utf8'));
38
+ if (alive(r.pid) || daemonOrStoppableByItsDown(r))
39
+ out.push(r);
40
+ else
41
+ rmSync(file, { force: true });
42
+ }
43
+ catch {
44
+ rmSync(file, { force: true });
45
+ }
46
+ }
47
+ return out.sort((a, b) => a.name.localeCompare(b.name) || a.since.localeCompare(b.since));
48
+ }
49
+ export const runningOf = (manifestDir, name, checkout) => runningServices(manifestDir).find((r) => r.name === name && path.resolve(r.checkout) === path.resolve(checkout)) ?? null;
@@ -0,0 +1,22 @@
1
+ import { type Manifest, type Service, type Standin } from '../manifest/index.ts';
2
+ import { type Running } from './registry.ts';
3
+ export declare function freePort(): Promise<number>;
4
+ export declare function standinsFor(m: Manifest, service: string, real: ReadonlySet<string>): {
5
+ standin: Standin;
6
+ real: boolean;
7
+ }[];
8
+ export interface UpOptions {
9
+ world: string | null;
10
+ real: ReadonlySet<string>;
11
+ vars: Record<string, string>;
12
+ progress?: (line: string) => void;
13
+ }
14
+ export declare const logOf: (m: Manifest, name: string, checkout: string) => string;
15
+ export declare function liveServices(m: Manifest, checkout?: string | null): Promise<Running[]>;
16
+ export declare const restartable: (r: Running) => boolean;
17
+ export declare function restart(m: Manifest, r: Running): Promise<string | null>;
18
+ export declare const release: (r: Running) => boolean;
19
+ export declare function downStartedHere(): Promise<void>;
20
+ export declare function bringUp(m: Manifest, s: Service, checkout: string, options: UpOptions): Promise<Running>;
21
+ export declare function bringDown(m: Manifest, r: Running, progress?: (line: string) => void): Promise<void>;
22
+ export declare function makeRoom(m: Manifest, checkout: string, progress?: (line: string) => void): Promise<void>;