|
| 1 | +import CID from 'cids' |
| 2 | +import { AwaitIterable } from './basic' |
| 3 | +import { Mtime } from 'ipfs-unixfs' |
| 4 | + |
| 5 | +export type Entry<Content extends AsyncIterable<Uint8Array>|Blob> = |
| 6 | + | FileEntry<Content> |
| 7 | + | DirectoryEntry |
| 8 | + |
| 9 | +export interface BaseEntry { |
| 10 | + path: string |
| 11 | + mode?: number |
| 12 | + mtime?: Mtime |
| 13 | +} |
| 14 | +export interface FileEntry <Content extends AsyncIterable<Uint8Array>|Blob> extends BaseEntry { |
| 15 | + content?: Content |
| 16 | +} |
| 17 | + |
| 18 | +export interface DirectoryEntry extends BaseEntry { |
| 19 | + content?: undefined |
| 20 | +} |
| 21 | + |
| 22 | +export type ImportSource = |
| 23 | +| AwaitIterable<ToEntry> |
| 24 | +| ReadableStream<ToEntry> |
| 25 | + |
| 26 | +export type ToEntry = |
| 27 | + | ToFile |
| 28 | + | ToDirectory |
| 29 | + | ToContent |
| 30 | + |
| 31 | +export interface ToFile extends ToFileMetadata { |
| 32 | + path?: string |
| 33 | + content: ToContent |
| 34 | +} |
| 35 | + |
| 36 | +export interface ToDirectory extends ToFileMetadata { |
| 37 | + path: string |
| 38 | + content?: undefined |
| 39 | +} |
| 40 | + |
| 41 | +export interface ToFileMetadata { |
| 42 | + mode?: ToMode |
| 43 | + mtime?: ToMTime |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * File content in arbitrary (supported) representation. It is used in input |
| 48 | + * positions and is usually normalized to `Blob` in browser contexts and |
| 49 | + * `AsyncIterable<Uint8Array>` in node. |
| 50 | + */ |
| 51 | +export type ToContent = |
| 52 | + | string |
| 53 | + | InstanceType<typeof String> |
| 54 | + | ArrayBufferView |
| 55 | + | ArrayBuffer |
| 56 | + | Blob |
| 57 | + | AwaitIterable<Uint8Array> |
| 58 | + | ReadableStream<Uint8Array> |
| 59 | + |
| 60 | +/** |
| 61 | + * Timestamp representation in arbitrary (supported) in representations. It is |
| 62 | + * used in input positions and usually gets normalised to `MTime` before use. |
| 63 | + */ |
| 64 | +export type ToMTime = |
| 65 | + | Date |
| 66 | + | HRTime |
| 67 | + | MTimeLike |
| 68 | + |
| 69 | +export type ToMode = |
| 70 | + | string |
| 71 | + | number |
| 72 | + |
| 73 | +export interface BaseFile { |
| 74 | + cid: CID |
| 75 | + path: string |
| 76 | + name: string |
| 77 | +} |
| 78 | + |
| 79 | +export interface InputFile extends BaseFile { |
| 80 | + unixfs: undefined |
| 81 | +} |
| 82 | + |
| 83 | +export interface MTimeLike { |
| 84 | + /** |
| 85 | + * The number of seconds since (positive) or before (negative) the Unix Epoch |
| 86 | + * began. |
| 87 | + */ |
| 88 | + secs: number |
| 89 | + |
| 90 | + /** |
| 91 | + * The number of nanoseconds since the last full second |
| 92 | + */ |
| 93 | + nsecs?: number |
| 94 | +} |
| 95 | + |
| 96 | +/** |
| 97 | + * Time representation as tuple of two integers, as per the output of |
| 98 | + * [`process.hrtime()`](https://nodejs.org/dist/latest/docs/api/process.html#process_process_hrtime_time). |
| 99 | + */ |
| 100 | +type HRTime = [number, number] |
| 101 | + |
| 102 | +export interface BrowserImportCandidate { |
| 103 | + path?: string, |
| 104 | + content?: Blob, |
| 105 | + mtime?: Mtime, |
| 106 | + mode?: number |
| 107 | +} |
| 108 | + |
1 | 109 | /**
|
2 | 110 | * Represents a value that you can await on, which is either value or a promise
|
3 | 111 | * of one.
|
@@ -30,10 +138,27 @@ export interface AbortOptions {
|
30 | 138 | timeout?: number
|
31 | 139 | }
|
32 | 140 |
|
| 141 | +export interface PreloadOptions { |
| 142 | + preload?: boolean |
| 143 | +} |
| 144 | + |
33 | 145 | export type ToJSON =
|
34 | 146 | | null
|
35 | 147 | | string
|
36 | 148 | | number
|
37 | 149 | | boolean
|
38 | 150 | | ToJSON[]
|
39 | 151 | | { toJSON?: () => ToJSON } & { [key: string]: ToJSON }
|
| 152 | + |
| 153 | +/** |
| 154 | + * An IPFS path or CID |
| 155 | + */ |
| 156 | +export type IPFSPath = CID | string |
| 157 | + |
| 158 | +export interface BufferStore { |
| 159 | + put: (key: Uint8Array, value: Uint8Array) => Promise<void> |
| 160 | + get: (key: Uint8Array) => Promise<Uint8Array> |
| 161 | + stores: any[] |
| 162 | +} |
| 163 | + |
| 164 | +export type HigherOrderFn = (fn: (...args: Parameters<T>) => ReturnType<T>) => (...args: Parameters<T>) => ReturnType<T> |
0 commit comments