@instantdb/react-native-mmkv 0.0.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.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ <p align="center">
2
+ <a href="https://instantdb.com">
3
+ <img alt="Shows the Instant logo" src="https://instantdb.com/img/icon/android-chrome-512x512.png" width="10%">
4
+ </a>
5
+ <h1 align="center">@instantdb/react-native-mmkv</h1>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a
10
+ href="https://discord.com/invite/VU53p7uQcE" >
11
+ <img height=20 src="https://img.shields.io/discord/1031957483243188235" />
12
+ </a>
13
+ <img src="https://img.shields.io/github/stars/instantdb/instant" alt="stars">
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="https://www.instantdb.com/docs/start-rn">Get Started</a> ·
18
+ <a href="https://instantdb.com/examples">Examples</a> ·
19
+ <a href="https://www.instantdb.com/docs/start-rn">Docs</a> ·
20
+ <a href="https://discord.com/invite/VU53p7uQcE">Discord</a>
21
+ <p>
22
+
23
+ Welcome to [Instant's](http://instantdb.com) React Native MMKV interface.
24
+
25
+ ```javascript
26
+ // ༼ つ ◕_◕ ༽つ Real-time Chat
27
+ // ----------------------------------
28
+ // * Updates instantly
29
+ // * Multiplayer
30
+ // * Works offline
31
+
32
+ import { init, id } from '@instantdb/react-native';
33
+ improt Storage from '@instantdb/react-native-mmkv';
34
+
35
+ const db = init({
36
+ appId: process.env.NEXT_PUBLIC_APP_ID,
37
+ Storage: Storage
38
+ });
39
+
40
+ function Chat() {
41
+ // 1. Read
42
+ const { isLoading, error, data } = db.useQuery({
43
+ messages: {},
44
+ });
45
+
46
+ // 2. Write
47
+ const addMessage = (message) => {
48
+ db.transact(db.tx.messages[id()].update(message));
49
+ };
50
+
51
+ // 3. Render!
52
+ return <UI data={data} onAdd={addMessage} />;
53
+ }
54
+ ```
55
+
56
+ # Get Started
57
+
58
+ Follow the [getting started](https://www.instantdb.com/docs/start-rn) tutorial to set up a live React Native app in under 5 minutes!
59
+
60
+ # Questions?
61
+
62
+ If you have any questions, feel free to drop us a line on our [Discord](https://discord.com/invite/VU53p7uQcE)
@@ -0,0 +1,12 @@
1
+ import { StorageInterface, StorageInterfaceStoreName } from '@instantdb/core';
2
+ import { MMKV } from 'react-native-mmkv';
3
+ export default class Storage extends StorageInterface {
4
+ _store: MMKV;
5
+ constructor(appId: string, storeName: StorageInterfaceStoreName);
6
+ getItem(k: string): Promise<any>;
7
+ setItem(k: string, v: any): Promise<void>;
8
+ multiSet(keyValuePairs: Array<[string, any]>): Promise<void>;
9
+ removeItem(k: string): Promise<void>;
10
+ getAllKeys(): Promise<string[]>;
11
+ }
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAc,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IACnD,MAAM,EAAE,IAAI,CAAC;gBACD,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,yBAAyB;IASzD,OAAO,CAAC,CAAC,EAAE,MAAM;IAQjB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG;IAIzB,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAM5C,UAAU,CAAC,CAAC,EAAE,MAAM;IAIpB,UAAU;CAGjB"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@instantdb/core");
4
+ const react_native_mmkv_1 = require("react-native-mmkv");
5
+ class Storage extends core_1.StorageInterface {
6
+ _store;
7
+ constructor(appId, storeName) {
8
+ super(appId, storeName);
9
+ this._store = (0, react_native_mmkv_1.createMMKV)({
10
+ id: `instant-${appId}-${storeName}`,
11
+ readOnly: false,
12
+ mode: 'multi-process',
13
+ });
14
+ }
15
+ async getItem(k) {
16
+ const item = this._store.getString(k);
17
+ if (item) {
18
+ return JSON.parse(item);
19
+ }
20
+ return null;
21
+ }
22
+ async setItem(k, v) {
23
+ this._store.set(k, JSON.stringify(v));
24
+ }
25
+ async multiSet(keyValuePairs) {
26
+ for (const [k, v] of keyValuePairs) {
27
+ this.setItem(k, v);
28
+ }
29
+ }
30
+ async removeItem(k) {
31
+ this._store.remove(k);
32
+ }
33
+ async getAllKeys() {
34
+ return this._store.getAllKeys();
35
+ }
36
+ }
37
+ exports.default = Storage;
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,0CAA8E;AAC9E,yDAAqD;AAErD,MAAqB,OAAQ,SAAQ,uBAAgB;IACnD,MAAM,CAAO;IACb,YAAY,KAAa,EAAE,SAAoC;QAC7D,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,IAAA,8BAAU,EAAC;YACvB,EAAE,EAAE,WAAW,KAAK,IAAI,SAAS,EAAE;YACnC,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,eAAe;SACtB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACrB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACtC,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS,EAAE,CAAM;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,aAAmC;QAChD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,aAAa,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,CAAS;QACxB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;CACF;AApCD,0BAoCC","sourcesContent":["import { StorageInterface, StorageInterfaceStoreName } from '@instantdb/core';\nimport { createMMKV, MMKV } from 'react-native-mmkv';\n\nexport default class Storage extends StorageInterface {\n _store: MMKV;\n constructor(appId: string, storeName: StorageInterfaceStoreName) {\n super(appId, storeName);\n this._store = createMMKV({\n id: `instant-${appId}-${storeName}`,\n readOnly: false,\n mode: 'multi-process',\n });\n }\n\n async getItem(k: string) {\n const item = this._store.getString(k);\n if (item) {\n return JSON.parse(item);\n }\n return null;\n }\n\n async setItem(k: string, v: any) {\n this._store.set(k, JSON.stringify(v));\n }\n\n async multiSet(keyValuePairs: Array<[string, any]>) {\n for (const [k, v] of keyValuePairs) {\n this.setItem(k, v);\n }\n }\n\n async removeItem(k: string) {\n this._store.remove(k);\n }\n\n async getAllKeys() {\n return this._store.getAllKeys();\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { StorageInterface, StorageInterfaceStoreName } from '@instantdb/core';
2
+ import { MMKV } from 'react-native-mmkv';
3
+ export default class Storage extends StorageInterface {
4
+ _store: MMKV;
5
+ constructor(appId: string, storeName: StorageInterfaceStoreName);
6
+ getItem(k: string): Promise<any>;
7
+ setItem(k: string, v: any): Promise<void>;
8
+ multiSet(keyValuePairs: Array<[string, any]>): Promise<void>;
9
+ removeItem(k: string): Promise<void>;
10
+ getAllKeys(): Promise<string[]>;
11
+ }
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAc,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IACnD,MAAM,EAAE,IAAI,CAAC;gBACD,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,yBAAyB;IASzD,OAAO,CAAC,CAAC,EAAE,MAAM;IAQjB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG;IAIzB,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAM5C,UAAU,CAAC,CAAC,EAAE,MAAM;IAIpB,UAAU;CAGjB"}
@@ -0,0 +1,35 @@
1
+ import { StorageInterface } from '@instantdb/core';
2
+ import { createMMKV } from 'react-native-mmkv';
3
+ export default class Storage extends StorageInterface {
4
+ _store;
5
+ constructor(appId, storeName) {
6
+ super(appId, storeName);
7
+ this._store = createMMKV({
8
+ id: `instant-${appId}-${storeName}`,
9
+ readOnly: false,
10
+ mode: 'multi-process',
11
+ });
12
+ }
13
+ async getItem(k) {
14
+ const item = this._store.getString(k);
15
+ if (item) {
16
+ return JSON.parse(item);
17
+ }
18
+ return null;
19
+ }
20
+ async setItem(k, v) {
21
+ this._store.set(k, JSON.stringify(v));
22
+ }
23
+ async multiSet(keyValuePairs) {
24
+ for (const [k, v] of keyValuePairs) {
25
+ this.setItem(k, v);
26
+ }
27
+ }
28
+ async removeItem(k) {
29
+ this._store.remove(k);
30
+ }
31
+ async getAllKeys() {
32
+ return this._store.getAllKeys();
33
+ }
34
+ }
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6B,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAQ,MAAM,mBAAmB,CAAC;AAErD,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IACnD,MAAM,CAAO;IACb,YAAY,KAAa,EAAE,SAAoC;QAC7D,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC;YACvB,EAAE,EAAE,WAAW,KAAK,IAAI,SAAS,EAAE;YACnC,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,eAAe;SACtB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACrB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACtC,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS,EAAE,CAAM;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,aAAmC;QAChD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,aAAa,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,CAAS;QACxB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;CACF","sourcesContent":["import { StorageInterface, StorageInterfaceStoreName } from '@instantdb/core';\nimport { createMMKV, MMKV } from 'react-native-mmkv';\n\nexport default class Storage extends StorageInterface {\n _store: MMKV;\n constructor(appId: string, storeName: StorageInterfaceStoreName) {\n super(appId, storeName);\n this._store = createMMKV({\n id: `instant-${appId}-${storeName}`,\n readOnly: false,\n mode: 'multi-process',\n });\n }\n\n async getItem(k: string) {\n const item = this._store.getString(k);\n if (item) {\n return JSON.parse(item);\n }\n return null;\n }\n\n async setItem(k: string, v: any) {\n this._store.set(k, JSON.stringify(v));\n }\n\n async multiSet(keyValuePairs: Array<[string, any]>) {\n for (const [k, v] of keyValuePairs) {\n this.setItem(k, v);\n }\n }\n\n async removeItem(k: string) {\n this._store.remove(k);\n }\n\n async getAllKeys() {\n return this._store.getAllKeys();\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@instantdb/react-native-mmkv",
3
+ "version": "0.0.0",
4
+ "description": "React Native MMKV interface for Instant DB",
5
+ "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/react-native-mmkv",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/instantdb/instant.git",
9
+ "directory": "client/packages/react-native-mmkv"
10
+ },
11
+ "main": "dist/index.js",
12
+ "module": "dist/module/index.js",
13
+ "types": "dist/module/index.d.ts",
14
+ "unpkg": "dist/index.js",
15
+ "devDependencies": {
16
+ "@babel/core": "^7.17.9",
17
+ "@babel/preset-env": "^7.16.11",
18
+ "@types/node": "^22.6.1",
19
+ "npm-run-all": "^4.1.5",
20
+ "react-native-mmkv": "^4.1.1",
21
+ "typescript": "^5.9.3",
22
+ "vitest": "^0.21.0"
23
+ },
24
+ "peerDependencies": {
25
+ "react-native-mmkv": ">=1.15"
26
+ },
27
+ "dependencies": {
28
+ "@instantdb/core": "0.0.0"
29
+ },
30
+ "scripts": {
31
+ "test": "vitest",
32
+ "test:types": "tsc -p tsconfig.test.json --noEmit",
33
+ "test:ci": "pnpm run test:types",
34
+ "build": "rm -rf dist; npm run build:main && npm run build:module",
35
+ "dev:main": "tsc -p tsconfig.json -w --skipLibCheck --preserveWatchOutput | grep -v '^$'",
36
+ "dev:module": "tsc -p tsconfig.module.json -w --skipLibCheck --preserveWatchOutput | grep -v '^$'",
37
+ "dev": "run-p dev:main dev:module",
38
+ "clean": "rm -rf dist",
39
+ "build:main": "tsc -p tsconfig.json",
40
+ "build:module": "tsc -p tsconfig.module.json",
41
+ "publish-package": "pnpm pack && npm publish *.tgz --access public"
42
+ }
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { StorageInterface, StorageInterfaceStoreName } from '@instantdb/core';
2
+ import { createMMKV, MMKV } from 'react-native-mmkv';
3
+
4
+ export default class Storage extends StorageInterface {
5
+ _store: MMKV;
6
+ constructor(appId: string, storeName: StorageInterfaceStoreName) {
7
+ super(appId, storeName);
8
+ this._store = createMMKV({
9
+ id: `instant-${appId}-${storeName}`,
10
+ readOnly: false,
11
+ mode: 'multi-process',
12
+ });
13
+ }
14
+
15
+ async getItem(k: string) {
16
+ const item = this._store.getString(k);
17
+ if (item) {
18
+ return JSON.parse(item);
19
+ }
20
+ return null;
21
+ }
22
+
23
+ async setItem(k: string, v: any) {
24
+ this._store.set(k, JSON.stringify(v));
25
+ }
26
+
27
+ async multiSet(keyValuePairs: Array<[string, any]>) {
28
+ for (const [k, v] of keyValuePairs) {
29
+ this.setItem(k, v);
30
+ }
31
+ }
32
+
33
+ async removeItem(k: string) {
34
+ this._store.remove(k);
35
+ }
36
+
37
+ async getAllKeys() {
38
+ return this._store.getAllKeys();
39
+ }
40
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "exclude": ["node_modules", "dist", "src/__types__"],
5
+ "compilerOptions": {
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strictNullChecks": true,
9
+ "skipLibCheck": true
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig",
3
+ "compilerOptions": {
4
+ "module": "es2015",
5
+ "moduleResolution": "node",
6
+ "outDir": "dist/module"
7
+ }
8
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["src", "src/__types__"],
4
+ "exclude": ["node_modules", "dist"]
5
+ }