@sous-io/sous 0.2.36 → 1.0.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.
- package/README.md +14 -256
- package/dist/bin.js +11 -0
- package/dist/sous.js +1093 -0
- package/docs/markdown/README.md +5 -4
- package/docs/markdown/_sidebar.md +21 -1
- package/docs/markdown/commands.md +294 -431
- package/docs/markdown/config-discovery.md +25 -14
- package/docs/markdown/config-inspection.md +53 -31
- package/docs/markdown/config-layers.md +168 -66
- package/docs/markdown/config-variables.md +44 -11
- package/docs/markdown/configuration.md +104 -17
- package/docs/markdown/design-principles.md +4 -1
- package/docs/markdown/repositories-authoring.md +30 -0
- package/docs/markdown/repositories-consuming.md +72 -14
- package/docs/markdown/repositories-file-formats.md +31 -13
- package/docs/markdown/repositories-providers.md +48 -57
- package/docs/markdown/repositories-quickstart.md +3 -2
- package/docs/markdown/repositories-troubleshooting.md +27 -1
- package/docs/markdown/repositories-variables.md +6 -1
- package/docs/markdown/repositories.md +18 -8
- package/package.json +48 -107
- package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +4 -6
- package/recipes/core/sous-skills/skills/about-liquid-templates/references/liquid-filters.tpl.md +2 -0
- package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +10 -9
- package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +35 -14
- package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +51 -20
- package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
- package/sous.config.schema.json +351 -132
- package/bin/run.js +0 -51
- package/src/base-command.ts +0 -457
- package/src/commands/build.ts +0 -181
- package/src/commands/clear.ts +0 -79
- package/src/commands/compile.ts +0 -155
- package/src/commands/config/get.ts +0 -110
- package/src/commands/config/show.ts +0 -32
- package/src/commands/config/validate.ts +0 -53
- package/src/commands/help.ts +0 -46
- package/src/commands/init.ts +0 -289
- package/src/commands/launch.ts +0 -139
- package/src/commands/lock/rebuild.ts +0 -239
- package/src/commands/lock/show.ts +0 -115
- package/src/commands/namespace/list.ts +0 -138
- package/src/commands/namespace/show.ts +0 -130
- package/src/commands/prune.ts +0 -43
- package/src/commands/recipe/list.ts +0 -112
- package/src/commands/recipe/show.ts +0 -439
- package/src/commands/repo/add.ts +0 -145
- package/src/commands/repo/contribute.ts +0 -604
- package/src/commands/repo/gc.ts +0 -173
- package/src/commands/repo/init.ts +0 -136
- package/src/commands/repo/link.ts +0 -899
- package/src/commands/repo/list.ts +0 -236
- package/src/commands/repo/release.ts +0 -685
- package/src/commands/repo/remove.ts +0 -194
- package/src/commands/repo/search.ts +0 -243
- package/src/commands/repo/submit.ts +0 -341
- package/src/commands/repo/unlink.ts +0 -461
- package/src/commands/subscription/add.ts +0 -286
- package/src/commands/subscription/list.ts +0 -208
- package/src/commands/subscription/remove.ts +0 -182
- package/src/commands/subscription/update.ts +0 -216
- package/src/commands/update.ts +0 -178
- package/src/commands/vars/ask.ts +0 -417
- package/src/commands/vars/index.ts +0 -79
- package/src/commands/vars/list.ts +0 -67
- package/src/commands/vars/show.ts +0 -77
- package/src/config-command.ts +0 -30
- package/src/lib/build-preparation.ts +0 -128
- package/src/lib/build-service.ts +0 -580
- package/src/lib/config-discovery.ts +0 -378
- package/src/lib/config-inspect.ts +0 -145
- package/src/lib/config-kernel.mjs +0 -379
- package/src/lib/config-schema.ts +0 -401
- package/src/lib/env-file.ts +0 -328
- package/src/lib/env-local.ts +0 -212
- package/src/lib/errors.ts +0 -32
- package/src/lib/glob-pattern.ts +0 -24
- package/src/lib/include-resolver.ts +0 -523
- package/src/lib/interactive.ts +0 -165
- package/src/lib/markdown-compiler.ts +0 -947
- package/src/lib/package-info.ts +0 -25
- package/src/lib/pid-service.ts +0 -99
- package/src/lib/project-install.d.mts +0 -44
- package/src/lib/project-install.mjs +0 -234
- package/src/lib/project-scaffold/index.ts +0 -332
- package/src/lib/project-scaffold/templates.ts +0 -240
- package/src/lib/repos/catalog-display.ts +0 -215
- package/src/lib/repos/catalog-inputs.ts +0 -288
- package/src/lib/repos/catalog.ts +0 -842
- package/src/lib/repos/contribute.ts +0 -452
- package/src/lib/repos/core-recipe.ts +0 -105
- package/src/lib/repos/declarations.ts +0 -187
- package/src/lib/repos/defaults.ts +0 -175
- package/src/lib/repos/formats/common.ts +0 -440
- package/src/lib/repos/formats/index-file.ts +0 -253
- package/src/lib/repos/formats/links-map.ts +0 -98
- package/src/lib/repos/formats/lockfile.ts +0 -169
- package/src/lib/repos/formats/patterns.ts +0 -57
- package/src/lib/repos/formats/recipe-manifest.ts +0 -205
- package/src/lib/repos/formats/repo-manifest.ts +0 -97
- package/src/lib/repos/formats/store-entry.ts +0 -84
- package/src/lib/repos/formats/variable-definition.ts +0 -268
- package/src/lib/repos/freshness.ts +0 -264
- package/src/lib/repos/git-clone.ts +0 -850
- package/src/lib/repos/identity.ts +0 -89
- package/src/lib/repos/index.ts +0 -57
- package/src/lib/repos/links.ts +0 -356
- package/src/lib/repos/load-manifest.ts +0 -237
- package/src/lib/repos/lock-service.ts +0 -454
- package/src/lib/repos/locked-namespace-resolver.ts +0 -232
- package/src/lib/repos/locked-recipe-lookup.ts +0 -123
- package/src/lib/repos/locked-recipes.ts +0 -254
- package/src/lib/repos/managed-layer.ts +0 -422
- package/src/lib/repos/memories-hash-name.ts +0 -33
- package/src/lib/repos/namespace-resolver.ts +0 -527
- package/src/lib/repos/providers/base.ts +0 -268
- package/src/lib/repos/providers/git.ts +0 -237
- package/src/lib/repos/providers/github.ts +0 -589
- package/src/lib/repos/providers/gitlab.ts +0 -332
- package/src/lib/repos/providers/http.ts +0 -128
- package/src/lib/repos/providers/index-cache.ts +0 -421
- package/src/lib/repos/providers/index.ts +0 -106
- package/src/lib/repos/providers/local.ts +0 -391
- package/src/lib/repos/providers/provider.ts +0 -615
- package/src/lib/repos/recipe-config-layers.ts +0 -316
- package/src/lib/repos/recipe-key-matcher.ts +0 -62
- package/src/lib/repos/recipe-memories.ts +0 -178
- package/src/lib/repos/recipe-targets.ts +0 -236
- package/src/lib/repos/ref-search.ts +0 -46
- package/src/lib/repos/release/bump.ts +0 -161
- package/src/lib/repos/release/changelog.ts +0 -461
- package/src/lib/repos/release/git-state.ts +0 -460
- package/src/lib/repos/release/index-builder.ts +0 -1108
- package/src/lib/repos/release/index.ts +0 -19
- package/src/lib/repos/release/plan.ts +0 -521
- package/src/lib/repos/release/settle.ts +0 -154
- package/src/lib/repos/release/submissions.ts +0 -214
- package/src/lib/repos/release/submit-checkout.ts +0 -290
- package/src/lib/repos/release/submit-questions.ts +0 -153
- package/src/lib/repos/release/submit-service.ts +0 -898
- package/src/lib/repos/release/tags.ts +0 -239
- package/src/lib/repos/release/validate.ts +0 -463
- package/src/lib/repos/resolver.ts +0 -1028
- package/src/lib/repos/scaffold/index.ts +0 -245
- package/src/lib/repos/scaffold/templates.ts +0 -517
- package/src/lib/repos/seed.ts +0 -473
- package/src/lib/repos/store/contract.ts +0 -64
- package/src/lib/repos/store/hash.ts +0 -191
- package/src/lib/repos/store/recipe-store.ts +0 -599
- package/src/lib/repos/store/settings.ts +0 -58
- package/src/lib/repos/subscription-service.ts +0 -3859
- package/src/lib/repos/trust.ts +0 -447
- package/src/lib/repos/update-plan.ts +0 -235
- package/src/lib/self-update/index.ts +0 -14
- package/src/lib/self-update/installs.ts +0 -412
- package/src/lib/self-update/managers.ts +0 -126
- package/src/lib/self-update/plan.ts +0 -315
- package/src/lib/self-update/registry.ts +0 -99
- package/src/lib/self-update/run.ts +0 -506
- package/src/lib/self-update/versions.ts +0 -243
- package/src/lib/settings.ts +0 -1105
- package/src/lib/sous-home.ts +0 -104
- package/src/lib/state.ts +0 -167
- package/src/lib/vars/answers.ts +0 -192
- package/src/lib/vars/ask.ts +0 -1152
- package/src/lib/vars/definition-source.ts +0 -261
- package/src/lib/vars/display.ts +0 -231
- package/src/lib/vars/index.ts +0 -20
- package/src/lib/vars/ladder.ts +0 -282
- package/src/lib/vars/mappings.ts +0 -260
- package/src/lib/vars/names.ts +0 -94
- package/src/lib/vars/preanswers.ts +0 -395
- package/src/lib/vars/question-plan.ts +0 -241
- package/src/lib/vars/report.ts +0 -228
- package/src/lib/vars/safe-regex.ts +0 -235
- package/src/lib/vars/secrets.ts +0 -131
- package/src/lib/vars/validate.ts +0 -312
- package/src/lib/version-report.ts +0 -90
- package/src/lib/watch-loop.ts +0 -148
- package/src/lib/watch-service.ts +0 -116
- package/src/services/ref-resolver/container.ts +0 -107
- package/src/services/ref-resolver/dependency.ts +0 -60
- package/src/services/ref-resolver/format.ts +0 -197
- package/src/services/ref-resolver/glob.ts +0 -115
- package/src/services/ref-resolver/hash-names.ts +0 -155
- package/src/services/ref-resolver/index.ts +0 -55
- package/src/services/ref-resolver/injectable.ts +0 -36
- package/src/services/ref-resolver/location.ts +0 -62
- package/src/services/ref-resolver/lookups/cached-index-lookup.ts +0 -53
- package/src/services/ref-resolver/lookups/catalog-lookup.ts +0 -23
- package/src/services/ref-resolver/lookups/catalog-matcher.ts +0 -261
- package/src/services/ref-resolver/lookups/chained-lookup.ts +0 -27
- package/src/services/ref-resolver/lookups/env-var-lookup.ts +0 -65
- package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +0 -150
- package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +0 -62
- package/src/services/ref-resolver/lookups/ref-lookup.ts +0 -54
- package/src/services/ref-resolver/lookups/variable-lookup.ts +0 -123
- package/src/services/ref-resolver/named-refs.ts +0 -144
- package/src/services/ref-resolver/parser/env-var-splitter.ts +0 -27
- package/src/services/ref-resolver/parser/location-splitter.ts +0 -239
- package/src/services/ref-resolver/parser/name-path-splitter.ts +0 -200
- package/src/services/ref-resolver/parser/partial-ref.ts +0 -84
- package/src/services/ref-resolver/parser/query-splitter.ts +0 -61
- package/src/services/ref-resolver/parser/range-splitter.ts +0 -52
- package/src/services/ref-resolver/parser/ref-parser.ts +0 -115
- package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +0 -51
- package/src/services/ref-resolver/parts.ts +0 -115
- package/src/services/ref-resolver/pruners/command-line-pruner.ts +0 -47
- package/src/services/ref-resolver/pruners/include-pruner.ts +0 -66
- package/src/services/ref-resolver/pruners/manifest-pruner.ts +0 -130
- package/src/services/ref-resolver/pruners/ref-pruner.ts +0 -135
- package/src/services/ref-resolver/pruners/rule-helpers.ts +0 -44
- package/src/services/ref-resolver/pruners/stored-key-pruner.ts +0 -136
- package/src/services/ref-resolver/ref-helpers.ts +0 -62
- package/src/services/ref-resolver/ref-picker-service.ts +0 -204
- package/src/services/ref-resolver/ref-report.ts +0 -84
- package/src/services/ref-resolver/ref-resolve-arguments.ts +0 -47
- package/src/services/ref-resolver/ref-resolve-result.ts +0 -36
- package/src/services/ref-resolver/ref-resolver-service.ts +0 -323
- package/src/services/ref-resolver/source.ts +0 -48
- package/src/services/ref-resolver/tokens.ts +0 -25
- package/src/services/ref-resolver/types.ts +0 -155
- package/src/templating/filters/bullet-list.ts +0 -9
- package/src/templating/filters/index.ts +0 -8
- package/src/templating/init-liquid-engine.ts +0 -139
- package/src/templating/lib/glob-files.ts +0 -74
- package/src/templating/lib/import-export.ts +0 -32
- package/src/templating/lib/secret-scope.ts +0 -41
- package/src/templating/lib/tag-args.ts +0 -19
- package/src/templating/tags/exportScalarVarsJs.ts +0 -46
- package/src/templating/tags/getFiles.ts +0 -89
- package/src/templating/tags/index.ts +0 -14
- package/src/templating/tags/listFiles.ts +0 -54
- package/src/templating/tags/showVars.ts +0 -28
- package/src/utils/choice-prompt.ts +0 -143
- package/src/utils/command-errors.ts +0 -186
- package/src/utils/command-help.ts +0 -45
- package/src/utils/confirm-prompt.ts +0 -110
- package/src/utils/flags.ts +0 -177
- package/src/utils/formatting.ts +0 -849
- package/src/utils/prompts.ts +0 -53
- package/src/utils/sous-directory.ts +0 -245
- package/src/utils/table.ts +0 -603
- package/src/utils/value-prompt.ts +0 -119
|
@@ -1,440 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared building blocks for every Repositories on-disk format.
|
|
3
|
-
*
|
|
4
|
-
* Each format module (repo manifest, recipe manifest, index file, lockfile,
|
|
5
|
-
* store entry marker, links map) composes the primitives defined here, so a
|
|
6
|
-
* namespace name, a content hash or a timestamp means exactly the same thing
|
|
7
|
-
* everywhere. This module also holds the canonical file names and the shared
|
|
8
|
-
* `parseFormat` helper that turns a zod failure into a readable ConfigError.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { z } from "zod";
|
|
12
|
-
import semver from "semver";
|
|
13
|
-
import { ConfigError } from "../../errors.js";
|
|
14
|
-
import {
|
|
15
|
-
CONTENT_HASH_PATTERN,
|
|
16
|
-
ENV_VAR_NAME_PATTERN,
|
|
17
|
-
ISO_TIMESTAMP_PATTERN,
|
|
18
|
-
KEBAB_NAME_PATTERN,
|
|
19
|
-
NAMESPACE_NAME_PATTERN,
|
|
20
|
-
RECIPE_KEY_PATTERN,
|
|
21
|
-
RECIPE_NAME_PATTERN,
|
|
22
|
-
REF_KEY_PATTERN,
|
|
23
|
-
REPO_IDENTITY_PATTERN,
|
|
24
|
-
REPO_NAME_PATTERN,
|
|
25
|
-
VARIABLE_NAME_PATTERN,
|
|
26
|
-
} from "./patterns.js";
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
CONTENT_HASH_PATTERN,
|
|
30
|
-
ENV_VAR_NAME_PATTERN,
|
|
31
|
-
ISO_TIMESTAMP_PATTERN,
|
|
32
|
-
KEBAB_NAME_PATTERN,
|
|
33
|
-
NAMESPACE_NAME_PATTERN,
|
|
34
|
-
RECIPE_KEY_PATTERN,
|
|
35
|
-
RECIPE_NAME_PATTERN,
|
|
36
|
-
REF_KEY_PATTERN,
|
|
37
|
-
REPO_IDENTITY_PATTERN,
|
|
38
|
-
REPO_NAME_PATTERN,
|
|
39
|
-
VARIABLE_NAME_PATTERN,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// --- Format version -----------------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The only on-disk format version this sous understands. Every manifest, index,
|
|
46
|
-
* lockfile, store entry marker and links map carries it as `formatVersion`, so
|
|
47
|
-
* a future incompatible change can be detected instead of misread.
|
|
48
|
-
*/
|
|
49
|
-
export const SUPPORTED_FORMAT_VERSION = 1;
|
|
50
|
-
|
|
51
|
-
/** The `formatVersion` field, present in every Repositories format. */
|
|
52
|
-
export const formatVersionSchema = z.literal(SUPPORTED_FORMAT_VERSION, {
|
|
53
|
-
message:
|
|
54
|
-
`must be ${SUPPORTED_FORMAT_VERSION}; this version of sous understands no other ` +
|
|
55
|
-
`on-disk format version`,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// --- Canonical file names -----------------------------------------------------------------------
|
|
59
|
-
|
|
60
|
-
/** Base name (without extension) of the repo manifest, at a repo's root. */
|
|
61
|
-
export const REPO_MANIFEST_BASENAME = "sous.repo";
|
|
62
|
-
|
|
63
|
-
/** Base name (without extension) of a recipe manifest, in each recipe folder. */
|
|
64
|
-
export const RECIPE_MANIFEST_BASENAME = "sous.recipe";
|
|
65
|
-
|
|
66
|
-
/** File name of the machine-written repo index, at a repo's root. */
|
|
67
|
-
export const INDEX_FILENAME = "sous.index.json";
|
|
68
|
-
|
|
69
|
-
/** File name of the project lockfile, inside the project's `.sous/` directory. */
|
|
70
|
-
export const LOCKFILE_FILENAME = "sous.lock.json";
|
|
71
|
-
|
|
72
|
-
/** File name of the marker written beside every store entry. */
|
|
73
|
-
export const STORE_ENTRY_FILENAME = ".sous.entry.json";
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Directory, inside the store root, that cached repository indexes live in. It
|
|
77
|
-
* is named here rather than in the index cache so the store can skip it while
|
|
78
|
-
* walking its own entries without depending on the provider layer.
|
|
79
|
-
*/
|
|
80
|
-
export const INDEX_CACHE_DIRNAME = "_indexes";
|
|
81
|
-
|
|
82
|
-
/** File name of the links map, in a project's `.sous/` directory or in `$SOUS_HOME`. */
|
|
83
|
-
export const LINKS_FILENAME = "sous.links.json";
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Extensions a hand-written manifest may use, in the order they are tried when
|
|
87
|
-
* discovering one. Both `.json` and `.jsonc` are parsed permissively (comments
|
|
88
|
-
* and trailing commas are allowed); see `load-manifest.ts`.
|
|
89
|
-
*/
|
|
90
|
-
export const MANIFEST_EXTENSIONS = [".yaml", ".yml", ".json", ".jsonc"] as const;
|
|
91
|
-
|
|
92
|
-
// --- Name primitives ----------------------------------------------------------------------------
|
|
93
|
-
|
|
94
|
-
/** Builds a kebab-case name schema with a message naming what is being named. */
|
|
95
|
-
function kebabName(label: string, example: string) {
|
|
96
|
-
return z
|
|
97
|
-
.string()
|
|
98
|
-
.regex(
|
|
99
|
-
KEBAB_NAME_PATTERN,
|
|
100
|
-
`a ${label} must be lowercase kebab-case: a letter, then letters, digits or ` +
|
|
101
|
-
`hyphens (for example '${example}')`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** A repo's short name, as used by the `repo:` qualifier on a ref. */
|
|
106
|
-
export const repoNameSchema = kebabName("repo name", "sous-recipes");
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* A repository's canonical identity, `<host>/<owner path>/<name>`. Everything
|
|
110
|
-
* shared between projects (the machine-wide store, the index cache, a
|
|
111
|
-
* lockfile's record of where a recipe came from) keys by this rather than by a
|
|
112
|
-
* short name, because a short name is one project's private label.
|
|
113
|
-
*/
|
|
114
|
-
export const repoIdentitySchema = z
|
|
115
|
-
.string()
|
|
116
|
-
.regex(
|
|
117
|
-
REPO_IDENTITY_PATTERN,
|
|
118
|
-
"a repository identity must be its host followed by the path it lives at, all " +
|
|
119
|
-
"lowercase (for example 'github.com/sous-io/sous-recipes')"
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
/** A namespace name. */
|
|
123
|
-
export const namespaceNameSchema = kebabName("namespace name", "tool-usage");
|
|
124
|
-
|
|
125
|
-
/** A recipe name, unique within its namespace. */
|
|
126
|
-
export const recipeNameSchema = kebabName("recipe name", "task-files");
|
|
127
|
-
|
|
128
|
-
/** A camelCase variable name, as declared by a recipe variable definition. */
|
|
129
|
-
export const variableNameSchema = z
|
|
130
|
-
.string()
|
|
131
|
-
.regex(
|
|
132
|
-
VARIABLE_NAME_PATTERN,
|
|
133
|
-
"a variable name must be camelCase: a lowercase letter, then letters or digits " +
|
|
134
|
-
"(for example 'apiBaseUrl')"
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
/** An explicit environment variable name for a variable definition. */
|
|
138
|
-
export const envVarNameSchema = z
|
|
139
|
-
.string()
|
|
140
|
-
.regex(
|
|
141
|
-
ENV_VAR_NAME_PATTERN,
|
|
142
|
-
"an environment variable name must be upper snake case: a capital letter, then " +
|
|
143
|
-
"capitals, digits or underscores (for example 'GITHUB_TOKEN')"
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
/** A ref key: a bare namespace, or `namespace/recipe`. Never repo-qualified or ranged. */
|
|
147
|
-
export const refKeySchema = z
|
|
148
|
-
.string()
|
|
149
|
-
.regex(
|
|
150
|
-
REF_KEY_PATTERN,
|
|
151
|
-
"a ref key must be a namespace ('workflow') or a namespace and recipe " +
|
|
152
|
-
"('workflow/task-files'), with no repo qualifier and no version range"
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
/** A recipe key: always `namespace/recipe`. */
|
|
156
|
-
export const recipeKeySchema = z
|
|
157
|
-
.string()
|
|
158
|
-
.regex(
|
|
159
|
-
RECIPE_KEY_PATTERN,
|
|
160
|
-
"a recipe key must be a namespace and recipe joined by a slash " +
|
|
161
|
-
"(for example 'workflow/task-files')"
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* The two ways one recipe can bring in another, named after the manifest lists
|
|
166
|
-
* that declare them: `subscribes` is a co-subscription, whose files land in the
|
|
167
|
-
* project and whose questions are asked; `depends` is a build dependency, a
|
|
168
|
-
* library whose files never reach the project's output.
|
|
169
|
-
*/
|
|
170
|
-
export const DEPENDENCY_KINDS = ["subscribes", "depends"] as const;
|
|
171
|
-
|
|
172
|
-
/** A co-subscription or a build dependency. */
|
|
173
|
-
export const dependencyKindSchema = z.enum(DEPENDENCY_KINDS);
|
|
174
|
-
|
|
175
|
-
/** A co-subscription or a build dependency. */
|
|
176
|
-
export type DependencyKind = (typeof DEPENDENCY_KINDS)[number];
|
|
177
|
-
|
|
178
|
-
// --- Value primitives ---------------------------------------------------------------------------
|
|
179
|
-
|
|
180
|
-
/** An exact semantic version, as published by a recipe. */
|
|
181
|
-
export const semverVersionSchema = z
|
|
182
|
-
.string()
|
|
183
|
-
.refine((value) => semver.valid(value) !== null, {
|
|
184
|
-
message:
|
|
185
|
-
"must be an exact semantic version, such as '1.4.0' or '2.0.0-beta.1'",
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
/** A semantic version range, resolved with the same rules npm uses. */
|
|
189
|
-
export const semverRangeSchema = z
|
|
190
|
-
.string()
|
|
191
|
-
.refine((value) => semver.validRange(value) !== null, {
|
|
192
|
-
message:
|
|
193
|
-
"must be a semantic version range, such as '^1.2.0', '~2.1', '>=1.0.0 <2.0.0' or '*'",
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
/** A content hash over a recipe's files, written as `sha256-` plus lowercase hex. */
|
|
197
|
-
export const contentHashSchema = z
|
|
198
|
-
.string()
|
|
199
|
-
.regex(
|
|
200
|
-
CONTENT_HASH_PATTERN,
|
|
201
|
-
"a content hash must be written as 'sha256-' followed by 64 lowercase hexadecimal characters"
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
/** An ISO 8601 timestamp with an explicit offset. */
|
|
205
|
-
export const isoTimestampSchema = z
|
|
206
|
-
.string()
|
|
207
|
-
.regex(
|
|
208
|
-
ISO_TIMESTAMP_PATTERN,
|
|
209
|
-
"must be an ISO 8601 timestamp with an offset, such as '2026-09-09T14:03:11.482Z'"
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
/** A byte count: a whole number, never negative. */
|
|
213
|
-
export const byteCountSchema = z
|
|
214
|
-
.number()
|
|
215
|
-
.int("must be a whole number of bytes")
|
|
216
|
-
.min(0, "must not be negative");
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Where a repository lives. A hosted repository is named by a URL; a repository
|
|
220
|
-
* on this machine, which the `local` provider reads, is named by an absolute
|
|
221
|
-
* path or by the same path in `file:///...` form (which is already a URL).
|
|
222
|
-
*/
|
|
223
|
-
export const repoUrlSchema = z.union([
|
|
224
|
-
z.url(),
|
|
225
|
-
z
|
|
226
|
-
.string()
|
|
227
|
-
.min(1, "must not be empty")
|
|
228
|
-
.refine((value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value), {
|
|
229
|
-
message: "must be a repository URL, or an absolute path to one on this machine",
|
|
230
|
-
}),
|
|
231
|
-
]);
|
|
232
|
-
|
|
233
|
-
/** An absolute filesystem path. */
|
|
234
|
-
export const absolutePathSchema = z
|
|
235
|
-
.string()
|
|
236
|
-
.min(1, "must not be empty")
|
|
237
|
-
.refine((value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value), {
|
|
238
|
-
message: "must be an absolute path",
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Builds a schema for a path that stays inside the directory holding the file
|
|
243
|
-
* that declares it. Rejects absolute paths, backslashes, `.` and `..` segments,
|
|
244
|
-
* empty segments and trailing slashes, so a manifest can never reach outside
|
|
245
|
-
* its own repo or recipe.
|
|
246
|
-
*
|
|
247
|
-
* @param label - What the path names, used in error messages.
|
|
248
|
-
* @param allowGlobs - When true, `*`, `?`, `[...]`, `{...}` and a `**` segment are allowed.
|
|
249
|
-
*/
|
|
250
|
-
export function relativePathSchema(label: string, allowGlobs = false) {
|
|
251
|
-
return z.string().superRefine((value, ctx) => {
|
|
252
|
-
const fail = (message: string) => {
|
|
253
|
-
ctx.addIssue({ code: "custom", message: `${label} ${message}` });
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
if (value.length === 0) {
|
|
257
|
-
fail("must not be empty");
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
if (value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value)) {
|
|
261
|
-
fail("must be relative, not absolute");
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
if (value.includes("\\")) {
|
|
265
|
-
fail("must use forward slashes, never backslashes");
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
if (value.endsWith("/")) {
|
|
269
|
-
fail("must not end with a slash");
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (!allowGlobs && /[*?[\]{}]/.test(value)) {
|
|
273
|
-
fail("must be a plain path, with no glob characters");
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
for (const segment of value.split("/")) {
|
|
278
|
-
if (segment.length === 0) {
|
|
279
|
-
fail("must not contain an empty path segment");
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (segment === "." || segment === "..") {
|
|
283
|
-
fail("must not contain a '.' or '..' segment");
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// --- Object helpers -----------------------------------------------------------------------------
|
|
291
|
-
|
|
292
|
-
/** True when the value is a plain object (not null, not an array). */
|
|
293
|
-
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
294
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Drops keys in the reserved `x-` extension namespace from a plain object.
|
|
299
|
-
* Anything that is not a plain object passes through untouched, so the wrapped
|
|
300
|
-
* object schema still reports "expected object" for a string or an array.
|
|
301
|
-
*/
|
|
302
|
-
function stripExtensionKeys(value: unknown): unknown {
|
|
303
|
-
if (!isPlainObject(value)) return value;
|
|
304
|
-
let found = false;
|
|
305
|
-
for (const key of Object.keys(value)) {
|
|
306
|
-
if (key.startsWith("x-")) {
|
|
307
|
-
found = true;
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
if (!found) return value;
|
|
312
|
-
|
|
313
|
-
const copy: Record<string, unknown> = {};
|
|
314
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
315
|
-
if (!key.startsWith("x-")) copy[key] = entry;
|
|
316
|
-
}
|
|
317
|
-
return copy;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Builds a strict object schema for a HAND-WRITTEN format: unknown keys are
|
|
322
|
-
* rejected so typos surface immediately, except keys in the reserved `x-`
|
|
323
|
-
* extension namespace, which are accepted and ignored. Machine-written formats
|
|
324
|
-
* use `z.strictObject` or `forwardCompatibleObject` instead; nothing writes
|
|
325
|
-
* extension keys into them.
|
|
326
|
-
*/
|
|
327
|
-
export function extensibleObject<Shape extends z.ZodRawShape>(shape: Shape) {
|
|
328
|
-
return z.preprocess(stripExtensionKeys, z.strictObject(shape));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Builds an object schema for a machine-written format that other versions of
|
|
333
|
-
* sous publish and this one reads: the repo index. Every known key is validated
|
|
334
|
-
* exactly as strictly as `z.strictObject` would, and a key this version does not
|
|
335
|
-
* define is kept, unread, rather than refused.
|
|
336
|
-
*
|
|
337
|
-
* A later sous adds fields to the index, and a repository published by it is
|
|
338
|
-
* read by every older sous a project happens to pin; refusing the whole index
|
|
339
|
-
* over a field it cannot use would break those projects for nothing. The key is
|
|
340
|
-
* kept rather than dropped, so a release carrying a published version forward
|
|
341
|
-
* writes it back byte for byte, whichever sous runs the release.
|
|
342
|
-
*/
|
|
343
|
-
export function forwardCompatibleObject<Shape extends z.ZodRawShape>(shape: Shape) {
|
|
344
|
-
return z.looseObject(shape);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* The `submissions` block a repo manifest and a recipe manifest may both carry:
|
|
349
|
-
* whether the recipes it covers take proposed changes, and where to send a
|
|
350
|
-
* change instead when they do not. On a repo manifest it covers every recipe;
|
|
351
|
-
* on a recipe manifest it covers that recipe, and wins over the repository's.
|
|
352
|
-
*
|
|
353
|
-
* submissions:
|
|
354
|
-
* allowed: false
|
|
355
|
-
* instead: Propose changes in sous-io/sous, under recipes/core/sous-skills/.
|
|
356
|
-
*/
|
|
357
|
-
export const submissionsSchema = extensibleObject({
|
|
358
|
-
/** Whether a proposed change to the covered recipes is accepted. Defaults to true. */
|
|
359
|
-
allowed: z.boolean().default(true),
|
|
360
|
-
/** Where a change should go instead, printed when one is proposed anyway. */
|
|
361
|
-
instead: z.string().min(1, "must not be empty").optional(),
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
/** A validated `submissions` block. */
|
|
365
|
-
export type Submissions = z.infer<typeof submissionsSchema>;
|
|
366
|
-
|
|
367
|
-
// --- Error reporting ----------------------------------------------------------------------------
|
|
368
|
-
|
|
369
|
-
/** Renders a zod issue path (`["variables",0,"name"]`) as `variables[0].name`. */
|
|
370
|
-
export function formatIssuePath(parts: ReadonlyArray<PropertyKey>): string {
|
|
371
|
-
let out = "";
|
|
372
|
-
for (const part of parts) {
|
|
373
|
-
if (typeof part === "number") out += `[${part}]`;
|
|
374
|
-
else out += out.length > 0 ? `.${String(part)}` : String(part);
|
|
375
|
-
}
|
|
376
|
-
return out;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Validates a value against a format schema, returning it typed. Throws a
|
|
381
|
-
* ConfigError (never a raw ZodError) naming the format, the file it came from
|
|
382
|
-
* and the path of every bad field.
|
|
383
|
-
*
|
|
384
|
-
* @param schema - The zod schema for the format.
|
|
385
|
-
* @param value - The already-parsed file contents.
|
|
386
|
-
* @param sourceLabel - The file path (or other label) named in error messages.
|
|
387
|
-
* @param formatLabel - Plain-language name of the format, such as "recipe manifest".
|
|
388
|
-
*/
|
|
389
|
-
export function parseFormat<Schema extends z.ZodType>(
|
|
390
|
-
schema: Schema,
|
|
391
|
-
value: unknown,
|
|
392
|
-
sourceLabel: string,
|
|
393
|
-
formatLabel: string
|
|
394
|
-
): z.output<Schema> {
|
|
395
|
-
const result = schema.safeParse(value);
|
|
396
|
-
if (result.success) return result.data;
|
|
397
|
-
|
|
398
|
-
const lines: string[] = [`Invalid ${formatLabel} at ${sourceLabel}:`];
|
|
399
|
-
for (const issue of result.error.issues) {
|
|
400
|
-
const where = formatIssuePath(issue.path);
|
|
401
|
-
if (issue.code === "unrecognized_keys") {
|
|
402
|
-
const keys = issue.keys.map((key) => `'${key}'`).join(", ");
|
|
403
|
-
const location = where.length > 0 ? `under '${where}'` : "at the top level";
|
|
404
|
-
lines.push(
|
|
405
|
-
` - unknown key ${keys} ${location}. This is likely a typo; sous ignores ` +
|
|
406
|
-
`only keys that start with 'x-'.`
|
|
407
|
-
);
|
|
408
|
-
} else if (issue.code === "invalid_key") {
|
|
409
|
-
// zod reports a bad record KEY as a generic "Invalid key in record" and
|
|
410
|
-
// hides the real reason in a nested issue list. Surface the reason, since
|
|
411
|
-
// it is the part that tells the author how to fix the key.
|
|
412
|
-
const reasons = issue.issues.map((inner) => inner.message).join("; ");
|
|
413
|
-
lines.push(` - ${where}: invalid key; ${reasons}`);
|
|
414
|
-
} else {
|
|
415
|
-
lines.push(` - ${where.length > 0 ? where : "(root)"}: ${issue.message}`);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
throw new ConfigError(lines.join("\n"));
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Serializes a value as pretty-printed JSON with every object key sorted, so a
|
|
424
|
-
* machine-written file produces a stable, minimal diff between runs.
|
|
425
|
-
*/
|
|
426
|
-
export function stableJsonStringify(value: unknown): string {
|
|
427
|
-
return JSON.stringify(sortKeysDeep(value), null, 2) + "\n";
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/** Recursively rebuilds plain objects with their keys in sorted order. */
|
|
431
|
-
function sortKeysDeep(value: unknown): unknown {
|
|
432
|
-
if (Array.isArray(value)) return value.map(sortKeysDeep);
|
|
433
|
-
if (!isPlainObject(value)) return value;
|
|
434
|
-
|
|
435
|
-
const sorted: Record<string, unknown> = {};
|
|
436
|
-
for (const key of Object.keys(value).sort()) {
|
|
437
|
-
sorted[key] = sortKeysDeep(value[key]);
|
|
438
|
-
}
|
|
439
|
-
return sorted;
|
|
440
|
-
}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The repo index: `sous.index.json` at a repo's root.
|
|
3
|
-
*
|
|
4
|
-
* The index is MACHINE-WRITTEN by `sous repo release` and committed alongside
|
|
5
|
-
* the recipes it describes. It is the portable contract across providers: every
|
|
6
|
-
* provider, whatever its API looks like, can hand back this one file, and it is
|
|
7
|
-
* all sous needs to resolve a ref, enumerate published versions and check
|
|
8
|
-
* whether a cached copy is current.
|
|
9
|
-
*
|
|
10
|
-
* Adding a repo fetches only this file. Nothing else is downloaded until a
|
|
11
|
-
* project subscribes to something inside it.
|
|
12
|
-
*
|
|
13
|
-
* Every object in it is a `forwardCompatibleObject`: a field a later sous adds is
|
|
14
|
-
* kept and ignored rather than refused, so an index published by a newer sous
|
|
15
|
-
* still reads here. The fields this version defines are validated in full.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { z } from "zod";
|
|
19
|
-
import {
|
|
20
|
-
contentHashSchema,
|
|
21
|
-
dependencyKindSchema,
|
|
22
|
-
formatVersionSchema,
|
|
23
|
-
forwardCompatibleObject,
|
|
24
|
-
isoTimestampSchema,
|
|
25
|
-
namespaceNameSchema,
|
|
26
|
-
parseFormat,
|
|
27
|
-
recipeKeySchema,
|
|
28
|
-
relativePathSchema,
|
|
29
|
-
repoIdentitySchema,
|
|
30
|
-
repoNameSchema,
|
|
31
|
-
semverRangeSchema,
|
|
32
|
-
semverVersionSchema,
|
|
33
|
-
stableJsonStringify,
|
|
34
|
-
} from "./common.js";
|
|
35
|
-
import { publishedVariableDefinitionSchema } from "./variable-definition.js";
|
|
36
|
-
import { namespaceOfKey } from "../../../services/ref-resolver/index.js";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* One dependency of one published version, as the release resolved it.
|
|
40
|
-
*
|
|
41
|
-
* A SIBLING (a recipe in this same repository) always resolves to an exact
|
|
42
|
-
* version, because the release that wrote this entry cut that sibling's tag or
|
|
43
|
-
* found it already cut. A CROSS-REPOSITORY dependency carries the identity of
|
|
44
|
-
* the repository it lives in, which is what a consumer needs in order to add
|
|
45
|
-
* that repository and find the recipe in the store; the version it resolves to
|
|
46
|
-
* belongs to that repository's own index, so this entry carries the range the
|
|
47
|
-
* manifest declared instead.
|
|
48
|
-
*/
|
|
49
|
-
export const indexDependencySchema = forwardCompatibleObject({
|
|
50
|
-
/** The exact version this dependency resolved to, when the release could resolve one. */
|
|
51
|
-
version: semverVersionSchema.optional(),
|
|
52
|
-
/** The range the manifest declared, recorded when no exact version could be resolved. */
|
|
53
|
-
range: semverRangeSchema.optional(),
|
|
54
|
-
/**
|
|
55
|
-
* The canonical identity of the repository publishing it
|
|
56
|
-
* (`github.com/sous-io/sous-recipes`). Omitted for a sibling, which lives in
|
|
57
|
-
* this same repository.
|
|
58
|
-
*/
|
|
59
|
-
repo: repoIdentitySchema.optional(),
|
|
60
|
-
/**
|
|
61
|
-
* The entry of the version's manifest that brings this dependency in, exactly
|
|
62
|
-
* as it was written: a recipe (`workflow/task-files`, with its range when it
|
|
63
|
-
* has one), a whole namespace of this repository (`workflow`), or a locator
|
|
64
|
-
* naming a recipe in another repository. When several entries cover the same
|
|
65
|
-
* recipe, the one naming it wins over a namespace. Absent on an entry recorded
|
|
66
|
-
* before sous described recipes in the index (ADR 0010).
|
|
67
|
-
*/
|
|
68
|
-
declared: z.string().min(1, "must not be empty").optional(),
|
|
69
|
-
/**
|
|
70
|
-
* Whether that brings it in as a co-subscription (`subscribes`: its files
|
|
71
|
-
* land in the project and its questions are asked) or as a build dependency
|
|
72
|
-
* (`depends`: a library only); `subscribes` when any entry covering it is a
|
|
73
|
-
* co-subscription. Recorded alongside `declared`.
|
|
74
|
-
*/
|
|
75
|
-
kind: dependencyKindSchema.optional(),
|
|
76
|
-
}).refine((entry) => entry.version !== undefined || entry.range !== undefined, {
|
|
77
|
-
message:
|
|
78
|
-
"must record either the exact version this dependency resolved to or the range " +
|
|
79
|
-
"the recipe declared",
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
/** One published version of one recipe. */
|
|
83
|
-
export const indexVersionSchema = forwardCompatibleObject({
|
|
84
|
-
/** Content hash of the recipe folder at this version, verified after every fetch. */
|
|
85
|
-
hash: contentHashSchema,
|
|
86
|
-
/**
|
|
87
|
-
* The git tag carrying this version, shaped `namespace/recipe@version`. The
|
|
88
|
-
* index's `superRefine` checks it against the key and version it sits under,
|
|
89
|
-
* so a version can never point at a branch or at another recipe's tag.
|
|
90
|
-
*/
|
|
91
|
-
tag: z.string().min(1, "must not be empty"),
|
|
92
|
-
/** True when the version is a prerelease, which ranges skip unless opted in. */
|
|
93
|
-
prerelease: z.boolean(),
|
|
94
|
-
/**
|
|
95
|
-
* True when this version is not one the repository published, but the copy of
|
|
96
|
-
* the recipe that ships inside the installed sous package, folded into the
|
|
97
|
-
* index in memory so it can be resolved like anything else.
|
|
98
|
-
*
|
|
99
|
-
* Sous never writes this onto a copy of an index it fetched; a cached index
|
|
100
|
-
* stays exactly what upstream served. The field exists so that a listing can
|
|
101
|
-
* say the version came packaged with sous rather than from the repository, and
|
|
102
|
-
* so a reader of the stand-in index sous writes for itself can tell.
|
|
103
|
-
*/
|
|
104
|
-
seeded: z.boolean().optional(),
|
|
105
|
-
/** When the version was released. */
|
|
106
|
-
releasedAt: isoTimestampSchema.optional(),
|
|
107
|
-
/**
|
|
108
|
-
* What this exact version depends on, resolved at release time and keyed
|
|
109
|
-
* `namespace/recipe`. A consumer installing this version installs these
|
|
110
|
-
* versions rather than re-resolving the ranges its manifest declared, so a
|
|
111
|
-
* published version means one thing forever.
|
|
112
|
-
*
|
|
113
|
-
* The field is additive: an index written before it existed still parses, and
|
|
114
|
-
* a consumer that finds no entry falls back to the manifest's ranges. A
|
|
115
|
-
* version described in full (ADR 0010) carries this field even when it is
|
|
116
|
-
* empty, so "depends on nothing" and "not recorded" read differently.
|
|
117
|
-
*/
|
|
118
|
-
dependencies: z.record(recipeKeySchema, indexDependencySchema).optional(),
|
|
119
|
-
/**
|
|
120
|
-
* The variable definitions this version's manifest publishes, in manifest
|
|
121
|
-
* order: the questions subscribing to it asks. An empty list means it asks
|
|
122
|
-
* none; an absent field means the release that recorded the version did not
|
|
123
|
-
* record them (a release made before ADR 0010), and only the recipe's own
|
|
124
|
-
* files can say.
|
|
125
|
-
*/
|
|
126
|
-
variables: z.array(publishedVariableDefinitionSchema).optional(),
|
|
127
|
-
/**
|
|
128
|
-
* The version's manifest `depends` and `subscribes` lists, exactly as
|
|
129
|
-
* written, so a consumer walks a recipe whose files it has not fetched the
|
|
130
|
-
* same way it walks its manifest: a namespace still expands to what the
|
|
131
|
-
* namespace holds, including a namespace of another repository, which no
|
|
132
|
-
* key of `dependencies` can record. Written, even when empty, beside
|
|
133
|
-
* `variables`; absent on a version recorded before ADR 0010. Kept as plain
|
|
134
|
-
* strings, so a ref form a later sous accepts never breaks this reader.
|
|
135
|
-
*/
|
|
136
|
-
depends: z.array(z.string().min(1, "must not be empty")).optional(),
|
|
137
|
-
subscribes: z.array(z.string().min(1, "must not be empty")).optional(),
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
/** One recipe, with every version the repo publishes of it. */
|
|
141
|
-
export const indexRecipeSchema = forwardCompatibleObject({
|
|
142
|
-
/** The recipe folder, relative to the repo root. */
|
|
143
|
-
path: relativePathSchema("a recipe path"),
|
|
144
|
-
/** One-paragraph summary, copied from the recipe manifest at release time. */
|
|
145
|
-
description: z.string().optional(),
|
|
146
|
-
/** Every published version, keyed by the exact version string. */
|
|
147
|
-
versions: z
|
|
148
|
-
.record(semverVersionSchema, indexVersionSchema)
|
|
149
|
-
.refine((versions) => Object.keys(versions).length > 0, {
|
|
150
|
-
message: "must list at least one published version",
|
|
151
|
-
}),
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
/** One namespace declaration, copied from the repo manifest at release time. */
|
|
155
|
-
export const indexNamespaceSchema = forwardCompatibleObject({
|
|
156
|
-
description: z.string().optional(),
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
/** The repo index schema. */
|
|
160
|
-
export const indexFileSchema = forwardCompatibleObject({
|
|
161
|
-
/**
|
|
162
|
-
* A plain-language note about where this copy of the index came from. JSON
|
|
163
|
-
* has no comment syntax and an index is machine-written, so this is the one
|
|
164
|
-
* place a writer can say something to whoever opens the file. Sous ignores
|
|
165
|
-
* the value everywhere except one place: the seed index it writes for its
|
|
166
|
-
* own built-in repository carries `SEED_INDEX_COMMENT`, which is how a
|
|
167
|
-
* later run recognizes its own placeholder and is willing to replace it.
|
|
168
|
-
*/
|
|
169
|
-
$comment: z.string().optional(),
|
|
170
|
-
formatVersion: formatVersionSchema,
|
|
171
|
-
/** The repo's suggested short name, copied from its manifest. */
|
|
172
|
-
name: repoNameSchema,
|
|
173
|
-
/** When this index was generated. */
|
|
174
|
-
generatedAt: isoTimestampSchema,
|
|
175
|
-
/** The version of sous that generated it. */
|
|
176
|
-
generator: semverVersionSchema,
|
|
177
|
-
/** Every namespace the repo publishes. */
|
|
178
|
-
namespaces: z.record(namespaceNameSchema, indexNamespaceSchema),
|
|
179
|
-
/** Every recipe the repo publishes, keyed `namespace/recipe`. */
|
|
180
|
-
recipes: z.record(recipeKeySchema, indexRecipeSchema),
|
|
181
|
-
}).superRefine((index, ctx) => {
|
|
182
|
-
// A recipe whose namespace is not declared could never be resolved, so a
|
|
183
|
-
// release that produced one is broken; say which recipe and which namespace.
|
|
184
|
-
for (const key of Object.keys(index.recipes)) {
|
|
185
|
-
const namespace = namespaceOfKey(key);
|
|
186
|
-
if (!Object.hasOwn(index.namespaces, namespace)) {
|
|
187
|
-
ctx.addIssue({
|
|
188
|
-
code: "custom",
|
|
189
|
-
path: ["recipes", key],
|
|
190
|
-
message:
|
|
191
|
-
`belongs to the namespace '${namespace}', which this index does not ` +
|
|
192
|
-
`declare under 'namespaces'`,
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// A version's tag is what the provider fetches, so a tag that does not
|
|
198
|
-
// name this exact recipe and version is a version pointing somewhere else.
|
|
199
|
-
// Nothing on the consumer side could otherwise tell: an index publishing
|
|
200
|
-
// `1.0.0` with `tag: "main"` would hand `git clone --branch main` a moving
|
|
201
|
-
// target, whose content changes on every push and whose pinned hash then
|
|
202
|
-
// simply starts failing. Sous writes these tags itself, so requiring the
|
|
203
|
-
// shape it writes costs a correct index nothing.
|
|
204
|
-
for (const [key, recipe] of Object.entries(index.recipes)) {
|
|
205
|
-
for (const [version, published] of Object.entries(recipe.versions)) {
|
|
206
|
-
const expected = `${key}@${version}`;
|
|
207
|
-
if (published.tag === expected) continue;
|
|
208
|
-
ctx.addIssue({
|
|
209
|
-
code: "custom",
|
|
210
|
-
path: ["recipes", key, "versions", version, "tag"],
|
|
211
|
-
message:
|
|
212
|
-
`is '${published.tag}', but a published version's tag names the recipe and ` +
|
|
213
|
-
`the version it carries, so this one must be '${expected}'`,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
/** A validated repo index. */
|
|
220
|
-
export type IndexFile = z.infer<typeof indexFileSchema>;
|
|
221
|
-
|
|
222
|
-
/** One recipe entry in a repo index. */
|
|
223
|
-
export type IndexRecipe = z.infer<typeof indexRecipeSchema>;
|
|
224
|
-
|
|
225
|
-
/** One published version entry in a repo index. */
|
|
226
|
-
export type IndexVersion = z.infer<typeof indexVersionSchema>;
|
|
227
|
-
|
|
228
|
-
/** One resolved dependency of one published version. */
|
|
229
|
-
export type IndexDependency = z.infer<typeof indexDependencySchema>;
|
|
230
|
-
|
|
231
|
-
/** One namespace entry in a repo index. */
|
|
232
|
-
export type IndexNamespace = z.infer<typeof indexNamespaceSchema>;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Validates a parsed repo index, throwing a ConfigError that names the file and
|
|
236
|
-
* the path of every bad field.
|
|
237
|
-
*
|
|
238
|
-
* @param value - The parsed contents of the index file.
|
|
239
|
-
* @param sourceLabel - The index's file path or URL, named in error messages.
|
|
240
|
-
*/
|
|
241
|
-
export function parseIndexFile(value: unknown, sourceLabel: string): IndexFile {
|
|
242
|
-
return parseFormat(indexFileSchema, value, sourceLabel, "repo index");
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Serializes a repo index for writing, with every object key sorted so a
|
|
247
|
-
* regenerated index produces a minimal diff.
|
|
248
|
-
*
|
|
249
|
-
* @param index - The index to write.
|
|
250
|
-
*/
|
|
251
|
-
export function stringifyIndexFile(index: IndexFile): string {
|
|
252
|
-
return stableJsonStringify(index);
|
|
253
|
-
}
|