├── .editorconfig ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .node-version ├── .prettierignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bsconfig.json ├── package-lock.json ├── package.json └── src ├── ReactNativeAsyncStorage.bs.js └── ReactNativeAsyncStorage.res /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | root = true 3 | 4 | [*] 5 | end_of_line = lf 6 | insert_final_newline = true 7 | charset = utf-8 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | tests: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: actions/setup-node@v2 11 | with: 12 | node-version-file: ".node-version" 13 | 14 | - uses: actions/cache@v2 15 | with: 16 | path: ~/.npm 17 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 18 | restore-keys: | 19 | ${{ runner.os }}-node- 20 | 21 | - run: npm install -g npm && npm --version 22 | 23 | - run: npm ci 24 | 25 | - run: npm test 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | 3 | # macOS crap 4 | .DS_Store 5 | 6 | # node 7 | node_modules 8 | 9 | # ReScript artifacts 10 | # *.bs.js # we do want this files to ensure zero-cost 11 | .bsb.lock 12 | **/lib/bs 13 | **/lib/ocaml 14 | **/.merlin 15 | -------------------------------------------------------------------------------- /.node-version: -------------------------------------------------------------------------------- 1 | 16 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.bs.js 2 | package.json 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog of `@rescript-react-native/async-storage` 2 | 3 | ## 1.6.3 - 2021-05-03 4 | 5 | ReScript 6 | 7 | ## 1.6.2 - 2021-20-19 8 | 9 | Add `useAsyncStorage_` for record syntax & deprecated `useAsyncStorage` 10 | 11 | ## 1.6.1 - 2020-11-17 12 | 13 | - Fix npm description 14 | 15 | ## 1.6.0 - 2019-11-20 16 | 17 | Initial release. 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 @rescript-react-native contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `@rescript-react-native/async-storage` 2 | 3 | [![Build Status](https://github.com/rescript-react-native/async-storage/workflows/Build/badge.svg)](https://github.com/rescript-react-native/async-storage/actions) 4 | [![Version](https://img.shields.io/npm/v/@rescript-react-native/async-storage.svg)](https://www.npmjs.com/@rescript-react-native/async-storage) 5 | [![ReScript Forum](https://img.shields.io/discourse/posts?color=e6484f&label=ReScript%20Forum&server=https%3A%2F%2Fforum.rescript-lang.org)](https://forum.rescript-lang.org/) 6 | 7 | [ReScript](https://rescript-lang.org) bindings for 8 | [`@react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage). 9 | 10 | Exposed as `ReactNativeAsyncStorage` module. 11 | 12 | `@rescript-react-native/async-storage` X.y.\* means it's compatible with 13 | `@react-native-async-storage/async-storage` X.y.\* 14 | 15 | ## Installation 16 | 17 | When 18 | [`@react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage) 19 | is properly installed & configured by following their installation instructions, 20 | you can install the bindings: 21 | 22 | ```console 23 | npm install @rescript-react-native/async-storage 24 | # or 25 | yarn add @rescript-react-native/async-storage 26 | ``` 27 | 28 | `@rescript-react-native/async-storage` should be added to `bs-dependencies` in 29 | your `bsconfig.json`: 30 | 31 | ```diff 32 | { 33 | //... 34 | "bs-dependencies": [ 35 | "@rescript/react", 36 | "rescript-react-native", 37 | // ... 38 | + "@rescript-react-native/async-storage" 39 | ], 40 | //... 41 | } 42 | ``` 43 | 44 | ## Usage 45 | 46 | ### Types 47 | 48 | #### `ReactNativeAsyncStorage.asyncStorageState` 49 | 50 | ```rescript 51 | type asyncStorageState = { 52 | getItem: unit => Js.Promise.t(Js.Null.t(string)), 53 | setItem: string => Js.Promise.t(unit), 54 | mergeItem: string => Js.Promise.t(unit), 55 | removeItem: unit => Js.Promise.t(unit), 56 | }; 57 | 58 | 59 | let ReactNativeAsyncStorage.{getItem, setItem} = 60 | ReactNativeAsyncStorage.useAsyncStorage("useAsyncStorage"); 61 | ``` 62 | 63 | ### Methods 64 | 65 | #### `ReactNativeAsyncStorage.getItem` 66 | 67 | ```rescript 68 | string => Js.Promise.t(Js.Null.t(string)) 69 | ``` 70 | 71 | #### `ReactNativeAsyncStorage.setItem` 72 | 73 | ```rescript 74 | (string, string) => Js.Promise.t(unit) 75 | ``` 76 | 77 | #### `ReactNativeAsyncStorage.removeItem` 78 | 79 | ```rescript 80 | string => Js.Promise.t(unit) 81 | ``` 82 | 83 | #### `ReactNativeAsyncStorage.mergeItem` 84 | 85 | ```rescript 86 | (string, string) => Js.Promise.t(unit) 87 | ``` 88 | 89 | #### `ReactNativeAsyncStorage.clear` 90 | 91 | ```rescript 92 | unit => Js.Promise.t(unit) 93 | ``` 94 | 95 | #### `ReactNativeAsyncStorage.getAllKeys` 96 | 97 | ```rescript 98 | unit => Js.Promise.t(Js.Null.t(array(string))) 99 | ``` 100 | 101 | #### `ReactNativeAsyncStorage.multiGet` 102 | 103 | ```rescript 104 | array(string) => Js.Promise.t(array((string, Js.Null.t(string)))) 105 | ``` 106 | 107 | #### `ReactNativeAsyncStorage.multiSet` 108 | 109 | ```rescript 110 | array((string, string)) => Js.Promise.t(unit) 111 | ``` 112 | 113 | #### `ReactNativeAsyncStorage.multiMerge` 114 | 115 | ```rescript 116 | array((string, string)) => Js.Promise.t(unit) 117 | ``` 118 | 119 | #### `ReactNativeAsyncStorage.multiRemove` 120 | 121 | ```rescript 122 | array(string) => Js.Promise.t(unit) 123 | ``` 124 | 125 | #### `ReactNativeAsyncStorage.flushGetRequests` 126 | 127 | ```rescript 128 | unit => unit 129 | ``` 130 | 131 | #### `ReactNativeAsyncStorage.useAsyncStorage` 132 | 133 | ```rescript 134 | string => asyncStorageState 135 | ``` 136 | 137 | --- 138 | 139 | ## Changelog 140 | 141 | Check the [changelog](./CHANGELOG.md) for more informations about recent 142 | releases. 143 | 144 | --- 145 | 146 | ## Contribute 147 | 148 | Read the 149 | [contribution guidelines](https://github.com/rescript-react-native/.github/blob/master/CONTRIBUTING.md) 150 | before contributing. 151 | 152 | ## Code of Conduct 153 | 154 | We want this community to be friendly and respectful to each other. Please read 155 | [our full code of conduct](https://github.com/rescript-react-native/.github/blob/master/CODE_OF_CONDUCT.md) 156 | so that you can understand what actions will and will not be tolerated. 157 | -------------------------------------------------------------------------------- /bsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@rescript-react-native/async-storage", 3 | "reason": { "react-jsx": 3 }, 4 | "package-specs": { 5 | "module": "commonjs", 6 | "in-source": true 7 | }, 8 | "suffix": ".bs.js", 9 | "sources": [ 10 | { 11 | "dir": "src", 12 | "subdirs": false 13 | } 14 | ], 15 | "bsc-flags": ["-bs-no-version-header"], 16 | "warnings": { 17 | "error": true 18 | }, 19 | "bs-dependencies": [] 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@rescript-react-native/async-storage", 3 | "description": "ReScript bindings for @react-native-async-storage/async-storage.", 4 | "version": "1.6.3", 5 | "publishConfig": { 6 | "access": "public" 7 | }, 8 | "peerDependencies": { 9 | "@react-native-community/async-storage": ">=1.6.0" 10 | }, 11 | "overrides": { 12 | "react": "17.0.2" 13 | }, 14 | "repository": "https://github.com/rescript-react-native/async-storage.git", 15 | "funding": "https://github.com/rescript-react-native/rescript-react-native?sponsor=1", 16 | "license": "MIT", 17 | "keywords": [ 18 | "rescript", 19 | "react-native" 20 | ], 21 | "files": [ 22 | "*.md", 23 | "bsconfig.json", 24 | "src/**/*.res", 25 | "src/**/*.resi", 26 | "src/**/*.js", 27 | "!src/**/*.bs.js" 28 | ], 29 | "scripts": { 30 | "format:most": "prettier --write \"**/*.{md,json,js,css}\"", 31 | "format:res": "rescript format -all", 32 | "format": "npm run format:most && npm run format:res", 33 | "re:start": "rescript build -w", 34 | "re:build": "rescript", 35 | "re:clean-build": "rescript clean && rescript", 36 | "start": "npm run re:start", 37 | "build": "npm run re:build", 38 | "test": "npm run re:clean-build", 39 | "release": "npmpub" 40 | }, 41 | "devDependencies": { 42 | "rescript": "^10.0.0", 43 | "husky": "^4.0.0", 44 | "lint-staged": "^10.0.0", 45 | "npmpub": "^5.0.0", 46 | "prettier": "^2.0.0" 47 | }, 48 | "prettier": { 49 | "trailingComma": "all" 50 | }, 51 | "lint-staged": { 52 | "*.{md,json,js,css}": "prettier --write", 53 | "*.{res,resi}": "rescript format" 54 | }, 55 | "husky": { 56 | "hooks": { 57 | "pre-commit": "lint-staged" 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/ReactNativeAsyncStorage.bs.js: -------------------------------------------------------------------------------- 1 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 2 | -------------------------------------------------------------------------------- /src/ReactNativeAsyncStorage.res: -------------------------------------------------------------------------------- 1 | @scope("default") @module("@react-native-async-storage/async-storage") 2 | external getItem: string => Js.Promise.t> = "getItem" 3 | 4 | @scope("default") @module("@react-native-async-storage/async-storage") 5 | external setItem: (string, string) => Js.Promise.t = "setItem" 6 | 7 | @scope("default") @module("@react-native-async-storage/async-storage") 8 | external removeItem: string => Js.Promise.t = "removeItem" 9 | 10 | @scope("default") @module("@react-native-async-storage/async-storage") 11 | external mergeItem: (string, string) => Js.Promise.t = "mergeItem" 12 | 13 | @scope("default") @module("@react-native-async-storage/async-storage") 14 | external clear: unit => Js.Promise.t = "clear" 15 | 16 | @scope("default") @module("@react-native-async-storage/async-storage") 17 | external getAllKeys: unit => Js.Promise.t>> = "getAllKeys" 18 | 19 | @scope("default") @module("@react-native-async-storage/async-storage") 20 | external multiGet: array => Js.Promise.t)>> = "multiGet" 21 | 22 | @scope("default") @module("@react-native-async-storage/async-storage") 23 | external multiSet: array<(string, string)> => Js.Promise.t = "multiSet" 24 | 25 | @scope("default") @module("@react-native-async-storage/async-storage") 26 | external multiMerge: array<(string, string)> => Js.Promise.t = "multiMerge" 27 | 28 | @scope("default") @module("@react-native-async-storage/async-storage") 29 | external multiRemove: array => Js.Promise.t = "multiRemove" 30 | 31 | @scope("default") @module("@react-native-async-storage/async-storage") 32 | external flushGetRequests: unit => unit = "flushGetRequests" 33 | 34 | type asyncStorageState = { 35 | @meth 36 | "getItem": unit => Js.Promise.t>, 37 | @meth 38 | "setItem": string => Js.Promise.t, 39 | @meth 40 | "mergeItem": string => Js.Promise.t, 41 | @meth 42 | "removeItem": unit => Js.Promise.t, 43 | } 44 | 45 | @deprecated( 46 | "Please use `useAsyncStorage_` instead of `useAsyncStorage` to use record syntax. In next major release, `useAsyncStorage_` will become `useAsyncStorage`." 47 | ) 48 | @module("@react-native-async-storage/async-storage") 49 | external useAsyncStorage: string => asyncStorageState = "useAsyncStorage" 50 | type asyncStorageStateAlt = { 51 | getItem: unit => Js.Promise.t>, 52 | setItem: string => Js.Promise.t, 53 | mergeItem: string => Js.Promise.t, 54 | removeItem: unit => Js.Promise.t, 55 | } 56 | 57 | @module("@react-native-async-storage/async-storage") 58 | external useAsyncStorage_: string => asyncStorageState = "useAsyncStorage" 59 | --------------------------------------------------------------------------------