@intentius/chant 0.124.57 → 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 (121) hide show
  1. package/dist/ci-product-words.d.ts +47 -2
  2. package/dist/ci-product-words.d.ts.map +1 -1
  3. package/dist/ci-product-words.js +59 -1
  4. package/dist/ci-product.d.ts +26 -2
  5. package/dist/ci-product.d.ts.map +1 -1
  6. package/dist/ci-product.js +26 -2
  7. package/dist/cli/commands/init.d.ts +2 -0
  8. package/dist/cli/commands/init.d.ts.map +1 -1
  9. package/dist/cli/commands/init.js +1 -1
  10. package/dist/cli/handlers/build.d.ts.map +1 -1
  11. package/dist/cli/handlers/build.js +5 -1
  12. package/dist/cli/handlers/init.d.ts.map +1 -1
  13. package/dist/cli/handlers/init.js +16 -0
  14. package/dist/cli/handlers/serve.d.ts.map +1 -1
  15. package/dist/cli/handlers/serve.js +9 -0
  16. package/dist/cli/main.d.ts.map +1 -1
  17. package/dist/cli/main.js +6 -2
  18. package/dist/cli/mcp/product-tools.d.ts +40 -7
  19. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  20. package/dist/cli/mcp/product-tools.js +59 -15
  21. package/dist/cli/mcp/read-only.d.ts +2 -1
  22. package/dist/cli/mcp/read-only.d.ts.map +1 -1
  23. package/dist/cli/mcp/read-only.js +2 -1
  24. package/dist/cli/mcp/server.d.ts +11 -0
  25. package/dist/cli/mcp/server.d.ts.map +1 -1
  26. package/dist/cli/mcp/server.js +15 -3
  27. package/dist/cli/mcp-config.d.ts +4 -1
  28. package/dist/cli/mcp-config.d.ts.map +1 -1
  29. package/dist/cli/mcp-config.js +6 -2
  30. package/dist/cli/parse-args.d.ts.map +1 -1
  31. package/dist/cli/parse-args.js +9 -0
  32. package/dist/cli/registry.d.ts +8 -0
  33. package/dist/cli/registry.d.ts.map +1 -1
  34. package/dist/components/pr-pipeline.d.ts +56 -0
  35. package/dist/components/pr-pipeline.d.ts.map +1 -1
  36. package/dist/components/pr-pipeline.js +55 -2
  37. package/dist/components/product-pipeline.d.ts +18 -1
  38. package/dist/components/product-pipeline.d.ts.map +1 -1
  39. package/dist/components/product-pipeline.js +8 -2
  40. package/dist/e2e-harness/driver.d.ts.map +1 -1
  41. package/dist/e2e-harness/driver.js +97 -0
  42. package/dist/e2e-harness/forgejo.d.ts +5 -1
  43. package/dist/e2e-harness/forgejo.d.ts.map +1 -1
  44. package/dist/e2e-harness/forgejo.js +35 -0
  45. package/dist/e2e-harness/index.d.ts +7 -0
  46. package/dist/e2e-harness/index.d.ts.map +1 -1
  47. package/dist/e2e-harness/index.js +11 -1
  48. package/dist/e2e-harness/ports.d.ts +31 -0
  49. package/dist/e2e-harness/ports.d.ts.map +1 -1
  50. package/dist/e2e-harness/scenario.d.ts.map +1 -1
  51. package/dist/e2e-harness/scenario.js +9 -5
  52. package/dist/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
  53. package/dist/e2e-harness/schemas/index.d.ts +22 -1
  54. package/dist/e2e-harness/schemas/index.d.ts.map +1 -1
  55. package/dist/e2e-harness/schemas/index.js +1 -1
  56. package/dist/e2e-harness/steps.d.ts.map +1 -1
  57. package/dist/e2e-harness/steps.js +4 -0
  58. package/dist/mcp/types.d.ts +9 -0
  59. package/dist/mcp/types.d.ts.map +1 -1
  60. package/dist/release-floors.d.ts +1 -1
  61. package/dist/release-floors.js +1 -1
  62. package/dist/template-request/index.d.ts +9 -0
  63. package/dist/template-request/index.d.ts.map +1 -0
  64. package/dist/template-request/index.js +8 -0
  65. package/dist/template-request/request-body.d.ts +21 -0
  66. package/dist/template-request/request-body.d.ts.map +1 -0
  67. package/dist/template-request/request-body.js +86 -0
  68. package/dist/template-request/template-request.d.ts +100 -0
  69. package/dist/template-request/template-request.d.ts.map +1 -0
  70. package/dist/template-request/template-request.js +150 -0
  71. package/dist/template-request/template-request.schema.json +100 -0
  72. package/dist/template-request/template-spec.d.ts +83 -0
  73. package/dist/template-request/template-spec.d.ts.map +1 -0
  74. package/dist/template-request/template-spec.js +146 -0
  75. package/dist/template-request/template.schema.json +114 -0
  76. package/dist/template-request/validate.d.ts +4 -0
  77. package/dist/template-request/validate.d.ts.map +1 -0
  78. package/dist/template-request/validate.js +21 -0
  79. package/dist/wave-runtime.mjs +4 -4
  80. package/package.json +8 -1
  81. package/src/ci-product-words.test.ts +23 -0
  82. package/src/ci-product-words.ts +68 -3
  83. package/src/ci-product.ts +32 -1
  84. package/src/cli/commands/init.ts +3 -1
  85. package/src/cli/handlers/build.ts +5 -1
  86. package/src/cli/handlers/init.ts +18 -0
  87. package/src/cli/handlers/serve.ts +9 -0
  88. package/src/cli/main.ts +6 -2
  89. package/src/cli/mcp/product-tools.test.ts +57 -1
  90. package/src/cli/mcp/product-tools.ts +67 -15
  91. package/src/cli/mcp/read-only.ts +2 -1
  92. package/src/cli/mcp/server.ts +20 -5
  93. package/src/cli/mcp-config.test.ts +52 -2
  94. package/src/cli/mcp-config.ts +6 -3
  95. package/src/cli/parse-args.ts +7 -0
  96. package/src/cli/registry.ts +8 -0
  97. package/src/components/pr-pipeline.ts +87 -2
  98. package/src/components/product-actions.test.ts +76 -0
  99. package/src/components/product-pipeline.ts +21 -2
  100. package/src/e2e-harness/driver.test.ts +163 -0
  101. package/src/e2e-harness/driver.ts +86 -1
  102. package/src/e2e-harness/forgejo.ts +42 -1
  103. package/src/e2e-harness/index.ts +12 -1
  104. package/src/e2e-harness/ports.ts +33 -0
  105. package/src/e2e-harness/scenario.ts +8 -6
  106. package/src/e2e-harness/schemas/README.md +11 -2
  107. package/src/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
  108. package/src/e2e-harness/schemas/index.ts +5 -1
  109. package/src/e2e-harness/schemas.test.ts +44 -1
  110. package/src/e2e-harness/steps.ts +4 -0
  111. package/src/mcp/types.ts +9 -0
  112. package/src/release-floors.ts +1 -1
  113. package/src/template-request/__fixtures__/request-body.md +41 -0
  114. package/src/template-request/index.ts +8 -0
  115. package/src/template-request/request-body.ts +91 -0
  116. package/src/template-request/template-request.schema.json +100 -0
  117. package/src/template-request/template-request.test.ts +316 -0
  118. package/src/template-request/template-request.ts +235 -0
  119. package/src/template-request/template-spec.ts +176 -0
  120. package/src/template-request/template.schema.json +114 -0
  121. package/src/template-request/validate.ts +28 -0
@@ -0,0 +1,100 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://intentius.io/chant/schemas/template-request/v1/template-request.schema.json",
4
+ "title": "chant template request",
5
+ "description": "A request for an app, or an add-on to an app, made from one version of a template in a release catalog, version 1 of its contract. A product turns it into a pull request on the branch requestBranch names, with requestBody as the body; the body carries this document in a fenced block whose info string is `json` and this schema's id, so a reader recovers it from the pull request alone. checkTemplateRequest refuses a request against the catalog and the version's template.yml (template.schema.json). Readers ignore fields they do not know; a field is only ever added within a version.",
6
+ "type": "object",
7
+ "required": [
8
+ "$schema",
9
+ "contract",
10
+ "kind",
11
+ "template",
12
+ "version",
13
+ "app",
14
+ "inputs",
15
+ "requestedBy",
16
+ "via"
17
+ ],
18
+ "properties": {
19
+ "$schema": {
20
+ "const": "https://intentius.io/chant/schemas/template-request/v1/template-request.schema.json"
21
+ },
22
+ "contract": {
23
+ "const": 1
24
+ },
25
+ "kind": {
26
+ "enum": [
27
+ "app",
28
+ "addon"
29
+ ],
30
+ "description": "app: a new app. addon: an add-on to the app named in `app`, which must exist."
31
+ },
32
+ "template": {
33
+ "type": "string",
34
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*(/[A-Za-z0-9][A-Za-z0-9._-]*)*$",
35
+ "description": "The template's address, such as `acme/bucket/aws` (namespace, name, system). The branch uses its name: the second-to-last segment of an address with three or more, else the last."
36
+ },
37
+ "version": {
38
+ "type": "string",
39
+ "minLength": 1,
40
+ "description": "The version in the catalog, or its digest for a release that names no version."
41
+ },
42
+ "app": {
43
+ "type": "string",
44
+ "pattern": "^[a-z][a-z0-9-]{0,39}$",
45
+ "description": "The app's name: a lowercase letter, then up to 39 lowercase letters, digits and -."
46
+ },
47
+ "addon": {
48
+ "type": "string",
49
+ "pattern": "^[a-z][a-z0-9-]{0,39}$",
50
+ "description": "For kind addon: the add-on's name, with the same rule as `app`."
51
+ },
52
+ "inputs": {
53
+ "type": "object",
54
+ "description": "The values given, by input name. An input left out takes its default. A sensitive input is never here. In an add-on request, a string `app.<output>` names an output of the app's module, for an input of any kind; the engine's renderer resolves it. In an app request it is a plain string and is checked against the input's kind.",
55
+ "additionalProperties": true
56
+ },
57
+ "requestedBy": {
58
+ "type": "string",
59
+ "minLength": 1,
60
+ "description": "Who asked, as the forge vouches for it: the login of the run's actor, a person or the identity an agent runs as."
61
+ },
62
+ "claimedBy": {
63
+ "type": "string",
64
+ "minLength": 1,
65
+ "description": "The person the client says filled the form or asked the agent, when it names one. The forge does not vouch for it, so a reader shows it as claimed, next to requestedBy."
66
+ },
67
+ "via": {
68
+ "enum": [
69
+ "form",
70
+ "mcp",
71
+ "cli"
72
+ ],
73
+ "description": "Where the request came from: a form, an agent over MCP, or the command line."
74
+ }
75
+ },
76
+ "allOf": [
77
+ {
78
+ "if": {
79
+ "properties": {
80
+ "kind": {
81
+ "const": "addon"
82
+ }
83
+ }
84
+ },
85
+ "then": {
86
+ "properties": {
87
+ "addon": true
88
+ },
89
+ "required": [
90
+ "addon"
91
+ ]
92
+ },
93
+ "else": {
94
+ "properties": {
95
+ "addon": false
96
+ }
97
+ }
98
+ }
99
+ ]
100
+ }
@@ -0,0 +1,83 @@
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
+ /** The template.yml `$schema`, when the file names one. */
18
+ export declare const TEMPLATE_SPEC_SCHEMA_ID: string;
19
+ /** The template.yml contract version. */
20
+ export declare const TEMPLATE_SPEC_CONTRACT = 1;
21
+ /** A kind whose values are JSON scalars. */
22
+ export type TemplateScalarKind = "string" | "number" | "bool";
23
+ /** An input's engine-neutral kind. */
24
+ export type TemplateInputKind = TemplateScalarKind | "list" | "map" | "object";
25
+ /** Every input kind, in the order the schema lists them. */
26
+ export declare const TEMPLATE_INPUT_KINDS: readonly TemplateInputKind[];
27
+ /** One input of a template. */
28
+ export interface TemplateInput {
29
+ name: string;
30
+ kind: TemplateInputKind;
31
+ /** For a list or a map: the kind of each element or value. Absent: any JSON value. */
32
+ of?: TemplateScalarKind;
33
+ /** The form field's label. Absent: the name. */
34
+ label?: string;
35
+ description?: string;
36
+ /** The value a request that gives none takes. */
37
+ default?: unknown;
38
+ /** Absent: true when there is no default. */
39
+ required?: boolean;
40
+ /** A secret, which a request never carries. */
41
+ sensitive?: boolean;
42
+ }
43
+ /** A parsed template.yml. */
44
+ export interface TemplateSpec {
45
+ $schema?: string;
46
+ contract: 1;
47
+ /** Absent: `app`. */
48
+ kind?: "app" | "addon";
49
+ description: string;
50
+ inputs: TemplateInput[];
51
+ }
52
+ /** Thrown when a template.yml is not valid, with one line per problem. */
53
+ export declare class TemplateSpecError extends Error {
54
+ readonly problems: string[];
55
+ constructor(problems: string[]);
56
+ }
57
+ /** Whether a request must give `input`: its own `required`, else true when it has no default. */
58
+ export declare function inputRequired(input: TemplateInput): boolean;
59
+ /** The JSON type a value has, as a problem line names it. */
60
+ export declare function jsonKindOf(value: unknown): string;
61
+ /** An app-output reference, `app.<output>`, with the output in group 1. */
62
+ export declare const APP_OUTPUT_REF: RegExp;
63
+ /** The output an `app.<output>` value names, or undefined when `value` is not one. */
64
+ export declare function appOutputRef(value: unknown): string | undefined;
65
+ /** True when `value` is an app-output reference, `app.<output>`. */
66
+ export declare function isAppOutputRef(value: unknown): value is string;
67
+ /**
68
+ * Why `value` is not of `input`'s kind, or undefined when it is. A null is
69
+ * never of a kind: a request that wants the default leaves the input out.
70
+ */
71
+ export declare function inputKindProblem(input: Pick<TemplateInput, "kind" | "of">, value: unknown): string | undefined;
72
+ /**
73
+ * Every problem with a template.yml document, one line each: the schema's,
74
+ * then two inputs with one name, a default that is not of its input's kind,
75
+ * and an input both required and given a default.
76
+ */
77
+ export declare function templateSpecProblems(doc: unknown): string[];
78
+ /**
79
+ * Read a template.yml from its YAML text or its parsed value. Throws
80
+ * {@link TemplateSpecError} when it does not parse or is not valid.
81
+ */
82
+ export declare function parseTemplateSpec(text: string | unknown): TemplateSpec;
83
+ //# sourceMappingURL=template-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-spec.d.ts","sourceRoot":"","sources":["../../src/template-request/template-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,2DAA2D;AAC3D,eAAO,MAAM,uBAAuB,EAAE,MAAmB,CAAC;AAE1D,yCAAyC;AACzC,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,4CAA4C;AAC5C,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE9D,sCAAsC;AACtC,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE/E,4DAA4D;AAC5D,eAAO,MAAM,oBAAoB,EAAE,SAAS,iBAAiB,EAA0D,CAAC;AAExH,+BAA+B;AAC/B,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;IACxB,sFAAsF;IACtF,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,6BAA6B;AAC7B,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,CAAC,CAAC;IACZ,qBAAqB;IACrB,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;AAED,0EAA0E;AAC1E,qBAAa,iBAAkB,SAAQ,KAAK;aACd,QAAQ,EAAE,MAAM,EAAE;IAA9C,YAA4B,QAAQ,EAAE,MAAM,EAAE,EAG7C;CACF;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAE3D;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMjD;AAUD,2EAA2E;AAC3E,eAAO,MAAM,cAAc,EAAE,MAA2C,CAAC;AAEzE,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAE/D;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAuB9G;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAgB3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,YAAY,CAatE"}
@@ -0,0 +1,146 @@
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
+ import schema from "./template.schema.json" with { type: "json" };
18
+ import { parseYAMLDocument, YAMLParseError } from "../yaml.js";
19
+ import { schemaProblems } from "./validate.js";
20
+ /** The template.yml `$schema`, when the file names one. */
21
+ export const TEMPLATE_SPEC_SCHEMA_ID = schema.$id;
22
+ /** The template.yml contract version. */
23
+ export const TEMPLATE_SPEC_CONTRACT = 1;
24
+ /** Every input kind, in the order the schema lists them. */
25
+ export const TEMPLATE_INPUT_KINDS = ["string", "number", "bool", "list", "map", "object"];
26
+ /** Thrown when a template.yml is not valid, with one line per problem. */
27
+ export class TemplateSpecError extends Error {
28
+ constructor(problems) {
29
+ super(`template.yml is not valid: ${problems.join("; ")}`);
30
+ this.problems = problems;
31
+ this.name = "TemplateSpecError";
32
+ }
33
+ }
34
+ /** Whether a request must give `input`: its own `required`, else true when it has no default. */
35
+ export function inputRequired(input) {
36
+ return input.required ?? !("default" in input);
37
+ }
38
+ /** The JSON type a value has, as a problem line names it. */
39
+ export function jsonKindOf(value) {
40
+ if (value === null)
41
+ return "null";
42
+ if (Array.isArray(value))
43
+ return "list";
44
+ if (typeof value === "boolean")
45
+ return "bool";
46
+ if (typeof value === "object")
47
+ return "object";
48
+ return typeof value;
49
+ }
50
+ const isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
51
+ function scalarFits(kind, value) {
52
+ if (kind === "string")
53
+ return typeof value === "string";
54
+ if (kind === "number")
55
+ return typeof value === "number" && Number.isFinite(value);
56
+ return typeof value === "boolean";
57
+ }
58
+ /** An app-output reference, `app.<output>`, with the output in group 1. */
59
+ export const APP_OUTPUT_REF = /^app\.([A-Za-z_][A-Za-z0-9_-]*)$/;
60
+ /** The output an `app.<output>` value names, or undefined when `value` is not one. */
61
+ export function appOutputRef(value) {
62
+ return typeof value === "string" ? APP_OUTPUT_REF.exec(value)?.[1] : undefined;
63
+ }
64
+ /** True when `value` is an app-output reference, `app.<output>`. */
65
+ export function isAppOutputRef(value) {
66
+ return appOutputRef(value) !== undefined;
67
+ }
68
+ /**
69
+ * Why `value` is not of `input`'s kind, or undefined when it is. A null is
70
+ * never of a kind: a request that wants the default leaves the input out.
71
+ */
72
+ export function inputKindProblem(input, value) {
73
+ const want = input.of ? `${input.kind} of ${input.of}` : input.kind;
74
+ const bad = (detail) => `is ${detail ?? jsonKindOf(value)}, and the input is a ${want}`;
75
+ switch (input.kind) {
76
+ case "string":
77
+ case "number":
78
+ case "bool":
79
+ return scalarFits(input.kind, value) ? undefined : bad();
80
+ case "list": {
81
+ if (!Array.isArray(value))
82
+ return bad();
83
+ if (!input.of)
84
+ return undefined;
85
+ const at = value.findIndex((v) => !scalarFits(input.of, v));
86
+ return at < 0 ? undefined : bad(`a list whose element ${at} is ${jsonKindOf(value[at])}`);
87
+ }
88
+ case "map": {
89
+ if (!isPlainObject(value))
90
+ return bad();
91
+ if (!input.of)
92
+ return undefined;
93
+ const key = Object.keys(value).find((k) => !scalarFits(input.of, value[k]));
94
+ return key === undefined ? undefined : bad(`a map whose ${JSON.stringify(key)} is ${jsonKindOf(value[key])}`);
95
+ }
96
+ case "object":
97
+ return isPlainObject(value) ? undefined : bad();
98
+ }
99
+ }
100
+ /**
101
+ * Every problem with a template.yml document, one line each: the schema's,
102
+ * then two inputs with one name, a default that is not of its input's kind,
103
+ * and an input both required and given a default.
104
+ */
105
+ export function templateSpecProblems(doc) {
106
+ const problems = schemaProblems(TEMPLATE_SPEC_SCHEMA_ID, doc);
107
+ if (problems.length > 0)
108
+ return problems;
109
+ const spec = doc;
110
+ const seen = new Set();
111
+ spec.inputs.forEach((input, i) => {
112
+ const where = `/inputs/${i} (${input.name})`;
113
+ if (seen.has(input.name))
114
+ problems.push(`${where} repeats the name ${JSON.stringify(input.name)}`);
115
+ seen.add(input.name);
116
+ if ("default" in input) {
117
+ const p = inputKindProblem(input, input.default);
118
+ if (p)
119
+ problems.push(`${where} default ${p}`);
120
+ if (input.required === true)
121
+ problems.push(`${where} is required and has a default; an input with a default is optional`);
122
+ }
123
+ });
124
+ return problems;
125
+ }
126
+ /**
127
+ * Read a template.yml from its YAML text or its parsed value. Throws
128
+ * {@link TemplateSpecError} when it does not parse or is not valid.
129
+ */
130
+ export function parseTemplateSpec(text) {
131
+ let doc = text;
132
+ if (typeof text === "string") {
133
+ try {
134
+ doc = parseYAMLDocument(text);
135
+ }
136
+ catch (e) {
137
+ if (e instanceof YAMLParseError)
138
+ throw new TemplateSpecError([`not YAML: ${e.message}`]);
139
+ throw e;
140
+ }
141
+ }
142
+ const problems = templateSpecProblems(doc);
143
+ if (problems.length > 0)
144
+ throw new TemplateSpecError(problems);
145
+ return doc;
146
+ }
@@ -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,4 @@
1
+ /** One Ajv for the template-request/v1 schemas (template.yml and the request), compiled on first use. */
2
+ /** The problems of `doc` against the schema `id`, one line each; empty when it is valid. */
3
+ export declare function schemaProblems(id: string, doc: unknown): string[];
4
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/template-request/validate.ts"],"names":[],"mappings":"AAAA,yGAAyG;AAezG,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAWjE"}
@@ -0,0 +1,21 @@
1
+ /** One Ajv for the template-request/v1 schemas (template.yml and the request), compiled on first use. */
2
+ import requestSchema from "./template-request.schema.json" with { type: "json" };
3
+ import templateSchema from "./template.schema.json" with { type: "json" };
4
+ import { loadAjv2020 } from "../workspace/ajv2020.js";
5
+ let ajv;
6
+ /** The problems of `doc` against the schema `id`, one line each; empty when it is valid. */
7
+ export function schemaProblems(id, doc) {
8
+ if (!ajv) {
9
+ const Ajv = loadAjv2020();
10
+ const made = new Ajv({ allErrors: true, strict: true });
11
+ for (const s of [requestSchema, templateSchema])
12
+ made.addSchema(s);
13
+ ajv = made;
14
+ }
15
+ const fn = ajv.getSchema(id);
16
+ if (!fn)
17
+ throw new Error(`no schema ${id}`);
18
+ if (fn(doc))
19
+ return [];
20
+ return (fn.errors ?? []).map((e) => `${e.instancePath || "/"} ${e.message ?? "is not valid"}`);
21
+ }