@hostr/upload 0.1.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.
@@ -0,0 +1,2 @@
1
+ import type { Hasher } from '../core/types.js';
2
+ export declare const nodeHasher: Hasher;
@@ -0,0 +1,43 @@
1
+ import type { FileSource, HttpTransport, StateStore } from '../core/types.js';
2
+ import { type Upload } from '../core/upload.js';
3
+ export { createUploadSession, mintUploadToken } from '../api/client.js';
4
+ export { NetworkError, ApiError } from '../api/client.js';
5
+ export { IntegrityError } from '../core/engine.js';
6
+ export { nodeHasher } from './hasher.js';
7
+ export type { Upload } from '../core/upload.js';
8
+ /** Opens `path` and holds the `FileHandle` open for the adapter's lifetime;
9
+ * callers must `close()` it when done (createUpload does this implicitly
10
+ * never — it hands the FileSource to the engine, which only ever reads).
11
+ * Identity is `path:size:mtimeMs-floored` so a relaunch against the same
12
+ * file resolves to the same session, and a modified file (different size
13
+ * or mtime) correctly starts a fresh one. */
14
+ export declare function nodeFileSource(path: string): Promise<FileSource>;
15
+ /** One file per key under `dir`, created on first write. Keys are sanitized
16
+ * to filesystem-safe names — collisions between distinct keys that
17
+ * sanitize identically are possible but not a concern in practice (session
18
+ * keys are namespaced storage keys, not arbitrary user input). */
19
+ export declare function fileStateStore(dir: string): StateStore;
20
+ /** Default transport: a plain `fetch` PUT. Node's `fetch` exposes no
21
+ * upload-progress events, so `onProgress` is documented (not simulated) to
22
+ * fire exactly once, with the full body length, after the PUT resolves —
23
+ * callers wanting finer-grained progress must supply their own `transport`. */
24
+ export declare function nodeTransport(fetchFn?: typeof fetch): HttpTransport;
25
+ export type CreateUploadOptions = {
26
+ endpoint: string;
27
+ uploadToken: string;
28
+ assetId: string;
29
+ /** Filesystem path to the file to upload. */
30
+ file: string;
31
+ /** Directory for the persisted session; defaults to `${os.tmpdir()}/hostr-upload`. */
32
+ stateDir?: string;
33
+ concurrency?: number;
34
+ checksum?: 'sha256' | 'none';
35
+ onTokenExpired?: (assetId: string) => Promise<string>;
36
+ /** Advanced: override the fetch implementation used for API calls and the
37
+ * default transport's PUTs. Mainly for tests. */
38
+ fetchFn?: typeof fetch;
39
+ /** Advanced: override the PUT transport entirely (e.g. to inject failures
40
+ * or corruption in tests) instead of the default `fetch`-based one. */
41
+ transport?: HttpTransport;
42
+ };
43
+ export declare function createUpload(opts: CreateUploadOptions): Promise<Upload>;