@drakkar.software/sunglasses-storage-async-storage 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.
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +59 -0
- package/dist/index.mjs +22 -0
- package/package.json +38 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IStorageAdapter } from '@drakkar.software/sunglasses-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* IStorageAdapter implementation using React Native AsyncStorage.
|
|
5
|
+
*
|
|
6
|
+
* Keys are namespaced with a configurable prefix (default: 'sg_') to avoid
|
|
7
|
+
* collisions with other libraries or application data.
|
|
8
|
+
*
|
|
9
|
+
* Peer dependency: @react-native-async-storage/async-storage
|
|
10
|
+
*/
|
|
11
|
+
declare class AsyncStorageAdapter implements IStorageAdapter {
|
|
12
|
+
private readonly prefix;
|
|
13
|
+
constructor(prefix?: string);
|
|
14
|
+
read(key: string): Promise<string | null>;
|
|
15
|
+
write(key: string, value: string): Promise<void>;
|
|
16
|
+
delete(key: string): Promise<void>;
|
|
17
|
+
private prefixed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { AsyncStorageAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IStorageAdapter } from '@drakkar.software/sunglasses-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* IStorageAdapter implementation using React Native AsyncStorage.
|
|
5
|
+
*
|
|
6
|
+
* Keys are namespaced with a configurable prefix (default: 'sg_') to avoid
|
|
7
|
+
* collisions with other libraries or application data.
|
|
8
|
+
*
|
|
9
|
+
* Peer dependency: @react-native-async-storage/async-storage
|
|
10
|
+
*/
|
|
11
|
+
declare class AsyncStorageAdapter implements IStorageAdapter {
|
|
12
|
+
private readonly prefix;
|
|
13
|
+
constructor(prefix?: string);
|
|
14
|
+
read(key: string): Promise<string | null>;
|
|
15
|
+
write(key: string, value: string): Promise<void>;
|
|
16
|
+
delete(key: string): Promise<void>;
|
|
17
|
+
private prefixed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { AsyncStorageAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AsyncStorageAdapter: () => AsyncStorageAdapter
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/AsyncStorageAdapter.ts
|
|
38
|
+
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
|
|
39
|
+
var AsyncStorageAdapter = class {
|
|
40
|
+
constructor(prefix = "sg_") {
|
|
41
|
+
this.prefix = prefix;
|
|
42
|
+
}
|
|
43
|
+
async read(key) {
|
|
44
|
+
return import_async_storage.default.getItem(this.prefixed(key));
|
|
45
|
+
}
|
|
46
|
+
async write(key, value) {
|
|
47
|
+
await import_async_storage.default.setItem(this.prefixed(key), value);
|
|
48
|
+
}
|
|
49
|
+
async delete(key) {
|
|
50
|
+
await import_async_storage.default.removeItem(this.prefixed(key));
|
|
51
|
+
}
|
|
52
|
+
prefixed(key) {
|
|
53
|
+
return `${this.prefix}${key}`;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
AsyncStorageAdapter
|
|
59
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/AsyncStorageAdapter.ts
|
|
2
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
3
|
+
var AsyncStorageAdapter = class {
|
|
4
|
+
constructor(prefix = "sg_") {
|
|
5
|
+
this.prefix = prefix;
|
|
6
|
+
}
|
|
7
|
+
async read(key) {
|
|
8
|
+
return AsyncStorage.getItem(this.prefixed(key));
|
|
9
|
+
}
|
|
10
|
+
async write(key, value) {
|
|
11
|
+
await AsyncStorage.setItem(this.prefixed(key), value);
|
|
12
|
+
}
|
|
13
|
+
async delete(key) {
|
|
14
|
+
await AsyncStorage.removeItem(this.prefixed(key));
|
|
15
|
+
}
|
|
16
|
+
prefixed(key) {
|
|
17
|
+
return `${this.prefix}${key}`;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
AsyncStorageAdapter
|
|
22
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@drakkar.software/sunglasses-storage-async-storage",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AsyncStorage adapter for SunGlasses (React Native / Expo)",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@drakkar.software/sunglasses-core": "0.2.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@react-native-async-storage/async-storage": ">=1.x"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "^8.3.5",
|
|
26
|
+
"typescript": "^5.7.2",
|
|
27
|
+
"vitest": "^2.1.8",
|
|
28
|
+
"@drakkar.software/sunglasses-tsconfig": "0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
32
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"lint": "eslint src/",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"clean": "rm -rf dist .tsbuildinfo"
|
|
37
|
+
}
|
|
38
|
+
}
|