@inventarch/distribution 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LANGUAGE.md +56 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +2 -2
- package/SPEC.md +5 -0
- package/assets/host-launcher.mjs +167 -0
- package/dist/acquire.d.ts +13 -0
- package/dist/acquire.d.ts.map +1 -0
- package/dist/acquire.js +46 -0
- package/dist/acquire.js.map +1 -0
- package/dist/archive.d.ts +20 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +165 -0
- package/dist/archive.js.map +1 -0
- package/dist/authoring-assets.d.ts +11 -0
- package/dist/authoring-assets.d.ts.map +1 -0
- package/dist/authoring-assets.js +251 -0
- package/dist/authoring-assets.js.map +1 -0
- package/dist/bounded-fetch.d.ts +17 -0
- package/dist/bounded-fetch.d.ts.map +1 -0
- package/dist/bounded-fetch.js +67 -0
- package/dist/bounded-fetch.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/command.d.ts +6 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +189 -0
- package/dist/command.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +43 -0
- package/dist/config.js.map +1 -0
- package/dist/decisions.d.ts +26 -0
- package/dist/decisions.d.ts.map +1 -0
- package/dist/decisions.js +119 -0
- package/dist/decisions.js.map +1 -0
- package/dist/files.d.ts +38 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +224 -0
- package/dist/files.js.map +1 -0
- package/dist/guard-registration.d.ts +95 -0
- package/dist/guard-registration.d.ts.map +1 -0
- package/dist/guard-registration.js +282 -0
- package/dist/guard-registration.js.map +1 -0
- package/dist/host-home.d.ts +33 -0
- package/dist/host-home.d.ts.map +1 -0
- package/dist/host-home.js +116 -0
- package/dist/host-home.js.map +1 -0
- package/dist/host-modes.d.ts +13 -0
- package/dist/host-modes.d.ts.map +1 -0
- package/dist/host-modes.js +36 -0
- package/dist/host-modes.js.map +1 -0
- package/dist/host-observe.d.ts +24 -0
- package/dist/host-observe.d.ts.map +1 -0
- package/dist/host-observe.js +233 -0
- package/dist/host-observe.js.map +1 -0
- package/dist/host.d.ts +100 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +505 -0
- package/dist/host.js.map +1 -0
- package/dist/hosts.d.ts +66 -0
- package/dist/hosts.d.ts.map +1 -0
- package/dist/hosts.js +39 -0
- package/dist/hosts.js.map +1 -0
- package/dist/ia-home.d.ts +15 -0
- package/dist/ia-home.d.ts.map +1 -0
- package/dist/ia-home.js +101 -0
- package/dist/ia-home.js.map +1 -0
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +402 -0
- package/dist/install.js.map +1 -0
- package/dist/installation-core.d.ts +41 -0
- package/dist/installation-core.d.ts.map +1 -0
- package/dist/installation-core.js +163 -0
- package/dist/installation-core.js.map +1 -0
- package/dist/inventory.d.ts +3 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +49 -0
- package/dist/inventory.js.map +1 -0
- package/dist/json-edit.d.ts +19 -0
- package/dist/json-edit.d.ts.map +1 -0
- package/dist/json-edit.js +81 -0
- package/dist/json-edit.js.map +1 -0
- package/dist/lifecycle-registration.d.ts +47 -0
- package/dist/lifecycle-registration.d.ts.map +1 -0
- package/dist/lifecycle-registration.js +351 -0
- package/dist/lifecycle-registration.js.map +1 -0
- package/dist/minting.d.ts +46 -0
- package/dist/minting.d.ts.map +1 -0
- package/dist/minting.js +192 -0
- package/dist/minting.js.map +1 -0
- package/dist/native-command.d.ts +6 -0
- package/dist/native-command.d.ts.map +1 -0
- package/dist/native-command.js +273 -0
- package/dist/native-command.js.map +1 -0
- package/dist/pack.d.ts +4 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +30 -0
- package/dist/pack.js.map +1 -0
- package/dist/plugin-home.d.ts +45 -0
- package/dist/plugin-home.d.ts.map +1 -0
- package/dist/plugin-home.js +371 -0
- package/dist/plugin-home.js.map +1 -0
- package/dist/program.d.ts +64 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +126 -0
- package/dist/program.js.map +1 -0
- package/dist/projection.d.ts +45 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +218 -0
- package/dist/projection.js.map +1 -0
- package/dist/publication.d.ts +20 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/publication.js +284 -0
- package/dist/publication.js.map +1 -0
- package/dist/registry-admission.d.ts +5 -0
- package/dist/registry-admission.d.ts.map +1 -0
- package/dist/registry-admission.js +17 -0
- package/dist/registry-admission.js.map +1 -0
- package/dist/registry-build.d.ts +35 -0
- package/dist/registry-build.d.ts.map +1 -0
- package/dist/registry-build.js +156 -0
- package/dist/registry-build.js.map +1 -0
- package/dist/registry-config.d.ts +32 -0
- package/dist/registry-config.d.ts.map +1 -0
- package/dist/registry-config.js +191 -0
- package/dist/registry-config.js.map +1 -0
- package/dist/registry-layout.d.ts +41 -0
- package/dist/registry-layout.d.ts.map +1 -0
- package/dist/registry-layout.js +142 -0
- package/dist/registry-layout.js.map +1 -0
- package/dist/registry-resolve.d.ts +56 -0
- package/dist/registry-resolve.d.ts.map +1 -0
- package/dist/registry-resolve.js +406 -0
- package/dist/registry-resolve.js.map +1 -0
- package/dist/registry-source.d.ts +37 -0
- package/dist/registry-source.d.ts.map +1 -0
- package/dist/registry-source.js +101 -0
- package/dist/registry-source.js.map +1 -0
- package/dist/registry.d.ts +10 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +6 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolve.d.ts +31 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +115 -0
- package/dist/resolve.js.map +1 -0
- package/dist/services.d.ts +179 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +290 -0
- package/dist/services.js.map +1 -0
- package/dist/snapshot.d.ts +24 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +343 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/system-package.d.ts +71 -0
- package/dist/system-package.d.ts.map +1 -0
- package/dist/system-package.js +169 -0
- package/dist/system-package.js.map +1 -0
- package/dist/transfer.d.ts +22 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +98 -0
- package/dist/transfer.js.map +1 -0
- package/dist/updates.d.ts +57 -0
- package/dist/updates.d.ts.map +1 -0
- package/dist/updates.js +201 -0
- package/dist/updates.js.map +1 -0
- package/dist/ustar.d.ts +28 -0
- package/dist/ustar.d.ts.map +1 -0
- package/dist/ustar.js +145 -0
- package/dist/ustar.js.map +1 -0
- package/package.json +323 -3
- package/references/system-package.md +13 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { DISTRIBUTION_LIMITS, decodeDistributionJson, packageId, range, text, version, } from '@inventarch/db/distribution';
|
|
2
|
+
import { DistributionError, fail, object } from './files.js';
|
|
3
|
+
/** Registry spec §3 and §5.1 bounds. */
|
|
4
|
+
export const REGISTRY_LIMITS = Object.freeze({ indexBytes: 4 * 1024 * 1024, releases: 1000, reads: 256 });
|
|
5
|
+
/** Deep freeze, matching installation-core.ts/minting.ts. */
|
|
6
|
+
function frozen(value) {
|
|
7
|
+
if (value && typeof value === 'object') {
|
|
8
|
+
Object.values(value).forEach(frozen);
|
|
9
|
+
Object.freeze(value);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
const hex = (v, what) => {
|
|
14
|
+
if (typeof v !== 'string' || !/^[a-f0-9]{64}$/.test(v))
|
|
15
|
+
fail('INPUT-INVALID', `Invalid registry ${what} digest`);
|
|
16
|
+
return v;
|
|
17
|
+
};
|
|
18
|
+
export const isDbRefusal = (error) => error instanceof Error &&
|
|
19
|
+
'code' in error &&
|
|
20
|
+
typeof error.code === 'string' &&
|
|
21
|
+
/^IA-DB-/.test(error.code);
|
|
22
|
+
/** `DbError.message` is `<IA-DB-code>: Distribution <reason>: <detail>` (packages/db/src/errors.ts:8); strip both so only the detail remains. */
|
|
23
|
+
export const stripDbPrefix = (message) => message.replace(/^IA-DB-[A-Z-]+: (?:Distribution [a-z-]+: )?/, '');
|
|
24
|
+
/** Re-raises a refusal from `work` with `prefix` and `suffix` around its message: a distribution refusal keeps its code, a db-layer refusal becomes INPUT-INVALID with its db prefix stripped. */
|
|
25
|
+
export function relabel(work, prefix, suffix = '') {
|
|
26
|
+
try {
|
|
27
|
+
return work();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof DistributionError)
|
|
31
|
+
fail(error.code.replace(/^IA-DIST-/, ''), `${prefix}${error.message}${suffix}`);
|
|
32
|
+
if (isDbRefusal(error))
|
|
33
|
+
fail('INPUT-INVALID', `${prefix}${stripDbPrefix(error.message)}${suffix}`);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Wraps one named field's decode: on a db-layer refusal, names the field (and the release version, once known) and drops the db code so the caller sees only `IA-DIST-*`. */
|
|
38
|
+
function field(name, context, work) {
|
|
39
|
+
try {
|
|
40
|
+
return work();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (isDbRefusal(error))
|
|
44
|
+
fail('INPUT-INVALID', `Invalid registry metadata${context !== undefined ? ` for ${context}` : ''}: ${name}: ${stripDbPrefix(error.message)}`);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Catch-all for db-layer refusals not tied to one named field, e.g. malformed JSON. */
|
|
49
|
+
function dbDecode(work) {
|
|
50
|
+
try {
|
|
51
|
+
return work();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (isDbRefusal(error))
|
|
55
|
+
fail('INPUT-INVALID', stripDbPrefix(error.message));
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function packageIndexPath(id) {
|
|
60
|
+
return dbDecode(() => `packages/${packageId(id)}.json`);
|
|
61
|
+
}
|
|
62
|
+
export function decodeRegistryInfo(content) {
|
|
63
|
+
return dbDecode(() => {
|
|
64
|
+
const row = object(decodeDistributionJson(content), ['format', 'name']);
|
|
65
|
+
if (row['format'] !== 'ia.registry.v1')
|
|
66
|
+
fail('INPUT-INVALID', 'Not an ia.registry.v1 registry');
|
|
67
|
+
return frozen({ format: 'ia.registry.v1', name: field('name', undefined, () => text(row['name'], 128)) });
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export function decodePackageIndex(content, expectedId) {
|
|
71
|
+
return dbDecode(() => {
|
|
72
|
+
const id = field('id', undefined, () => packageId(expectedId));
|
|
73
|
+
const value = decodeDistributionJson(content), keys = value !== null && typeof value === 'object' && Object.hasOwn(value, 'signatures')
|
|
74
|
+
? ['format', 'id', 'releases', 'signatures']
|
|
75
|
+
: ['format', 'id', 'releases'];
|
|
76
|
+
const row = object(value, keys);
|
|
77
|
+
if (row['format'] !== 'ia.registry-package.v1')
|
|
78
|
+
fail('INPUT-INVALID', 'Not an ia.registry-package.v1 index');
|
|
79
|
+
if (row['id'] !== id)
|
|
80
|
+
fail('INPUT-INVALID', `Registry index names a different package than ${id}`);
|
|
81
|
+
if (!Array.isArray(row['releases']))
|
|
82
|
+
fail('INPUT-INVALID', 'Registry releases must be an array');
|
|
83
|
+
if (row['releases'].length > REGISTRY_LIMITS.releases)
|
|
84
|
+
fail('LIMIT-EXCEEDED', 'Registry index exceeds 1000 releases');
|
|
85
|
+
const versions = new Set();
|
|
86
|
+
const releases = row['releases'].map((entry) => {
|
|
87
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry))
|
|
88
|
+
fail('INPUT-INVALID', 'Registry release must be an object');
|
|
89
|
+
const raw = entry, access = raw['access'];
|
|
90
|
+
if (access !== 'public' && access !== 'licensed')
|
|
91
|
+
fail('INPUT-INVALID', 'Registry release access must be "public" or "licensed"');
|
|
92
|
+
const licensed = access === 'licensed';
|
|
93
|
+
// §3: `artifact` is present if and only if `access` is `"public"`; check that up front so the refusal names "artifact" instead of a generic unknown-field message.
|
|
94
|
+
const hasArtifactField = Object.hasOwn(raw, 'artifact');
|
|
95
|
+
if (hasArtifactField === licensed)
|
|
96
|
+
fail('INPUT-INVALID', 'Registry artifact must be present if and only if access is public');
|
|
97
|
+
const r = object(entry, licensed
|
|
98
|
+
? ['version', 'archive', 'manifest', 'engine', 'language', 'dependencies', 'withdrawn', 'access']
|
|
99
|
+
: ['version', 'archive', 'manifest', 'engine', 'language', 'dependencies', 'withdrawn', 'access', 'artifact']);
|
|
100
|
+
// Registry metadata copies the release manifest's own fields (spec §3), so it decodes with the same codecs: `version`, `range` (engine and each dependency range) and the exact `['1.0']` grammar.
|
|
101
|
+
const releaseVersion = field('version', undefined, () => version(r['version']));
|
|
102
|
+
const archive = hex(r['archive'], 'archive');
|
|
103
|
+
if (versions.has(releaseVersion))
|
|
104
|
+
fail('INPUT-INVALID', `Registry lists ${releaseVersion} more than once`);
|
|
105
|
+
versions.add(releaseVersion);
|
|
106
|
+
if (typeof r['withdrawn'] !== 'boolean')
|
|
107
|
+
fail('INPUT-INVALID', 'Invalid registry withdrawn flag');
|
|
108
|
+
if (!licensed && r['artifact'] !== `artifacts/${archive}.ia.tgz`)
|
|
109
|
+
fail('INPUT-INVALID', 'Registry artifact must be artifacts/<archive>.ia.tgz relative to the base');
|
|
110
|
+
if (!Array.isArray(r['language']) || r['language'].length !== 1 || r['language'][0] !== '1.0')
|
|
111
|
+
fail('INPUT-INVALID', 'Registry language must be exactly ["1.0"]');
|
|
112
|
+
if (!Array.isArray(r['dependencies']) || r['dependencies'].length > DISTRIBUTION_LIMITS.bundles)
|
|
113
|
+
fail('INPUT-INVALID', 'Invalid registry dependency list');
|
|
114
|
+
// Duplicate/self dependencies refuse the same way the manifest's own dependency lists do (packages/db/src/distribution/contracts.ts:29,45).
|
|
115
|
+
const seenDependencies = new Set();
|
|
116
|
+
const dependencies = r['dependencies'].map((d) => {
|
|
117
|
+
const dep = object(d, ['id', 'range']);
|
|
118
|
+
const depId = field('dependency id', releaseVersion, () => packageId(dep['id']));
|
|
119
|
+
if (depId === id)
|
|
120
|
+
fail('INPUT-INVALID', `Registry release ${releaseVersion} depends on itself: ${depId}`);
|
|
121
|
+
if (seenDependencies.has(depId))
|
|
122
|
+
fail('INPUT-INVALID', `Registry release ${releaseVersion} lists dependency ${depId} more than once`);
|
|
123
|
+
seenDependencies.add(depId);
|
|
124
|
+
return { id: depId, range: field('dependency range', releaseVersion, () => range(dep['range'])) };
|
|
125
|
+
});
|
|
126
|
+
const engineValue = field('engine', releaseVersion, () => range(r['engine']));
|
|
127
|
+
return {
|
|
128
|
+
version: releaseVersion,
|
|
129
|
+
archive,
|
|
130
|
+
manifest: hex(r['manifest'], 'manifest'),
|
|
131
|
+
engine: engineValue,
|
|
132
|
+
language: ['1.0'],
|
|
133
|
+
dependencies,
|
|
134
|
+
withdrawn: r['withdrawn'],
|
|
135
|
+
access,
|
|
136
|
+
...(licensed ? {} : { artifact: r['artifact'] }),
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
return frozen({ format: 'ia.registry-package.v1', id, releases });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=registry-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-layout.js","sourceRoot":"","sources":["../src/registry-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,SAAS,EACT,KAAK,EACL,IAAI,EACJ,OAAO,GACR,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE7D,wCAAwC;AACxC,MAAM,CAAC,MAAM,eAAe,GAAG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ACzB,MAAM;gBACN,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAW,EAAE,CAAC;aAC3D,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,EAAE,MAAM,EAAE,wBAAiC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { BundleMetadata, Dependency, DistributionLock } from '@inventarch/db/distribution';
|
|
2
|
+
import type { RegistryChoice } from './registry-config.js';
|
|
3
|
+
import type { ReleaseCandidate } from './resolve.js';
|
|
4
|
+
/** Registry spec §7: delivers the exact bytes of a licensed release into the workspace cache and returns its sha256 location. */
|
|
5
|
+
export interface Acquirer {
|
|
6
|
+
acquire(release: {
|
|
7
|
+
id: string;
|
|
8
|
+
version: string;
|
|
9
|
+
archive: string;
|
|
10
|
+
manifest: string;
|
|
11
|
+
}, signal?: AbortSignal): Promise<{
|
|
12
|
+
location: `sha256:${string}`;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export interface RegistryResolveRequest {
|
|
16
|
+
readonly root: string;
|
|
17
|
+
readonly requests: readonly Dependency[];
|
|
18
|
+
readonly engine: string;
|
|
19
|
+
/** The lock to prefer and to check against (§3 append-only rule). */
|
|
20
|
+
readonly previous?: DistributionLock | undefined;
|
|
21
|
+
/** §6.2 `update <id>`: this id's pin is dropped from the preference, so the newest satisfying release wins. It is always named. */
|
|
22
|
+
readonly preferredExcept?: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* §5.1: the ids the command names — `install`'s arguments, `update`'s id. Their indexes are always read. Absent, every
|
|
25
|
+
* request id is named, which reads every request's index.
|
|
26
|
+
*/
|
|
27
|
+
readonly named?: readonly string[] | undefined;
|
|
28
|
+
/** One command's read-once chooser (`registryChooser`). */
|
|
29
|
+
readonly choose: (id: string) => RegistryChoice;
|
|
30
|
+
readonly acquirer?: Acquirer | undefined;
|
|
31
|
+
readonly signal?: AbortSignal | undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `candidates` are exactly the selected releases, admitted. A selected cached lock pin retains its manifest-level
|
|
35
|
+
* metadata and the lock's own location. `sources` names the registry each selected id came from; a kept lock pin came
|
|
36
|
+
* from none.
|
|
37
|
+
*/
|
|
38
|
+
export interface RegistryResolution {
|
|
39
|
+
readonly candidates: readonly ReleaseCandidate<BundleMetadata>[];
|
|
40
|
+
readonly sources: ReadonlyMap<string, RegistryChoice>;
|
|
41
|
+
}
|
|
42
|
+
/** Registry spec §6.3: the locked ids whose cached archive is unpublished, so restore consults no registry for them. */
|
|
43
|
+
export declare function unpublishedPins(root: string, lock: DistributionLock): ReadonlySet<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Registry spec §5.1-5.3: reads the metadata closure, selects on metadata with the shared search, then fetches and
|
|
46
|
+
* verifies only the selected archives. Feeding `candidates` to the unchanged `resolveReleases` reproduces the selection.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveFromRegistries(request: RegistryResolveRequest): Promise<RegistryResolution>;
|
|
49
|
+
/**
|
|
50
|
+
* Registry spec §6.3: reads each locked package's index and returns the `id@version` pins it marks withdrawn. A locked
|
|
51
|
+
* version the index no longer lists, or lists with different digests, is a conflict. A locked package whose cached
|
|
52
|
+
* archive is unpublished (null provenance) is skipped: no registry lists it, so none can withdraw it. A package that is
|
|
53
|
+
* not cached (a fresh clone) is read like any other.
|
|
54
|
+
*/
|
|
55
|
+
export declare function registryWithdrawals(root: string, lock: DistributionLock, choose: (id: string) => RegistryChoice, signal?: AbortSignal): Promise<readonly string[]>;
|
|
56
|
+
//# sourceMappingURL=registry-resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-resolve.d.ts","sourceRoot":"","sources":["../src/registry-resolve.ts"],"names":[],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BAAgB,CAAC,cAAc,CAAC,EAAE,CAAC;IACjE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACvD;AA8CD,wHAAwH;AACxH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,WAAW,CAAC,MAAM,CAAC,CAUzF;AA+ED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkBxG;AA0RD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,cAAc,EACtC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAe5B"}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { decodeDistributionRequests, DISTRIBUTION_LIMITS, satisfies } from '@inventarch/db/distribution';
|
|
2
|
+
import { acquireArtifact, readArtifactBytes } from './acquire.js';
|
|
3
|
+
import { inspectArchiveMetadata, verifyArchive } from './archive.js';
|
|
4
|
+
import { bytes, DistributionError, fail, workspace } from './files.js';
|
|
5
|
+
import { cacheArchive, cachePath, cacheSelectedArchiveClosure } from './install.js';
|
|
6
|
+
import { relabel } from './registry-layout.js';
|
|
7
|
+
import { matchRegistryRelease as matches } from './registry-admission.js';
|
|
8
|
+
import { openRegistry, registryBudget, registryLocation } from './registry-source.js';
|
|
9
|
+
import { resolveReleases, selectReleases } from './resolve.js';
|
|
10
|
+
const isRefusal = (error) => error instanceof DistributionError ||
|
|
11
|
+
(error instanceof Error && 'code' in error && typeof error.code === 'string' && error.code.startsWith('IA-'));
|
|
12
|
+
/**
|
|
13
|
+
* The locked package's cached pin; `{ corrupt }` when the cache file exists but cannot be read or verified; undefined
|
|
14
|
+
* when it is absent, or verifies but is not the release the lock pins (the lock, not the cache, is then the question).
|
|
15
|
+
*/
|
|
16
|
+
function inspectPin(root, locked) {
|
|
17
|
+
const path = cachePath(locked.archive);
|
|
18
|
+
let archive;
|
|
19
|
+
try {
|
|
20
|
+
const content = bytes(root, path, DISTRIBUTION_LIMITS.compressed);
|
|
21
|
+
if (content === null)
|
|
22
|
+
return undefined;
|
|
23
|
+
archive = inspectArchiveMetadata(content, locked.archive).pending;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (isRefusal(error))
|
|
27
|
+
return { corrupt: path };
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
const { manifest, archiveDigest, manifestDigest } = archive;
|
|
31
|
+
if (manifestDigest !== locked.manifest || manifest.id !== locked.id || manifest.version !== locked.version)
|
|
32
|
+
return undefined;
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
locked,
|
|
35
|
+
release: Object.freeze({ manifest, archiveDigest, manifestDigest }),
|
|
36
|
+
unpublished: manifest.source.repository === null,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const isPin = (state) => state !== undefined && 'locked' in state;
|
|
40
|
+
/** Registry spec §6.3: the locked ids whose cached archive is unpublished, so restore consults no registry for them. */
|
|
41
|
+
export function unpublishedPins(root, lock) {
|
|
42
|
+
const at = workspace(root);
|
|
43
|
+
return new Set(lock.packages
|
|
44
|
+
.filter((locked) => {
|
|
45
|
+
const state = inspectPin(at, locked);
|
|
46
|
+
return isPin(state) && state.unpublished;
|
|
47
|
+
})
|
|
48
|
+
.map((locked) => locked.id));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Registry spec §6.4 and §3: a configured base without `ia-registry.json` stays "Not a registry" (INPUT-INVALID), but
|
|
52
|
+
* the built-in default that has not been provisioned is an unavailable resource, not a wrong URL.
|
|
53
|
+
*/
|
|
54
|
+
function open(choice, budget, signal) {
|
|
55
|
+
const missing = choice.level === 'default'
|
|
56
|
+
? (where) => fail('ARTIFACT-UNAVAILABLE', `The default registry ${where} is not available; pass --registry, map the provider in .ia/registries.json, or use --catalog`)
|
|
57
|
+
: undefined;
|
|
58
|
+
return openRegistry(choice.base, { budget, signal, missing });
|
|
59
|
+
}
|
|
60
|
+
/** One command's registries: each distinct base is opened once, and every read draws on one shared budget (§5.1). */
|
|
61
|
+
function registries(choose, signal) {
|
|
62
|
+
const budget = registryBudget(), opened = new Map();
|
|
63
|
+
return async (id) => {
|
|
64
|
+
const choice = choose(id), key = registryLocation(choice.base);
|
|
65
|
+
let registry = opened.get(key);
|
|
66
|
+
if (registry === undefined) {
|
|
67
|
+
registry = await open(choice, budget, signal);
|
|
68
|
+
opened.set(key, registry);
|
|
69
|
+
}
|
|
70
|
+
return { choice, registry, index: await registry.index(id) };
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const pin = (id, version) => `${id}@${version}`;
|
|
74
|
+
/** §3: a version's digests never change. */
|
|
75
|
+
function unchanged(id, release, locked) {
|
|
76
|
+
if (release.archive !== locked.archive || release.manifest !== locked.manifest)
|
|
77
|
+
fail('CONFLICT', `Registry changed the bytes of a published release: ${pin(id, release.version)}`);
|
|
78
|
+
}
|
|
79
|
+
/** §7: a licensed release through the acquirer, which must cache exactly the named archive and return its sha256 location. */
|
|
80
|
+
async function acquired(root, acquirer, id, entry, signal) {
|
|
81
|
+
const { version, archive, manifest } = entry, at = pin(id, version);
|
|
82
|
+
let result;
|
|
83
|
+
try {
|
|
84
|
+
result = await acquirer.acquire({ id, version, archive, manifest }, signal);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
// A caller abort and a coded refusal pass through; anything else is the acquirer failing to deliver.
|
|
88
|
+
if (signal?.aborted === true ||
|
|
89
|
+
error instanceof DistributionError ||
|
|
90
|
+
(error instanceof Error && 'code' in error && typeof error.code === 'string' && error.code.startsWith('IA-')))
|
|
91
|
+
throw error;
|
|
92
|
+
return fail('ARTIFACT-UNAVAILABLE', `Acquirer failed for ${at}: ${error instanceof Error ? error.message : String(error)}`);
|
|
93
|
+
}
|
|
94
|
+
const location = result !== null && typeof result === 'object' ? result.location : undefined;
|
|
95
|
+
if (location !== `sha256:${archive}`)
|
|
96
|
+
fail('INTEGRITY-MISMATCH', `Acquirer did not return sha256:${archive} for ${at}`);
|
|
97
|
+
const content = bytes(root, cachePath(archive), DISTRIBUTION_LIMITS.compressed);
|
|
98
|
+
if (content === null)
|
|
99
|
+
fail('ARTIFACT-UNAVAILABLE', `Acquirer did not cache ${at} (${archive})`);
|
|
100
|
+
return { release: relabel(() => verifyArchive(content, archive), `${at}: `), location };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Registry spec §5.1-5.3: reads the metadata closure, selects on metadata with the shared search, then fetches and
|
|
104
|
+
* verifies only the selected archives. Feeding `candidates` to the unchanged `resolveReleases` reproduces the selection.
|
|
105
|
+
*/
|
|
106
|
+
export async function resolveFromRegistries(request) {
|
|
107
|
+
request.signal?.throwIfAborted();
|
|
108
|
+
const root = workspace(request.root), verified = new Map(), corrupt = [];
|
|
109
|
+
for (const locked of request.previous?.packages ?? []) {
|
|
110
|
+
const state = inspectPin(root, locked);
|
|
111
|
+
if (isPin(state))
|
|
112
|
+
verified.set(locked.id, state);
|
|
113
|
+
else if (state !== undefined)
|
|
114
|
+
corrupt.push(state.corrupt);
|
|
115
|
+
}
|
|
116
|
+
// A corrupt cached pin falls back to a registry lookup. If that fails too, the refusal is located at the corrupt cache
|
|
117
|
+
// file, whose repair (delete it) is what a user can do; a refusal already located elsewhere keeps its location.
|
|
118
|
+
try {
|
|
119
|
+
return await resolveWithPins(request, root, verified);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (corrupt.length === 0 || !isRefusal(error) || error.path !== undefined)
|
|
123
|
+
throw error;
|
|
124
|
+
throw new DistributionError(error.code, error.message, corrupt[0]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function resolveWithPins(request, root, verified) {
|
|
128
|
+
const { signal, engine, previous, acquirer } = request;
|
|
129
|
+
const requests = decodeDistributionRequests(request.requests), read = registries(request.choose, signal);
|
|
130
|
+
// §5.1: a usable cached pin is a verified cached lock pin whose engine range admits the running engine; each is a
|
|
131
|
+
// candidate at the lock's own location. One the engine no longer admits is looked up like an uncached pin.
|
|
132
|
+
const pins = new Map([...verified].filter(([, pin]) => satisfies(engine, pin.release.manifest.engine)));
|
|
133
|
+
const named = new Set([
|
|
134
|
+
...(request.named ?? requests.map((r) => r.id)),
|
|
135
|
+
...(request.preferredExcept === undefined ? [] : [request.preferredExcept]),
|
|
136
|
+
]);
|
|
137
|
+
// §5.1: the closure follows only releases selection could pick for some known constraint: not withdrawn, admitted by the
|
|
138
|
+
// engine, and inside a range a request or a followed release places on the id. A locked version counts as known, so the
|
|
139
|
+
// pin stays selectable and preferred. Licensed releases are followed too, so a licensed-only need can be named (§7).
|
|
140
|
+
const known = new Map(), indexed = new Map();
|
|
141
|
+
const pending = [], queued = new Set(), followed = new Set(), followedPins = new Set();
|
|
142
|
+
// §5.1: an id's index is read when the command names it, when it has no usable cached pin, or once a known range
|
|
143
|
+
// excludes the pin's version. Otherwise the pin answers for it and no registry is consulted.
|
|
144
|
+
const mustRead = (id, ranges) => {
|
|
145
|
+
const pin = pins.get(id);
|
|
146
|
+
return pin === undefined || named.has(id) || [...ranges].some((r) => !satisfies(pin.locked.version, r));
|
|
147
|
+
};
|
|
148
|
+
const need = (id, range, version) => {
|
|
149
|
+
let entry = known.get(id), grew = entry === undefined;
|
|
150
|
+
if (entry === undefined) {
|
|
151
|
+
entry = { ranges: new Set(), pinned: new Set() };
|
|
152
|
+
known.set(id, entry);
|
|
153
|
+
}
|
|
154
|
+
if (range !== null && !entry.ranges.has(range)) {
|
|
155
|
+
entry.ranges.add(range);
|
|
156
|
+
grew = true;
|
|
157
|
+
}
|
|
158
|
+
if (version !== null && !entry.pinned.has(version)) {
|
|
159
|
+
entry.pinned.add(version);
|
|
160
|
+
grew = true;
|
|
161
|
+
}
|
|
162
|
+
// An index already read is re-scanned for the new constraint, as before.
|
|
163
|
+
if (grew && !queued.has(id) && (indexed.has(id) || mustRead(id, entry.ranges))) {
|
|
164
|
+
queued.add(id);
|
|
165
|
+
pending.push(id);
|
|
166
|
+
}
|
|
167
|
+
// A cached pin is a candidate, so its own dependencies join the closure (once).
|
|
168
|
+
const pin = pins.get(id);
|
|
169
|
+
if (pin !== undefined && !followedPins.has(id)) {
|
|
170
|
+
followedPins.add(id);
|
|
171
|
+
for (const d of pin.release.manifest.dependencies)
|
|
172
|
+
need(d.id, d.range, null);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const admissible = (id, release) => {
|
|
176
|
+
const entry = known.get(id);
|
|
177
|
+
return (entry !== undefined &&
|
|
178
|
+
!release.withdrawn &&
|
|
179
|
+
satisfies(engine, release.engine) &&
|
|
180
|
+
(entry.pinned.has(release.version) || [...entry.ranges].some((r) => satisfies(release.version, r))));
|
|
181
|
+
};
|
|
182
|
+
for (const r of requests)
|
|
183
|
+
need(r.id, r.range, null);
|
|
184
|
+
for (const p of previous?.packages ?? [])
|
|
185
|
+
need(p.id, null, p.version);
|
|
186
|
+
while (pending.length) {
|
|
187
|
+
const id = pending.shift();
|
|
188
|
+
queued.delete(id);
|
|
189
|
+
// Each index is read once per command; a new range for an id re-scans the index already held.
|
|
190
|
+
let entry = indexed.get(id);
|
|
191
|
+
if (entry === undefined) {
|
|
192
|
+
entry = await read(id);
|
|
193
|
+
indexed.set(id, entry);
|
|
194
|
+
}
|
|
195
|
+
for (const release of entry.index.releases)
|
|
196
|
+
if (!followed.has(release) && admissible(id, release)) {
|
|
197
|
+
followed.add(release);
|
|
198
|
+
for (const d of release.dependencies)
|
|
199
|
+
need(d.id, d.range, null);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// §3: a pinned version whose digests changed is a conflict; an absent one is not, since the id may have been re-resolved.
|
|
203
|
+
// An unpublished cached pin is exempt: no registry can list it, so a same-version entry is some other release.
|
|
204
|
+
for (const locked of previous?.packages ?? []) {
|
|
205
|
+
if (verified.get(locked.id)?.unpublished === true)
|
|
206
|
+
continue;
|
|
207
|
+
const release = indexed.get(locked.id)?.index.releases.find((r) => r.version === locked.version);
|
|
208
|
+
if (release)
|
|
209
|
+
unchanged(locked.id, release, locked);
|
|
210
|
+
}
|
|
211
|
+
const origin = new Map();
|
|
212
|
+
const registryLocationOf = (source, entry) => entry.access !== 'public'
|
|
213
|
+
? undefined
|
|
214
|
+
: source.registry.base.kind === 'https'
|
|
215
|
+
? source.registry.artifactUrl(entry.archive)
|
|
216
|
+
: `sha256:${entry.archive}`;
|
|
217
|
+
// §5.1: one candidate per cached pin the closure reached. A registry release naming the same archive is the same
|
|
218
|
+
// release: the registry's candidate is kept only when its location equals the lock's, otherwise the pin (and its
|
|
219
|
+
// location) is. A pin is withdrawn only when its id's index was read and marks that archive withdrawn.
|
|
220
|
+
const pinned = new Map();
|
|
221
|
+
for (const [id, pin] of pins) {
|
|
222
|
+
if (!known.has(id))
|
|
223
|
+
continue;
|
|
224
|
+
const source = indexed.get(id), entry = source?.index.releases.find((r) => r.archive === pin.locked.archive);
|
|
225
|
+
if (source !== undefined &&
|
|
226
|
+
entry !== undefined &&
|
|
227
|
+
admissible(id, entry) &&
|
|
228
|
+
registryLocationOf(source, entry) === pin.locked.location)
|
|
229
|
+
continue;
|
|
230
|
+
pinned.set(id, { pin, withdrawn: entry?.withdrawn ?? false });
|
|
231
|
+
}
|
|
232
|
+
// Pins come first. The search orders by preference, then version, and is otherwise stable, so the one tie left — an
|
|
233
|
+
// unpublished pin and a registry release of the same version with other bytes (a published pin with that tie is an
|
|
234
|
+
// append-only conflict, §3) — keeps the pin, even for the id `update` names (§5.1).
|
|
235
|
+
const view = (licensed) => [
|
|
236
|
+
...[...pinned].map(([id, { pin, withdrawn }]) => {
|
|
237
|
+
const { manifest } = pin.release;
|
|
238
|
+
const candidate = {
|
|
239
|
+
id,
|
|
240
|
+
version: manifest.version,
|
|
241
|
+
engine: manifest.engine,
|
|
242
|
+
dependencies: manifest.dependencies,
|
|
243
|
+
archive: pin.locked.archive,
|
|
244
|
+
withdrawn,
|
|
245
|
+
};
|
|
246
|
+
origin.set(candidate, { kind: 'pin', pin });
|
|
247
|
+
return candidate;
|
|
248
|
+
}),
|
|
249
|
+
...[...indexed].flatMap(([id, source]) => source.index.releases
|
|
250
|
+
.filter((r) => (r.access === 'public' || licensed) &&
|
|
251
|
+
admissible(id, r) &&
|
|
252
|
+
pinned.get(id)?.pin.locked.archive !== r.archive)
|
|
253
|
+
.map((entry) => {
|
|
254
|
+
const candidate = {
|
|
255
|
+
id,
|
|
256
|
+
version: entry.version,
|
|
257
|
+
engine: entry.engine,
|
|
258
|
+
dependencies: entry.dependencies,
|
|
259
|
+
archive: entry.archive,
|
|
260
|
+
withdrawn: entry.withdrawn,
|
|
261
|
+
};
|
|
262
|
+
origin.set(candidate, { kind: 'registry', entry, source });
|
|
263
|
+
return candidate;
|
|
264
|
+
})),
|
|
265
|
+
];
|
|
266
|
+
const licensedPick = (c) => {
|
|
267
|
+
const found = origin.get(c);
|
|
268
|
+
return found.kind === 'registry' && found.entry.access === 'licensed';
|
|
269
|
+
};
|
|
270
|
+
const preferred = new Map((previous?.packages ?? []).filter((p) => p.id !== request.preferredExcept).map((p) => [p.id, p.archive]));
|
|
271
|
+
let selected;
|
|
272
|
+
try {
|
|
273
|
+
selected = selectReleases(requests, view(acquirer !== undefined), engine, preferred);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
if (acquirer !== undefined || !(error instanceof DistributionError) || error.code !== 'IA-DIST-CONFLICT')
|
|
277
|
+
throw error;
|
|
278
|
+
// §7: rerun with licensed releases admitted. If that succeeds, name each licensed pick that is individually necessary:
|
|
279
|
+
// with that id's licensed releases removed (everything else, licensed included, kept), selection fails with CONFLICT.
|
|
280
|
+
// One re-selection per licensed pick. When none is individually necessary (only a set of them is), name them all.
|
|
281
|
+
let licensed;
|
|
282
|
+
try {
|
|
283
|
+
licensed = [...selectReleases(requests, view(true), engine, preferred).values()].filter(licensedPick);
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
if (!licensed.length)
|
|
289
|
+
throw error;
|
|
290
|
+
const necessary = licensed.filter((pick) => {
|
|
291
|
+
try {
|
|
292
|
+
selectReleases(requests, view(true).filter((c) => c.id !== pick.id || !licensedPick(c)), engine, preferred);
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
catch (without) {
|
|
296
|
+
if (without instanceof DistributionError && without.code === 'IA-DIST-CONFLICT')
|
|
297
|
+
return true;
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
const needed = (necessary.length ? necessary : licensed).map((c) => pin(c.id, c.version)).sort();
|
|
302
|
+
return fail('LICENSE-REQUIRED', `${needed.join(', ')} ${needed.length === 1 ? 'is available only as a licensed release' : 'are available only as licensed releases'}; this CLI has no licensed acquisition path`);
|
|
303
|
+
}
|
|
304
|
+
// Public selection obtains all bounded bytes before contextual admission or any new cache effects.
|
|
305
|
+
// The legacy licensed callback has cache effects by contract; it keeps its standalone path below.
|
|
306
|
+
if (![...selected.values()].some(licensedPick)) {
|
|
307
|
+
const pending = [], archives = new Map();
|
|
308
|
+
const sources = new Map();
|
|
309
|
+
let total = 0;
|
|
310
|
+
for (const [id, chosen] of [...selected].sort(([a], [b]) => (a < b ? -1 : 1))) {
|
|
311
|
+
signal?.throwIfAborted();
|
|
312
|
+
const found = origin.get(chosen);
|
|
313
|
+
let content, location, release;
|
|
314
|
+
if (found.kind === 'pin') {
|
|
315
|
+
content =
|
|
316
|
+
bytes(root, cachePath(found.pin.locked.archive), DISTRIBUTION_LIMITS.compressed) ??
|
|
317
|
+
fail('RESTORE-REQUIRED', `Missing selected cache archive ${found.pin.locked.archive}`);
|
|
318
|
+
release = inspectArchiveMetadata(content, found.pin.locked.archive).pending;
|
|
319
|
+
if (release.manifestDigest !== found.pin.locked.manifest)
|
|
320
|
+
fail('INTEGRITY-MISMATCH', 'Selected cache manifest changed');
|
|
321
|
+
location = found.pin.locked.location;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const { entry, source } = found;
|
|
325
|
+
location =
|
|
326
|
+
source.registry.base.kind === 'https'
|
|
327
|
+
? source.registry.artifactUrl(entry.archive)
|
|
328
|
+
: `sha256:${entry.archive}`;
|
|
329
|
+
content =
|
|
330
|
+
source.registry.base.kind === 'https'
|
|
331
|
+
? await readArtifactBytes({ root, url: location, digest: entry.archive, signal })
|
|
332
|
+
: source.registry.artifactBytes(entry.archive);
|
|
333
|
+
release = matches(id, entry, inspectArchiveMetadata(content, entry.archive).pending);
|
|
334
|
+
sources.set(id, source.choice);
|
|
335
|
+
}
|
|
336
|
+
total += content.length;
|
|
337
|
+
if (total > DISTRIBUTION_LIMITS.expanded)
|
|
338
|
+
fail('LIMIT-EXCEEDED', 'Combined registry archive selection exceeds its ceiling');
|
|
339
|
+
archives.set(release.archiveDigest, content);
|
|
340
|
+
pending.push({ release, location, withdrawn: false });
|
|
341
|
+
}
|
|
342
|
+
const resolved = resolveReleases(requests, pending, engine);
|
|
343
|
+
signal?.throwIfAborted();
|
|
344
|
+
const admitted = cacheSelectedArchiveClosure(root, resolved.lock, archives);
|
|
345
|
+
return {
|
|
346
|
+
candidates: pending.map((candidate) => ({ ...candidate, release: admitted.get(candidate.release.manifest.id) })),
|
|
347
|
+
sources,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
// §5.3: only the selected archives are fetched and verified, in id order.
|
|
351
|
+
const candidates = [], sources = new Map();
|
|
352
|
+
for (const [id, chosen] of [...selected].sort(([a], [b]) => (a < b ? -1 : 1))) {
|
|
353
|
+
signal?.throwIfAborted();
|
|
354
|
+
const found = origin.get(chosen);
|
|
355
|
+
// A kept lock pin on the legacy licensed path must pass standalone admission; it keeps the lock's location and came from no registry.
|
|
356
|
+
if (found.kind === 'pin') {
|
|
357
|
+
const content = bytes(root, cachePath(found.pin.locked.archive), DISTRIBUTION_LIMITS.compressed) ??
|
|
358
|
+
fail('RESTORE-REQUIRED', 'Missing selected cached pin');
|
|
359
|
+
const release = verifyArchive(content, found.pin.locked.archive);
|
|
360
|
+
candidates.push({ release, location: found.pin.locked.location, withdrawn: false });
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const { entry, source } = found, { archive } = entry;
|
|
364
|
+
let release, location;
|
|
365
|
+
if (entry.access === 'licensed')
|
|
366
|
+
({ release, location } = await acquired(root, acquirer, id, entry, signal));
|
|
367
|
+
else if (source.registry.base.kind === 'https')
|
|
368
|
+
({ release, location } = await acquireArtifact({
|
|
369
|
+
root,
|
|
370
|
+
url: source.registry.artifactUrl(archive),
|
|
371
|
+
digest: archive,
|
|
372
|
+
signal,
|
|
373
|
+
}));
|
|
374
|
+
else {
|
|
375
|
+
release = cacheArchive(root, source.registry.artifactBytes(archive), archive);
|
|
376
|
+
location = `sha256:${archive}`;
|
|
377
|
+
}
|
|
378
|
+
candidates.push({ release: matches(id, entry, release), location, withdrawn: entry.withdrawn });
|
|
379
|
+
sources.set(id, source.choice);
|
|
380
|
+
}
|
|
381
|
+
return { candidates, sources };
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Registry spec §6.3: reads each locked package's index and returns the `id@version` pins it marks withdrawn. A locked
|
|
385
|
+
* version the index no longer lists, or lists with different digests, is a conflict. A locked package whose cached
|
|
386
|
+
* archive is unpublished (null provenance) is skipped: no registry lists it, so none can withdraw it. A package that is
|
|
387
|
+
* not cached (a fresh clone) is read like any other.
|
|
388
|
+
*/
|
|
389
|
+
export async function registryWithdrawals(root, lock, choose, signal) {
|
|
390
|
+
signal?.throwIfAborted();
|
|
391
|
+
const at = workspace(root);
|
|
392
|
+
const read = registries(choose, signal), withdrawn = [];
|
|
393
|
+
for (const locked of lock.packages) {
|
|
394
|
+
const state = inspectPin(at, locked);
|
|
395
|
+
if (isPin(state) && state.unpublished)
|
|
396
|
+
continue;
|
|
397
|
+
const release = (await read(locked.id)).index.releases.find((r) => r.version === locked.version);
|
|
398
|
+
if (release === undefined)
|
|
399
|
+
fail('CONFLICT', `Registry no longer lists the locked release: ${pin(locked.id, locked.version)}`);
|
|
400
|
+
unchanged(locked.id, release, locked);
|
|
401
|
+
if (release.withdrawn)
|
|
402
|
+
withdrawn.push(pin(locked.id, locked.version));
|
|
403
|
+
}
|
|
404
|
+
return withdrawn;
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=registry-resolve.js.map
|