@beehexa/hexasync-template-assets 2608.20.18 → 2608.20.31
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/dist/assetPath.d.ts +96 -0
- package/dist/assetPath.d.ts.map +1 -0
- package/dist/assetPath.js +170 -0
- package/dist/assetPath.js.map +1 -0
- package/dist/classify.d.ts +44 -0
- package/dist/classify.d.ts.map +1 -0
- package/dist/classify.js +147 -0
- package/dist/classify.js.map +1 -0
- package/dist/env.d.ts +57 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +97 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/install.d.ts +83 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +248 -0
- package/dist/install.js.map +1 -0
- package/dist/lint.d.ts +66 -0
- package/dist/lint.d.ts.map +1 -0
- package/dist/lint.js +141 -0
- package/dist/lint.js.map +1 -0
- package/dist/mcpClients.d.ts +65 -0
- package/dist/mcpClients.d.ts.map +1 -0
- package/dist/mcpClients.js +114 -0
- package/dist/mcpClients.js.map +1 -0
- package/dist/ports.d.ts +62 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +9 -0
- package/dist/ports.js.map +1 -0
- package/dist/update.d.ts +55 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +158 -0
- package/dist/update.js.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ASSET_SEGMENT_PATTERN, AssetPathError, BUNDLE_VERSION_FILENAME, DOCS_PREFIX, isKind, type AssetKind, encodeAssetSegments, isAssetFileName, parseAssetRelativePath, parseBundleVersion, } from './assetPath.js';
|
|
2
|
+
export { AssetInstallError, CANONICAL_SUBPATH, MANIFEST_FILENAME, installAssets, type InstallManifest, type InstallOptions, type InstallProgress, type InstallResult, type InstalledFile, } from './install.js';
|
|
3
|
+
export type { AssetSource, Clock, FileSink, Hasher } from './ports.js';
|
|
4
|
+
export { basenameUri, dirnameUri, isInsideUri, joinUri, normalizeUri, relativeUri, resolveUri, } from '@beehexa/hexasync-template-model';
|
|
5
|
+
export { classifyTarget, summariseClassification, type ClassifiedFile, type Classification, type ClassifyOptions, type FileState, } from './classify.js';
|
|
6
|
+
export { assertInstalled, updateAssets, type ConfirmOverwrite, type OverwriteDiff, type UpdateOptions, type UpdateOutcome, type UpdateResult, } from './update.js';
|
|
7
|
+
export type { FileReader } from './ports.js';
|
|
8
|
+
export { COLLECTIONS, FILENAME_CONVENTION, MAX_COLLECTIONS_PER_FILE, declaredCollections, lintDocument, summariseLint, type Collection, type LintDiagnostic, type LintSummary, type Severity, } from './lint.js';
|
|
9
|
+
export { checkEnvironment, formatEnvReport, type EnvItem, type EnvObservation, type EnvOutcome, type EnvReport, } from './env.js';
|
|
10
|
+
export { MCP_CLIENTS, SERVER_ENTRY, SERVER_NAME, clientSnippet, mergeClientConfig, type McpClient, type MergeOutcome, } from './mcpClients.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,MAAM,EACN,KAAK,SAAS,EACd,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EACL,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,EACP,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,GACd,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ASSET_SEGMENT_PATTERN, AssetPathError, BUNDLE_VERSION_FILENAME, DOCS_PREFIX, isKind, encodeAssetSegments, isAssetFileName, parseAssetRelativePath, parseBundleVersion, } from './assetPath.js';
|
|
2
|
+
export { AssetInstallError, CANONICAL_SUBPATH, MANIFEST_FILENAME, installAssets, } from './install.js';
|
|
3
|
+
export { basenameUri, dirnameUri, isInsideUri, joinUri, normalizeUri, relativeUri, resolveUri, } from '@beehexa/hexasync-template-model';
|
|
4
|
+
export { classifyTarget, summariseClassification, } from './classify.js';
|
|
5
|
+
export { assertInstalled, updateAssets, } from './update.js';
|
|
6
|
+
export { COLLECTIONS, FILENAME_CONVENTION, MAX_COLLECTIONS_PER_FILE, declaredCollections, lintDocument, summariseLint, } from './lint.js';
|
|
7
|
+
export { checkEnvironment, formatEnvReport, } from './env.js';
|
|
8
|
+
export { MCP_CLIENTS, SERVER_ENTRY, SERVER_NAME, clientSnippet, mergeClientConfig, } from './mcpClients.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,MAAM,EAEN,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GAMd,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,EACP,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,uBAAuB,GAKxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,YAAY,GAMb,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,aAAa,GAKd,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,gBAAgB,EAChB,eAAe,GAKhB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,GAGlB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { type AssetKind } from './assetPath.js';
|
|
9
|
+
import type { AssetSource, Clock, FileSink, Hasher } from './ports.js';
|
|
10
|
+
/** Where installed assets live, relative to a target. Dot-prefixed (FR-19). */
|
|
11
|
+
export declare const CANONICAL_SUBPATH = ".hexasync/intellisense";
|
|
12
|
+
export declare const MANIFEST_FILENAME = ".install-manifest.json";
|
|
13
|
+
export declare class AssetInstallError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/** Reported after each file, so a host can drive a progress indicator. */
|
|
17
|
+
export interface InstallProgress {
|
|
18
|
+
readonly written: number;
|
|
19
|
+
readonly total: number;
|
|
20
|
+
readonly path: string;
|
|
21
|
+
}
|
|
22
|
+
export interface InstallOptions {
|
|
23
|
+
readonly source: AssetSource;
|
|
24
|
+
readonly sink: FileSink;
|
|
25
|
+
readonly hasher: Hasher;
|
|
26
|
+
/**
|
|
27
|
+
* The install manifest already at the target, when there is one.
|
|
28
|
+
*
|
|
29
|
+
* Supplied by the host because reading the TARGET is not the source's job. When it describes exactly
|
|
30
|
+
* the bundle about to be written, every write is skipped — see the `unchanged` short-circuit below.
|
|
31
|
+
* Omitted by a caller that wants an unconditional install.
|
|
32
|
+
*/
|
|
33
|
+
readonly existingManifest?: () => Promise<string | undefined>;
|
|
34
|
+
readonly clock: Clock;
|
|
35
|
+
readonly targetUri: string;
|
|
36
|
+
/**
|
|
37
|
+
* Which half of the bundle to install — schemas, docs, or both. Defaults to `all`.
|
|
38
|
+
*
|
|
39
|
+
* Exists because `Install Documentation` and `Install IntelliSense` must each work on their
|
|
40
|
+
* own (Story 2.7), and the manifest must then describe exactly what was installed rather
|
|
41
|
+
* than what the bundle happens to contain.
|
|
42
|
+
*/
|
|
43
|
+
readonly kind?: AssetKind;
|
|
44
|
+
/**
|
|
45
|
+
* Optional progress callback.
|
|
46
|
+
*
|
|
47
|
+
* Exists because the editor wraps the install in a progress notification and
|
|
48
|
+
* had nothing to report into it — a static spinner regardless of file count.
|
|
49
|
+
* Synchronous and never awaited: a host's reporting must not be able to slow,
|
|
50
|
+
* reorder or fail the install. Exceptions from it are deliberately swallowed.
|
|
51
|
+
*/
|
|
52
|
+
readonly onProgress?: (progress: InstallProgress) => void;
|
|
53
|
+
}
|
|
54
|
+
export interface InstalledFile {
|
|
55
|
+
readonly path: string;
|
|
56
|
+
readonly checksum: string;
|
|
57
|
+
}
|
|
58
|
+
export interface InstallManifest {
|
|
59
|
+
readonly generator: string;
|
|
60
|
+
readonly assetBundleVersion: number;
|
|
61
|
+
readonly installedAt: string;
|
|
62
|
+
readonly files: readonly InstalledFile[];
|
|
63
|
+
}
|
|
64
|
+
export interface InstallResult {
|
|
65
|
+
readonly targetUri: string;
|
|
66
|
+
readonly destinationUri: string;
|
|
67
|
+
readonly manifestUri: string;
|
|
68
|
+
readonly assetBundleVersion: number;
|
|
69
|
+
readonly filesWritten: number;
|
|
70
|
+
/** True when the source held no assets. Reported, never silently treated as success. */
|
|
71
|
+
readonly empty: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* True when the target already held this exact bundle and nothing was written.
|
|
74
|
+
*
|
|
75
|
+
* Distinct from `filesWritten === 0`, which is also true for an empty source. A caller reporting
|
|
76
|
+
* "installed 0 files" for an up-to-date target says the wrong thing twice: it sounds like a failure,
|
|
77
|
+
* and it hides that the check is what made it fast.
|
|
78
|
+
*/
|
|
79
|
+
readonly unchanged: boolean;
|
|
80
|
+
readonly files: readonly InstalledFile[];
|
|
81
|
+
}
|
|
82
|
+
export declare function installAssets(options: InstallOptions): Promise<InstallResult>;
|
|
83
|
+
//# sourceMappingURL=install.d.ts.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,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,wFAAwF;IACxF,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;CAC1C;AAkJD,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CA8HxB"}
|
package/dist/install.js
ADDED
|
@@ -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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ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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,YACtB,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,YAAY,EAC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.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
|
package/dist/lint.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,yDAAyD;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,SAAS;IACT,SAAS;IACT,SAAS;IACT,QAAQ;IACR,aAAa;IACb,iBAAiB;IACjB,cAAc;IACd,UAAU;IACV,YAAY;IACZ,cAAc;IACd,cAAc;IACd,oBAAoB;IACpB,WAAW;CACH,CAAC;AAIX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAyC;IACvE,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE,OAAO;IACf,WAAW,EAAE,YAAY;IACzB,eAAe,EAAE,gBAAgB;IACjC,YAAY,EAAE,YAAY;IAC1B,QAAQ,EAAE,SAAS;IACnB,UAAU,EAAE,YAAY;IACxB,YAAY,EAAE,aAAa;IAC3B,YAAY,EAAE,aAAa;IAC3B,kBAAkB,EAAE,oBAAoB;IACxC,SAAS,EAAE,WAAW;CACvB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAW1C,6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