@editframe/api 0.11.0-beta.9 → 0.12.0-beta.2

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.
Files changed (51) hide show
  1. package/dist/CHUNK_SIZE_BYTES.js +1 -1
  2. package/dist/ProgressIterator.d.ts +25 -0
  3. package/dist/ProgressIterator.js +99 -0
  4. package/dist/ProgressIterator.test.d.ts +1 -0
  5. package/dist/StreamEventSource.d.ts +50 -0
  6. package/dist/StreamEventSource.js +130 -0
  7. package/dist/StreamEventSource.test.d.ts +1 -0
  8. package/dist/client.d.ts +6 -3
  9. package/dist/client.js +20 -6
  10. package/dist/index.d.ts +7 -5
  11. package/dist/index.js +20 -11
  12. package/dist/readableFromBuffers.d.ts +1 -2
  13. package/dist/resources/caption-file.d.ts +7 -3
  14. package/dist/resources/caption-file.js +22 -2
  15. package/dist/resources/image-file.d.ts +7 -3
  16. package/dist/resources/image-file.js +19 -0
  17. package/dist/resources/isobmff-file.d.ts +16 -3
  18. package/dist/resources/isobmff-file.js +37 -2
  19. package/dist/resources/isobmff-track.d.ts +5 -7
  20. package/dist/resources/isobmff-track.js +44 -1
  21. package/dist/resources/process-isobmff.d.ts +12 -0
  22. package/dist/resources/process-isobmff.js +22 -0
  23. package/dist/resources/process-isobmff.test.d.ts +1 -0
  24. package/dist/resources/renders.d.ts +10 -5
  25. package/dist/resources/renders.js +21 -2
  26. package/dist/resources/transcriptions.d.ts +24 -0
  27. package/dist/resources/transcriptions.js +45 -0
  28. package/dist/resources/transcriptions.test.d.ts +1 -0
  29. package/dist/resources/unprocessed-file.d.ts +12 -53
  30. package/dist/resources/unprocessed-file.js +31 -130
  31. package/dist/streamChunker.d.ts +1 -2
  32. package/dist/streamChunker.js +20 -9
  33. package/dist/uploadChunks.d.ts +1 -2
  34. package/dist/uploadChunks.js +1 -4
  35. package/package.json +3 -2
  36. package/src/resources/caption-file.test.ts +57 -6
  37. package/src/resources/caption-file.ts +34 -5
  38. package/src/resources/image-file.test.ts +56 -5
  39. package/src/resources/image-file.ts +32 -4
  40. package/src/resources/isobmff-file.test.ts +57 -6
  41. package/src/resources/isobmff-file.ts +64 -5
  42. package/src/resources/isobmff-track.test.ts +3 -3
  43. package/src/resources/isobmff-track.ts +50 -5
  44. package/src/resources/process-isobmff.test.ts +62 -0
  45. package/src/resources/process-isobmff.ts +33 -0
  46. package/src/resources/renders.test.ts +51 -6
  47. package/src/resources/renders.ts +34 -5
  48. package/src/resources/transcriptions.test.ts +49 -0
  49. package/src/resources/transcriptions.ts +64 -0
  50. package/src/resources/unprocessed-file.test.ts +19 -430
  51. package/src/resources/unprocessed-file.ts +45 -161
@@ -0,0 +1,33 @@
1
+ import { ProgressIterator } from "../ProgressIterator.ts";
2
+ import type { Client } from "../client.ts";
3
+
4
+ export interface IsobmffProcessInfoResult {
5
+ id: string;
6
+ created_at: string;
7
+ completed_at: string | null;
8
+ failed_at: string | null;
9
+ isobmff_file_id: string | null;
10
+ unprocessed_file_id: string;
11
+ }
12
+
13
+ export const getIsobmffProcessProgress = async (client: Client, id: string) => {
14
+ const eventSource = await client.authenticatedEventSource(
15
+ `/api/v1/process_isobmff/${id}/progress`,
16
+ );
17
+
18
+ return new ProgressIterator(eventSource);
19
+ };
20
+
21
+ export const getIsobmffProcessInfo = async (client: Client, id: string) => {
22
+ const response = await client.authenticatedFetch(
23
+ `/api/v1/process_isobmff/${id}`,
24
+ );
25
+
26
+ if (response.ok) {
27
+ return (await response.json()) as IsobmffProcessInfoResult;
28
+ }
29
+
30
+ throw new Error(
31
+ `Failed to get isobmff process info ${response.status} ${response.statusText}`,
32
+ );
33
+ };
@@ -1,10 +1,10 @@
1
- import { test, expect, beforeAll, afterEach, afterAll, describe } from "vitest";
2
1
  import { http, HttpResponse } from "msw";
3
2
  import { setupServer } from "msw/node";
3
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from "vitest";
4
4
 
5
5
  import { Client } from "../client.ts";
6
- import { readableFromBuffers } from "../readableFromBuffers.ts";
7
- import { createRender, uploadRender } from "./renders.ts";
6
+ import { webReadableFromBuffers } from "../readableFromBuffers.ts";
7
+ import { createRender, lookupRenderByMd5, uploadRender } from "./renders.ts";
8
8
 
9
9
  const server = setupServer();
10
10
  const client = new Client("ef_TEST_TOKEN", "http://localhost");
@@ -51,7 +51,7 @@ describe("Renders", () => {
51
51
  uploadRender(
52
52
  client,
53
53
  "test-id",
54
- readableFromBuffers(Buffer.from("test")),
54
+ webReadableFromBuffers(Buffer.from("test")),
55
55
  1024 * 1024 * 17,
56
56
  ),
57
57
  ).rejects.toThrowError(
@@ -70,7 +70,7 @@ describe("Renders", () => {
70
70
  uploadRender(
71
71
  client,
72
72
  "test-id",
73
- readableFromBuffers(Buffer.from("test")),
73
+ webReadableFromBuffers(Buffer.from("test")),
74
74
  1024 * 1024 * 2,
75
75
  ),
76
76
  ).rejects.toThrowError(
@@ -91,13 +91,58 @@ describe("Renders", () => {
91
91
  const response = await uploadRender(
92
92
  client,
93
93
  "test-id",
94
- readableFromBuffers(Buffer.from("test")),
94
+ webReadableFromBuffers(Buffer.from("test")),
95
95
  1024 * 1024 * 2,
96
96
  );
97
97
 
98
98
  expect(response).toEqual({ testResponse: "test" });
99
99
  });
100
100
  });
101
+
102
+ describe("lookupRenderByMd5", () => {
103
+ test("Returns json data from the http response", async () => {
104
+ server.use(
105
+ http.get("http://localhost/api/v1/renders/md5/test-md5", () =>
106
+ HttpResponse.json(
107
+ { id: "test-id", md5: "test-md5", status: "complete" },
108
+ { status: 200, statusText: "OK" },
109
+ ),
110
+ ),
111
+ );
112
+
113
+ const response = await lookupRenderByMd5(client, "test-md5");
114
+
115
+ expect(response).toEqual({
116
+ id: "test-id",
117
+ md5: "test-md5",
118
+ status: "complete",
119
+ });
120
+ });
121
+
122
+ test("Returns null when file is not found", async () => {
123
+ server.use(
124
+ http.get("http://localhost/api/v1/renders/md5/test-md5", () =>
125
+ HttpResponse.json({}, { status: 404 }),
126
+ ),
127
+ );
128
+
129
+ const response = await lookupRenderByMd5(client, "test-md5");
130
+
131
+ expect(response).toBeNull();
132
+ });
133
+
134
+ test("Throws when server returns an error", async () => {
135
+ server.use(
136
+ http.get("http://localhost/api/v1/renders/md5/test-md5", () =>
137
+ HttpResponse.text("Internal Server Error", { status: 500 }),
138
+ ),
139
+ );
140
+
141
+ await expect(lookupRenderByMd5(client, "test-md5")).rejects.toThrowError(
142
+ "Failed to lookup render by md5 test-md5 500 Internal Server Error",
143
+ );
144
+ });
145
+ });
101
146
  });
102
147
 
103
148
  const createTestRender = () =>
@@ -1,7 +1,5 @@
1
- import type { Readable } from "node:stream";
2
-
3
- import { z } from "zod";
4
1
  import debug from "debug";
2
+ import { z } from "zod";
5
3
 
6
4
  import type { Client } from "../client.ts";
7
5
 
@@ -21,7 +19,13 @@ export const CreateRenderPayload = z.object({
21
19
  export interface CreateRenderResult {
22
20
  id: string;
23
21
  md5: string;
24
- status: "complete" | "created" | "failed" | "pending" | "rendering";
22
+ status: "complete" | "created" | "failed" | "pending" | "rendering" | string;
23
+ }
24
+
25
+ export interface LookupRenderByMd5Result {
26
+ id: string;
27
+ md5: string;
28
+ status: "complete" | "created" | "failed" | "pending" | "rendering" | string;
25
29
  }
26
30
 
27
31
  export const createRender = async (
@@ -47,7 +51,7 @@ export const createRender = async (
47
51
  export const uploadRender = async (
48
52
  client: Client,
49
53
  fileId: string,
50
- fileStream: Readable,
54
+ fileStream: ReadableStream,
51
55
  folderSize: number,
52
56
  ) => {
53
57
  log("Uploading render", fileId);
@@ -60,6 +64,7 @@ export const uploadRender = async (
60
64
  {
61
65
  method: "POST",
62
66
  body: fileStream,
67
+ duplex: "half",
63
68
  },
64
69
  );
65
70
 
@@ -71,3 +76,27 @@ export const uploadRender = async (
71
76
  `Failed to upload render ${response.status} ${response.statusText}`,
72
77
  );
73
78
  };
79
+
80
+ export const lookupRenderByMd5 = async (
81
+ client: Client,
82
+ md5: string,
83
+ ): Promise<LookupRenderByMd5Result | null> => {
84
+ const response = await client.authenticatedFetch(
85
+ `/api/v1/renders/md5/${md5}`,
86
+ {
87
+ method: "GET",
88
+ },
89
+ );
90
+
91
+ if (response.ok) {
92
+ return (await response.json()) as LookupRenderByMd5Result;
93
+ }
94
+
95
+ if (response.status === 404) {
96
+ return null;
97
+ }
98
+
99
+ throw new Error(
100
+ `Failed to lookup render by md5 ${md5} ${response.status} ${response.statusText}`,
101
+ );
102
+ };
@@ -0,0 +1,49 @@
1
+ import { http, HttpResponse } from "msw";
2
+ import { setupServer } from "msw/node";
3
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from "vitest";
4
+
5
+ import { Client } from "../client.ts";
6
+ import { createTranscription } from "./transcriptions.ts";
7
+
8
+ const server = setupServer();
9
+ const client = new Client("ef_TEST_TOKEN", "http://localhost");
10
+
11
+ describe("Transcriptions", () => {
12
+ beforeAll(() => server.listen());
13
+ afterEach(() => server.resetHandlers());
14
+ afterAll(() => server.close());
15
+
16
+ describe("createTranscription", () => {
17
+ test("throws if server returns an error", async () => {
18
+ server.use(
19
+ http.post("http://localhost/api/v1/transcriptions", () =>
20
+ HttpResponse.text("Internal Server Error", { status: 500 }),
21
+ ),
22
+ );
23
+
24
+ await expect(
25
+ createTranscription(client, { file_id: "test", track_id: 1 }),
26
+ ).rejects.toThrowError(
27
+ "Failed to create transcription 500 Internal Server Error",
28
+ );
29
+ });
30
+
31
+ test("returns json data from the http response", async () => {
32
+ server.use(
33
+ http.post("http://localhost/api/v1/transcriptions", () =>
34
+ HttpResponse.json(
35
+ { testResponse: "test" },
36
+ { status: 200, statusText: "OK" },
37
+ ),
38
+ ),
39
+ );
40
+
41
+ const response = await createTranscription(client, {
42
+ file_id: "test",
43
+ track_id: 1,
44
+ });
45
+
46
+ expect(response).toEqual({ testResponse: "test" });
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,64 @@
1
+ import debug from "debug";
2
+ import { z } from "zod";
3
+
4
+ import { CompletionIterator } from "../ProgressIterator.ts";
5
+ import type { Client } from "../client.ts";
6
+
7
+ const log = debug("ef:api:transcriptions");
8
+
9
+ export const CreateTranscriptionPayload = z.object({
10
+ file_id: z.string(),
11
+ track_id: z.number().int(),
12
+ });
13
+
14
+ export interface CreateTranscriptionResult {
15
+ id: string;
16
+ status: "complete" | "created" | "failed" | "pending" | "transcribing";
17
+ }
18
+
19
+ export interface TranscriptionInfoResult {
20
+ id: string;
21
+ status: "complete" | "created" | "failed" | "pending" | "transcribing";
22
+ }
23
+
24
+ export const createTranscription = async (
25
+ client: Client,
26
+ payload: z.infer<typeof CreateTranscriptionPayload>,
27
+ ) => {
28
+ log("Creating transcription", payload);
29
+ const response = await client.authenticatedFetch("/api/v1/transcriptions", {
30
+ method: "POST",
31
+ body: JSON.stringify(payload),
32
+ });
33
+
34
+ log("Transcription created", response);
35
+ if (response.ok) {
36
+ return (await response.json()) as CreateTranscriptionResult;
37
+ }
38
+
39
+ throw new Error(
40
+ `Failed to create transcription ${response.status} ${response.statusText}`,
41
+ );
42
+ };
43
+
44
+ export const getTranscriptionProgress = async (client: Client, id: string) => {
45
+ const eventSource = await client.authenticatedEventSource(
46
+ `/api/v1/transcriptions/${id}/progress`,
47
+ );
48
+
49
+ return new CompletionIterator(eventSource);
50
+ };
51
+
52
+ export const getTranscriptionInfo = async (client: Client, id: string) => {
53
+ const response = await client.authenticatedFetch(
54
+ `/api/v1/transcriptions/${id}`,
55
+ );
56
+
57
+ if (response.ok) {
58
+ return (await response.json()) as TranscriptionInfoResult;
59
+ }
60
+
61
+ throw new Error(
62
+ `Failed to get transcription info ${response.status} ${response.statusText}`,
63
+ );
64
+ };