@beehexa/hexasync-template-assets 2608.7.4

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.
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Asset installation core (FR-17, FR-18, FR-19, FR-20).
3
+ *
4
+ * Pure: no IO, no Node builtins. Everything it touches arrives through a port,
5
+ * which is what lets the CLI and the extension share one implementation rather
6
+ * than growing two that drift.
7
+ */
8
+ import { AssetPathError, encodeAssetSegments, isKind, parseAssetRelativePath, } from './assetPath.js';
9
+ import { isInsideUri, joinUri, normalizeUri, } from '@beehexa/hexasync-template-model';
10
+ /** Where installed assets live, relative to a target. Dot-prefixed (FR-19). */
11
+ export const CANONICAL_SUBPATH = '.hexasync/intellisense';
12
+ export const MANIFEST_FILENAME = '.install-manifest.json';
13
+ export class AssetInstallError extends Error {
14
+ constructor(message) {
15
+ super(message);
16
+ this.name = 'AssetInstallError';
17
+ }
18
+ }
19
+ /**
20
+ * Turns reported asset paths into validated destination URIs, or throws.
21
+ *
22
+ * Every path is checked before any is written. `installAssets` calls this ahead
23
+ * of the write loop so a single bad path cannot leave a partial tree behind —
24
+ * and it validates EVERY entry, not just the first. (The escaping-path tests
25
+ * used to pass names beginning with `.`, which sort to index 0, so a bug that
26
+ * checked only `planned[0]` would have gone unnoticed.)
27
+ */
28
+ function plan(relativePaths, destinationUri) {
29
+ const planned = [];
30
+ const seen = new Map();
31
+ for (const relativePath of relativePaths) {
32
+ // Validate as a PATH before it becomes a URI — see assetPath.ts for why the
33
+ // order matters. Re-thrown as AssetInstallError so callers keep one type.
34
+ let segments;
35
+ try {
36
+ segments = parseAssetRelativePath(relativePath);
37
+ }
38
+ catch (error) {
39
+ if (error instanceof AssetPathError) {
40
+ throw new AssetInstallError(`${error.message} No files were written.`);
41
+ }
42
+ throw error;
43
+ }
44
+ if (segments.length === 1 && segments[0] === MANIFEST_FILENAME) {
45
+ throw new AssetInstallError(`Refusing to install "${relativePath}": ${MANIFEST_FILENAME} is the install manifest's ` +
46
+ `own name. Installing it would have it silently overwritten by the manifest, leaving a ` +
47
+ `recorded checksum for content that is not on disk. No files were written.`);
48
+ }
49
+ const uri = joinUri(destinationUri, encodeAssetSegments(segments));
50
+ // Defence in depth. The allowlist above already makes escape unreachable;
51
+ // this is the invariant stated directly, so a future widening of the
52
+ // allowlist cannot quietly reintroduce a traversal.
53
+ if (!isInsideUri(destinationUri, uri)) {
54
+ throw new AssetInstallError(`Refusing to install "${relativePath}": it resolves to ${uri}, which is outside the ` +
55
+ `install target ${destinationUri}. No files were written.`);
56
+ }
57
+ // Two paths that differ only in case are one file on APFS and NTFS. Left
58
+ // alone, the second write wins on disk while the manifest records both with
59
+ // different checksums — permanently unverifiable.
60
+ const identity = uri.toLowerCase();
61
+ const clash = seen.get(identity);
62
+ if (clash !== undefined) {
63
+ throw new AssetInstallError(clash === relativePath
64
+ ? `Refusing to install "${relativePath}": the bundle lists it more than once. ` +
65
+ `No files were written.`
66
+ : `Refusing to install "${relativePath}": it collides with "${clash}" on a ` +
67
+ `case-insensitive filesystem (macOS, Windows), where both would be the same file. ` +
68
+ `No files were written.`);
69
+ }
70
+ seen.set(identity, relativePath);
71
+ planned.push({ relativePath, uri });
72
+ }
73
+ return planned;
74
+ }
75
+ function messageOf(error) {
76
+ return error instanceof Error ? error.message : String(error);
77
+ }
78
+ /** Removes what was written, returning the URIs it could not remove. */
79
+ async function unwind(sink, writtenUris) {
80
+ if (sink.remove === undefined)
81
+ return [...writtenUris];
82
+ const unremoved = [];
83
+ // Reverse order, so nested files go before the directories that hold them if a
84
+ // sink ever chooses to prune empty parents.
85
+ for (const uri of [...writtenUris].reverse()) {
86
+ try {
87
+ await sink.remove(uri);
88
+ }
89
+ catch {
90
+ unremoved.push(uri);
91
+ }
92
+ }
93
+ return unremoved;
94
+ }
95
+ /**
96
+ * Parse a target's install manifest, or `undefined` when there is nothing usable there.
97
+ *
98
+ * Every failure is the same answer: absent, unreadable and malformed all mean "cannot claim the target is
99
+ * up to date", and the safe response to each is to install. Throwing here would turn a corrupt manifest
100
+ * into a broken command rather than a rewrite.
101
+ */
102
+ async function readManifest(read) {
103
+ let text;
104
+ try {
105
+ text = await read();
106
+ }
107
+ catch {
108
+ return undefined;
109
+ }
110
+ if (text === undefined)
111
+ return undefined;
112
+ try {
113
+ const parsed = JSON.parse(text);
114
+ return typeof parsed?.assetBundleVersion === 'number' &&
115
+ Array.isArray(parsed.files)
116
+ ? parsed
117
+ : undefined;
118
+ }
119
+ catch {
120
+ return undefined;
121
+ }
122
+ }
123
+ /**
124
+ * Do two file lists describe the same bytes?
125
+ *
126
+ * Compared as a MAP keyed by path, not as ordered arrays: the manifest's order is whatever a previous
127
+ * version happened to write, and a reordering is not a change. The length check is what catches a file
128
+ * added to or removed from the bundle, which a per-path lookup alone would miss in one direction.
129
+ */
130
+ function sameFiles(already, wanted) {
131
+ if (already.length !== wanted.length)
132
+ return false;
133
+ const byPath = new Map(already.map((file) => [file.path, file.checksum]));
134
+ return wanted.every((file) => byPath.get(file.path) === file.checksum);
135
+ }
136
+ export async function installAssets(options) {
137
+ const { source, sink, hasher, clock } = options;
138
+ const targetUri = normalizeUri(options.targetUri);
139
+ if (targetUri === '') {
140
+ throw new AssetInstallError('Refusing to install: the target URI is empty. An empty target normalizes to the ' +
141
+ 'filesystem root, which is never what a caller means.');
142
+ }
143
+ const destinationUri = joinUri(targetUri, CANONICAL_SUBPATH);
144
+ const kind = options.kind ?? 'all';
145
+ const relativePaths = [...(await source.list())]
146
+ .filter((p) => isKind(p, kind))
147
+ .sort();
148
+ // Everything that can fail is resolved BEFORE the first byte is written, so a
149
+ // rejected bundle leaves no half-installed tree behind. That includes the
150
+ // bundle version: reading it after the write loop meant the most likely
151
+ // failure in the whole flow (a missing or malformed BUNDLE_VERSION) fired only
152
+ // once every asset was already on disk, with no manifest to describe them.
153
+ const assetBundleVersion = await source.bundleVersion();
154
+ const planned = plan(relativePaths, destinationUri);
155
+ const manifestUriForCheck = joinUri(destinationUri, MANIFEST_FILENAME);
156
+ // Hash the SOURCE first, then compare. Reading and hashing the bundle is local and cheap; the cost
157
+ // being avoided is the WRITES, which on a remote or browser host are one round trip each — the reason
158
+ // installing IntelliSense felt like it re-did everything every time.
159
+ //
160
+ // Compared by CHECKSUM and not by bundle version alone. A version match would call a hand-edited
161
+ // target up to date and leave it broken, and the install target has been edited in place before —
162
+ // ADR 0003 records exactly that happening to `templates/.hexasync/intellisense`. Checksums notice, and
163
+ // rewrite.
164
+ const sourceFiles = [];
165
+ const sourceBytes = new Map();
166
+ for (const { relativePath } of planned) {
167
+ const bytes = await source.read(relativePath);
168
+ sourceBytes.set(relativePath, bytes);
169
+ sourceFiles.push({
170
+ path: relativePath,
171
+ checksum: await hasher.hash(bytes),
172
+ });
173
+ }
174
+ if (options.existingManifest !== undefined && sourceFiles.length > 0) {
175
+ const already = await readManifest(options.existingManifest);
176
+ if (already !== undefined &&
177
+ already.assetBundleVersion === assetBundleVersion &&
178
+ sameFiles(already.files, sourceFiles)) {
179
+ return {
180
+ targetUri,
181
+ destinationUri,
182
+ manifestUri: manifestUriForCheck,
183
+ assetBundleVersion,
184
+ filesWritten: 0,
185
+ empty: false,
186
+ unchanged: true,
187
+ files: sourceFiles,
188
+ };
189
+ }
190
+ }
191
+ const files = [];
192
+ const writtenUris = [];
193
+ try {
194
+ for (const { relativePath, uri } of planned) {
195
+ // Already read and hashed above for the comparison; reading a second time would double the source
196
+ // IO to learn nothing new.
197
+ const bytes = sourceBytes.get(relativePath);
198
+ files.push({ path: relativePath, checksum: await hasher.hash(bytes) });
199
+ await sink.write(uri, bytes);
200
+ writtenUris.push(uri);
201
+ if (options.onProgress !== undefined) {
202
+ try {
203
+ options.onProgress({
204
+ written: files.length,
205
+ total: planned.length,
206
+ path: relativePath,
207
+ });
208
+ }
209
+ catch {
210
+ // A host's progress reporting is never allowed to break an install.
211
+ }
212
+ }
213
+ }
214
+ }
215
+ catch (error) {
216
+ // Unwind. Validation already guarantees nothing is written when a path is
217
+ // bad; this covers the other half — an IO failure part way through — so that
218
+ // "no partial asset tree is left behind" is true in general and not only for
219
+ // the validation case. Best-effort by nature: a sink that cannot remove, or
220
+ // that fails to, is reported rather than hidden.
221
+ const unremoved = await unwind(sink, writtenUris);
222
+ throw new AssetInstallError(`Install failed after writing ${writtenUris.length} file(s): ${messageOf(error)}. ` +
223
+ (unremoved.length === 0
224
+ ? 'Files written before the failure were removed, so the target is unchanged.'
225
+ : `${unremoved.length} file(s) could not be removed and remain in the target: ` +
226
+ `${unremoved.join(', ')}. No manifest was written, so this cannot be mistaken ` +
227
+ `for a complete install.`));
228
+ }
229
+ const manifest = {
230
+ generator: '@beehexa/hexasync-template-assets',
231
+ assetBundleVersion,
232
+ installedAt: await clock.now(),
233
+ files,
234
+ };
235
+ const manifestUri = joinUri(destinationUri, MANIFEST_FILENAME);
236
+ await sink.write(manifestUri, new TextEncoder().encode(`${JSON.stringify(manifest, null, 2)}\n`));
237
+ return {
238
+ targetUri,
239
+ destinationUri,
240
+ manifestUri,
241
+ assetBundleVersion,
242
+ filesWritten: files.length,
243
+ empty: files.length === 0,
244
+ unchanged: false,
245
+ files,
246
+ };
247
+ }
248
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,sBAAsB,GAEvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,WAAW,EACX,OAAO,EACP,YAAY,GACb,MAAM,kCAAkC,CAAC;AAE1C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAC1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC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@
1
+ /**
2
+ * Structural lint rules for authored template files.
3
+ *
4
+ * These two constraints cannot live in JSON Schema:
5
+ *
6
+ * * **filename ↔ content agreement** — a schema has no access to the document's path;
7
+ * * **at most N collections per file** — JSON Schema cannot count matching properties, so it
8
+ * would take 286 generated `not`/`anyOf` branches to say "no three of these thirteen keys
9
+ * together", and the resulting message would name none of them.
10
+ *
11
+ * So they are code, in core, with real messages — one rule set that the CLI surfaces today and
12
+ * the editor's diagnostics will surface in Phase 1, rather than two implementations that drift.
13
+ *
14
+ * Pure: takes a path and an already-parsed document. No IO (AD-4).
15
+ */
16
+ /** The root collections a component file may declare. */
17
+ export declare const COLLECTIONS: readonly ["objects", "pullers", "pushers", "tables", "validations", "transformations", "dependencies", "webhooks", "connectors", "metricGroups", "startupTasks", "objectAssociations", "variables"];
18
+ export type Collection = (typeof COLLECTIONS)[number];
19
+ /**
20
+ * The filename each collection is expected to carry.
21
+ *
22
+ * Kept as a convention that must AGREE with the content, rather than as the thing that decides
23
+ * which schema applies — content decides that. A name and a content that disagree is the error,
24
+ * because it misleads every human reader even when the tooling gets it right.
25
+ */
26
+ export declare const FILENAME_CONVENTION: Readonly<Record<Collection, string>>;
27
+ /**
28
+ * How many collections one file may declare before it is an error.
29
+ *
30
+ * `main.yaml` is exempt: it is the project manifest and legitimately aggregates everything.
31
+ *
32
+ * Set to 2 — a file may pair a Task with its puller, which 192 corpus files do, but a
33
+ * three-way grab-bag is an error. Measured against the corpus: this threshold flags **26**
34
+ * files, where a threshold of 1 would flag **240** and condemn that established pairing.
35
+ * Raise or lower it here; the rule reports the limit it applied so a report is never ambiguous
36
+ * about which reading produced it.
37
+ */
38
+ export declare const MAX_COLLECTIONS_PER_FILE = 2;
39
+ export type Severity = 'critical' | 'warning';
40
+ export interface LintDiagnostic {
41
+ readonly ruleId: 'one-component-per-file' | 'filename-matches-content';
42
+ readonly severity: Severity;
43
+ readonly path: string;
44
+ readonly message: string;
45
+ }
46
+ /** The collections a parsed document declares, in declaration order. */
47
+ export declare function declaredCollections(document: unknown): Collection[];
48
+ /**
49
+ * Lints one authored file.
50
+ *
51
+ * @param path the file's path, used for the filename rule and for reporting.
52
+ * @param document the parsed YAML.
53
+ */
54
+ export declare function lintDocument(path: string, document: unknown): LintDiagnostic[];
55
+ export interface LintSummary {
56
+ readonly filesLinted: number;
57
+ readonly diagnostics: readonly LintDiagnostic[];
58
+ readonly byRule: Readonly<Record<string, number>>;
59
+ readonly criticalCount: number;
60
+ }
61
+ /** Rolls per-file diagnostics into a summary. */
62
+ export declare function summariseLint(results: readonly {
63
+ path: string;
64
+ diagnostics: readonly LintDiagnostic[];
65
+ }[]): LintSummary;
66
+ //# sourceMappingURL=lint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,yDAAyD;AACzD,eAAO,MAAM,WAAW,qMAcd,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAcpE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AAE9C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,wBAAwB,GAAG,0BAA0B,CAAC;IACvE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAWD,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,UAAU,EAAE,CASnE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,GAChB,cAAc,EAAE,CA6ClB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,iDAAiD;AACjD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,EAAE,GAC3E,WAAW,CAUb"}
package/dist/lint.js ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Structural lint rules for authored template files.
3
+ *
4
+ * These two constraints cannot live in JSON Schema:
5
+ *
6
+ * * **filename ↔ content agreement** — a schema has no access to the document's path;
7
+ * * **at most N collections per file** — JSON Schema cannot count matching properties, so it
8
+ * would take 286 generated `not`/`anyOf` branches to say "no three of these thirteen keys
9
+ * together", and the resulting message would name none of them.
10
+ *
11
+ * So they are code, in core, with real messages — one rule set that the CLI surfaces today and
12
+ * the editor's diagnostics will surface in Phase 1, rather than two implementations that drift.
13
+ *
14
+ * Pure: takes a path and an already-parsed document. No IO (AD-4).
15
+ */
16
+ /** The root collections a component file may declare. */
17
+ export const COLLECTIONS = [
18
+ 'objects',
19
+ 'pullers',
20
+ 'pushers',
21
+ 'tables',
22
+ 'validations',
23
+ 'transformations',
24
+ 'dependencies',
25
+ 'webhooks',
26
+ 'connectors',
27
+ 'metricGroups',
28
+ 'startupTasks',
29
+ 'objectAssociations',
30
+ 'variables',
31
+ ];
32
+ /**
33
+ * The filename each collection is expected to carry.
34
+ *
35
+ * Kept as a convention that must AGREE with the content, rather than as the thing that decides
36
+ * which schema applies — content decides that. A name and a content that disagree is the error,
37
+ * because it misleads every human reader even when the tooling gets it right.
38
+ */
39
+ export const FILENAME_CONVENTION = {
40
+ objects: 'Task',
41
+ pullers: 'Puller',
42
+ pushers: 'Pusher',
43
+ tables: 'Table',
44
+ validations: 'Validation',
45
+ transformations: 'Transformation',
46
+ dependencies: 'Dependency',
47
+ webhooks: 'Webhook',
48
+ connectors: 'Connection',
49
+ metricGroups: 'metricGroup',
50
+ startupTasks: 'StartupTask',
51
+ objectAssociations: 'ObjectAssociations',
52
+ variables: 'variables',
53
+ };
54
+ /**
55
+ * How many collections one file may declare before it is an error.
56
+ *
57
+ * `main.yaml` is exempt: it is the project manifest and legitimately aggregates everything.
58
+ *
59
+ * Set to 2 — a file may pair a Task with its puller, which 192 corpus files do, but a
60
+ * three-way grab-bag is an error. Measured against the corpus: this threshold flags **26**
61
+ * files, where a threshold of 1 would flag **240** and condemn that established pairing.
62
+ * Raise or lower it here; the rule reports the limit it applied so a report is never ambiguous
63
+ * about which reading produced it.
64
+ */
65
+ export const MAX_COLLECTIONS_PER_FILE = 2;
66
+ /** Files exempt from the one-component rule, by basename. */
67
+ const AGGREGATE_FILENAMES = new Set(['main.yaml', 'output.yaml']);
68
+ function basename(path) {
69
+ const normalized = path.replace(/\\/g, '/');
70
+ const slash = normalized.lastIndexOf('/');
71
+ return slash === -1 ? normalized : normalized.slice(slash + 1);
72
+ }
73
+ /** The collections a parsed document declares, in declaration order. */
74
+ export function declaredCollections(document) {
75
+ if (document === null ||
76
+ typeof document !== 'object' ||
77
+ Array.isArray(document))
78
+ return [];
79
+ const keys = Object.keys(document);
80
+ return COLLECTIONS.filter((c) => keys.includes(c));
81
+ }
82
+ /**
83
+ * Lints one authored file.
84
+ *
85
+ * @param path the file's path, used for the filename rule and for reporting.
86
+ * @param document the parsed YAML.
87
+ */
88
+ export function lintDocument(path, document) {
89
+ const name = basename(path);
90
+ const diagnostics = [];
91
+ const declared = declaredCollections(document);
92
+ if (declared.length === 0)
93
+ return diagnostics;
94
+ // --- one component per file ---
95
+ if (!AGGREGATE_FILENAMES.has(name) &&
96
+ declared.length > MAX_COLLECTIONS_PER_FILE) {
97
+ diagnostics.push({
98
+ ruleId: 'one-component-per-file',
99
+ severity: 'critical',
100
+ path,
101
+ message: `Declares ${declared.length} collections (${declared.join(', ')}), and at most ` +
102
+ `${MAX_COLLECTIONS_PER_FILE} are allowed outside main.yaml. Split it so each file holds ` +
103
+ `one component: a reader cannot tell what this file is, and its name can only ever ` +
104
+ `describe one of the ${declared.length} things inside it.`,
105
+ });
106
+ }
107
+ // --- filename agrees with content ---
108
+ //
109
+ // Only checked for a single-collection file. In a legitimately paired file the name cannot
110
+ // match both collections, so demanding it would produce an error no author could satisfy.
111
+ if (declared.length === 1 && !AGGREGATE_FILENAMES.has(name)) {
112
+ const collection = declared[0];
113
+ const expected = FILENAME_CONVENTION[collection];
114
+ if (!name.toLowerCase().includes(expected.toLowerCase())) {
115
+ diagnostics.push({
116
+ ruleId: 'filename-matches-content',
117
+ severity: 'critical',
118
+ path,
119
+ message: `Declares \`${collection}:\` but the filename does not contain "${expected}". ` +
120
+ `Rename it to something like \`<Something>${expected}.yaml\`. The schema still ` +
121
+ `applies — components are identified by content — but a name that disagrees with the ` +
122
+ `content misleads every human reading the folder.`,
123
+ });
124
+ }
125
+ }
126
+ return diagnostics;
127
+ }
128
+ /** Rolls per-file diagnostics into a summary. */
129
+ export function summariseLint(results) {
130
+ const diagnostics = results.flatMap((r) => r.diagnostics);
131
+ const byRule = {};
132
+ for (const d of diagnostics)
133
+ byRule[d.ruleId] = (byRule[d.ruleId] ?? 0) + 1;
134
+ return {
135
+ filesLinted: results.length,
136
+ diagnostics,
137
+ byRule,
138
+ criticalCount: diagnostics.filter((d) => d.severity === 'critical').length,
139
+ };
140
+ }
141
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"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C;QAChC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;YACzD,WAAW,CAAC,IAAI,CAAC;gBACf,MAAM,EAAE,0BAA0B;gBAClC,QAAQ,EAAE,UAAU;gBACpB,IAAI;gBACJ,OAAO,EACL,cAAc,UAAU,0CAA0C,QAAQ,KAAK;oBAC/E,4CAA4C,QAAQ,4BAA4B;oBAChF,sFAAsF;oBACtF,kDAAkD;aACrD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AASD,iDAAiD;AACjD,MAAM,UAAU,aAAa,CAC3B,OAA4E;IAE5E,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAC1D,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,IAAI,WAAW;QAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5E,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,MAAM;QAC3B,WAAW;QACX,MAAM;QACN,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,MAAM;KAC3E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Ports (AD-4). Core declares what it needs; adapters supply it.
3
+ *
4
+ * Every port is async (AD-11) even where a synchronous implementation would do,
5
+ * so promoting core into another process — or onto the web host, whose crypto
6
+ * and filesystem APIs are inherently async — is a transport swap, not a rewrite.
7
+ */
8
+ /** Supplies the canonical asset payload. Paths are relative, POSIX-separated. */
9
+ export interface AssetSource {
10
+ /** Every asset file, as paths relative to the bundle root. */
11
+ list(): Promise<readonly string[]>;
12
+ read(relativePath: string): Promise<Uint8Array>;
13
+ /** The asset-bundle integer (AD-16). */
14
+ bundleVersion(): Promise<number>;
15
+ }
16
+ /**
17
+ * Reads back what was installed, so an update can classify it before overwriting.
18
+ *
19
+ * Separate from `AssetSource`, which reads the *bundle*. This reads the *target* — the
20
+ * developer's copy, which may have been edited. Conflating the two is how an update
21
+ * would compare a file against itself.
22
+ */
23
+ export interface FileReader {
24
+ /** Bytes at a URI, or `undefined` when nothing is there. */
25
+ read(uri: string): Promise<Uint8Array | undefined>;
26
+ }
27
+ /** Receives bytes. The only thing in this package permitted to write. */
28
+ export interface FileSink {
29
+ write(uri: string, bytes: Uint8Array): Promise<void>;
30
+ /**
31
+ * Removes a file this sink wrote. Optional.
32
+ *
33
+ * Exists so a failed install can undo its own partial work. Without it the
34
+ * story's acceptance criterion — "no partial asset tree is left behind" — held
35
+ * only for validation failures: once writing started, a filesystem error on the
36
+ * third of four files left two behind and nothing could remove them.
37
+ *
38
+ * Optional rather than required because a sink may be genuinely append-only. A
39
+ * sink that cannot delete simply cannot be unwound, and `installAssets` reports
40
+ * that honestly instead of pretending.
41
+ */
42
+ remove?(uri: string): Promise<void>;
43
+ }
44
+ /**
45
+ * Content hashing. A port rather than `node:crypto` because AD-3 forbids Node
46
+ * builtins in core, and the web host offers only the async Web Crypto API.
47
+ */
48
+ export interface Hasher {
49
+ hash(bytes: Uint8Array): Promise<string>;
50
+ }
51
+ /**
52
+ * Injected so manifests are deterministic under test.
53
+ *
54
+ * Async like every other port even though `new Date()` is synchronous
55
+ * everywhere: AD-11 asks for async at the boundary *including* where a
56
+ * synchronous call would work, precisely so that no caller can grow a
57
+ * dependency on the sync shape and block the LSP promotion later.
58
+ */
59
+ export interface Clock {
60
+ now(): Promise<string>;
61
+ }
62
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../src/ports.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iFAAiF;AACjF,MAAM,WAAW,WAAW;IAC1B,8DAA8D;IAC9D,IAAI,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IACnC,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAChD,wCAAwC;IACxC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAClC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,4DAA4D;IAC5D,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACpD;AAED,yEAAyE;AACzE,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,KAAK;IACpB,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxB"}
package/dist/ports.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Ports (AD-4). Core declares what it needs; adapters supply it.
3
+ *
4
+ * Every port is async (AD-11) even where a synchronous implementation would do,
5
+ * so promoting core into another process — or onto the web host, whose crypto
6
+ * and filesystem APIs are inherently async — is a transport swap, not a rewrite.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.js","sourceRoot":"","sources":["../src/ports.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Updating an installed target without destroying local work (FR-21).
3
+ *
4
+ * The rule this implements: a write that would discard something the developer cannot recover
5
+ * requires explicit confirmation, per file. Everything else proceeds. A declined file is left
6
+ * exactly as it was and the rest of the update continues — refusing the whole update because
7
+ * one file was edited would make the feature unusable on any real target.
8
+ *
9
+ * Pure: no IO of its own (AD-4).
10
+ */
11
+ import { type AssetKind } from './assetPath.js';
12
+ import { type ClassifiedFile, type Classification, type FileState } from './classify.js';
13
+ import type { AssetSource, Clock, FileReader, FileSink, Hasher } from './ports.js';
14
+ /** Asked once per destructive write. Returning false leaves the file untouched. */
15
+ export type ConfirmOverwrite = (file: ClassifiedFile, diff: OverwriteDiff) => Promise<boolean>;
16
+ export interface OverwriteDiff {
17
+ readonly path: string;
18
+ readonly installedText: string;
19
+ readonly bundleText: string;
20
+ }
21
+ export interface UpdateOptions {
22
+ readonly source: AssetSource;
23
+ readonly reader: FileReader;
24
+ readonly sink: FileSink;
25
+ readonly hasher: Hasher;
26
+ readonly clock: Clock;
27
+ readonly targetUri: string;
28
+ /** Which half to update. Documentation must be updatable on its own (Story 2.7). */
29
+ readonly kind?: AssetKind;
30
+ readonly confirmOverwrite: ConfirmOverwrite;
31
+ readonly onProgress?: (progress: {
32
+ written: number;
33
+ total: number;
34
+ path: string;
35
+ }) => void;
36
+ }
37
+ export interface UpdateOutcome {
38
+ readonly path: string;
39
+ readonly state: FileState;
40
+ /** What actually happened, which is not always what the state implied. */
41
+ readonly action: 'written' | 'skipped-unchanged' | 'declined' | 'left-newer' | 'left-in-place';
42
+ }
43
+ export interface UpdateResult {
44
+ readonly destinationUri: string;
45
+ readonly classification: Classification;
46
+ readonly outcomes: readonly UpdateOutcome[];
47
+ readonly written: number;
48
+ readonly declined: number;
49
+ /** True when the target was pinned and nothing was touched (FR-24, Story 2.8). */
50
+ readonly pinned: boolean;
51
+ }
52
+ export declare function updateAssets(options: UpdateOptions): Promise<UpdateResult>;
53
+ /** Thrown when a caller asks to update a target that was never installed. */
54
+ export declare function assertInstalled(classification: Classification): void;
55
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,eAAe,CAAC;AAMvB,OAAO,KAAK,EACV,WAAW,EACX,KAAK,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACP,MAAM,YAAY,CAAC;AAGpB,mFAAmF;AACnF,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,aAAa,KAChB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oFAAoF;IACpF,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,UAAU,CAAC,EA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