|
| 1 | +type t |
| 2 | +@module("rn-fetch-blob") external fetchBlob: t = "default" |
| 3 | + |
| 4 | +module Config = { |
| 5 | + @deriving({abstract: light}) |
| 6 | + type t = { |
| 7 | + @optional |
| 8 | + fileCache: bool, |
| 9 | + @optional |
| 10 | + appendExt: string, |
| 11 | + @optional |
| 12 | + path: string, |
| 13 | + @optional |
| 14 | + key: string, |
| 15 | + @optional |
| 16 | + timeout: int, |
| 17 | + @optional |
| 18 | + wifiOnly: bool, |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +module ResponseInfo = { |
| 23 | + type t |
| 24 | + @get external headers: t => Js.Dict.t<string> = "headers" |
| 25 | + @get external status: t => int = "status" |
| 26 | +} |
| 27 | + |
| 28 | +module Response = { |
| 29 | + type t |
| 30 | + @send external info: t => ResponseInfo.t = "info" |
| 31 | + @send external text: t => string = "text" |
| 32 | + @send external json: t => Js.Json.t = "json" |
| 33 | + |
| 34 | + /* For file downloads */ |
| 35 | + @send external path: t => string = "path" |
| 36 | +} |
| 37 | + |
| 38 | +module Fetch = { |
| 39 | + type t |
| 40 | + @send |
| 41 | + external fetch: ( |
| 42 | + t, |
| 43 | + ~method: string, |
| 44 | + ~url: string, |
| 45 | + ~headers: {.}, |
| 46 | + ~body: 'a, |
| 47 | + ) => Js.Promise.t<Response.t> = "fetch" |
| 48 | +} |
| 49 | + |
| 50 | +module Fs = { |
| 51 | + module Stat = { |
| 52 | + @deriving({abstract: light}) |
| 53 | + type t = { |
| 54 | + filename: string, |
| 55 | + path: string, |
| 56 | + size: int, |
| 57 | + @as("type") |
| 58 | + type_: string, |
| 59 | + lastModified: float, |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + type dirs |
| 64 | + |
| 65 | + @get external documentDir: dirs => string = "DocumentDir" |
| 66 | + @get external cacheDir: dirs => string = "CacheDir" |
| 67 | + |
| 68 | + /* Can be used to access files embedded on iOS apps only */ |
| 69 | + @get external mainBundleDir: dirs => string = "MainBundleDir" |
| 70 | + |
| 71 | + /* Android Only */ |
| 72 | + @get external dcimDir: dirs => string = "DCIMDir" |
| 73 | + @get external downloadDir: dirs => string = "DownloadDir" |
| 74 | + @get external musicDir: dirs => string = "MusicDir" |
| 75 | + @get external pictureDir: dirs => string = "PictureDir" |
| 76 | + @get external movieDir: dirs => string = "MovieDir" |
| 77 | + @get external ringtoneDir: dirs => string = "RingtoneDir" |
| 78 | + @get external sdCardDir: dirs => string = "SDCardDir" |
| 79 | + |
| 80 | + type t |
| 81 | + |
| 82 | + @get external dirs: t => dirs = "dirs" |
| 83 | + @send |
| 84 | + external cp: (t, ~from: string, ~to_: string) => Js.Promise.t<unit> = "from" |
| 85 | + @send |
| 86 | + external unlink: (t, ~path: string) => Js.Promise.t<unit> = "unlink" |
| 87 | + @send |
| 88 | + external mkdir: (t, ~path: string) => Js.Promise.t<unit> = "mkdir" |
| 89 | + @send |
| 90 | + external exists: (t, ~path: string) => Js.Promise.t<bool> = "exists" |
| 91 | + @send |
| 92 | + external lstat: (t, ~path: string) => Js.Promise.t<array<Stat.t>> = "path" |
| 93 | + @send |
| 94 | + external stat: (t, ~path: string) => Js.Promise.t<Stat.t> = "stat" |
| 95 | + @send |
| 96 | + external readFile: (t, ~path: string, ~encoding: string) => Js.Promise.t<string> = "readFile" |
| 97 | + @send external asset: (t, ~path: string) => string = "asset" |
| 98 | +} |
| 99 | + |
| 100 | +@send external config: (t, Config.t) => Fetch.t = "config" |
| 101 | +@get external fs: t => Fs.t = "fs" |
| 102 | + |
| 103 | +type data |
| 104 | + |
| 105 | +@send external wrap: (t, ~path: string) => data = "wrap" |
0 commit comments