@intentius/chant 0.124.56 → 0.124.58

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 (199) hide show
  1. package/dist/ci-audit/index.d.ts.map +1 -1
  2. package/dist/ci-audit/index.js +1 -2
  3. package/dist/ci-product-words.d.ts +47 -2
  4. package/dist/ci-product-words.d.ts.map +1 -1
  5. package/dist/ci-product-words.js +59 -1
  6. package/dist/ci-product.d.ts +26 -2
  7. package/dist/ci-product.d.ts.map +1 -1
  8. package/dist/ci-product.js +30 -7
  9. package/dist/cli/commands/init.d.ts +2 -0
  10. package/dist/cli/commands/init.d.ts.map +1 -1
  11. package/dist/cli/commands/init.js +1 -1
  12. package/dist/cli/handlers/build.d.ts.map +1 -1
  13. package/dist/cli/handlers/build.js +5 -1
  14. package/dist/cli/handlers/init.d.ts.map +1 -1
  15. package/dist/cli/handlers/init.js +16 -0
  16. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  17. package/dist/cli/handlers/lifecycle.js +14 -0
  18. package/dist/cli/handlers/pr.d.ts.map +1 -1
  19. package/dist/cli/handlers/pr.js +90 -35
  20. package/dist/cli/handlers/serve.d.ts.map +1 -1
  21. package/dist/cli/handlers/serve.js +9 -0
  22. package/dist/cli/main.d.ts.map +1 -1
  23. package/dist/cli/main.js +6 -2
  24. package/dist/cli/mcp/product-tools.d.ts +40 -7
  25. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  26. package/dist/cli/mcp/product-tools.js +59 -15
  27. package/dist/cli/mcp/read-only.d.ts +2 -1
  28. package/dist/cli/mcp/read-only.d.ts.map +1 -1
  29. package/dist/cli/mcp/read-only.js +2 -1
  30. package/dist/cli/mcp/server.d.ts +11 -0
  31. package/dist/cli/mcp/server.d.ts.map +1 -1
  32. package/dist/cli/mcp/server.js +15 -3
  33. package/dist/cli/mcp-config.d.ts +4 -1
  34. package/dist/cli/mcp-config.d.ts.map +1 -1
  35. package/dist/cli/mcp-config.js +6 -2
  36. package/dist/cli/parse-args.d.ts.map +1 -1
  37. package/dist/cli/parse-args.js +9 -0
  38. package/dist/cli/registry.d.ts +8 -0
  39. package/dist/cli/registry.d.ts.map +1 -1
  40. package/dist/components/auto-release.d.ts +5 -2
  41. package/dist/components/auto-release.d.ts.map +1 -1
  42. package/dist/components/auto-release.js +9 -4
  43. package/dist/components/capability.d.ts +10 -0
  44. package/dist/components/capability.d.ts.map +1 -1
  45. package/dist/components/deploy-units.d.ts +12 -0
  46. package/dist/components/deploy-units.d.ts.map +1 -1
  47. package/dist/components/deploy-units.js +20 -1
  48. package/dist/components/pr-pipeline.d.ts +64 -2
  49. package/dist/components/pr-pipeline.d.ts.map +1 -1
  50. package/dist/components/pr-pipeline.js +66 -5
  51. package/dist/components/product-pipeline.d.ts +18 -1
  52. package/dist/components/product-pipeline.d.ts.map +1 -1
  53. package/dist/components/product-pipeline.js +8 -2
  54. package/dist/components/row-lease.d.ts +22 -1
  55. package/dist/components/row-lease.d.ts.map +1 -1
  56. package/dist/components/row-lease.js +32 -6
  57. package/dist/e2e-harness/driver.d.ts.map +1 -1
  58. package/dist/e2e-harness/driver.js +97 -0
  59. package/dist/e2e-harness/forgejo.d.ts +5 -1
  60. package/dist/e2e-harness/forgejo.d.ts.map +1 -1
  61. package/dist/e2e-harness/forgejo.js +35 -0
  62. package/dist/e2e-harness/index.d.ts +7 -0
  63. package/dist/e2e-harness/index.d.ts.map +1 -1
  64. package/dist/e2e-harness/index.js +11 -2
  65. package/dist/e2e-harness/ports.d.ts +31 -0
  66. package/dist/e2e-harness/ports.d.ts.map +1 -1
  67. package/dist/e2e-harness/scenario.d.ts.map +1 -1
  68. package/dist/e2e-harness/scenario.js +9 -5
  69. package/dist/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
  70. package/dist/e2e-harness/schemas/index.d.ts +22 -1
  71. package/dist/e2e-harness/schemas/index.d.ts.map +1 -1
  72. package/dist/e2e-harness/schemas/index.js +1 -1
  73. package/dist/e2e-harness/steps.d.ts.map +1 -1
  74. package/dist/e2e-harness/steps.js +4 -0
  75. package/dist/lexicon.d.ts +9 -0
  76. package/dist/lexicon.d.ts.map +1 -1
  77. package/dist/lifecycle/git.d.ts +39 -3
  78. package/dist/lifecycle/git.d.ts.map +1 -1
  79. package/dist/lifecycle/git.js +223 -15
  80. package/dist/lifecycle/lock-rows.d.ts +23 -0
  81. package/dist/lifecycle/lock-rows.d.ts.map +1 -1
  82. package/dist/lifecycle/lock-rows.js +47 -8
  83. package/dist/lifecycle/resource-lock.d.ts +70 -0
  84. package/dist/lifecycle/resource-lock.d.ts.map +1 -1
  85. package/dist/lifecycle/resource-lock.js +241 -5
  86. package/dist/mcp/types.d.ts +9 -0
  87. package/dist/mcp/types.d.ts.map +1 -1
  88. package/dist/op/gate.js +21 -4
  89. package/dist/op/op-waves-release-port.js +1 -1
  90. package/dist/op/op-waves-release.d.ts +2 -1
  91. package/dist/op/op-waves-release.d.ts.map +1 -1
  92. package/dist/op/op-waves-run.d.ts +8 -0
  93. package/dist/op/op-waves-run.d.ts.map +1 -1
  94. package/dist/op/op-waves-run.js +101 -29
  95. package/dist/op/op-waves.d.ts +18 -0
  96. package/dist/op/op-waves.d.ts.map +1 -1
  97. package/dist/op/op-waves.js +16 -0
  98. package/dist/pr-loop.d.ts.map +1 -1
  99. package/dist/pr-loop.js +1 -2
  100. package/dist/release-floors.d.ts +1 -1
  101. package/dist/release-floors.js +1 -1
  102. package/dist/template-request/index.d.ts +9 -0
  103. package/dist/template-request/index.d.ts.map +1 -0
  104. package/dist/template-request/index.js +8 -0
  105. package/dist/template-request/request-body.d.ts +21 -0
  106. package/dist/template-request/request-body.d.ts.map +1 -0
  107. package/dist/template-request/request-body.js +86 -0
  108. package/dist/template-request/template-request.d.ts +100 -0
  109. package/dist/template-request/template-request.d.ts.map +1 -0
  110. package/dist/template-request/template-request.js +150 -0
  111. package/dist/template-request/template-request.schema.json +100 -0
  112. package/dist/template-request/template-spec.d.ts +83 -0
  113. package/dist/template-request/template-spec.d.ts.map +1 -0
  114. package/dist/template-request/template-spec.js +146 -0
  115. package/dist/template-request/template.schema.json +114 -0
  116. package/dist/template-request/validate.d.ts +4 -0
  117. package/dist/template-request/validate.d.ts.map +1 -0
  118. package/dist/template-request/validate.js +21 -0
  119. package/dist/wave-runtime.mjs +310 -300
  120. package/package.json +8 -1
  121. package/src/ci-audit/index.ts +1 -2
  122. package/src/ci-product-words.test.ts +23 -0
  123. package/src/ci-product-words.ts +68 -3
  124. package/src/ci-product.ts +36 -6
  125. package/src/cli/commands/init.ts +3 -1
  126. package/src/cli/handlers/build.ts +5 -1
  127. package/src/cli/handlers/init.ts +18 -0
  128. package/src/cli/handlers/lifecycle.ts +13 -0
  129. package/src/cli/handlers/pr-before-merge.test.ts +1 -1
  130. package/src/cli/handlers/pr-deploy-inputs.test.ts +1 -1
  131. package/src/cli/handlers/pr-endpoint.test.ts +1 -1
  132. package/src/cli/handlers/pr-green.test.ts +1 -1
  133. package/src/cli/handlers/pr-plan-comment-targets.test.ts +1 -1
  134. package/src/cli/handlers/pr-plan-flags.test.ts +1 -1
  135. package/src/cli/handlers/pr-plan-targets.test.ts +1 -1
  136. package/src/cli/handlers/pr-record.test.ts +34 -2
  137. package/src/cli/handlers/pr-waves-blocked.test.ts +1 -1
  138. package/src/cli/handlers/pr-waves.test.ts +1 -1
  139. package/src/cli/handlers/pr.test.ts +1 -1
  140. package/src/cli/handlers/pr.ts +86 -31
  141. package/src/cli/handlers/serve.ts +9 -0
  142. package/src/cli/main.ts +6 -2
  143. package/src/cli/mcp/product-tools.test.ts +57 -1
  144. package/src/cli/mcp/product-tools.ts +67 -15
  145. package/src/cli/mcp/read-only.ts +2 -1
  146. package/src/cli/mcp/server.ts +20 -5
  147. package/src/cli/mcp-config.test.ts +52 -2
  148. package/src/cli/mcp-config.ts +6 -3
  149. package/src/cli/parse-args.ts +7 -0
  150. package/src/cli/registry.ts +8 -0
  151. package/src/components/auto-release.test.ts +4 -2
  152. package/src/components/auto-release.ts +9 -5
  153. package/src/components/capability.ts +10 -0
  154. package/src/components/deploy-units.test.ts +18 -1
  155. package/src/components/deploy-units.ts +26 -1
  156. package/src/components/pr-pipeline.ts +99 -5
  157. package/src/components/product-actions.test.ts +76 -0
  158. package/src/components/product-pipeline.ts +21 -2
  159. package/src/components/row-lease.test.ts +61 -1
  160. package/src/components/row-lease.ts +48 -7
  161. package/src/e2e-harness/driver.test.ts +163 -0
  162. package/src/e2e-harness/driver.ts +86 -1
  163. package/src/e2e-harness/forgejo.ts +42 -1
  164. package/src/e2e-harness/index.ts +12 -2
  165. package/src/e2e-harness/ports.ts +33 -0
  166. package/src/e2e-harness/scenario.ts +8 -6
  167. package/src/e2e-harness/schemas/README.md +11 -2
  168. package/src/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
  169. package/src/e2e-harness/schemas/index.ts +5 -1
  170. package/src/e2e-harness/schemas.test.ts +44 -1
  171. package/src/e2e-harness/steps.ts +4 -0
  172. package/src/lexicon.ts +9 -0
  173. package/src/lifecycle/git.test.ts +155 -0
  174. package/src/lifecycle/git.ts +213 -17
  175. package/src/lifecycle/lock-rows.test.ts +6 -1
  176. package/src/lifecycle/lock-rows.ts +58 -7
  177. package/src/lifecycle/resource-lock-wait.test.ts +292 -0
  178. package/src/lifecycle/resource-lock.ts +261 -7
  179. package/src/mcp/types.ts +9 -0
  180. package/src/op/gate.test.ts +7 -5
  181. package/src/op/gate.ts +20 -4
  182. package/src/op/op-waves-after-plan.test.ts +1 -2
  183. package/src/op/op-waves-ledger-lock.test.ts +208 -0
  184. package/src/op/op-waves-release-port.ts +1 -1
  185. package/src/op/op-waves-release.ts +1 -1
  186. package/src/op/op-waves-run.ts +104 -29
  187. package/src/op/op-waves.ts +18 -0
  188. package/src/pr-loop-bundle.test.ts +0 -2
  189. package/src/pr-loop.ts +1 -2
  190. package/src/release-floors.ts +1 -1
  191. package/src/template-request/__fixtures__/request-body.md +41 -0
  192. package/src/template-request/index.ts +8 -0
  193. package/src/template-request/request-body.ts +91 -0
  194. package/src/template-request/template-request.schema.json +100 -0
  195. package/src/template-request/template-request.test.ts +316 -0
  196. package/src/template-request/template-request.ts +235 -0
  197. package/src/template-request/template-spec.ts +176 -0
  198. package/src/template-request/template.schema.json +114 -0
  199. package/src/template-request/validate.ts +28 -0
@@ -0,0 +1,176 @@
1
+ /**
2
+ * template.yml, version 1 (#4651, ruling B of #4642): what a template asks
3
+ * for when someone requests an app or an add-on from it. The file sits in
4
+ * the template's signed release; a form shows one field per input, and an
5
+ * agent or a command line reads the same list.
6
+ *
7
+ * Each input has an engine-neutral kind (`string`, `number`, `bool`,
8
+ * `list`, `map`, `object`, with `of` naming a list's or map's element kind).
9
+ * Core checks request values against the kind and never parses an engine's
10
+ * own type syntax; an engine maps the kinds to its types (the terraform
11
+ * lexicon, #4652).
12
+ *
13
+ * In an add-on request, a value `app.<output>` names an output of the app's
14
+ * own module, whatever the input's kind. Core accepts it as is and leaves
15
+ * the engine's renderer to resolve it and refuse an output the module lacks.
16
+ */
17
+
18
+ import schema from "./template.schema.json" with { type: "json" };
19
+ import { parseYAMLDocument, YAMLParseError } from "../yaml";
20
+ import { schemaProblems } from "./validate";
21
+
22
+ /** The template.yml `$schema`, when the file names one. */
23
+ export const TEMPLATE_SPEC_SCHEMA_ID: string = schema.$id;
24
+
25
+ /** The template.yml contract version. */
26
+ export const TEMPLATE_SPEC_CONTRACT = 1;
27
+
28
+ /** A kind whose values are JSON scalars. */
29
+ export type TemplateScalarKind = "string" | "number" | "bool";
30
+
31
+ /** An input's engine-neutral kind. */
32
+ export type TemplateInputKind = TemplateScalarKind | "list" | "map" | "object";
33
+
34
+ /** Every input kind, in the order the schema lists them. */
35
+ export const TEMPLATE_INPUT_KINDS: readonly TemplateInputKind[] = ["string", "number", "bool", "list", "map", "object"];
36
+
37
+ /** One input of a template. */
38
+ export interface TemplateInput {
39
+ name: string;
40
+ kind: TemplateInputKind;
41
+ /** For a list or a map: the kind of each element or value. Absent: any JSON value. */
42
+ of?: TemplateScalarKind;
43
+ /** The form field's label. Absent: the name. */
44
+ label?: string;
45
+ description?: string;
46
+ /** The value a request that gives none takes. */
47
+ default?: unknown;
48
+ /** Absent: true when there is no default. */
49
+ required?: boolean;
50
+ /** A secret, which a request never carries. */
51
+ sensitive?: boolean;
52
+ }
53
+
54
+ /** A parsed template.yml. */
55
+ export interface TemplateSpec {
56
+ $schema?: string;
57
+ contract: 1;
58
+ /** Absent: `app`. */
59
+ kind?: "app" | "addon";
60
+ description: string;
61
+ inputs: TemplateInput[];
62
+ }
63
+
64
+ /** Thrown when a template.yml is not valid, with one line per problem. */
65
+ export class TemplateSpecError extends Error {
66
+ constructor(public readonly problems: string[]) {
67
+ super(`template.yml is not valid: ${problems.join("; ")}`);
68
+ this.name = "TemplateSpecError";
69
+ }
70
+ }
71
+
72
+ /** Whether a request must give `input`: its own `required`, else true when it has no default. */
73
+ export function inputRequired(input: TemplateInput): boolean {
74
+ return input.required ?? !("default" in input);
75
+ }
76
+
77
+ /** The JSON type a value has, as a problem line names it. */
78
+ export function jsonKindOf(value: unknown): string {
79
+ if (value === null) return "null";
80
+ if (Array.isArray(value)) return "list";
81
+ if (typeof value === "boolean") return "bool";
82
+ if (typeof value === "object") return "object";
83
+ return typeof value;
84
+ }
85
+
86
+ const isPlainObject = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
87
+
88
+ function scalarFits(kind: TemplateScalarKind, value: unknown): boolean {
89
+ if (kind === "string") return typeof value === "string";
90
+ if (kind === "number") return typeof value === "number" && Number.isFinite(value);
91
+ return typeof value === "boolean";
92
+ }
93
+
94
+ /** An app-output reference, `app.<output>`, with the output in group 1. */
95
+ export const APP_OUTPUT_REF: RegExp = /^app\.([A-Za-z_][A-Za-z0-9_-]*)$/;
96
+
97
+ /** The output an `app.<output>` value names, or undefined when `value` is not one. */
98
+ export function appOutputRef(value: unknown): string | undefined {
99
+ return typeof value === "string" ? APP_OUTPUT_REF.exec(value)?.[1] : undefined;
100
+ }
101
+
102
+ /** True when `value` is an app-output reference, `app.<output>`. */
103
+ export function isAppOutputRef(value: unknown): value is string {
104
+ return appOutputRef(value) !== undefined;
105
+ }
106
+
107
+ /**
108
+ * Why `value` is not of `input`'s kind, or undefined when it is. A null is
109
+ * never of a kind: a request that wants the default leaves the input out.
110
+ */
111
+ export function inputKindProblem(input: Pick<TemplateInput, "kind" | "of">, value: unknown): string | undefined {
112
+ const want = input.of ? `${input.kind} of ${input.of}` : input.kind;
113
+ const bad = (detail?: string) => `is ${detail ?? jsonKindOf(value)}, and the input is a ${want}`;
114
+ switch (input.kind) {
115
+ case "string":
116
+ case "number":
117
+ case "bool":
118
+ return scalarFits(input.kind, value) ? undefined : bad();
119
+ case "list": {
120
+ if (!Array.isArray(value)) return bad();
121
+ if (!input.of) return undefined;
122
+ const at = value.findIndex((v) => !scalarFits(input.of!, v));
123
+ return at < 0 ? undefined : bad(`a list whose element ${at} is ${jsonKindOf(value[at])}`);
124
+ }
125
+ case "map": {
126
+ if (!isPlainObject(value)) return bad();
127
+ if (!input.of) return undefined;
128
+ const key = Object.keys(value).find((k) => !scalarFits(input.of!, value[k]));
129
+ return key === undefined ? undefined : bad(`a map whose ${JSON.stringify(key)} is ${jsonKindOf(value[key])}`);
130
+ }
131
+ case "object":
132
+ return isPlainObject(value) ? undefined : bad();
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Every problem with a template.yml document, one line each: the schema's,
138
+ * then two inputs with one name, a default that is not of its input's kind,
139
+ * and an input both required and given a default.
140
+ */
141
+ export function templateSpecProblems(doc: unknown): string[] {
142
+ const problems = schemaProblems(TEMPLATE_SPEC_SCHEMA_ID, doc);
143
+ if (problems.length > 0) return problems;
144
+ const spec = doc as TemplateSpec;
145
+ const seen = new Set<string>();
146
+ spec.inputs.forEach((input, i) => {
147
+ const where = `/inputs/${i} (${input.name})`;
148
+ if (seen.has(input.name)) problems.push(`${where} repeats the name ${JSON.stringify(input.name)}`);
149
+ seen.add(input.name);
150
+ if ("default" in input) {
151
+ const p = inputKindProblem(input, input.default);
152
+ if (p) problems.push(`${where} default ${p}`);
153
+ if (input.required === true) problems.push(`${where} is required and has a default; an input with a default is optional`);
154
+ }
155
+ });
156
+ return problems;
157
+ }
158
+
159
+ /**
160
+ * Read a template.yml from its YAML text or its parsed value. Throws
161
+ * {@link TemplateSpecError} when it does not parse or is not valid.
162
+ */
163
+ export function parseTemplateSpec(text: string | unknown): TemplateSpec {
164
+ let doc: unknown = text;
165
+ if (typeof text === "string") {
166
+ try {
167
+ doc = parseYAMLDocument(text);
168
+ } catch (e) {
169
+ if (e instanceof YAMLParseError) throw new TemplateSpecError([`not YAML: ${e.message}`]);
170
+ throw e;
171
+ }
172
+ }
173
+ const problems = templateSpecProblems(doc);
174
+ if (problems.length > 0) throw new TemplateSpecError(problems);
175
+ return doc as TemplateSpec;
176
+ }
@@ -0,0 +1,114 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://intentius.io/chant/schemas/template-request/v1/template.schema.json",
4
+ "title": "chant template",
5
+ "description": "template.yml, version 1 of its contract: what a template asks for when someone requests an app or an add-on from it. It sits in the template's signed release beside the code it describes. A form shows one field per input; an agent and a command line read the same list. Each input has an engine-neutral kind, and each engine maps the kinds to its own types. Readers ignore fields they do not know; a field is only ever added within a version.",
6
+ "type": "object",
7
+ "required": [
8
+ "contract",
9
+ "description",
10
+ "inputs"
11
+ ],
12
+ "properties": {
13
+ "$schema": {
14
+ "const": "https://intentius.io/chant/schemas/template-request/v1/template.schema.json"
15
+ },
16
+ "contract": {
17
+ "const": 1
18
+ },
19
+ "kind": {
20
+ "enum": [
21
+ "app",
22
+ "addon"
23
+ ],
24
+ "default": "app",
25
+ "description": "What a request makes from this template: a new app, or an add-on to an app that already exists."
26
+ },
27
+ "description": {
28
+ "type": "string",
29
+ "minLength": 1,
30
+ "description": "One or two sentences a person reads before requesting it."
31
+ },
32
+ "inputs": {
33
+ "type": "array",
34
+ "description": "The inputs, in the order a form shows them. Names are unique. An add-on request may give any input the string `app.<output>`, naming an output of the app's module, which the engine resolves.",
35
+ "items": {
36
+ "$ref": "#/$defs/input"
37
+ }
38
+ }
39
+ },
40
+ "$defs": {
41
+ "scalarKind": {
42
+ "enum": [
43
+ "string",
44
+ "number",
45
+ "bool"
46
+ ]
47
+ },
48
+ "kind": {
49
+ "description": "An input's engine-neutral kind. string: a JSON string. number: a finite JSON number. bool: true or false. list: a JSON array, each element of kind `of` when given. map: a JSON object, each value of kind `of` when given. object: a JSON object with any fields. An engine maps each kind to one of its own types (Terraform: string, number, bool, list(<of>), map(<of>), and any for object or for a list or map without `of`).",
50
+ "enum": [
51
+ "string",
52
+ "number",
53
+ "bool",
54
+ "list",
55
+ "map",
56
+ "object"
57
+ ]
58
+ },
59
+ "input": {
60
+ "type": "object",
61
+ "required": [
62
+ "name",
63
+ "kind"
64
+ ],
65
+ "properties": {
66
+ "name": {
67
+ "type": "string",
68
+ "pattern": "^[A-Za-z_][A-Za-z0-9_-]*$",
69
+ "description": "The name a request gives the value under, and the variable the engine sets."
70
+ },
71
+ "kind": {
72
+ "$ref": "#/$defs/kind"
73
+ },
74
+ "of": {
75
+ "$ref": "#/$defs/scalarKind",
76
+ "description": "For a list or a map only: the kind of each element or value."
77
+ },
78
+ "label": {
79
+ "type": "string",
80
+ "minLength": 1,
81
+ "description": "The form field's label. Absent: the name."
82
+ },
83
+ "description": {
84
+ "type": "string",
85
+ "description": "Help text shown under the field."
86
+ },
87
+ "default": {
88
+ "description": "The value used when a request gives none. It must be of the input's kind. An input with a default is optional."
89
+ },
90
+ "required": {
91
+ "type": "boolean",
92
+ "description": "Whether a request must give a value. Absent: true when there is no default, false when there is. An input with a default cannot be required."
93
+ },
94
+ "sensitive": {
95
+ "type": "boolean",
96
+ "default": false,
97
+ "description": "A secret. A request never carries it, because the request is written into a pull request; the app reads it from its own secret store."
98
+ }
99
+ },
100
+ "dependentSchemas": {
101
+ "of": {
102
+ "properties": {
103
+ "kind": {
104
+ "enum": [
105
+ "list",
106
+ "map"
107
+ ]
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
@@ -0,0 +1,28 @@
1
+ /** One Ajv for the template-request/v1 schemas (template.yml and the request), compiled on first use. */
2
+
3
+ import requestSchema from "./template-request.schema.json" with { type: "json" };
4
+ import templateSchema from "./template.schema.json" with { type: "json" };
5
+ import { loadAjv2020 } from "../workspace/ajv2020";
6
+
7
+ type ValidateFn = ((data: unknown) => boolean) & { errors?: { instancePath: string; message?: string }[] | null };
8
+
9
+ interface AjvInstance {
10
+ addSchema(schema: object): unknown;
11
+ getSchema(id: string): unknown;
12
+ }
13
+
14
+ let ajv: AjvInstance | undefined;
15
+
16
+ /** The problems of `doc` against the schema `id`, one line each; empty when it is valid. */
17
+ export function schemaProblems(id: string, doc: unknown): string[] {
18
+ if (!ajv) {
19
+ const Ajv = loadAjv2020();
20
+ const made = new Ajv({ allErrors: true, strict: true }) as unknown as AjvInstance;
21
+ for (const s of [requestSchema, templateSchema]) made.addSchema(s);
22
+ ajv = made;
23
+ }
24
+ const fn = ajv.getSchema(id) as ValidateFn | undefined;
25
+ if (!fn) throw new Error(`no schema ${id}`);
26
+ if (fn(doc)) return [];
27
+ return (fn.errors ?? []).map((e) => `${e.instancePath || "/"} ${e.message ?? "is not valid"}`);
28
+ }