Skip to content

Commit ad6de00

Browse files
authored
Merge pull request #3 from pitzzahh/feat/perf-test
feat: optimize bundle size and fix type inference issues
2 parents 13ac083 + af9a870 commit ad6de00

File tree

4 files changed

+145
-93
lines changed

4 files changed

+145
-93
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"module": "dist/index.js",
66
"type": "module",
77
"scripts": {
8-
"build": "bun build src/index.ts --outdir dist --target node && bun tsc",
8+
"build": "bun build src/index.ts --outdir dist --target node --minify && tsc --declaration --emitDeclarationOnly --outDir dist",
99
"test": "bun test",
1010
"test:watch": "bun test --watch",
1111
"test:coverage": "bun test --coverage",
@@ -33,9 +33,14 @@
3333
"license": "MIT",
3434
"main": "dist/index.js",
3535
"types": "dist/index.d.ts",
36+
"exports": {
37+
".": {
38+
"types": "./dist/index.d.ts",
39+
"import": "./dist/index.js"
40+
}
41+
},
3642
"files": [
37-
"dist/index.js",
38-
"dist/index.d.ts",
43+
"dist/**/*",
3944
"README.md",
4045
"LICENSE"
4146
],

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function createBackupFilename(filename: string): string {
7272
*/
7373
export function createTauriFileSystemAdapter<T extends { id: ID } & Record<string, any>, ID = string>(
7474
filename: string,
75-
options?: AdapterOptions
75+
options?: AdapterOptions<T>
7676
): PersistenceAdapter<T, ID> {
7777
// Validate filename for security
7878
validateFilename(filename);
@@ -118,7 +118,7 @@ export function createTauriFileSystemAdapter<T extends { id: ID } & Record<strin
118118

119119
try {
120120
if (options?.encrypt) {
121-
initial_data = await options.encrypt<T[]>([]);
121+
initial_data = await options.encrypt([]);
122122
} else {
123123
initial_data = JSON.stringify([]);
124124
}
@@ -160,7 +160,7 @@ export function createTauriFileSystemAdapter<T extends { id: ID } & Record<strin
160160

161161
if (options?.decrypt) {
162162
try {
163-
decrypted_data = await options.decrypt<T[]>(text_content);
163+
decrypted_data = await options.decrypt(text_content);
164164

165165
// Validate decrypted data structure if validation is enabled
166166
if (security.validateDecryptedData) {
@@ -298,7 +298,7 @@ export function createTauriFileSystemAdapter<T extends { id: ID } & Record<strin
298298

299299
if (options?.encrypt) {
300300
try {
301-
data_to_save = await options.encrypt<T[]>(updated_items);
301+
data_to_save = await options.encrypt(updated_items);
302302
} catch (error) {
303303
throw new Error(`Failed to encrypt data for ${filename}`, { cause: error });
304304
}

src/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export type EncryptFunction = <T>(data: T) => Promise<string>;
2-
export type DecryptFunction = <T>(encrypted: string) => Promise<T>;
1+
export type EncryptFunction<T> = (data: T[]) => Promise<string>;
2+
export type DecryptFunction<T> = (encrypted: string) => Promise<T[]>;
33

44
export interface SecurityOptions {
55
/** Whether to enforce encryption (throw error if encrypt/decrypt not provided) */
@@ -14,9 +14,9 @@ export interface SecurityOptions {
1414
dataValidator?: <T>(data: unknown) => data is T[];
1515
}
1616

17-
export interface AdapterOptions {
17+
export interface AdapterOptions<T> {
1818
base_dir?: import('@tauri-apps/plugin-fs').BaseDirectory;
19-
encrypt?: EncryptFunction;
20-
decrypt?: DecryptFunction;
19+
encrypt?: EncryptFunction<T>;
20+
decrypt?: DecryptFunction<T>;
2121
security?: SecurityOptions;
2222
}

0 commit comments

Comments
 (0)