@hyperframes/share 0.9.103 → 0.9.104

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 CHANGED
@@ -21,7 +21,7 @@ bindShareHost({
21
21
  reviewUploadOrigins: ["https://review-bucket.s3.us-east-1.amazonaws.com"],
22
22
  signedInRequest,
23
23
  projectFingerprint,
24
- latestExportFile, // (dir) => { path, fingerprint, id } | null
24
+ latestExportFile, // (dir) => { path, fingerprint, id } | null, or a promise of it
25
25
  ffBinary, // ('ffprobe') => executable path
26
26
  });
27
27
  const client = reviewClient({ access, signedInEmail });
package/dist/hosts.d.ts CHANGED
@@ -25,7 +25,13 @@ export interface ShareHost {
25
25
  /** Requests to HeyGen's sign-in host as the signed-in person, traced as the host traces its API calls. */
26
26
  signedInRequest(deps: Omit<SignedInDeps, "trace">): ReturnType<typeof signedInRequest>;
27
27
  /** The newest finished export recorded in the project's renders folder whose file is still there. */
28
- latestExportFile(dir: string): { path: string; fingerprint?: string; id: string } | null;
28
+ /** May answer later, so a host can read its disk off its main thread. */
29
+ latestExportFile(
30
+ dir: string,
31
+ ):
32
+ | { path: string; fingerprint?: string; id: string }
33
+ | null
34
+ | Promise<{ path: string; fingerprint?: string; id: string } | null>;
29
35
  /** Trusted video upload origins configured by the host independently of the review API response. */
30
36
  reviewUploadOrigins?: readonly string[];
31
37
  /** This install's own secret: change-of-space journals are sealed with it; one it did not seal reads as none. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/share",
3
- "version": "0.9.103",
3
+ "version": "0.9.104",
4
4
  "description": "Shared review identity, version upload and sharing state for HyperFrames hosts",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -113,7 +113,7 @@
113
113
  "css-tree": "^3.2.1",
114
114
  "ignore": "^5.3.2",
115
115
  "linkedom": "^0.18.12",
116
- "@hyperframes/parsers": "0.9.103"
116
+ "@hyperframes/parsers": "0.9.104"
117
117
  },
118
118
  "devDependencies": {
119
119
  "@types/css-tree": "^3.2.0",
package/src/hosts.d.ts CHANGED
@@ -25,7 +25,13 @@ export interface ShareHost {
25
25
  /** Requests to HeyGen's sign-in host as the signed-in person, traced as the host traces its API calls. */
26
26
  signedInRequest(deps: Omit<SignedInDeps, "trace">): ReturnType<typeof signedInRequest>;
27
27
  /** The newest finished export recorded in the project's renders folder whose file is still there. */
28
- latestExportFile(dir: string): { path: string; fingerprint?: string; id: string } | null;
28
+ /** May answer later, so a host can read its disk off its main thread. */
29
+ latestExportFile(
30
+ dir: string,
31
+ ):
32
+ | { path: string; fingerprint?: string; id: string }
33
+ | null
34
+ | Promise<{ path: string; fingerprint?: string; id: string } | null>;
29
35
  /** Trusted video upload origins configured by the host independently of the review API response. */
30
36
  reviewUploadOrigins?: readonly string[];
31
37
  /** This install's own secret: change-of-space journals are sealed with it; one it did not seal reads as none. */
@@ -261,15 +261,15 @@ const woken = new Set();
261
261
  const failures = new Map();
262
262
 
263
263
  /** Which export a failure was about: the newest export file and the project as it was rendered. @param {string} dir */
264
- const exportKeyOf = (dir) => {
265
- const latest = latestExportFile(dir);
264
+ const exportKeyOf = async (dir) => {
265
+ const latest = await latestExportFile(dir);
266
266
  return latest ? `${latest.id}\n${latest.path}\n${latest.fingerprint ?? ""}` : "";
267
267
  };
268
268
 
269
269
  /** Whether the newest export can go up now: there is one, it is MP4, and the project has not moved past it.
270
- * @param {string} dir @param {string} now @returns {ReviewVersion["source"]} */
271
- function sourceOf(dir, now) {
272
- const latest = latestExportFile(dir);
270
+ * @param {string} dir @param {string} now @returns {Promise<ReviewVersion["source"]>} */
271
+ async function sourceOf(dir, now) {
272
+ const latest = await latestExportFile(dir);
273
273
  if (!latest) return "none";
274
274
  if (!/\.mp4$/i.test(latest.path)) return "not-mp4";
275
275
  return latest.fingerprint === now ? "ready" : "stale";
@@ -290,13 +290,17 @@ export async function reviewVersion(projectPath, server = {}) {
290
290
  server.latestReadyVersionId === undefined || server.latestReadyVersionId === last?.versionId;
291
291
  const savedFailure = state.failure?.projectId === projectId ? state.failure : null;
292
292
  const failed = savedFailure ?? failures.get(key);
293
+ const [source, exportKey] = await Promise.all([
294
+ sourceOf(projectPath, now),
295
+ exportKeyOf(projectPath),
296
+ ]);
293
297
  return {
294
298
  last: last
295
299
  ? { exportedAt: last.exportedAt, current: last.fingerprint === now && onServer }
296
300
  : null,
297
- source: sourceOf(projectPath, now),
301
+ source,
298
302
  exporting: inFlight.get(key) ?? null,
299
- ...(failed?.exportKey === exportKeyOf(projectPath)
303
+ ...(failed?.exportKey === exportKey
300
304
  ? {
301
305
  failure: failed.sentence,
302
306
  retryable: !failed.final,
@@ -311,8 +315,8 @@ export async function reviewVersion(projectPath, server = {}) {
311
315
  * @param {string} dir @param {string} title @param {(file: string) => Promise<VideoFacts | null>} probe
312
316
  * @param {FilesForRender} filesForExport @param {boolean} requireSource */
313
317
  async function exportSource(dir, title, probe, filesForExport, requireSource) {
314
- const latest = latestExportFile(dir);
315
- if (!latest || sourceOf(dir, await projectFingerprint(dir)) !== "ready")
318
+ const latest = await latestExportFile(dir);
319
+ if (!latest || (await sourceOf(dir, await projectFingerprint(dir))) !== "ready")
316
320
  return { failure: local("Export an MP4 of the project as it is now first.") };
317
321
  const { size } = await stat(latest.path);
318
322
  if (size > MAX_BYTES) return { failure: said(new ReviewFailed(400, "export_too_large")) };
@@ -623,14 +627,14 @@ async function finish(dir, state, pending, id, done, fromReview) {
623
627
  /** @param {string} dir @param {NonNullable<VersionRecord["pending"]>} pending */
624
628
  async function failedExportKey(dir, pending) {
625
629
  if (typeof pending.renderKey === "string") return pending.renderKey;
626
- const latest = latestExportFile(dir);
630
+ const latest = await latestExportFile(dir);
627
631
  if (!latest) return "";
628
632
  const checksum =
629
633
  latest.fingerprint === pending.body.source_fingerprint
630
634
  ? await fileSha256Base64(latest.path).catch(() => null)
631
635
  : null;
632
636
  return checksum === pending.body.local_upload.checksum_sha256
633
- ? exportKeyOf(dir)
637
+ ? await exportKeyOf(dir)
634
638
  : `pending:${pending.body.client_operation_id}`;
635
639
  }
636
640
 
@@ -681,7 +685,7 @@ async function alreadyUploaded(client, id, state, body) {
681
685
  * @param {{file: string, body: ExportRequest}} source @param {string} id @param {VersionRecord} state */
682
686
  async function sendVersion(r, report, source, id, state) {
683
687
  const first = state.last?.projectId !== id;
684
- let pending = bindRenderKey(bodyToSend(state, source.body, id), r.projectPath);
688
+ let pending = await bindRenderKey(bodyToSend(state, source.body, id), r.projectPath);
685
689
  const sourceConflict = pendingSourceConflict(r, pending, source.body);
686
690
  if (sourceConflict) return local(sourceConflict);
687
691
  await writeState(r.projectPath, (state = { ...state, pending, failure: null }));
@@ -788,7 +792,7 @@ export async function addVersion(request) {
788
792
  report({ step: "preparing", sent: 0, total: 0 });
789
793
  const failure = await withProjectShareLock(r.projectPath, "export", () => run(r, report));
790
794
  const kept = failure && (uploaded || !request.projectId);
791
- if (kept) failures.set(key, { ...failure, exportKey: exportKeyOf(r.projectPath) });
795
+ if (kept) failures.set(key, { ...failure, exportKey: await exportKeyOf(r.projectPath) });
792
796
  return failure?.sentence ?? null;
793
797
  } catch (error) {
794
798
  const sentence =
@@ -797,7 +801,7 @@ export async function addVersion(request) {
797
801
  sentence,
798
802
  final: false,
799
803
  exportHelps: false,
800
- exportKey: exportKeyOf(r.projectPath),
804
+ exportKey: await exportKeyOf(r.projectPath),
801
805
  });
802
806
  return sentence;
803
807
  } finally {
@@ -863,7 +867,7 @@ async function settleSavedExport(dir, client, fromReview) {
863
867
  if (done.status === "upload_pending" || going(done)) return;
864
868
  const failure = await finish(dir, state, pending, id, done, fromReview);
865
869
  const key = normalize(dir);
866
- if (failure) failures.set(key, { ...failure, exportKey: exportKeyOf(dir) });
870
+ if (failure) failures.set(key, { ...failure, exportKey: await exportKeyOf(dir) });
867
871
  else failures.delete(key);
868
872
  }
869
873
 
@@ -887,7 +891,7 @@ export async function versionFacts(dir) {
887
891
  const last = state.last?.projectId === projectId ? state.last : null;
888
892
  return {
889
893
  last: last && { ...last, current: last.fingerprint === now },
890
- source: sourceOf(dir, now),
894
+ source: await sourceOf(dir, now),
891
895
  running: inFlight.has(normalize(dir)),
892
896
  };
893
897
  }
@@ -945,8 +949,8 @@ function readyRecord(pending, id, done) {
945
949
  }
946
950
 
947
951
  /** @param {NonNullable<VersionRecord["pending"]>} pending @param {string} dir */
948
- function bindRenderKey(pending, dir) {
952
+ async function bindRenderKey(pending, dir) {
949
953
  return typeof pending.renderKey === "string"
950
954
  ? pending
951
- : { ...pending, renderKey: exportKeyOf(dir) };
955
+ : { ...pending, renderKey: await exportKeyOf(dir) };
952
956
  }