@solidnative-dev/storage 0.0.0-stage → 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +61 -2
- package/dist/async-storage-3.d.ts +23 -0
- package/dist/async-storage-3.d.ts.map +1 -0
- package/dist/async-storage-3.js +70 -0
- package/dist/async-storage-3.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Solid 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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@solidnative-dev/storage`
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package exposes a small validated asynchronous string store. Portable
|
|
4
|
+
application and navigation code depend on `KeyValueStorage`; versioned native
|
|
5
|
+
ABI adapters remain explicit subpath imports.
|
|
6
|
+
|
|
7
|
+
The preferred AsyncStorage 3.x boundary accepts an injected, generated native
|
|
8
|
+
binding and never evaluates the dependency's React-facing JavaScript wrapper:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { createAsyncStorage3KeyValueStorage } from "@solidnative-dev/storage/async-storage-3";
|
|
12
|
+
import { requireRNAsyncStorageNativeModule } from "./generated/SolidNativeBindings";
|
|
13
|
+
import * as TurboModuleRegistry from "react-native/Libraries/TurboModule/TurboModuleRegistry";
|
|
14
|
+
|
|
15
|
+
const native = requireRNAsyncStorageNativeModule(TurboModuleRegistry);
|
|
16
|
+
const storage = createAsyncStorage3KeyValueStorage(native, {
|
|
17
|
+
databaseName: "application",
|
|
18
|
+
prefix: "solid-native",
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Only `getValues`, `setValues`, and `removeValues` enter this adapter. Native
|
|
23
|
+
methods are bound to their module, input collections are frozen, and the
|
|
24
|
+
`getValues` result is treated as `unknown` until its key/value shape and
|
|
25
|
+
requested-key identity have been validated. Unknown legacy ABI members never
|
|
26
|
+
reach the portable storage contract. The package has no AsyncStorage or React
|
|
27
|
+
Native JavaScript dependency; the application owns installation, autolinking,
|
|
28
|
+
and generated registry resolution. The adapter validates database names, keys,
|
|
29
|
+
and returned native values. It does not encrypt values; credentials and other
|
|
30
|
+
secrets require a secure platform store instead.
|
|
31
|
+
|
|
32
|
+
Adapter construction is an explicit runtime boundary, not a harmless import to
|
|
33
|
+
perform speculatively. AsyncStorage 3.1.1's iOS implementation embeds a
|
|
34
|
+
Kotlin/Native `SharedAsyncStorage` framework; creating the adapter activates
|
|
35
|
+
its coroutine and garbage-collection runtime for the rest of the process. An
|
|
36
|
+
application that does not need storage during its first screen should load and
|
|
37
|
+
construct this adapter on demand. Applications that require process
|
|
38
|
+
restoration before first mount necessarily accept that startup cost or should
|
|
39
|
+
select and validate a different native backend.
|
|
40
|
+
|
|
41
|
+
The portable result also satisfies `@solidnative-dev/navigation`'s explicit
|
|
42
|
+
storage contract:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const launch = await createNativeHistoryFromStorage({
|
|
46
|
+
storage,
|
|
47
|
+
storageKey: "navigation",
|
|
48
|
+
});
|
|
49
|
+
const persistence = createNativeHistoryPersistence(launch.history, storage, {
|
|
50
|
+
storageKey: "navigation",
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Navigation owns versioning, validation, ordered/coalesced writes, and the
|
|
55
|
+
durability boundary. This package only owns the native storage adapter. The
|
|
56
|
+
generated-binding path is unit-tested against malformed native results and is
|
|
57
|
+
present in the Android Release bundle; a source-map gate rejects the build if
|
|
58
|
+
the dependency's JavaScript wrapper enters that bundle. The existing process
|
|
59
|
+
restoration suites remain the physical promotion gate. Their refreshed Android
|
|
60
|
+
run passes on a tethered Pixel 9a, including process restoration, 30 native
|
|
61
|
+
navigation cycles, and cold-link precedence. The equivalent generated-path
|
|
62
|
+
iPhone run remains pending.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type KeyValueStorage } from "./index.js";
|
|
2
|
+
export interface AsyncStorage3NativeEntry {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly value: string | null;
|
|
5
|
+
}
|
|
6
|
+
/** The narrow AsyncStorage 3.x native ABI consumed by this adapter. */
|
|
7
|
+
export interface AsyncStorage3NativeModule {
|
|
8
|
+
readonly getValues: (databaseName: string, keys: ReadonlyArray<string>) => Promise<unknown>;
|
|
9
|
+
readonly setValues: (databaseName: string, entries: ReadonlyArray<AsyncStorage3NativeEntry>) => Promise<unknown>;
|
|
10
|
+
readonly removeValues: (databaseName: string, keys: ReadonlyArray<string>) => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface AsyncStorage3KeyValueStorageOptions {
|
|
13
|
+
/** Selects one AsyncStorage 3.x SQLite database. */
|
|
14
|
+
readonly databaseName: string;
|
|
15
|
+
/** Prefixes keys within the selected database. */
|
|
16
|
+
readonly prefix?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Narrows an injected AsyncStorage 3.x TurboModule to portable string storage.
|
|
20
|
+
* This entry point never evaluates the dependency's React-facing wrapper.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createAsyncStorage3KeyValueStorage(native: AsyncStorage3NativeModule, options: AsyncStorage3KeyValueStorageOptions): KeyValueStorage;
|
|
23
|
+
//# sourceMappingURL=async-storage-3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-storage-3.d.ts","sourceRoot":"","sources":["../src/async-storage-3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,uEAAuE;AACvE,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,SAAS,EAAE,CAClB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,KACxB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,CAClB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,aAAa,CAAC,wBAAwB,CAAC,KAC7C,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,CACrB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,KACxB,OAAO,CAAC,OAAO,CAAC,CAAC;CACvB;AAED,MAAM,WAAW,mCAAmC;IAClD,oDAAoD;IACpD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,kDAAkD;IAClD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAwDD;;;GAGG;AACH,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,yBAAyB,EACjC,OAAO,EAAE,mCAAmC,GAC3C,eAAe,CAkCjB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createKeyValueStorage } from "./index.js";
|
|
2
|
+
function databaseName(value) {
|
|
3
|
+
if (typeof value !== "string" ||
|
|
4
|
+
value.length === 0 ||
|
|
5
|
+
value.length > 128 ||
|
|
6
|
+
value.includes("\0")) {
|
|
7
|
+
throw new TypeError("AsyncStorage database name must be a 1-128 character string without null bytes.");
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function nativeMethod(native, name) {
|
|
12
|
+
if (typeof native[name] !== "function") {
|
|
13
|
+
throw new TypeError(`AsyncStorage 3 native module ${name} must be a function.`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function decodedValue(value, expectedKey) {
|
|
17
|
+
if (!Array.isArray(value) || value.length > 1) {
|
|
18
|
+
throw new TypeError("AsyncStorage 3 getValues must return at most one entry for one requested key.");
|
|
19
|
+
}
|
|
20
|
+
if (value.length === 0)
|
|
21
|
+
return null;
|
|
22
|
+
const entry = value[0];
|
|
23
|
+
if (typeof entry !== "object" ||
|
|
24
|
+
entry === null ||
|
|
25
|
+
Array.isArray(entry) ||
|
|
26
|
+
!("key" in entry) ||
|
|
27
|
+
!("value" in entry)) {
|
|
28
|
+
throw new TypeError("AsyncStorage 3 getValues returned a malformed entry.");
|
|
29
|
+
}
|
|
30
|
+
const candidate = entry;
|
|
31
|
+
if (candidate.key !== expectedKey ||
|
|
32
|
+
(candidate.value !== null && typeof candidate.value !== "string")) {
|
|
33
|
+
throw new TypeError("AsyncStorage 3 getValues returned an entry outside the requested string contract.");
|
|
34
|
+
}
|
|
35
|
+
return candidate.value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Narrows an injected AsyncStorage 3.x TurboModule to portable string storage.
|
|
39
|
+
* This entry point never evaluates the dependency's React-facing wrapper.
|
|
40
|
+
*/
|
|
41
|
+
export function createAsyncStorage3KeyValueStorage(native, options) {
|
|
42
|
+
if (typeof native !== "object" || native === null) {
|
|
43
|
+
throw new TypeError("AsyncStorage 3 native module must be an object.");
|
|
44
|
+
}
|
|
45
|
+
if (typeof options !== "object" || options === null) {
|
|
46
|
+
throw new TypeError("AsyncStorage 3 adapter options must be an object.");
|
|
47
|
+
}
|
|
48
|
+
nativeMethod(native, "getValues");
|
|
49
|
+
nativeMethod(native, "setValues");
|
|
50
|
+
nativeMethod(native, "removeValues");
|
|
51
|
+
const selectedDatabase = databaseName(options.databaseName);
|
|
52
|
+
const getValues = native.getValues.bind(native);
|
|
53
|
+
const setValues = native.setValues.bind(native);
|
|
54
|
+
const removeValues = native.removeValues.bind(native);
|
|
55
|
+
return createKeyValueStorage({
|
|
56
|
+
async getItem(key) {
|
|
57
|
+
const result = await getValues(selectedDatabase, Object.freeze([key]));
|
|
58
|
+
return decodedValue(result, key);
|
|
59
|
+
},
|
|
60
|
+
async setItem(key, value) {
|
|
61
|
+
await setValues(selectedDatabase, Object.freeze([Object.freeze({ key, value })]));
|
|
62
|
+
},
|
|
63
|
+
async removeItem(key) {
|
|
64
|
+
await removeValues(selectedDatabase, Object.freeze([key]));
|
|
65
|
+
},
|
|
66
|
+
}, {
|
|
67
|
+
...(options.prefix === undefined ? {} : { prefix: options.prefix }),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=async-storage-3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-storage-3.js","sourceRoot":"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C,CAAC;QACnC,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK;YACtB,MAAM,SAAS,CACb,gBAAgB,EAChB,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAC/C,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,GAAG;YAClB,MAAM,YAAY,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7D,CAAC;KACF,EACD;QACE,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;KACpE,CACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const KEY_VALUE_STORAGE_MAX_KEY_LENGTH = 1024;
|
|
2
|
+
export interface KeyValueStorage {
|
|
3
|
+
getItem(key: string): Promise<string | null>;
|
|
4
|
+
setItem(key: string, value: string): Promise<void>;
|
|
5
|
+
removeItem(key: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export interface KeyValueStorageAdapter {
|
|
8
|
+
getItem(key: string): Promise<unknown>;
|
|
9
|
+
setItem(key: string, value: string): Promise<unknown>;
|
|
10
|
+
removeItem(key: string): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface KeyValueStorageOptions {
|
|
13
|
+
/** Prefixes every adapter key so unrelated application data cannot collide. */
|
|
14
|
+
readonly prefix?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Narrows an untrusted native storage implementation to a small portable
|
|
18
|
+
* string contract. Native failures remain rejected promises; malformed values
|
|
19
|
+
* never enter application or restoration state.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createKeyValueStorage(adapter: KeyValueStorageAdapter, options?: KeyValueStorageOptions): KeyValueStorage;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gCAAgC,OAAQ,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,sBAAsB;IACrC,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AA2BD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,EAC/B,OAAO,GAAE,sBAA2B,GACnC,eAAe,CAkCjB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const KEY_VALUE_STORAGE_MAX_KEY_LENGTH = 1_024;
|
|
2
|
+
function storageKey(value, path) {
|
|
3
|
+
if (typeof value !== "string" ||
|
|
4
|
+
value.length === 0 ||
|
|
5
|
+
value.length > KEY_VALUE_STORAGE_MAX_KEY_LENGTH ||
|
|
6
|
+
value.includes("\0")) {
|
|
7
|
+
throw new TypeError(`${path} must be a 1-${KEY_VALUE_STORAGE_MAX_KEY_LENGTH} character string without null bytes.`);
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function adapterMethod(adapter, name) {
|
|
12
|
+
if (typeof adapter[name] !== "function") {
|
|
13
|
+
throw new TypeError(`Key-value storage adapter ${name} must be a function.`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Narrows an untrusted native storage implementation to a small portable
|
|
18
|
+
* string contract. Native failures remain rejected promises; malformed values
|
|
19
|
+
* never enter application or restoration state.
|
|
20
|
+
*/
|
|
21
|
+
export function createKeyValueStorage(adapter, options = {}) {
|
|
22
|
+
if (typeof adapter !== "object" || adapter === null) {
|
|
23
|
+
throw new TypeError("Key-value storage adapter must be an object.");
|
|
24
|
+
}
|
|
25
|
+
adapterMethod(adapter, "getItem");
|
|
26
|
+
adapterMethod(adapter, "setItem");
|
|
27
|
+
adapterMethod(adapter, "removeItem");
|
|
28
|
+
const prefix = options.prefix === undefined
|
|
29
|
+
? ""
|
|
30
|
+
: `${storageKey(options.prefix, "Storage prefix")}:`;
|
|
31
|
+
const resolveKey = (key) => `${prefix}${storageKey(key, "Storage key")}`;
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
async getItem(key) {
|
|
34
|
+
const value = await adapter.getItem(resolveKey(key));
|
|
35
|
+
if (value !== null && typeof value !== "string") {
|
|
36
|
+
throw new TypeError("The native key-value storage adapter returned a non-string value.");
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
},
|
|
40
|
+
async setItem(key, value) {
|
|
41
|
+
if (typeof value !== "string") {
|
|
42
|
+
throw new TypeError("Storage values must be strings.");
|
|
43
|
+
}
|
|
44
|
+
await adapter.setItem(resolveKey(key), value);
|
|
45
|
+
},
|
|
46
|
+
async removeItem(key) {
|
|
47
|
+
await adapter.removeItem(resolveKey(key));
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AC,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAC;IACzD,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE,CACzC,GAAG,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,CAAC;IAE/C,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,KAAK,CAAC,OAAO,CAAC,GAAW;YACvB,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YACrD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAChD,MAAM,IAAI,SAAS,CACjB,mEAAmE,CACpE,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;YACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,GAAW;YAC1B,MAAM,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidnative-dev/storage",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Validated asynchronous key-value storage for Solid Native applications.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://solidnative.dev",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/solid-native/solid-native.git",
|
|
11
|
+
"directory": "packages/storage"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "^22.13.0 || ^24.3.0 || >=26.0.0"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./async-storage-3": {
|
|
25
|
+
"types": "./dist/async-storage-3.d.ts",
|
|
26
|
+
"default": "./dist/async-storage-3.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/async-storage-3.d.ts",
|
|
31
|
+
"dist/async-storage-3.d.ts.map",
|
|
32
|
+
"dist/async-storage-3.js",
|
|
33
|
+
"dist/async-storage-3.js.map",
|
|
34
|
+
"dist/index.d.ts",
|
|
35
|
+
"dist/index.d.ts.map",
|
|
36
|
+
"dist/index.js",
|
|
37
|
+
"dist/index.js.map"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
42
|
+
"test": "pnpm build && node --test test/*.test.mjs"
|
|
43
|
+
}
|
|
6
44
|
}
|