@lumeweb/pinner 0.0.1 → 0.1.1
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/LICENSE +9 -0
- package/README.md +707 -28
- package/dist/cjs/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/cjs/adapters/pinata/index.cjs +6 -0
- package/dist/cjs/adapters/pinata/legacy/adapter.cjs +83 -0
- package/dist/cjs/adapters/pinata/legacy/adapter.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/legacy/adapter.d.cts +74 -0
- package/dist/cjs/adapters/pinata/legacy/index.cjs +1 -0
- package/dist/cjs/adapters/pinata/shared/index.cjs +1 -0
- package/dist/cjs/adapters/pinata/shared/types.d.cts +218 -0
- package/dist/cjs/adapters/pinata/shared/utils.cjs +83 -0
- package/dist/cjs/adapters/pinata/shared/utils.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/v2/adapter-interface.d.cts +198 -0
- package/dist/cjs/adapters/pinata/v2/adapter.cjs +636 -0
- package/dist/cjs/adapters/pinata/v2/adapter.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/v2/adapter.d.cts +17 -0
- package/dist/cjs/adapters/pinata/v2/index.cjs +1 -0
- package/dist/cjs/adapters/pinata/v2/types.d.cts +308 -0
- package/dist/cjs/blockstore/index.cjs +2 -0
- package/dist/cjs/blockstore/unstorage-base.cjs +240 -0
- package/dist/cjs/blockstore/unstorage-base.cjs.map +1 -0
- package/dist/cjs/blockstore/unstorage-base.d.cts +23 -0
- package/dist/cjs/blockstore/unstorage.cjs +39 -0
- package/dist/cjs/blockstore/unstorage.cjs.map +1 -0
- package/dist/cjs/blockstore/unstorage.d.cts +36 -0
- package/dist/cjs/config.d.cts +51 -0
- package/dist/cjs/encoder/base64.cjs +38 -0
- package/dist/cjs/encoder/base64.cjs.map +1 -0
- package/dist/cjs/encoder/csv/csv-formatter.cjs +81 -0
- package/dist/cjs/encoder/csv/csv-formatter.cjs.map +1 -0
- package/dist/cjs/encoder/csv/field-formatter.cjs +76 -0
- package/dist/cjs/encoder/csv/field-formatter.cjs.map +1 -0
- package/dist/cjs/encoder/csv/row-formatter.cjs +159 -0
- package/dist/cjs/encoder/csv/row-formatter.cjs.map +1 -0
- package/dist/cjs/encoder/csv.cjs +44 -0
- package/dist/cjs/encoder/csv.cjs.map +1 -0
- package/dist/cjs/encoder/error.cjs +19 -0
- package/dist/cjs/encoder/error.cjs.map +1 -0
- package/dist/cjs/encoder/index.cjs +6 -0
- package/dist/cjs/encoder/json.cjs +36 -0
- package/dist/cjs/encoder/json.cjs.map +1 -0
- package/dist/cjs/encoder/text.cjs +35 -0
- package/dist/cjs/encoder/text.cjs.map +1 -0
- package/dist/cjs/encoder/url.cjs +39 -0
- package/dist/cjs/encoder/url.cjs.map +1 -0
- package/dist/cjs/errors/index.cjs +104 -0
- package/dist/cjs/errors/index.cjs.map +1 -0
- package/dist/cjs/errors/index.d.cts +47 -0
- package/dist/cjs/index.cjs +44 -0
- package/dist/cjs/index.d.cts +16 -0
- package/dist/cjs/pin/client.cjs +98 -0
- package/dist/cjs/pin/client.cjs.map +1 -0
- package/dist/cjs/pin/index.cjs +1 -0
- package/dist/cjs/pinner.cjs +132 -0
- package/dist/cjs/pinner.cjs.map +1 -0
- package/dist/cjs/pinner.d.cts +81 -0
- package/dist/cjs/types/constants.cjs +39 -0
- package/dist/cjs/types/constants.cjs.map +1 -0
- package/dist/cjs/types/mime-types.cjs +11 -0
- package/dist/cjs/types/mime-types.cjs.map +1 -0
- package/dist/cjs/types/mime-types.d.cts +7 -0
- package/dist/cjs/types/pin.d.cts +78 -0
- package/dist/cjs/types/type-guards.cjs +20 -0
- package/dist/cjs/types/type-guards.cjs.map +1 -0
- package/dist/cjs/types/type-guards.d.cts +15 -0
- package/dist/cjs/types/upload.cjs +18 -0
- package/dist/cjs/types/upload.cjs.map +1 -0
- package/dist/cjs/types/upload.d.cts +189 -0
- package/dist/cjs/upload/base-upload.cjs +135 -0
- package/dist/cjs/upload/base-upload.cjs.map +1 -0
- package/dist/cjs/upload/builder.cjs +174 -0
- package/dist/cjs/upload/builder.cjs.map +1 -0
- package/dist/cjs/upload/builder.d.cts +60 -0
- package/dist/cjs/upload/car.cjs +129 -0
- package/dist/cjs/upload/car.cjs.map +1 -0
- package/dist/cjs/upload/car.d.cts +19 -0
- package/dist/cjs/upload/constants.cjs +9 -0
- package/dist/cjs/upload/constants.cjs.map +1 -0
- package/dist/cjs/upload/index.cjs +8 -0
- package/dist/cjs/upload/manager.cjs +249 -0
- package/dist/cjs/upload/manager.cjs.map +1 -0
- package/dist/cjs/upload/manager.d.cts +35 -0
- package/dist/cjs/upload/normalize.cjs +28 -0
- package/dist/cjs/upload/normalize.cjs.map +1 -0
- package/dist/cjs/upload/tus-upload.cjs +74 -0
- package/dist/cjs/upload/tus-upload.cjs.map +1 -0
- package/dist/cjs/upload/xhr-upload.cjs +41 -0
- package/dist/cjs/upload/xhr-upload.cjs.map +1 -0
- package/dist/cjs/utils/env.cjs +12 -0
- package/dist/cjs/utils/env.cjs.map +1 -0
- package/dist/cjs/utils/stream.cjs +141 -0
- package/dist/cjs/utils/stream.cjs.map +1 -0
- package/dist/cjs/utils/stream.d.cts +23 -0
- package/dist/cjs/utils/tus-patch.cjs +50 -0
- package/dist/cjs/utils/tus-patch.cjs.map +1 -0
- package/dist/cjs/utils/validation.cjs +62 -0
- package/dist/cjs/utils/validation.cjs.map +1 -0
- package/dist/esm/_virtual/rolldown_runtime.js +8 -0
- package/dist/esm/adapters/pinata/index.d.ts +7 -0
- package/dist/esm/adapters/pinata/index.js +6 -0
- package/dist/esm/adapters/pinata/legacy/adapter.d.ts +74 -0
- package/dist/esm/adapters/pinata/legacy/adapter.js +83 -0
- package/dist/esm/adapters/pinata/legacy/adapter.js.map +1 -0
- package/dist/esm/adapters/pinata/legacy/index.d.ts +1 -0
- package/dist/esm/adapters/pinata/legacy/index.js +1 -0
- package/dist/esm/adapters/pinata/shared/index.d.ts +2 -0
- package/dist/esm/adapters/pinata/shared/index.js +1 -0
- package/dist/esm/adapters/pinata/shared/types.d.ts +218 -0
- package/dist/esm/adapters/pinata/shared/utils.d.ts +1 -0
- package/dist/esm/adapters/pinata/shared/utils.js +78 -0
- package/dist/esm/adapters/pinata/shared/utils.js.map +1 -0
- package/dist/esm/adapters/pinata/v2/adapter-interface.d.ts +198 -0
- package/dist/esm/adapters/pinata/v2/adapter.d.ts +17 -0
- package/dist/esm/adapters/pinata/v2/adapter.js +636 -0
- package/dist/esm/adapters/pinata/v2/adapter.js.map +1 -0
- package/dist/esm/adapters/pinata/v2/index.d.ts +3 -0
- package/dist/esm/adapters/pinata/v2/index.js +1 -0
- package/dist/esm/adapters/pinata/v2/types.d.ts +308 -0
- package/dist/esm/blockstore/index.d.ts +2 -0
- package/dist/esm/blockstore/index.js +2 -0
- package/dist/esm/blockstore/unstorage-base.d.ts +23 -0
- package/dist/esm/blockstore/unstorage-base.js +231 -0
- package/dist/esm/blockstore/unstorage-base.js.map +1 -0
- package/dist/esm/blockstore/unstorage.d.ts +36 -0
- package/dist/esm/blockstore/unstorage.js +38 -0
- package/dist/esm/blockstore/unstorage.js.map +1 -0
- package/dist/esm/config.d.ts +51 -0
- package/dist/esm/encoder/base64.js +37 -0
- package/dist/esm/encoder/base64.js.map +1 -0
- package/dist/esm/encoder/csv/csv-formatter.js +81 -0
- package/dist/esm/encoder/csv/csv-formatter.js.map +1 -0
- package/dist/esm/encoder/csv/field-formatter.js +75 -0
- package/dist/esm/encoder/csv/field-formatter.js.map +1 -0
- package/dist/esm/encoder/csv/row-formatter.js +159 -0
- package/dist/esm/encoder/csv/row-formatter.js.map +1 -0
- package/dist/esm/encoder/csv.js +43 -0
- package/dist/esm/encoder/csv.js.map +1 -0
- package/dist/esm/encoder/error.js +18 -0
- package/dist/esm/encoder/error.js.map +1 -0
- package/dist/esm/encoder/index.js +6 -0
- package/dist/esm/encoder/json.js +35 -0
- package/dist/esm/encoder/json.js.map +1 -0
- package/dist/esm/encoder/text.js +34 -0
- package/dist/esm/encoder/text.js.map +1 -0
- package/dist/esm/encoder/url.js +36 -0
- package/dist/esm/encoder/url.js.map +1 -0
- package/dist/esm/errors/index.d.ts +47 -0
- package/dist/esm/errors/index.js +93 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/index.d.ts +18 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/pin/client.js +97 -0
- package/dist/esm/pin/client.js.map +1 -0
- package/dist/esm/pin/index.js +1 -0
- package/dist/esm/pinner.d.ts +81 -0
- package/dist/esm/pinner.js +131 -0
- package/dist/esm/pinner.js.map +1 -0
- package/dist/esm/types/constants.js +33 -0
- package/dist/esm/types/constants.js.map +1 -0
- package/dist/esm/types/mime-types.d.ts +7 -0
- package/dist/esm/types/mime-types.js +8 -0
- package/dist/esm/types/mime-types.js.map +1 -0
- package/dist/esm/types/pin.d.ts +78 -0
- package/dist/esm/types/type-guards.d.ts +15 -0
- package/dist/esm/types/type-guards.js +19 -0
- package/dist/esm/types/type-guards.js.map +1 -0
- package/dist/esm/types/upload.d.ts +189 -0
- package/dist/esm/types/upload.js +16 -0
- package/dist/esm/types/upload.js.map +1 -0
- package/dist/esm/upload/base-upload.js +132 -0
- package/dist/esm/upload/base-upload.js.map +1 -0
- package/dist/esm/upload/builder.d.ts +60 -0
- package/dist/esm/upload/builder.js +173 -0
- package/dist/esm/upload/builder.js.map +1 -0
- package/dist/esm/upload/car.d.ts +19 -0
- package/dist/esm/upload/car.js +125 -0
- package/dist/esm/upload/car.js.map +1 -0
- package/dist/esm/upload/constants.js +7 -0
- package/dist/esm/upload/constants.js.map +1 -0
- package/dist/esm/upload/index.js +8 -0
- package/dist/esm/upload/manager.d.ts +35 -0
- package/dist/esm/upload/manager.js +248 -0
- package/dist/esm/upload/manager.js.map +1 -0
- package/dist/esm/upload/normalize.js +28 -0
- package/dist/esm/upload/normalize.js.map +1 -0
- package/dist/esm/upload/tus-upload.js +72 -0
- package/dist/esm/upload/tus-upload.js.map +1 -0
- package/dist/esm/upload/xhr-upload.js +39 -0
- package/dist/esm/upload/xhr-upload.js.map +1 -0
- package/dist/esm/utils/env.js +11 -0
- package/dist/esm/utils/env.js.map +1 -0
- package/dist/esm/utils/stream.d.ts +23 -0
- package/dist/esm/utils/stream.js +134 -0
- package/dist/esm/utils/stream.js.map +1 -0
- package/dist/esm/utils/tus-patch.js +51 -0
- package/dist/esm/utils/tus-patch.js.map +1 -0
- package/dist/esm/utils/validation.js +60 -0
- package/dist/esm/utils/validation.js.map +1 -0
- package/package.json +95 -8
- package/public/mockServiceWorker.js +349 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
2
|
+
import { Status } from "@ipfs-shipyard/pinning-service-client";
|
|
3
|
+
|
|
4
|
+
//#region src/types/pin.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options that can be passed to abort async operations
|
|
8
|
+
*/
|
|
9
|
+
interface AbortOptions {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Allows passing extra options accepted by the remote pinning service
|
|
14
|
+
*/
|
|
15
|
+
interface RemoteAddOptions extends AbortOptions {
|
|
16
|
+
name?: string;
|
|
17
|
+
metadata?: Record<string, string>;
|
|
18
|
+
origins?: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Allows passing extra options accepted by the remote pinning service
|
|
22
|
+
*/
|
|
23
|
+
interface RemoteLsOptions extends AbortOptions {
|
|
24
|
+
name?: string;
|
|
25
|
+
status?: Status[];
|
|
26
|
+
limit?: number;
|
|
27
|
+
cursor?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Includes extra metadata supported by the remote pinning service
|
|
31
|
+
*/
|
|
32
|
+
interface RemotePin {
|
|
33
|
+
cid: CID;
|
|
34
|
+
name?: string;
|
|
35
|
+
status: Status;
|
|
36
|
+
created: Date;
|
|
37
|
+
size?: number;
|
|
38
|
+
metadata?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extends the Pins interface with remote pinning-specific arguments and return
|
|
42
|
+
* types (e.g. metadata as `Record<string, string>` and pins with an added
|
|
43
|
+
* `.status` property)
|
|
44
|
+
*/
|
|
45
|
+
interface RemotePins {
|
|
46
|
+
/**
|
|
47
|
+
* Pin a block in the blockstore. It will not be deleted
|
|
48
|
+
* when garbage collection is run.
|
|
49
|
+
*/
|
|
50
|
+
add(cid: CID, options?: RemoteAddOptions): AsyncGenerator<CID, void, undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* List all blocks that have been pinned.
|
|
53
|
+
*/
|
|
54
|
+
ls(options?: RemoteLsOptions): AsyncGenerator<RemotePin, void, undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Return true if the passed CID is pinned
|
|
57
|
+
*/
|
|
58
|
+
isPinned(cid: CID, options?: AbortOptions): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Return pin details
|
|
61
|
+
*/
|
|
62
|
+
get(cid: CID, options?: AbortOptions): Promise<RemotePin>;
|
|
63
|
+
/**
|
|
64
|
+
* Update pin metadata
|
|
65
|
+
*/
|
|
66
|
+
setMetadata(cid: CID, metadata: Record<string, string> | undefined, options?: AbortOptions): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Remove a pin. The block may be deleted when garbage collection is run.
|
|
69
|
+
*/
|
|
70
|
+
rm(cid: CID, options?: AbortOptions): AsyncGenerator<CID, void, undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Remove a pin by request ID. The block may be deleted when garbage collection is run.
|
|
73
|
+
*/
|
|
74
|
+
rmByRequestId(requestId: string, options?: AbortOptions): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { AbortOptions, RemoteAddOptions, RemoteLsOptions, RemotePin, RemotePins };
|
|
78
|
+
//# sourceMappingURL=pin.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PinnerError } from "../errors/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/type-guards.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Check if error is retryable.
|
|
7
|
+
*/
|
|
8
|
+
declare function isRetryable(error: PinnerError): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Check if error is authentication-related.
|
|
11
|
+
*/
|
|
12
|
+
declare function isAuthenticationError(error: PinnerError): boolean;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { isAuthenticationError, isRetryable };
|
|
15
|
+
//# sourceMappingURL=type-guards.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PinnerError } from "../errors/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/type-guards.ts
|
|
4
|
+
/**
|
|
5
|
+
* Check if error is retryable.
|
|
6
|
+
*/
|
|
7
|
+
function isRetryable(error) {
|
|
8
|
+
return error.retryable;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Check if error is authentication-related.
|
|
12
|
+
*/
|
|
13
|
+
function isAuthenticationError(error) {
|
|
14
|
+
return error instanceof PinnerError && error.code === "AUTHENTICATION_ERROR";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { isAuthenticationError, isRetryable };
|
|
19
|
+
//# sourceMappingURL=type-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.js","names":[],"sources":["../../../src/types/type-guards.ts"],"sourcesContent":["import { PinnerError } from \"../errors\";\n\n/**\n * Check if error is retryable.\n */\nexport function isRetryable(error: PinnerError): boolean {\n return error.retryable;\n}\n\n/**\n * Check if error is authentication-related.\n */\nexport function isAuthenticationError(error: PinnerError): boolean {\n return error instanceof PinnerError && error.code === \"AUTHENTICATION_ERROR\";\n}\n"],"mappings":";;;;;;AAKA,SAAgB,YAAY,OAA6B;AACvD,QAAO,MAAM;;;;;AAMf,SAAgB,sBAAsB,OAA6B;AACjE,QAAO,iBAAiB,eAAe,MAAM,SAAS"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { OperationPollingOptions } from "@lumeweb/portal-sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/types/upload.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Symbol used to brand UploadResult for type checking
|
|
7
|
+
*/
|
|
8
|
+
declare const UploadResultSymbol: unique symbol;
|
|
9
|
+
interface UploadResult {
|
|
10
|
+
/**
|
|
11
|
+
* Unique identifier for this upload operation.
|
|
12
|
+
*/
|
|
13
|
+
id: string;
|
|
14
|
+
/**
|
|
15
|
+
* IPFS Content Identifier for the uploaded content.
|
|
16
|
+
*/
|
|
17
|
+
cid: string;
|
|
18
|
+
/**
|
|
19
|
+
* User-provided or auto-generated name for the content.
|
|
20
|
+
*/
|
|
21
|
+
name: string;
|
|
22
|
+
/**
|
|
23
|
+
* Total size in bytes.
|
|
24
|
+
*/
|
|
25
|
+
size: number;
|
|
26
|
+
/**
|
|
27
|
+
* MIME type of the content.
|
|
28
|
+
*/
|
|
29
|
+
mimeType: string;
|
|
30
|
+
/**
|
|
31
|
+
* ISO timestamp when content was created.
|
|
32
|
+
*/
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
/**
|
|
35
|
+
* Number of files (1 for single file, N for directory).
|
|
36
|
+
*/
|
|
37
|
+
numberOfFiles: number;
|
|
38
|
+
/**
|
|
39
|
+
* Custom key-value metadata.
|
|
40
|
+
*/
|
|
41
|
+
keyvalues?: Record<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Whether this upload is a directory.
|
|
44
|
+
*/
|
|
45
|
+
isDirectory?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Whether this upload is already a valid CAR file.
|
|
48
|
+
* If true, the upload system will skip CAR preprocessing and upload the file as-is.
|
|
49
|
+
* Useful for passthrough of pre-generated CAR files.
|
|
50
|
+
*/
|
|
51
|
+
isCarFile?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Portal operation ID for tracking the pinning operation.
|
|
54
|
+
* Can be used with waitForOperation() to wait for the operation to complete.
|
|
55
|
+
*/
|
|
56
|
+
operationId?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Symbol brand for type checking - used to identify UploadResult objects
|
|
59
|
+
*/
|
|
60
|
+
[UploadResultSymbol]?: true;
|
|
61
|
+
}
|
|
62
|
+
type UploadInput = File | ReadableStream<Uint8Array>;
|
|
63
|
+
interface UploadOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Name for the uploaded content.
|
|
66
|
+
*/
|
|
67
|
+
name?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Custom key-value metadata.
|
|
70
|
+
*/
|
|
71
|
+
keyvalues?: Record<string, string>;
|
|
72
|
+
/**
|
|
73
|
+
* Progress callback invoked during upload.
|
|
74
|
+
*/
|
|
75
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Callback invoked when upload completes successfully.
|
|
78
|
+
*/
|
|
79
|
+
onComplete?: (result: UploadResult) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Callback invoked when upload fails.
|
|
82
|
+
*/
|
|
83
|
+
onError?: (error: Error) => void;
|
|
84
|
+
/**
|
|
85
|
+
* AbortSignal for cancellation.
|
|
86
|
+
*/
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
/**
|
|
89
|
+
* Optional size override for the upload input.
|
|
90
|
+
* Useful for ReadableStream inputs where size detection is difficult.
|
|
91
|
+
*/
|
|
92
|
+
size?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Whether this upload is a directory.
|
|
95
|
+
*/
|
|
96
|
+
isDirectory?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Whether this upload is already a valid CAR file.
|
|
99
|
+
* If true, the upload system will skip CAR preprocessing and upload the file as-is.
|
|
100
|
+
* Useful for passthrough of pre-generated CAR files.
|
|
101
|
+
*/
|
|
102
|
+
isCarFile?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Whether to wait for the pinning operation to complete/fail.
|
|
105
|
+
* When true, the upload will block until the operation reaches a settled state
|
|
106
|
+
* (completed, failed, or error). Default is false (upload only).
|
|
107
|
+
*/
|
|
108
|
+
waitForOperation?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Polling options for waiting on operation completion.
|
|
111
|
+
* Only used when waitForOperation is true.
|
|
112
|
+
*/
|
|
113
|
+
operationPollingOptions?: OperationPollingOptions;
|
|
114
|
+
}
|
|
115
|
+
interface UploadProgress {
|
|
116
|
+
/**
|
|
117
|
+
* Percentage complete (0-100).
|
|
118
|
+
*/
|
|
119
|
+
percentage: number;
|
|
120
|
+
/**
|
|
121
|
+
* Number of bytes uploaded.
|
|
122
|
+
*/
|
|
123
|
+
bytesUploaded: number;
|
|
124
|
+
/**
|
|
125
|
+
* Total bytes to upload.
|
|
126
|
+
*/
|
|
127
|
+
bytesTotal: number;
|
|
128
|
+
/**
|
|
129
|
+
* Upload speed in bytes per second.
|
|
130
|
+
*/
|
|
131
|
+
speed?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Estimated time remaining in seconds.
|
|
134
|
+
*/
|
|
135
|
+
eta?: number;
|
|
136
|
+
}
|
|
137
|
+
interface UploadOperation {
|
|
138
|
+
/**
|
|
139
|
+
* Cancel the ongoing upload.
|
|
140
|
+
*/
|
|
141
|
+
cancel(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Pause the upload (TUS only).
|
|
144
|
+
*/
|
|
145
|
+
pause(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Resume a paused upload (TUS only).
|
|
148
|
+
*/
|
|
149
|
+
resume(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Promise that resolves when upload completes.
|
|
152
|
+
*/
|
|
153
|
+
result: Promise<UploadResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Current progress.
|
|
156
|
+
*/
|
|
157
|
+
progress: Readonly<UploadProgress>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Builder interface for Pinner upload API.
|
|
161
|
+
* Supports chaining name/keyvalues and returns UploadOperation with controls.
|
|
162
|
+
*/
|
|
163
|
+
interface PinnerUploadBuilder {
|
|
164
|
+
/**
|
|
165
|
+
* Set the name for the upload.
|
|
166
|
+
*/
|
|
167
|
+
name(name: string): this;
|
|
168
|
+
/**
|
|
169
|
+
* Set custom key-value metadata.
|
|
170
|
+
*/
|
|
171
|
+
keyvalues(kv: Record<string, string>): this;
|
|
172
|
+
/**
|
|
173
|
+
* Whether to wait for the pinning operation to complete/fail.
|
|
174
|
+
* When true, the upload will block until the operation reaches a settled state.
|
|
175
|
+
*/
|
|
176
|
+
waitForOperation(wait: boolean): this;
|
|
177
|
+
/**
|
|
178
|
+
* Set polling options for waiting on operation completion.
|
|
179
|
+
* Only used when waitForOperation is true.
|
|
180
|
+
*/
|
|
181
|
+
operationPollingOptions(options: OperationPollingOptions): this;
|
|
182
|
+
/**
|
|
183
|
+
* Start the upload and return UploadOperation with controls.
|
|
184
|
+
*/
|
|
185
|
+
pin(): Promise<UploadOperation>;
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
export { PinnerUploadBuilder, UploadInput, UploadOperation, UploadOptions, UploadProgress, UploadResult };
|
|
189
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/types/upload.ts
|
|
2
|
+
/**
|
|
3
|
+
* Symbol used to brand UploadResult for type checking
|
|
4
|
+
*/
|
|
5
|
+
const UploadResultSymbol = Symbol("UploadResult");
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if a value is an UploadResult
|
|
8
|
+
* Uses the UploadResultSymbol for reliable type checking
|
|
9
|
+
*/
|
|
10
|
+
function isUploadResult(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && UploadResultSymbol in value && value[UploadResultSymbol] === true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { UploadResultSymbol, isUploadResult };
|
|
16
|
+
//# sourceMappingURL=upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","names":[],"sources":["../../../src/types/upload.ts"],"sourcesContent":["import type { OperationPollingOptions } from \"@lumeweb/portal-sdk\";\n\n/**\n * Symbol used to brand UploadResult for type checking\n */\nexport const UploadResultSymbol = Symbol(\"UploadResult\");\n\nexport interface UploadResult {\n /**\n * Unique identifier for this upload operation.\n */\n id: string;\n\n /**\n * IPFS Content Identifier for the uploaded content.\n */\n cid: string;\n\n /**\n * User-provided or auto-generated name for the content.\n */\n name: string;\n\n /**\n * Total size in bytes.\n */\n size: number;\n\n /**\n * MIME type of the content.\n */\n mimeType: string;\n\n /**\n * ISO timestamp when content was created.\n */\n createdAt: Date;\n\n /**\n * Number of files (1 for single file, N for directory).\n */\n numberOfFiles: number;\n\n /**\n * Custom key-value metadata.\n */\n keyvalues?: Record<string, string>;\n\n /**\n * Whether this upload is a directory.\n */\n isDirectory?: boolean;\n\n /**\n * Whether this upload is already a valid CAR file.\n * If true, the upload system will skip CAR preprocessing and upload the file as-is.\n * Useful for passthrough of pre-generated CAR files.\n */\n isCarFile?: boolean;\n\n /**\n * Portal operation ID for tracking the pinning operation.\n * Can be used with waitForOperation() to wait for the operation to complete.\n */\n operationId?: number;\n\n /**\n * Symbol brand for type checking - used to identify UploadResult objects\n */\n [UploadResultSymbol]?: true;\n}\n\nexport type UploadInput = File | ReadableStream<Uint8Array>;\n\n/**\n * Type guard to check if a value is an UploadResult\n * Uses the UploadResultSymbol for reliable type checking\n */\nexport function isUploadResult(value: unknown): value is UploadResult {\n return (\n typeof value === \"object\" &&\n value !== null &&\n UploadResultSymbol in value &&\n value[UploadResultSymbol] === true\n );\n}\n\nexport interface UploadOptions {\n /**\n * Name for the uploaded content.\n */\n name?: string;\n\n /**\n * Custom key-value metadata.\n */\n keyvalues?: Record<string, string>;\n\n /**\n * Progress callback invoked during upload.\n */\n onProgress?: (progress: UploadProgress) => void;\n\n /**\n * Callback invoked when upload completes successfully.\n */\n onComplete?: (result: UploadResult) => void;\n\n /**\n * Callback invoked when upload fails.\n */\n onError?: (error: Error) => void;\n\n /**\n * AbortSignal for cancellation.\n */\n signal?: AbortSignal;\n\n /**\n * Optional size override for the upload input.\n * Useful for ReadableStream inputs where size detection is difficult.\n */\n size?: number;\n\n /**\n * Whether this upload is a directory.\n */\n isDirectory?: boolean;\n\n /**\n * Whether this upload is already a valid CAR file.\n * If true, the upload system will skip CAR preprocessing and upload the file as-is.\n * Useful for passthrough of pre-generated CAR files.\n */\n isCarFile?: boolean;\n\n /**\n * Whether to wait for the pinning operation to complete/fail.\n * When true, the upload will block until the operation reaches a settled state\n * (completed, failed, or error). Default is false (upload only).\n */\n waitForOperation?: boolean;\n\n /**\n * Polling options for waiting on operation completion.\n * Only used when waitForOperation is true.\n */\n operationPollingOptions?: OperationPollingOptions;\n}\n\nexport interface UploadProgress {\n /**\n * Percentage complete (0-100).\n */\n percentage: number;\n\n /**\n * Number of bytes uploaded.\n */\n bytesUploaded: number;\n\n /**\n * Total bytes to upload.\n */\n bytesTotal: number;\n\n /**\n * Upload speed in bytes per second.\n */\n speed?: number;\n\n /**\n * Estimated time remaining in seconds.\n */\n eta?: number;\n}\n\nexport interface UploadOperation {\n /**\n * Cancel the ongoing upload.\n */\n cancel(): void;\n\n /**\n * Pause the upload (TUS only).\n */\n pause(): void;\n\n /**\n * Resume a paused upload (TUS only).\n */\n resume(): void;\n\n /**\n * Promise that resolves when upload completes.\n */\n result: Promise<UploadResult>;\n\n /**\n * Current progress.\n */\n progress: Readonly<UploadProgress>;\n}\n\n/**\n * Builder interface for Pinner upload API.\n * Supports chaining name/keyvalues and returns UploadOperation with controls.\n */\nexport interface PinnerUploadBuilder {\n /**\n * Set the name for the upload.\n */\n name(name: string): this;\n\n /**\n * Set custom key-value metadata.\n */\n keyvalues(kv: Record<string, string>): this;\n\n /**\n * Whether to wait for the pinning operation to complete/fail.\n * When true, the upload will block until the operation reaches a settled state.\n */\n waitForOperation(wait: boolean): this;\n\n /**\n * Set polling options for waiting on operation completion.\n * Only used when waitForOperation is true.\n */\n operationPollingOptions(options: OperationPollingOptions): this;\n\n /**\n * Start the upload and return UploadOperation with controls.\n */\n pin(): Promise<UploadOperation>;\n}\n"],"mappings":";;;;AAKA,MAAa,qBAAqB,OAAO,eAAe;;;;;AAyExD,SAAgB,eAAe,OAAuC;AACpE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,sBAAsB,SACtB,MAAM,wBAAwB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { normalizeUploadInput } from "./normalize.js";
|
|
2
|
+
import { isNodeEnvironment } from "../utils/env.js";
|
|
3
|
+
import { fileToReadableStream, readableStreamToNodeStream } from "../utils/stream.js";
|
|
4
|
+
import { UPLOAD_SOURCE_TUS, UPLOAD_SOURCE_XHR } from "./constants.js";
|
|
5
|
+
import Uppy from "@uppy/core";
|
|
6
|
+
import defer from "p-defer";
|
|
7
|
+
|
|
8
|
+
//#region src/upload/base-upload.ts
|
|
9
|
+
var BaseUploadHandler = class {
|
|
10
|
+
config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
async upload(input, options) {
|
|
15
|
+
const normalized = normalizeUploadInput(input, options);
|
|
16
|
+
const uppy = new Uppy();
|
|
17
|
+
const { fileId, resultPromise, progress } = this.#setupUppyHandlers(uppy, normalized, options);
|
|
18
|
+
await this.#addFileToUppy(uppy, normalized, normalized.size);
|
|
19
|
+
this.#startUpload(uppy, options);
|
|
20
|
+
return this.#createUploadOperation(uppy, fileId, resultPromise, progress);
|
|
21
|
+
}
|
|
22
|
+
#setupUppyHandlers(uppy, normalized, options) {
|
|
23
|
+
let fileId = null;
|
|
24
|
+
let hasRejected = false;
|
|
25
|
+
const progress = {
|
|
26
|
+
percentage: 0,
|
|
27
|
+
bytesUploaded: 0,
|
|
28
|
+
bytesTotal: normalized.size
|
|
29
|
+
};
|
|
30
|
+
const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = defer();
|
|
31
|
+
const handleError = (error) => {
|
|
32
|
+
if (hasRejected) return;
|
|
33
|
+
hasRejected = true;
|
|
34
|
+
options?.onError?.(error);
|
|
35
|
+
rejectResult(error);
|
|
36
|
+
};
|
|
37
|
+
this.configurePlugin(uppy);
|
|
38
|
+
uppy.on("progress", (progressBytes) => {
|
|
39
|
+
progress.bytesUploaded = progressBytes;
|
|
40
|
+
progress.percentage = progressBytes / progress.bytesTotal * 100;
|
|
41
|
+
options?.onProgress?.(progress);
|
|
42
|
+
});
|
|
43
|
+
uppy.on("upload-success", (_file, result) => {
|
|
44
|
+
if (hasRejected) return;
|
|
45
|
+
const uploadResult = this.parseResult(result);
|
|
46
|
+
options?.onComplete?.(uploadResult);
|
|
47
|
+
resolveResult(uploadResult);
|
|
48
|
+
});
|
|
49
|
+
uppy.on("error", (error) => {
|
|
50
|
+
handleError(new Error(this.#extractErrorMessage(error)));
|
|
51
|
+
});
|
|
52
|
+
uppy.on("file-added", (file) => {
|
|
53
|
+
fileId = file.id;
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
fileId,
|
|
57
|
+
resultPromise,
|
|
58
|
+
progress
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
#extractErrorMessage(error) {
|
|
62
|
+
let errorMessage = "Upload fainormalizeDataled";
|
|
63
|
+
if (!error) return errorMessage;
|
|
64
|
+
if (typeof error === "string") errorMessage = error;
|
|
65
|
+
else if (error instanceof Error) errorMessage = error.message;
|
|
66
|
+
else if (error.message) errorMessage = error.message;
|
|
67
|
+
else if (error.toString && typeof error.toString === "function") errorMessage = error.toString();
|
|
68
|
+
const errorObj = error;
|
|
69
|
+
if (errorObj?.xhr?.response) try {
|
|
70
|
+
const response = typeof errorObj.xhr.response === "string" ? JSON.parse(errorObj.xhr.response) : errorObj.xhr.response;
|
|
71
|
+
if (response.error) errorMessage = response.error;
|
|
72
|
+
else if (response.message) errorMessage = response.message;
|
|
73
|
+
} catch {}
|
|
74
|
+
return errorMessage;
|
|
75
|
+
}
|
|
76
|
+
async #normalizeData(data) {
|
|
77
|
+
if (isNodeEnvironment()) return this.#normalizeDataForNode(data);
|
|
78
|
+
return this.#normalizeDataForBrowser(data);
|
|
79
|
+
}
|
|
80
|
+
async #normalizeDataForBrowser(data) {
|
|
81
|
+
if (this.getUploadSource() === UPLOAD_SOURCE_TUS) {
|
|
82
|
+
if (data instanceof ReadableStream) {
|
|
83
|
+
const { streamToBlobViaResponse } = await import("../utils/stream.js");
|
|
84
|
+
return streamToBlobViaResponse(data);
|
|
85
|
+
}
|
|
86
|
+
return data;
|
|
87
|
+
}
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
async #normalizeDataForNode(data) {
|
|
91
|
+
if (this.getUploadSource() === UPLOAD_SOURCE_XHR) return data;
|
|
92
|
+
if (data instanceof File) return await readableStreamToNodeStream(fileToReadableStream(data));
|
|
93
|
+
if (data instanceof ReadableStream) return await readableStreamToNodeStream(data);
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
async #addFileToUppy(uppy, normalized, size) {
|
|
97
|
+
const fileData = await this.#normalizeData(normalized.data);
|
|
98
|
+
const fileOptions = {
|
|
99
|
+
source: this.getUploadSource(),
|
|
100
|
+
name: normalized.name,
|
|
101
|
+
type: normalized.type,
|
|
102
|
+
data: fileData
|
|
103
|
+
};
|
|
104
|
+
const fileId = uppy.addFile(fileOptions);
|
|
105
|
+
if (this.getUploadSource() === UPLOAD_SOURCE_TUS && size !== void 0 && size > 0) uppy.setFileState(fileId, { tus: { uploadSize: size } });
|
|
106
|
+
}
|
|
107
|
+
#startUpload(uppy, options) {
|
|
108
|
+
uppy.upload().catch((error) => {
|
|
109
|
+
options?.onError?.(new Error(this.#extractErrorMessage(error)));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
#createUploadOperation(uppy, fileId, resultPromise, progress) {
|
|
113
|
+
return {
|
|
114
|
+
cancel: () => {
|
|
115
|
+
uppy.cancelAll();
|
|
116
|
+
},
|
|
117
|
+
pause: () => {
|
|
118
|
+
if (fileId) uppy.pauseResume(fileId);
|
|
119
|
+
},
|
|
120
|
+
resume: () => {
|
|
121
|
+
if (fileId) uppy.pauseResume(fileId);
|
|
122
|
+
},
|
|
123
|
+
result: resultPromise,
|
|
124
|
+
progress: Object.freeze({ ...progress })
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
destroy() {}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { BaseUploadHandler };
|
|
132
|
+
//# sourceMappingURL=base-upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-upload.js","names":["#setupUppyHandlers","#addFileToUppy","#startUpload","#createUploadOperation","#extractErrorMessage","#normalizeData","#normalizeDataForNode","#normalizeDataForBrowser"],"sources":["../../../src/upload/base-upload.ts"],"sourcesContent":["import Uppy from \"@uppy/core\";\nimport { default as defer } from \"p-defer\";\nimport type { Readable } from \"stream\";\n\nimport type { PinnerConfig } from \"../config\";\nimport type {\n UploadInput,\n UploadOperation,\n UploadOptions,\n UploadProgress,\n UploadResult,\n} from \"@/types/upload\";\nimport { normalizeUploadInput, type UploadInputObject } from \"./normalize\";\nimport {\n fileToReadableStream,\n readableStreamToNodeStream,\n} from \"@/utils/stream\";\nimport { isNodeEnvironment } from \"@/utils/env\";\nimport { UPLOAD_SOURCE_TUS, UPLOAD_SOURCE_XHR } from \"./constants\";\n\n// Node.js Readable stream with size property for Uppy compatibility\ntype NodeStreamWithSize = Readable & { size: number | null };\n\nexport abstract class BaseUploadHandler {\n protected config: Required<PinnerConfig>;\n\n constructor(config: PinnerConfig) {\n this.config = config as Required<PinnerConfig>;\n }\n\n async upload(\n input: UploadInput | UploadInputObject,\n options?: UploadOptions,\n ): Promise<UploadOperation> {\n const normalized = normalizeUploadInput(input, options);\n const uppy = new Uppy();\n const { fileId, resultPromise, progress } = this.#setupUppyHandlers(\n uppy,\n normalized,\n options,\n );\n\n await this.#addFileToUppy(uppy, normalized, normalized.size);\n this.#startUpload(uppy, options);\n\n return this.#createUploadOperation(uppy, fileId, resultPromise, progress);\n }\n\n #setupUppyHandlers(\n uppy: Uppy,\n normalized: { size: number },\n options?: UploadOptions,\n ): {\n fileId: string | null;\n resultPromise: Promise<UploadResult>;\n progress: UploadProgress;\n } {\n let fileId: string | null = null;\n let hasRejected = false;\n\n const progress: UploadProgress = {\n percentage: 0,\n bytesUploaded: 0,\n bytesTotal: normalized.size,\n };\n\n const {\n promise: resultPromise,\n resolve: resolveResult,\n reject: rejectResult,\n } = defer<UploadResult>();\n\n const handleError = (error: Error) => {\n if (hasRejected) return;\n hasRejected = true;\n options?.onError?.(error);\n rejectResult(error);\n };\n\n this.configurePlugin(uppy);\n\n uppy.on(\"progress\", (progressBytes) => {\n progress.bytesUploaded = progressBytes;\n progress.percentage = (progressBytes / progress.bytesTotal) * 100;\n options?.onProgress?.(progress);\n });\n\n uppy.on(\"upload-success\", (_file, result) => {\n if (hasRejected) return;\n const uploadResult = this.parseResult(result);\n options?.onComplete?.(uploadResult);\n resolveResult(uploadResult);\n });\n\n uppy.on(\"error\", (error) => {\n handleError(new Error(this.#extractErrorMessage(error)));\n });\n\n uppy.on(\"file-added\", (file) => {\n fileId = file.id;\n });\n\n return { fileId, resultPromise, progress };\n }\n\n #extractErrorMessage(error: unknown): string {\n let errorMessage = \"Upload fainormalizeDataled\";\n\n if (!error) return errorMessage;\n\n if (typeof error === \"string\") {\n errorMessage = error;\n } else if (error instanceof Error) {\n errorMessage = error.message;\n } else if ((error as any).message) {\n errorMessage = (error as any).message;\n } else if (\n (error as any).toString &&\n typeof (error as any).toString === \"function\"\n ) {\n errorMessage = (error as any).toString();\n }\n\n // Try to extract error from response (XHRUpload/TusPlugin)\n const errorObj = error as any;\n if (errorObj?.xhr?.response) {\n try {\n const response =\n typeof errorObj.xhr.response === \"string\"\n ? JSON.parse(errorObj.xhr.response)\n : errorObj.xhr.response;\n if (response.error) {\n errorMessage = response.error;\n } else if (response.message) {\n errorMessage = response.message;\n }\n } catch {\n // If parsing fails, use the original error message\n }\n }\n\n return errorMessage;\n }\n\n async #normalizeData(\n data: File | ReadableStream<Uint8Array>,\n ): Promise<File | ReadableStream<Uint8Array> | NodeStreamWithSize | Blob> {\n if (isNodeEnvironment()) {\n return this.#normalizeDataForNode(data);\n }\n return this.#normalizeDataForBrowser(data);\n }\n\n async #normalizeDataForBrowser(\n data: File | ReadableStream<Uint8Array>,\n ): Promise<File | Blob | ReadableStream<Uint8Array>> {\n // TUS plugin requires File, Blob, or Reader in browser\n if (this.getUploadSource() === UPLOAD_SOURCE_TUS) {\n if (data instanceof ReadableStream) {\n const { streamToBlobViaResponse } = await import(\"@/utils/stream\");\n return streamToBlobViaResponse(data);\n }\n return data;\n }\n\n // XHRUpload handles File/Blob directly\n return data;\n }\n\n async #normalizeDataForNode(\n data: File | ReadableStream<Uint8Array>,\n ): Promise<NodeStreamWithSize | File | Blob | ReadableStream<Uint8Array>> {\n // XHRUpload with formData: true requires Blob/File for FormData.append()\n // Do not convert to Node.js stream for XHRUpload\n if (this.getUploadSource() === UPLOAD_SOURCE_XHR) {\n return data;\n }\n\n // Convert File to ReadableStream without loading entire blob into memory\n if (data instanceof File) {\n const stream = fileToReadableStream(data);\n // Convert to Node.js stream for tus-js-client\n const nodeStream = await readableStreamToNodeStream(stream);\n return nodeStream as NodeStreamWithSize;\n }\n\n // In Node.js, convert ReadableStream to Node.js stream.Readable for tus-js-client's NodeFileReader\n if (data instanceof ReadableStream) {\n const nodeStream = await readableStreamToNodeStream(data);\n // Add size property to satisfy Uppy's type requirements\n return nodeStream as NodeStreamWithSize;\n }\n\n return data;\n }\n\n async #addFileToUppy(\n uppy: Uppy,\n normalized: {\n data: File | ReadableStream<Uint8Array>;\n name: string;\n type: string;\n },\n size?: number,\n ): Promise<void> {\n const fileData = await this.#normalizeData(normalized.data);\n const fileOptions = {\n source: this.getUploadSource(),\n name: normalized.name,\n type: normalized.type,\n data: fileData as any,\n };\n\n // Add file to Uppy first\n // Note: Uppy accepts any data type as it defers to the drivers\n const fileId = uppy.addFile(fileOptions);\n\n // Set TUS upload size if provided\n // In Node.js, streams need explicit size for tus-js-client\n // In browser, Uppy's TUS plugin may not derive size from Blob automatically\n if (\n this.getUploadSource() === UPLOAD_SOURCE_TUS &&\n size !== undefined &&\n size > 0\n ) {\n uppy.setFileState(fileId, {\n tus: { uploadSize: size },\n });\n }\n }\n\n #startUpload(uppy: Uppy, options?: UploadOptions): void {\n uppy.upload().catch((error) => {\n options?.onError?.(new Error(this.#extractErrorMessage(error)));\n });\n }\n\n #createUploadOperation(\n uppy: Uppy,\n fileId: string | null,\n resultPromise: Promise<UploadResult>,\n progress: UploadProgress,\n ): UploadOperation {\n return {\n cancel: () => {\n uppy.cancelAll();\n },\n pause: () => {\n if (fileId) {\n uppy.pauseResume(fileId);\n }\n },\n resume: () => {\n if (fileId) {\n uppy.pauseResume(fileId);\n }\n },\n result: resultPromise,\n progress: Object.freeze({ ...progress }),\n };\n }\n\n destroy(): void {\n // No-op since each upload creates its own Uppy instance\n }\n\n protected abstract configurePlugin(uppy: Uppy): void;\n protected abstract parseResult(result: unknown): UploadResult;\n protected abstract getUploadSource(): string;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PinnerUploadBuilder, UploadOperation, UploadOptions } from "../types/upload.js";
|
|
2
|
+
import { Pinner } from "../pinner.js";
|
|
3
|
+
|
|
4
|
+
//#region src/upload/builder.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Pinner upload builder namespace.
|
|
8
|
+
* Provides fluent API for file, JSON, Base64, and URL uploads.
|
|
9
|
+
*/
|
|
10
|
+
declare class UploadBuilderNamespace {
|
|
11
|
+
private pinner;
|
|
12
|
+
constructor(pinner: Pinner);
|
|
13
|
+
/**
|
|
14
|
+
* Upload a file.
|
|
15
|
+
* Returns a builder for chaining name/keyvalues.
|
|
16
|
+
*/
|
|
17
|
+
file(file: File): PinnerUploadBuilder;
|
|
18
|
+
/**
|
|
19
|
+
* Upload JSON data (encoded as JSON file).
|
|
20
|
+
* Returns a builder for chaining name/keyvalues.
|
|
21
|
+
*/
|
|
22
|
+
json(data: object): PinnerUploadBuilder;
|
|
23
|
+
/**
|
|
24
|
+
* Upload Base64 encoded content (decoded and uploaded as file).
|
|
25
|
+
* Returns a builder for chaining name/keyvalues.
|
|
26
|
+
*/
|
|
27
|
+
base64(base64String: string): PinnerUploadBuilder;
|
|
28
|
+
/**
|
|
29
|
+
* Upload content from a URL (fetched and uploaded as file).
|
|
30
|
+
* Returns a builder for chaining name/keyvalues.
|
|
31
|
+
*/
|
|
32
|
+
url(urlString: string): PinnerUploadBuilder;
|
|
33
|
+
/**
|
|
34
|
+
* Upload CSV data (string, array of objects, or array of arrays).
|
|
35
|
+
* Returns a builder for chaining name/keyvalues.
|
|
36
|
+
*/
|
|
37
|
+
csv(data: string | object[] | any[][]): PinnerUploadBuilder;
|
|
38
|
+
/**
|
|
39
|
+
* Upload raw CAR data without preprocessing.
|
|
40
|
+
* Useful for passthrough of pre-generated CAR files.
|
|
41
|
+
* Returns a builder for chaining name/keyvalues.
|
|
42
|
+
*/
|
|
43
|
+
raw(carInput: File | ReadableStream<Uint8Array>): PinnerUploadBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Upload text content (encoded as text file).
|
|
46
|
+
* Returns a builder for chaining name/keyvalues.
|
|
47
|
+
*/
|
|
48
|
+
text(textData: string): PinnerUploadBuilder;
|
|
49
|
+
/**
|
|
50
|
+
* Alias for text() - upload text content.
|
|
51
|
+
*/
|
|
52
|
+
get content(): (textData: string) => PinnerUploadBuilder;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Combined interface for upload that works as both a method and a builder namespace.
|
|
56
|
+
*/
|
|
57
|
+
type UploadMethodAndBuilder = ((file: File, options?: UploadOptions) => Promise<UploadOperation>) & UploadBuilderNamespace;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { UploadMethodAndBuilder };
|
|
60
|
+
//# sourceMappingURL=builder.d.ts.map
|