diffio 0.4.62 → 1.0.0

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 (60) hide show
  1. package/README.md +208 -296
  2. package/dist/Client.d.ts +85 -148
  3. package/dist/Client.js +73 -798
  4. package/dist/api/resources/account.d.ts +38 -0
  5. package/dist/api/resources/account.js +96 -0
  6. package/dist/api/resources/editing.d.ts +54 -0
  7. package/dist/api/resources/editing.js +168 -0
  8. package/dist/api/resources/generations.d.ts +52 -0
  9. package/dist/api/resources/generations.js +145 -0
  10. package/dist/api/resources/index.d.ts +5 -7
  11. package/dist/api/resources/index.js +18 -15
  12. package/dist/api/resources/models.d.ts +9 -0
  13. package/dist/api/resources/models.js +23 -0
  14. package/dist/api/resources/projects.d.ts +51 -0
  15. package/dist/api/resources/projects.js +128 -0
  16. package/dist/api/types.d.ts +423 -222
  17. package/dist/api/types.js +2 -0
  18. package/dist/core/edgeUpload.d.ts +39 -39
  19. package/dist/core/edgeUpload.js +170 -125
  20. package/dist/core/files.d.ts +15 -0
  21. package/dist/core/files.js +121 -0
  22. package/dist/core/node.d.ts +7 -0
  23. package/dist/core/node.js +17 -0
  24. package/dist/core/pagination.d.ts +33 -0
  25. package/dist/core/pagination.js +64 -0
  26. package/dist/core/poll.d.ts +23 -0
  27. package/dist/core/poll.js +30 -0
  28. package/dist/core/retry.d.ts +8 -7
  29. package/dist/core/retry.js +39 -25
  30. package/dist/core/transport.d.ts +75 -0
  31. package/dist/core/transport.js +220 -0
  32. package/dist/core/url.d.ts +10 -0
  33. package/dist/core/url.js +38 -0
  34. package/dist/core/webhookSignature.d.ts +20 -0
  35. package/dist/core/webhookSignature.js +147 -0
  36. package/dist/errors/index.d.ts +60 -18
  37. package/dist/errors/index.js +61 -13
  38. package/dist/index.d.ts +8 -1
  39. package/dist/index.js +9 -1
  40. package/dist/version.d.ts +1 -1
  41. package/dist/version.js +1 -1
  42. package/package.json +2 -7
  43. package/dist/BaseClient.d.ts +0 -26
  44. package/dist/BaseClient.js +0 -17
  45. package/dist/api/resources/account/client/Client.d.ts +0 -15
  46. package/dist/api/resources/account/client/Client.js +0 -15
  47. package/dist/api/resources/apiKeys/client/Client.d.ts +0 -27
  48. package/dist/api/resources/apiKeys/client/Client.js +0 -21
  49. package/dist/api/resources/audioIsolation/client/Client.d.ts +0 -43
  50. package/dist/api/resources/audioIsolation/client/Client.js +0 -33
  51. package/dist/api/resources/generations/client/Client.d.ts +0 -48
  52. package/dist/api/resources/generations/client/Client.js +0 -36
  53. package/dist/api/resources/projects/client/Client.d.ts +0 -21
  54. package/dist/api/resources/projects/client/Client.js +0 -19
  55. package/dist/api/resources/usage/client/Client.d.ts +0 -11
  56. package/dist/api/resources/usage/client/Client.js +0 -12
  57. package/dist/api/resources/webhooks/client/Client.d.ts +0 -29
  58. package/dist/api/resources/webhooks/client/Client.js +0 -76
  59. package/dist/api/serialization.d.ts +0 -21
  60. package/dist/api/serialization.js +0 -274
@@ -0,0 +1,51 @@
1
+ import type { RequestOptions, Transport } from "../../core/transport";
2
+ import { PagePromise } from "../../core/pagination";
3
+ import { type FileInput } from "../../core/files";
4
+ import type { ListParams, Project, ProjectCreateParams, ProjectDeleted, ProjectWithUpload } from "../types";
5
+ export interface ProjectUploadOptions extends RequestOptions {
6
+ /**
7
+ * Call `POST .../upload/complete` after the bytes land so the project is checked and prepared now
8
+ * (default true). With false the project becomes ready by itself about 30 s later.
9
+ */
10
+ complete?: boolean;
11
+ /** Parts in flight at once (default 3). */
12
+ partConcurrency?: number;
13
+ /** Seconds before one media host request gives up (default 300). */
14
+ partTimeout?: number;
15
+ /** Called after each part lands. */
16
+ onUploadProgress?: (progress: {
17
+ bytes_sent: number;
18
+ bytes_total: number;
19
+ parts_done: number;
20
+ parts_total: number;
21
+ }) => void;
22
+ }
23
+ export declare class ProjectsResource {
24
+ private readonly transport;
25
+ constructor(transport: Transport);
26
+ /**
27
+ * `POST /v2/projects`: creates a project and returns it with `upload` instructions. Send the bytes with
28
+ * `projects.upload(project, file)`. `generation: { model }` requests the first restore now.
29
+ */
30
+ create(params: ProjectCreateParams, options?: RequestOptions): Promise<ProjectWithUpload>;
31
+ /** `GET /v2/projects`: newest first. Await for one page, or `for await` to walk every project. */
32
+ list(params?: ListParams, options?: RequestOptions): PagePromise<Project>;
33
+ /** `GET /v2/projects/{project_id}`. */
34
+ get(projectId: string, options?: RequestOptions): Promise<Project>;
35
+ /** `DELETE /v2/projects/{project_id}`: deletes the upload, every result, exports, drafts and the share. */
36
+ delete(projectId: string, options?: RequestOptions): Promise<ProjectDeleted>;
37
+ /** `POST /v2/projects/{project_id}/upload`: fresh upload instructions while the project awaits its file. */
38
+ reopenUpload(projectId: string, options?: RequestOptions): Promise<ProjectWithUpload>;
39
+ /**
40
+ * `POST /v2/projects/{project_id}/upload/complete`: say the upload finished so the file is checked and
41
+ * prepared now. Safe to repeat; `projects.upload` calls it for you.
42
+ */
43
+ completeUpload(projectId: string, options?: RequestOptions): Promise<Project>;
44
+ /**
45
+ * Sends the media bytes to Diffio's media host by following `project.upload.requests` (start, parts of
46
+ * `part_size_bytes`, complete; parts retried), then calls `completeUpload` unless `complete: false`.
47
+ * `project` is the object `create` returned, or a project id (new instructions are fetched with
48
+ * `reopenUpload`). `file` is a path (Node), a Blob or File, or bytes. Returns the project after upload.
49
+ */
50
+ upload(project: ProjectWithUpload | string, file: FileInput, options?: ProjectUploadOptions): Promise<Project>;
51
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectsResource = void 0;
4
+ const pagination_1 = require("../../core/pagination");
5
+ const url_1 = require("../../core/url");
6
+ const edgeUpload_1 = require("../../core/edgeUpload");
7
+ const files_1 = require("../../core/files");
8
+ const errors_1 = require("../../errors");
9
+ /** `upload.complete` probes the file inside the request; the API allows it 180 s. */
10
+ const COMPLETE_UPLOAD_TIMEOUT_SECONDS = 180;
11
+ const COMPLETE_UPLOAD_MAX_RETRIES = 3;
12
+ class ProjectsResource {
13
+ constructor(transport) {
14
+ this.transport = transport;
15
+ }
16
+ /**
17
+ * `POST /v2/projects`: creates a project and returns it with `upload` instructions. Send the bytes with
18
+ * `projects.upload(project, file)`. `generation: { model }` requests the first restore now.
19
+ */
20
+ async create(params, options) {
21
+ if (!params || typeof params.file_name !== "string" || !params.file_name.trim()) {
22
+ throw new TypeError("file_name is required");
23
+ }
24
+ const { end_user: endUser, ...body } = params;
25
+ return this.transport.request({
26
+ method: "POST",
27
+ path: "/projects",
28
+ body,
29
+ idempotent: false,
30
+ acceptsIdempotencyKey: true,
31
+ options: endUser !== undefined && options?.endUser === undefined ? { ...options, endUser } : options
32
+ });
33
+ }
34
+ /** `GET /v2/projects`: newest first. Await for one page, or `for await` to walk every project. */
35
+ list(params = {}, options) {
36
+ return pagination_1.PagePromise.from(async () => {
37
+ const response = await this.transport.request({
38
+ method: "GET",
39
+ path: `/projects${(0, url_1.queryString)({ limit: params.limit, cursor: params.cursor })}`,
40
+ idempotent: true,
41
+ options
42
+ });
43
+ return new pagination_1.Page(response, async (cursor) => this.list({ ...params, cursor }, options));
44
+ });
45
+ }
46
+ /** `GET /v2/projects/{project_id}`. */
47
+ async get(projectId, options) {
48
+ return this.transport.request({
49
+ method: "GET",
50
+ path: `/projects/${(0, url_1.segment)(projectId, "projectId")}`,
51
+ idempotent: true,
52
+ options
53
+ });
54
+ }
55
+ /** `DELETE /v2/projects/{project_id}`: deletes the upload, every result, exports, drafts and the share. */
56
+ async delete(projectId, options) {
57
+ return this.transport.request({
58
+ method: "DELETE",
59
+ path: `/projects/${(0, url_1.segment)(projectId, "projectId")}`,
60
+ idempotent: true,
61
+ options
62
+ });
63
+ }
64
+ /** `POST /v2/projects/{project_id}/upload`: fresh upload instructions while the project awaits its file. */
65
+ async reopenUpload(projectId, options) {
66
+ return this.transport.request({
67
+ method: "POST",
68
+ path: `/projects/${(0, url_1.segment)(projectId, "projectId")}/upload`,
69
+ idempotent: true,
70
+ options
71
+ });
72
+ }
73
+ /**
74
+ * `POST /v2/projects/{project_id}/upload/complete`: say the upload finished so the file is checked and
75
+ * prepared now. Safe to repeat; `projects.upload` calls it for you.
76
+ */
77
+ async completeUpload(projectId, options) {
78
+ return this.transport.request({
79
+ method: "POST",
80
+ path: `/projects/${(0, url_1.segment)(projectId, "projectId")}/upload/complete`,
81
+ idempotent: true,
82
+ defaultTimeout: COMPLETE_UPLOAD_TIMEOUT_SECONDS,
83
+ options: { ...options, maxRetries: options?.maxRetries ?? Math.max(COMPLETE_UPLOAD_MAX_RETRIES, this.transport.retryPolicy().maxRetries) }
84
+ });
85
+ }
86
+ /**
87
+ * Sends the media bytes to Diffio's media host by following `project.upload.requests` (start, parts of
88
+ * `part_size_bytes`, complete; parts retried), then calls `completeUpload` unless `complete: false`.
89
+ * `project` is the object `create` returned, or a project id (new instructions are fetched with
90
+ * `reopenUpload`). `file` is a path (Node), a Blob or File, or bytes. Returns the project after upload.
91
+ */
92
+ async upload(project, file, options = {}) {
93
+ let target;
94
+ if (typeof project === "string")
95
+ target = await this.reopenUpload(project, options);
96
+ else
97
+ target = project;
98
+ if (!target || !target.id)
99
+ throw new TypeError("project is required");
100
+ if (!target.upload) {
101
+ throw new errors_1.DiffioError(`Project ${target.id} has no upload instructions (status ${target.status}); its file may already have arrived.`);
102
+ }
103
+ const resolved = await (0, files_1.resolveFileInput)(file);
104
+ try {
105
+ await (0, edgeUpload_1.uploadToMediaHost)({
106
+ upload: target.upload,
107
+ source: resolved.source,
108
+ fetch: this.transport.fetchFn,
109
+ partConcurrency: options.partConcurrency,
110
+ timeout: options.partTimeout,
111
+ signal: options.signal,
112
+ onProgress: options.onUploadProgress
113
+ });
114
+ }
115
+ catch (error) {
116
+ if (error instanceof errors_1.DiffioUploadError)
117
+ error.project_id = error.project_id ?? target.id;
118
+ throw error;
119
+ }
120
+ finally {
121
+ await resolved.source.close?.();
122
+ }
123
+ if (options.complete === false)
124
+ return this.get(target.id, options);
125
+ return this.completeUpload(target.id, options);
126
+ }
127
+ }
128
+ exports.ProjectsResource = ProjectsResource;