@hyperframes/share 0.9.96 → 0.9.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/projectSnapshot.d.mts +4 -0
- package/dist/shareSources.d.mts +7 -3
- package/dist/sourceIgnore.d.mts +10 -3
- package/dist/sources/adapterTypes.d.ts +5 -0
- package/dist/sources/assetReferences.d.mts +10 -0
- package/dist/sources/capture.d.mts +20 -2
- package/dist/sources/pathPolicy.d.mts +7 -4
- package/dist/sources/referencedFiles.d.mts +18 -0
- package/dist/sources/types.d.ts +3 -0
- package/dist/sources/upload.d.mts +2 -2
- package/dist/sources/variableAssets.d.mts +11 -0
- package/package.json +8 -2
- package/src/projectSnapshot.mjs +7 -0
- package/src/shareSources.mjs +70 -23
- package/src/sourceIgnore.mjs +62 -33
- package/src/sources/adapterTypes.d.ts +5 -0
- package/src/sources/assetReferences.mjs +209 -0
- package/src/sources/capture.mjs +114 -20
- package/src/sources/contract/path-policy.json +32 -3
- package/src/sources/manifest.mjs +7 -5
- package/src/sources/pathPolicy.mjs +39 -8
- package/src/sources/referencedFiles.mjs +221 -0
- package/src/sources/types.d.ts +3 -0
- package/src/sources/upload.mjs +18 -7
- package/src/sources/variableAssets.mjs +116 -0
package/README.md
CHANGED
|
@@ -78,6 +78,39 @@ can use video-only; changed source, conflicts and unexpected upload failures nee
|
|
|
78
78
|
an explicit choice to omit source. The CLI exposes `--video-only` for that choice.
|
|
79
79
|
`filesForExport` only validates already-prepared source; it does not upload.
|
|
80
80
|
|
|
81
|
+
For editable projects, show the paths returned by `listReferencedHiddenSourceAssets(projectPath)`
|
|
82
|
+
with the usual Share action. Both this function and `referencedHiddenDigest` are exported from
|
|
83
|
+
`@hyperframes/share/projectSnapshot.mjs`. Pass `expectedReferencedHiddenDigest: referencedHiddenDigest(paths)`
|
|
84
|
+
to `shareSources`. If the captured paths differ, refresh the summary and retry. An older host that
|
|
85
|
+
omits the digest can still send projects with no referenced hidden assets.
|
|
86
|
+
|
|
87
|
+
Hosts can set `reuseOnly: true` to attach an existing published snapshot without creating, resuming or cancelling a source upload. The workspace, manifest and rendered project must still match at attachment time.
|
|
88
|
+
|
|
89
|
+
Hosts that use gitignore syntax can pass the same syntax choice to disclosure and the adapter:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
const selection = { ignoreSyntax: "gitignore" };
|
|
93
|
+
const paths = await listReferencedHiddenSourceAssets(projectPath, undefined, selection);
|
|
94
|
+
await showShareSummary(paths);
|
|
95
|
+
const sources = shareSources({
|
|
96
|
+
access,
|
|
97
|
+
spaceId,
|
|
98
|
+
...selection,
|
|
99
|
+
expectedReferencedHiddenDigest: referencedHiddenDigest(paths),
|
|
100
|
+
});
|
|
101
|
+
const result = await sources.prepare(projectPath, renderedFingerprint);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The adapter reads the current rules for each capture, including retries and final checks in
|
|
105
|
+
`filesForExport`. Hosts that use `shareSourceFingerprint` for content identity pass the same
|
|
106
|
+
`selection` as its second argument. Omitting `ignoreSyntax` retains the strict project-relative syntax.
|
|
107
|
+
|
|
108
|
+
Hosts with their own file inventory can instead read `readSourceIgnore(projectPath, { syntax: "gitignore" })`
|
|
109
|
+
once per capture. Pass the resulting `ignored` function to the inventory walk as
|
|
110
|
+
`ignored(relativePath, entry.isDirectory())` and reuse it for
|
|
111
|
+
`listReferencedHiddenSourceAssets(projectPath, observed, { ignored })`. Private-path rules apply
|
|
112
|
+
even when an ignore rule re-includes a path.
|
|
113
|
+
|
|
81
114
|
The adapter uses the portable-source-v12 capture/manifest rules and
|
|
82
115
|
multipart transport. The pinned policy, Unicode 15.1 registry (with its license),
|
|
83
116
|
and manifest test vectors are checked into this repository. Source is captured through
|
|
@@ -86,6 +119,10 @@ Workspace limits, upload receipts and published snapshot identity are checked.
|
|
|
86
119
|
Pending uploads retain their original idempotency key across retries. A conflict
|
|
87
120
|
is never auto-resolved. When local source changes, the adapter cancels an older
|
|
88
121
|
pending upload before starting another; uploads under verification are preserved.
|
|
122
|
+
If a Begin response was lost before its upload ID was saved, recovery can replay the original request
|
|
123
|
+
only while every marked hidden asset still has its disclosed path, hash and size in the current capture.
|
|
124
|
+
Otherwise the adapter starts a new request and any unconfirmed pending upload expires on the server.
|
|
125
|
+
When the upload ID is known, recovery can check its status directly.
|
|
89
126
|
A stalled storage PUT stops after 60 seconds without progress and can retry with
|
|
90
127
|
the same upload identity.
|
|
91
128
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Identity of the hidden paths shown with the normal share action. @param {readonly string[]} paths */
|
|
2
|
+
export function referencedHiddenDigest(paths: readonly string[]): string;
|
|
1
3
|
/** @param {string} html */
|
|
2
4
|
export function contentKey(html: string): string;
|
|
3
5
|
/** @typedef {Map<string, unknown>} Snapshot */
|
|
@@ -18,6 +20,8 @@ export function snapshotFiles(dir: string, files: Iterable<string>, { lenientIgn
|
|
|
18
20
|
/** @param {Snapshot} before @param {Snapshot} after */
|
|
19
21
|
export function diffChangedFiles(before: Snapshot, after: Snapshot): string[];
|
|
20
22
|
export { readSourceIgnore };
|
|
23
|
+
export { listReferencedHiddenSourceAssets } from "./sources/capture.mjs";
|
|
24
|
+
export { isEligibleHiddenSourcePath } from "./sources/pathPolicy.mjs";
|
|
21
25
|
export const HF_ID_ATTRIBUTE: RegExp;
|
|
22
26
|
export function projectFingerprint(projectPath: string, options?: {
|
|
23
27
|
byContent?: boolean;
|
package/dist/shareSources.d.mts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** Content identity for sharing, including portable hidden render inputs. The Desktop watch inventory stays separate.
|
|
2
|
-
* @param {string} projectPath @
|
|
3
|
-
|
|
2
|
+
* @param {string} projectPath @param {{ignoreSyntax?: import("./sourceIgnore.mjs").SourceIgnoreSyntax}} [options]
|
|
3
|
+
* @returns {Promise<string | null>} */
|
|
4
|
+
export function shareSourceFingerprint(projectPath: string, { ignoreSyntax }?: {
|
|
5
|
+
ignoreSyntax?: import("./sourceIgnore.mjs").SourceIgnoreSyntax;
|
|
6
|
+
}): Promise<string | null>;
|
|
4
7
|
/** Prepare source explicitly before adding the video version. No unexpected network or filesystem failure is
|
|
5
8
|
* converted to video-only. `filesForExport` revalidates the prepared bytes and never starts another upload.
|
|
6
9
|
* @param {import("./sources/adapterTypes.js").SourceOptions} options */
|
|
@@ -12,10 +15,11 @@ export { createProjectShareSourceStore } from "./sources/store.mjs";
|
|
|
12
15
|
export type Preparation = {
|
|
13
16
|
binding: Binding;
|
|
14
17
|
own: boolean;
|
|
15
|
-
|
|
18
|
+
readOnly: boolean;
|
|
16
19
|
api: import("./sources/api.mjs").SourceApi;
|
|
17
20
|
store: import("./sources/adapterTypes.js").SourceStore;
|
|
18
21
|
options: import("./sources/adapterTypes.js").SourceOptions;
|
|
22
|
+
ignoreSyntax?: import("./sourceIgnore.mjs").SourceIgnoreSyntax;
|
|
19
23
|
signal: AbortSignal;
|
|
20
24
|
fingerprint: (path: string) => Promise<string | null>;
|
|
21
25
|
rendered: string;
|
package/dist/sourceIgnore.d.mts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** @typedef {"gitignore"} SourceIgnoreSyntax */
|
|
2
|
+
/** @typedef {(path: string, directory?: boolean) => boolean} SourceIgnore */
|
|
3
|
+
/** Read one immutable set of file-selection rules for the project walks in a capture. Hosts
|
|
4
|
+
* with gitignore-style project rules opt into that syntax. Private-path checks apply separately.
|
|
5
|
+
* @param {string} root @param {{syntax?: SourceIgnoreSyntax}} [options] @returns {Promise<SourceIgnore>} */
|
|
6
|
+
export function readSourceIgnore(root: string, { syntax }?: {
|
|
7
|
+
syntax?: SourceIgnoreSyntax;
|
|
8
|
+
}): Promise<SourceIgnore>;
|
|
4
9
|
/** The exclusions change detection applies. Change detection must keep working whatever the file holds: the CLI
|
|
5
10
|
* reads `.hyperframesignore` as gitignore syntax (`/renders/`, `**`, `!keep`), which this reader refuses. An
|
|
6
11
|
* unreadable file then excludes only scratch files, so a scan sees more files, never fewer. Never use it to pick
|
|
@@ -10,3 +15,5 @@ export function readChangeIgnore(root: string): Promise<(path: string) => boolea
|
|
|
10
15
|
export class SourceIgnoreError extends Error {
|
|
11
16
|
code: string;
|
|
12
17
|
}
|
|
18
|
+
export type SourceIgnoreSyntax = "gitignore";
|
|
19
|
+
export type SourceIgnore = (path: string, directory?: boolean) => boolean;
|
|
@@ -13,6 +13,11 @@ export type SourceResult =
|
|
|
13
13
|
export interface SourceOptions {
|
|
14
14
|
access: SignedInAccess;
|
|
15
15
|
spaceId: string;
|
|
16
|
+
/** Parse project exclusions with gitignore rules on every source capture. The default uses strict project-relative patterns. */
|
|
17
|
+
ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax;
|
|
18
|
+
expectedReferencedHiddenDigest?: string;
|
|
19
|
+
/** Only verify a published snapshot. Never start or recover an upload. */
|
|
20
|
+
reuseOnly?: boolean;
|
|
16
21
|
store?: SourceStore;
|
|
17
22
|
enabled?: () => boolean;
|
|
18
23
|
fingerprint?: (path: string) => Promise<string | null>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @param {string} path @param {string} source @param {URL} url @param {URL} documentUrl @param {Reference} add */
|
|
2
|
+
export function collectAssetReferences(path: string, source: string, url: URL, documentUrl: URL, add: Reference): {
|
|
3
|
+
base: URL;
|
|
4
|
+
mediaSlots: import("./variableAssets.mjs").MediaSlots | undefined;
|
|
5
|
+
} | undefined;
|
|
6
|
+
export type Host = {
|
|
7
|
+
id: string;
|
|
8
|
+
values: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export type Reference = (value: string, base: URL, host?: Host) => void;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/** Paths included by a normal editable Share or Send. A host can reuse the project rules from its inventory walk.
|
|
2
|
+
* @param {string} root @param {Map<string,string>} [observed]
|
|
3
|
+
* @param {{ignored: import("../sourceIgnore.mjs").SourceIgnore, ignoreSyntax?: never} |
|
|
4
|
+
* {ignored?: never, ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax}} [options] */
|
|
5
|
+
export function listReferencedHiddenSourceAssets(root: string, observed?: Map<string, string>, { ignored, ignoreSyntax }?: {
|
|
6
|
+
ignored: import("../sourceIgnore.mjs").SourceIgnore;
|
|
7
|
+
ignoreSyntax?: never;
|
|
8
|
+
} | {
|
|
9
|
+
ignored?: never;
|
|
10
|
+
ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax;
|
|
11
|
+
}): Promise<string[]>;
|
|
1
12
|
/** A file's SHA-256 by path, size, time and inode, kept for the launch so a check after a focus reads no bytes.
|
|
2
13
|
* Only a settled file's hash is kept. */
|
|
3
14
|
export function hashMemo(now?: () => number): {
|
|
@@ -6,16 +17,23 @@ export function hashMemo(now?: () => number): {
|
|
|
6
17
|
/** @param {Found} file @param {string} sha256 */
|
|
7
18
|
set: (file: Found, sha256: string) => void;
|
|
8
19
|
};
|
|
20
|
+
/** The file the walk listed, as an open handle: never through a link at its own name (O_NOFOLLOW), and only when the
|
|
21
|
+
* opened file is the same regular file (inode, device, size) found inside the project, so a file or folder swapped
|
|
22
|
+
* for a link after the walk is refused rather than followed. Null when it is not. @param {string} root
|
|
23
|
+
* @param {Found} file @param {typeof realpath} [resolve] */
|
|
24
|
+
export function openListed(root: string, file: Found, resolve?: typeof realpath): Promise<import("node:fs/promises").FileHandle | null>;
|
|
9
25
|
/** The file's SHA-256, read through the handle `openListed` checked; null when the file is not the one listed, or its
|
|
10
26
|
* bytes changed while being read. `root` is the project's real path; `resolve` finds a folder's real path.
|
|
11
27
|
* @param {string} root @param {Found} file @param {typeof realpath} [resolve] */
|
|
12
28
|
export function hashListedFile(root: string, file: Found, resolve?: typeof realpath): Promise<string | null>;
|
|
13
29
|
/** Captures `root` (a project's real path). `memo` reuses hashes of unchanged files; a send should pass a fresh one.
|
|
14
|
-
* @param {string} root @param {{ memo?: ReturnType<typeof hashMemo>, limits?: import("./types.js").Limits
|
|
30
|
+
* @param {string} root @param {{ memo?: ReturnType<typeof hashMemo>, limits?: import("./types.js").Limits,
|
|
31
|
+
* ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax }} [options]
|
|
15
32
|
* @returns {Promise<Capture>} */
|
|
16
|
-
export function captureProject(root: string, { memo, limits }?: {
|
|
33
|
+
export function captureProject(root: string, { memo, limits, ignoreSyntax }?: {
|
|
17
34
|
memo?: ReturnType<typeof hashMemo>;
|
|
18
35
|
limits?: import("./types.js").Limits;
|
|
36
|
+
ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax;
|
|
19
37
|
}): Promise<Capture>;
|
|
20
38
|
export type CaptureProblem = import("./types.js").CaptureProblem;
|
|
21
39
|
export type Found = import("./types.js").Found;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/** The first rule matching a path's folded spelling. @param {string} path @returns {PathRule} */
|
|
2
2
|
export function classifyPath(path: string): PathRule;
|
|
3
|
+
/** @param {string} path */
|
|
4
|
+
export function isEligibleHiddenSourcePath(path: string): boolean;
|
|
3
5
|
/** @typedef {"current" | "stored" | "localV4"} PathMode */
|
|
4
6
|
/** `path` unchanged when every client can store it and the policy lets it travel; throws PathViolation otherwise,
|
|
5
7
|
* naming the first failing check in the registry's order. @param {string} path
|
|
6
|
-
* @param {PathMode} [mode] */
|
|
7
|
-
export function validatePath(path: string, mode?: PathMode): string;
|
|
8
|
+
* @param {PathMode} [mode] @param {boolean} [includeHidden] */
|
|
9
|
+
export function validatePath(path: string, mode?: PathMode, includeHidden?: boolean): string;
|
|
8
10
|
/** Refuses duplicates, and any two paths (or a path and a directory prefix) one filesystem would store as one name.
|
|
9
11
|
* Each path must already pass validatePath. @param {readonly string[]} paths @param {(value: string) => string} [keyOf] */
|
|
10
12
|
export function checkInventoryPaths(paths: readonly string[], keyOf?: (value: string) => string): void;
|
|
11
13
|
/** Whether no file under folder `dir` can be listed, so a capture need not open it: its first matching rule
|
|
12
14
|
* excludes the folder and all below it, and no include rule before that one can reach inside. @param {string} dir */
|
|
13
15
|
export function excludedFolder(dir: string): boolean;
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
+
/** Can an unconfirmed Begin replay this stored entry under today's rules?
|
|
17
|
+
* @param {import("./types.js").ManifestFile} file */
|
|
18
|
+
export function canReplayUploadFile({ path, include_hidden }: import("./types.js").ManifestFile): boolean;
|
|
16
19
|
export { isPrivateSourcePath };
|
|
17
20
|
/** @typedef {import("./types.js").PathRule} PathRule @typedef {import("./types.js").PolicyDocument} PolicyDocument */
|
|
18
21
|
/** A path the policy refuses: `code` is the golden vectors' shared vocabulary, `rule` the excluding rule's id. */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Keep reachable hidden dependencies and the hashes of the exact bytes used for discovery.
|
|
2
|
+
* @param {string} root @param {Walk} walk @param {typeof import("./capture.mjs").openListed} openListed */
|
|
3
|
+
export function retainReferencedFiles(root: string, walk: Walk, openListed: typeof import("./capture.mjs").openListed): Promise<Map<string, string>>;
|
|
4
|
+
export type Mount = import("./assetReferences.mjs").Host & {
|
|
5
|
+
ordinal: number;
|
|
6
|
+
};
|
|
7
|
+
export type AssetReference = {
|
|
8
|
+
value: string;
|
|
9
|
+
base: URL;
|
|
10
|
+
mount?: Mount;
|
|
11
|
+
};
|
|
12
|
+
export type Scanned = {
|
|
13
|
+
references: AssetReference[];
|
|
14
|
+
html: ReturnType<typeof collectAssetReferences>;
|
|
15
|
+
};
|
|
16
|
+
export type Found = import("./types.js").Found;
|
|
17
|
+
export type Walk = import("./types.js").Walk;
|
|
18
|
+
import { collectAssetReferences } from "./assetReferences.mjs";
|
package/dist/sources/types.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface SyncCaptureProblem {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface ManifestFile {
|
|
17
|
+
include_hidden?: true;
|
|
17
18
|
path: string;
|
|
18
19
|
sha256: string;
|
|
19
20
|
size: number;
|
|
@@ -97,6 +98,7 @@ export type SyncLimitsRead =
|
|
|
97
98
|
|
|
98
99
|
/** A file a capture lists, before hashing. */
|
|
99
100
|
export interface Found {
|
|
101
|
+
include_hidden?: true;
|
|
100
102
|
path: string;
|
|
101
103
|
full: string;
|
|
102
104
|
size: number;
|
|
@@ -106,6 +108,7 @@ export interface Found {
|
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
export interface Walk {
|
|
111
|
+
directoryEntries: Map<string, Set<string>>;
|
|
109
112
|
files: Found[];
|
|
110
113
|
problems: CaptureProblem[];
|
|
111
114
|
waiting: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Resolve an older capture before starting an upload for the current files.
|
|
2
|
-
* @param {SourceUpload} job @returns {Promise<import("./adapterTypes.js").SourceResult | null>} */
|
|
3
|
-
export function recoverSourceUpload(job: SourceUpload): Promise<import("./adapterTypes.js").SourceResult | null>;
|
|
2
|
+
* @param {SourceUpload & Pick<SourceRun, "manifest">} job @returns {Promise<import("./adapterTypes.js").SourceResult | null>} */
|
|
3
|
+
export function recoverSourceUpload(job: SourceUpload & Pick<SourceRun, "manifest">): Promise<import("./adapterTypes.js").SourceResult | null>;
|
|
4
4
|
/** Only published verification results can become share source; conflict_saved is preserved for explicit recovery.
|
|
5
5
|
* @param {SourceRun} run @returns {Promise<import("./adapterTypes.js").SourceResult>} */
|
|
6
6
|
export function uploadSource(run: SourceRun): Promise<import("./adapterTypes.js").SourceResult>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @param {string | null} raw @returns {Record<string,unknown>} */
|
|
2
|
+
export function overrides(raw: string | null): Record<string, unknown>;
|
|
3
|
+
/** @param {MediaSlots | undefined} slots @param {string} id @param {string} key @param {unknown} value */
|
|
4
|
+
export function mountedAsset(slots: MediaSlots | undefined, id: string, key: string, value: unknown): string | null;
|
|
5
|
+
/** @param {string} source @param {(url:string)=>void} add @returns {MediaSlots|undefined} */
|
|
6
|
+
export function variableReferences(source: string, add: (url: string) => void): MediaSlots | undefined;
|
|
7
|
+
export type AssetKey = "url" | "source";
|
|
8
|
+
export type MediaSlots = {
|
|
9
|
+
first: string | null;
|
|
10
|
+
scopes: Map<string, Map<string, AssetKey>>;
|
|
11
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/share",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.98",
|
|
4
4
|
"description": "Shared review identity, version upload and sharing state for HyperFrames hosts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -104,9 +104,15 @@
|
|
|
104
104
|
"access": "public"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"
|
|
107
|
+
"acorn": "^8.17.0",
|
|
108
|
+
"acorn-walk": "^8.3.5",
|
|
109
|
+
"css-tree": "^3.2.1",
|
|
110
|
+
"ignore": "^5.3.2",
|
|
111
|
+
"linkedom": "^0.18.12",
|
|
112
|
+
"@hyperframes/parsers": "0.9.98"
|
|
108
113
|
},
|
|
109
114
|
"devDependencies": {
|
|
115
|
+
"@types/css-tree": "^3.2.0",
|
|
110
116
|
"@types/node": "^25.0.10",
|
|
111
117
|
"typescript": "^5.0.0"
|
|
112
118
|
},
|
package/src/projectSnapshot.mjs
CHANGED
|
@@ -9,6 +9,8 @@ import { createHash } from "node:crypto";
|
|
|
9
9
|
import { isOutsideFilm } from "./appOwnedPaths.mjs";
|
|
10
10
|
|
|
11
11
|
export { readSourceIgnore };
|
|
12
|
+
export { listReferencedHiddenSourceAssets } from "./sources/capture.mjs";
|
|
13
|
+
export { isEligibleHiddenSourcePath } from "./sources/pathPolicy.mjs";
|
|
12
14
|
export { isPrivateSourcePath, privateSourceSpelling } from "./sources/privateSource.mjs";
|
|
13
15
|
|
|
14
16
|
export const HF_ID_ATTRIBUTE = /\sdata-hf-id\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/g;
|
|
@@ -16,6 +18,11 @@ export const HF_ID_ATTRIBUTE = /\sdata-hf-id\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/g
|
|
|
16
18
|
const sha256 = (/** @type {import("node:crypto").BinaryLike} */ data) =>
|
|
17
19
|
createHash("sha256").update(data).digest("hex");
|
|
18
20
|
|
|
21
|
+
/** Identity of the hidden paths shown with the normal share action. @param {readonly string[]} paths */
|
|
22
|
+
export function referencedHiddenDigest(paths) {
|
|
23
|
+
return sha256(JSON.stringify([...new Set(paths)].sort()));
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
// A write that only adds data-hf-id stamps must not count as a change, or reload -> stamp -> reload never ends (KTD4).
|
|
20
27
|
/** @param {string} html */
|
|
21
28
|
export function contentKey(html) {
|
package/src/shareSources.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { realpath } from "node:fs/promises";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { basename } from "node:path";
|
|
5
|
-
import { projectFingerprint } from "./projectSnapshot.mjs";
|
|
5
|
+
import { projectFingerprint, referencedHiddenDigest } from "./projectSnapshot.mjs";
|
|
6
6
|
import { withProjectShareLock } from "./projectLock.mjs";
|
|
7
7
|
import { captureProject } from "./sources/capture.mjs";
|
|
8
8
|
import { sourceApi } from "./sources/api.mjs";
|
|
@@ -15,9 +15,10 @@ import { recoverSourceUpload, uploadSource } from "./sources/upload.mjs";
|
|
|
15
15
|
/** @param {string} reason @returns {SourceResult} */
|
|
16
16
|
const unavailable = (reason) => ({ at: "unavailable", reason });
|
|
17
17
|
/** Content identity for sharing, including portable hidden render inputs. The Desktop watch inventory stays separate.
|
|
18
|
-
* @param {string} projectPath @
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
* @param {string} projectPath @param {{ignoreSyntax?: import("./sourceIgnore.mjs").SourceIgnoreSyntax}} [options]
|
|
19
|
+
* @returns {Promise<string | null>} */
|
|
20
|
+
export async function shareSourceFingerprint(projectPath, { ignoreSyntax } = {}) {
|
|
21
|
+
const capture = await captureProject(projectPath, { ignoreSyntax });
|
|
21
22
|
return capture.at === "captured" && !captureRefusal(capture) ? capture.manifest.sha256 : null;
|
|
22
23
|
}
|
|
23
24
|
/** @param {Binding} binding @param {string} space */
|
|
@@ -40,6 +41,7 @@ function captureRefusal(capture) {
|
|
|
40
41
|
* converted to video-only. `filesForExport` revalidates the prepared bytes and never starts another upload.
|
|
41
42
|
* @param {import("./sources/adapterTypes.js").SourceOptions} options */
|
|
42
43
|
export function shareSources(options) {
|
|
44
|
+
const { ignoreSyntax } = options;
|
|
43
45
|
const store = options.store ?? createProjectShareSourceStore();
|
|
44
46
|
const fingerprint = options.fingerprint ?? projectFingerprint;
|
|
45
47
|
const signal = options.signal ?? new AbortController().signal;
|
|
@@ -58,7 +60,11 @@ export function shareSources(options) {
|
|
|
58
60
|
async () => {
|
|
59
61
|
const signed = await options.access();
|
|
60
62
|
if (!signed?.owner) return unavailable("source_signed_out");
|
|
61
|
-
const key = {
|
|
63
|
+
const key = {
|
|
64
|
+
backend: signed.heygenApi,
|
|
65
|
+
account: signed.owner,
|
|
66
|
+
projectPath: root,
|
|
67
|
+
};
|
|
62
68
|
const guardedAccess = async (/** @type {string | undefined} */ refused) => {
|
|
63
69
|
const next = await options.access(refused);
|
|
64
70
|
if (!next || next.owner !== key.account || next.heygenApi !== key.backend)
|
|
@@ -73,18 +79,19 @@ export function shareSources(options) {
|
|
|
73
79
|
const result = await prepareBinding({
|
|
74
80
|
binding,
|
|
75
81
|
own: Boolean(own),
|
|
76
|
-
|
|
82
|
+
readOnly: Boolean(existing || options.reuseOnly),
|
|
77
83
|
api,
|
|
78
84
|
store,
|
|
79
85
|
options,
|
|
80
86
|
signal,
|
|
81
87
|
fingerprint,
|
|
88
|
+
ignoreSyntax,
|
|
82
89
|
rendered,
|
|
83
90
|
});
|
|
84
91
|
const manifest = result.manifest;
|
|
85
92
|
await guardedAccess(undefined);
|
|
86
93
|
if (result.at !== "ready" || !manifest) return result;
|
|
87
|
-
if (!(await stillMatches(root, rendered, manifest.sha256, fingerprint)))
|
|
94
|
+
if (!(await stillMatches(root, rendered, manifest.sha256, fingerprint, ignoreSyntax)))
|
|
88
95
|
return unavailable("source_render_changed");
|
|
89
96
|
prepared.set(root, {
|
|
90
97
|
rendered,
|
|
@@ -111,43 +118,85 @@ export function shareSources(options) {
|
|
|
111
118
|
!enabled(options)
|
|
112
119
|
)
|
|
113
120
|
return null;
|
|
114
|
-
|
|
121
|
+
if (!(await stillMatches(root, rendered, held.digest, fingerprint, ignoreSyntax))) return null;
|
|
122
|
+
if (options.reuseOnly) {
|
|
123
|
+
const key = { projectPath: root, account: held.account, backend: held.backend };
|
|
124
|
+
const { binding } = await selectBinding(key, options, store);
|
|
125
|
+
if (!holdsSnapshot(binding, held.snapshot, held.digest)) return null;
|
|
126
|
+
}
|
|
127
|
+
return held.snapshot;
|
|
115
128
|
};
|
|
116
129
|
return { prepare, filesForExport };
|
|
117
130
|
}
|
|
118
131
|
|
|
132
|
+
/** @param {Binding} binding @param {import("./types/reviewWire.js").SnapshotRef} snapshot @param {string} digest */
|
|
133
|
+
function holdsSnapshot(binding, snapshot, digest) {
|
|
134
|
+
return (
|
|
135
|
+
!bindingRefusal(binding, snapshot.space_id) &&
|
|
136
|
+
!binding.inflight &&
|
|
137
|
+
binding.compositionId === snapshot.composition_id &&
|
|
138
|
+
binding.base?.snapshotId === snapshot.snapshot_id &&
|
|
139
|
+
binding.base.manifestSha256 === digest
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
119
143
|
/** @param {import("./sources/adapterTypes.js").SourceOptions} options */
|
|
120
144
|
const enabled = (options) => options.enabled?.() ?? true;
|
|
121
145
|
/** @param {Awaited<ReturnType<import("./signedInRequest.mjs").SignedInAccess>>} signed
|
|
122
146
|
* @param {{account: string, backend: string}} held */
|
|
123
147
|
const sameOwner = (signed, held) =>
|
|
124
148
|
signed?.owner === held.account && signed?.heygenApi === held.backend;
|
|
125
|
-
/** @typedef {{ binding: Binding, own: boolean,
|
|
149
|
+
/** @typedef {{ binding: Binding, own: boolean, readOnly: boolean, api: import("./sources/api.mjs").SourceApi,
|
|
126
150
|
* store: import("./sources/adapterTypes.js").SourceStore, options: import("./sources/adapterTypes.js").SourceOptions,
|
|
151
|
+
* ignoreSyntax?: import("./sourceIgnore.mjs").SourceIgnoreSyntax,
|
|
127
152
|
* signal: AbortSignal, fingerprint: (path: string) => Promise<string | null>, rendered: string }} Preparation */
|
|
153
|
+
/** @param {Preparation} job @param {Extract<import("./sources/types.js").SyncLimitsRead,{at:"read"}>} limits */
|
|
154
|
+
function sourceAvailability(job, limits) {
|
|
155
|
+
if (!limits.syncAllowed) return "source_plan_required";
|
|
156
|
+
if (!job.options.reuseOnly) return null;
|
|
157
|
+
if (job.binding.base && !job.binding.inflight) return null;
|
|
158
|
+
if (!job.own && limits.compositions >= limits.maxCompositions) return "source_composition_limit";
|
|
159
|
+
return "source_sync_required";
|
|
160
|
+
}
|
|
128
161
|
/** @param {Preparation} job @returns {Promise<SourceResult & {manifest?: import("./sources/types.js").Manifest}>} */
|
|
129
162
|
async function prepareBinding(job) {
|
|
130
163
|
const { binding, api, fingerprint, rendered } = job;
|
|
131
164
|
const limits = await api.limits(binding.ownerSpaceId);
|
|
132
|
-
|
|
133
|
-
|
|
165
|
+
const refused = sourceAvailability(job, limits);
|
|
166
|
+
if (refused) return unavailable(refused);
|
|
167
|
+
const capture = await captureProject(binding.projectPath, {
|
|
168
|
+
limits: limits.push,
|
|
169
|
+
ignoreSyntax: job.ignoreSyntax,
|
|
170
|
+
});
|
|
134
171
|
const bad = captureRefusal(capture);
|
|
135
172
|
if (bad) return unavailable(bad);
|
|
136
173
|
if (capture.at !== "captured") return unavailable("source_invalid");
|
|
174
|
+
if (
|
|
175
|
+
!job.options.reuseOnly &&
|
|
176
|
+
!matchesDisclosure(capture.manifest, job.options.expectedReferencedHiddenDigest)
|
|
177
|
+
)
|
|
178
|
+
return unavailable("source_hidden_assets_changed");
|
|
137
179
|
if ((await fingerprint(binding.projectPath)) !== rendered)
|
|
138
180
|
return unavailable("source_render_changed");
|
|
139
181
|
const result = await snapshotFor(job, capture.manifest, limits);
|
|
140
182
|
return { ...result, manifest: capture.manifest };
|
|
141
183
|
}
|
|
184
|
+
/** @param {import("./sources/types.js").Manifest} manifest @param {string | undefined} expected */
|
|
185
|
+
function matchesDisclosure(manifest, expected) {
|
|
186
|
+
const paths = manifest.document.files
|
|
187
|
+
.filter((file) => file.include_hidden)
|
|
188
|
+
.map((file) => file.path);
|
|
189
|
+
return (!paths.length && expected === undefined) || referencedHiddenDigest(paths) === expected;
|
|
190
|
+
}
|
|
142
191
|
/** @param {Preparation} job @param {import("./sources/types.js").Manifest} manifest
|
|
143
192
|
* @param {Extract<import("./sources/types.js").SyncLimitsRead, {at: "read"}>} limits @returns {Promise<SourceResult>} */
|
|
144
193
|
async function snapshotFor(job, manifest, limits) {
|
|
145
194
|
const { binding, api, store, options, signal } = job;
|
|
146
|
-
const blocked = await recoverEarlierCapture(job, manifest
|
|
195
|
+
const blocked = await recoverEarlierCapture(job, manifest);
|
|
147
196
|
if (blocked) return blocked;
|
|
148
197
|
if (binding.base?.manifestSha256 === manifest.sha256 && !binding.inflight)
|
|
149
198
|
return reuseSnapshot(api, binding, manifest.sha256);
|
|
150
|
-
if (job.
|
|
199
|
+
if (job.readOnly) return unavailable("source_sync_required");
|
|
151
200
|
if (!job.own && limits.compositions >= limits.maxCompositions)
|
|
152
201
|
return unavailable("source_composition_limit");
|
|
153
202
|
await store.write(binding);
|
|
@@ -159,11 +208,11 @@ async function snapshotFor(job, manifest, limits) {
|
|
|
159
208
|
await store.write(binding);
|
|
160
209
|
return uploadSource({ binding, manifest, api, store, signal, ...uploadOptions(options) });
|
|
161
210
|
}
|
|
162
|
-
/** @param {Preparation} job @param {
|
|
163
|
-
function recoverEarlierCapture({
|
|
211
|
+
/** @param {Preparation} job @param {import("./sources/types.js").Manifest} manifest */
|
|
212
|
+
function recoverEarlierCapture({ readOnly, binding, api, store }, manifest) {
|
|
164
213
|
const inflight = binding.inflight;
|
|
165
|
-
if (
|
|
166
|
-
return recoverSourceUpload({ binding, api, store });
|
|
214
|
+
if (readOnly || !inflight || inflight.manifestSha256 === manifest.sha256) return null;
|
|
215
|
+
return recoverSourceUpload({ binding, api, store, manifest });
|
|
167
216
|
}
|
|
168
217
|
|
|
169
218
|
/** @param {import("./sources/adapterTypes.js").SourceOptions} options */
|
|
@@ -222,14 +271,12 @@ async function reuseSnapshot(api, binding, digest) {
|
|
|
222
271
|
},
|
|
223
272
|
};
|
|
224
273
|
}
|
|
225
|
-
/** @param {string} root @param {string} rendered @param {string} digest @param {(path: string) => Promise<string | null>} fingerprint
|
|
226
|
-
|
|
274
|
+
/** @param {string} root @param {string} rendered @param {string} digest @param {(path: string) => Promise<string | null>} fingerprint
|
|
275
|
+
* @param {import("./sourceIgnore.mjs").SourceIgnoreSyntax} [ignoreSyntax] */
|
|
276
|
+
async function stillMatches(root, rendered, digest, fingerprint, ignoreSyntax) {
|
|
227
277
|
if ((await fingerprint(root)) !== rendered) return false;
|
|
228
|
-
const capture = await captureProject(root);
|
|
229
278
|
return (
|
|
230
|
-
|
|
231
|
-
capture.at === "captured" &&
|
|
232
|
-
capture.manifest.sha256 === digest &&
|
|
279
|
+
(await shareSourceFingerprint(root, { ignoreSyntax })) === digest &&
|
|
233
280
|
(await fingerprint(root)) === rendered
|
|
234
281
|
);
|
|
235
282
|
}
|
package/src/sourceIgnore.mjs
CHANGED
|
@@ -8,41 +8,76 @@ export class SourceIgnoreError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
const scratch = (/** @type {string} */ path) => /(?:^|\/)[^/]+\.(?:log|swp)$/.test(path);
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
/** @typedef {"gitignore"} SourceIgnoreSyntax */
|
|
12
|
+
/** @typedef {(path: string, directory?: boolean) => boolean} SourceIgnore */
|
|
13
|
+
|
|
14
|
+
/** Read one immutable set of file-selection rules for the project walks in a capture. Hosts
|
|
15
|
+
* with gitignore-style project rules opt into that syntax. Private-path checks apply separately.
|
|
16
|
+
* @param {string} root @param {{syntax?: SourceIgnoreSyntax}} [options] @returns {Promise<SourceIgnore>} */
|
|
17
|
+
export async function readSourceIgnore(root, { syntax } = {}) {
|
|
18
|
+
const text = await readIgnoreText(root);
|
|
19
|
+
if (!text) return scratch;
|
|
20
|
+
if (syntax === "gitignore") {
|
|
21
|
+
const { default: ignore } = await import("ignore");
|
|
22
|
+
const rules = ignore({ allowRelativePaths: true }).add(text);
|
|
23
|
+
if (rules.ignores("index.html"))
|
|
24
|
+
throw new SourceIgnoreError(
|
|
25
|
+
".hyperframesignore must include index.html at the project root.",
|
|
26
|
+
);
|
|
27
|
+
return (path, directory) => scratch(path) || rules.ignores(directory ? `${path}/` : path);
|
|
28
|
+
}
|
|
29
|
+
const paths = text
|
|
30
|
+
.split(/\r?\n/)
|
|
31
|
+
.map((line) => line.trim())
|
|
32
|
+
.filter((line) => line && !line.startsWith("#"));
|
|
33
|
+
const entries = paths.map(ignorePattern);
|
|
34
|
+
return (path) => scratch(path) || entries.some((entry) => entry.test(path));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const invalidIgnoreFile = () =>
|
|
38
|
+
new SourceIgnoreError(
|
|
39
|
+
".hyperframesignore must be a regular file inside the project, smaller than 64 KiB.",
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
/** @param {string} file */
|
|
43
|
+
async function openIgnoreFile(file) {
|
|
44
|
+
return open(
|
|
20
45
|
file,
|
|
21
46
|
constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0),
|
|
22
47
|
).catch(async (/** @type {NodeJS.ErrnoException} */ error) => {
|
|
23
|
-
if (error.code !== "ENOENT") throw
|
|
48
|
+
if (error.code !== "ENOENT") throw invalidIgnoreFile();
|
|
24
49
|
// An absent file means no exclusions; a dangling symlink is invalid.
|
|
25
50
|
const named = await lstat(file).catch((/** @type {NodeJS.ErrnoException} */ missing) => {
|
|
26
51
|
if (missing.code === "ENOENT") return null;
|
|
27
|
-
throw
|
|
52
|
+
throw invalidIgnoreFile();
|
|
28
53
|
});
|
|
29
|
-
if (named) throw
|
|
54
|
+
if (named) throw invalidIgnoreFile();
|
|
30
55
|
return null;
|
|
31
56
|
});
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @param {import("node:fs/promises").FileHandle} handle @param {string} file */
|
|
60
|
+
async function verifyIgnoreFile(handle, file) {
|
|
61
|
+
// Validate the opened descriptor before reading. lstat additionally rejects links on
|
|
62
|
+
// platforms without O_NOFOLLOW; it never authorizes a later open of this path.
|
|
63
|
+
const [stat, named] = await Promise.all([handle.stat(), lstat(file)]);
|
|
64
|
+
if (
|
|
65
|
+
!stat.isFile() ||
|
|
66
|
+
stat.size >= 65536 ||
|
|
67
|
+
!named.isFile() ||
|
|
68
|
+
stat.ino !== named.ino ||
|
|
69
|
+
stat.dev !== named.dev
|
|
70
|
+
)
|
|
71
|
+
throw invalidIgnoreFile();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @param {string} root */
|
|
75
|
+
async function readIgnoreText(root) {
|
|
76
|
+
const file = join(root, ".hyperframesignore");
|
|
77
|
+
const handle = await openIgnoreFile(file);
|
|
78
|
+
if (!handle) return "";
|
|
34
79
|
try {
|
|
35
|
-
|
|
36
|
-
// platforms without O_NOFOLLOW; it never authorizes a later open of this path.
|
|
37
|
-
const [stat, named] = await Promise.all([handle.stat(), lstat(file)]);
|
|
38
|
-
if (
|
|
39
|
-
!stat.isFile() ||
|
|
40
|
-
stat.size >= 65536 ||
|
|
41
|
-
!named.isFile() ||
|
|
42
|
-
stat.ino !== named.ino ||
|
|
43
|
-
stat.dev !== named.dev
|
|
44
|
-
)
|
|
45
|
-
throw invalid();
|
|
80
|
+
await verifyIgnoreFile(handle, file);
|
|
46
81
|
const buffer = Buffer.alloc(65536);
|
|
47
82
|
let length = 0;
|
|
48
83
|
while (length < buffer.length) {
|
|
@@ -50,17 +85,11 @@ export async function readSourceIgnore(root) {
|
|
|
50
85
|
if (!bytesRead) break;
|
|
51
86
|
length += bytesRead;
|
|
52
87
|
}
|
|
53
|
-
if (length === buffer.length) throw
|
|
54
|
-
|
|
88
|
+
if (length === buffer.length) throw invalidIgnoreFile();
|
|
89
|
+
return buffer.subarray(0, length).toString("utf8");
|
|
55
90
|
} finally {
|
|
56
91
|
await handle.close();
|
|
57
92
|
}
|
|
58
|
-
const paths = text
|
|
59
|
-
.split(/\r?\n/)
|
|
60
|
-
.map((line) => line.trim())
|
|
61
|
-
.filter((line) => line && !line.startsWith("#"));
|
|
62
|
-
const entries = paths.map(ignorePattern);
|
|
63
|
-
return (path) => scratch(path) || entries.some((entry) => entry.test(path));
|
|
64
93
|
}
|
|
65
94
|
|
|
66
95
|
/** The exclusions change detection applies. Change detection must keep working whatever the file holds: the CLI
|