@ultimat3/core 30.5.0 → 30.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "30.5.0",
3
+ "version": "30.7.0",
4
4
  "description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -53,6 +53,6 @@
53
53
  "test": "bun test"
54
54
  },
55
55
  "dependencies": {
56
- "@ultimat3/schema": "30.5.0"
56
+ "@ultimat3/schema": "30.7.0"
57
57
  }
58
58
  }
@@ -0,0 +1,78 @@
1
+ // The `input:` an exercise fix pastes: `(drawn) => ({ ...drawn, <each owed field> })`. One renderer
2
+ // for every hint that names what a draw could not fill — action's and query's `X_CONTRACT_DRIFT`,
3
+ // and the `x exercise` override line — so the three cannot print different shapes.
4
+
5
+ import { renderFixLiteral } from './error-render';
6
+
7
+ /** A field the author supplies: its dotted path (`''` is the input itself) and what to put there. */
8
+ export interface DrawnBinding {
9
+ readonly path: string;
10
+ readonly placeholder: string;
11
+ }
12
+
13
+ const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
14
+
15
+ /** `@ultimat3/schema/sample`'s name for a gap at the root (`ROOT_PATH`): a bare `t.string` input. */
16
+ const SAMPLE_ROOT = '(the input)';
17
+
18
+ /**
19
+ * One `sampleGaps` path, as a binding: `describeSampleGap`'s answer (`digest (must match …)`)
20
+ * minus the path is what the placeholder asks for. Taken as two strings, so this tier never loads
21
+ * the sampler: the caller already has it.
22
+ */
23
+ export function sampleGapBinding(path: string, described: string): DrawnBinding {
24
+ const need = described.startsWith(path) ? described.slice(path.length).trim() : '';
25
+ const asked = /^\((.*)\)$/.exec(need)?.[1] ?? 'a value its schema accepts';
26
+ return { path: path === SAMPLE_ROOT ? '' : path, placeholder: `<${asked}>` };
27
+ }
28
+
29
+ /** A property key as source: bare when it is an identifier, a JSON string otherwise. */
30
+ export const renderExerciseKey = (key: string): string =>
31
+ IDENTIFIER.test(key) ? key : JSON.stringify(key);
32
+
33
+ interface Tree {
34
+ readonly leaves: Map<string, string | Tree>;
35
+ }
36
+
37
+ const placeholderOf = (text: string): string => renderFixLiteral(text, '"<a value>"');
38
+
39
+ function insert(tree: Tree, parts: readonly string[], placeholder: string): void {
40
+ const [head, ...rest] = parts;
41
+ if (head === undefined) return;
42
+ if (rest.length === 0) {
43
+ tree.leaves.set(head, placeholder);
44
+ return;
45
+ }
46
+ const existing = tree.leaves.get(head);
47
+ const child = typeof existing === 'object' ? existing : { leaves: new Map() };
48
+ tree.leaves.set(head, child);
49
+ insert(child, rest, placeholder);
50
+ }
51
+
52
+ /** `drawn.a`, then `(drawn.a as Record<string, unknown>).b`: each step typechecks as pasted. */
53
+ const member = (access: string, key: string): string => {
54
+ const on = access === 'drawn' ? access : `(${access} as Record<string, unknown>)`;
55
+ return IDENTIFIER.test(key) ? `${on}.${key}` : `${on}[${JSON.stringify(key)}]`;
56
+ };
57
+
58
+ function renderTree(tree: Tree, access: string): string {
59
+ const spread = access === 'drawn' ? '...drawn' : `...(${access} as object)`;
60
+ const fields = [...tree.leaves].map(([key, value]) => {
61
+ const rendered =
62
+ typeof value === 'string' ? placeholderOf(value) : renderTree(value, member(access, key));
63
+ return `, ${renderExerciseKey(key)}: ${rendered}`;
64
+ });
65
+ return `{ ${spread}${fields.join('')} }`;
66
+ }
67
+
68
+ /**
69
+ * `(drawn) => ({ ...drawn, digest: "<must match ^[0-9a-f]{64}$>" })`. A nested path keeps its
70
+ * parent's draw (`a: { ...(drawn.a as object), b: … }`); a gap at the root (`''`) replaces it.
71
+ */
72
+ export function renderDrawnInput(bindings: readonly DrawnBinding[]): string {
73
+ const root = bindings.find((binding) => binding.path === '');
74
+ if (root !== undefined) return `() => ${placeholderOf(root.placeholder)}`;
75
+ const tree: Tree = { leaves: new Map() };
76
+ for (const binding of bindings) insert(tree, binding.path.split('.'), binding.placeholder);
77
+ return `(drawn) => (${renderTree(tree, 'drawn')})`;
78
+ }
@@ -7,7 +7,7 @@
7
7
  import { assert } from './assert';
8
8
  import type { ErrorStatusOf } from './declared-errors';
9
9
  import { type Environment, resolveEnvironment } from './environment';
10
- import { isFixShellSafe, renderThrowable } from './error-render';
10
+ import { isFixShellSafe, renderFixShellArg, renderThrowable } from './error-render';
11
11
  import { isUltimateError } from './errors';
12
12
  import { ExerciseEnvironmentError, ExerciseUnscopedError } from './exercise-errors';
13
13
  import { fnv1a } from './fnv1a';
@@ -124,7 +124,8 @@ export async function runExercise(subject: ExerciseSubject): Promise<ExerciseVer
124
124
  assert(
125
125
  Number.isInteger(runs) && runs >= 1 && runs <= EXERCISE_RUNS_MAX,
126
126
  `${name}: exercise runs must be a whole number from 1 to ${EXERCISE_RUNS_MAX}`,
127
- `${name}.contract({ exercise: { actor, runs: ${EXERCISE_RUNS} } })`,
127
+ // The entry's one home, read by the contract step and `x exercise` alike.
128
+ `defineExercise({ ${renderFixShellArg(name, '<name>')}: { actor, runs: ${EXERCISE_RUNS} } }) # in apps/web/exercise.ts — runs is 1 to ${EXERCISE_RUNS_MAX}`,
128
129
  );
129
130
  const seed = fnv1a(name);
130
131
  const outcomes: string[] = [];
package/src/index.ts CHANGED
@@ -383,6 +383,9 @@ export {
383
383
  tryResolveEnvironment,
384
384
  } from './environment';
385
385
  export { ExerciseEnvironmentError, ExerciseUnscopedError } from './exercise-errors';
386
+ // The `input:` every exercise fix pastes, owed fields named: one renderer for action, query and testing.
387
+ export type { DrawnBinding } from './exercise-hint';
388
+ export { renderDrawnInput, renderExerciseKey, sampleGapBinding } from './exercise-hint';
386
389
  // A contract exercise's one loop: `@ultimat3/action`'s and `@ultimat3/query`'s, one tier apart from neither.
387
390
  export type {
388
391
  DrawnInput,