@rainte/js 0.0.16 → 0.0.17
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.js +4945 -1895
- package/dist/index.umd.cjs +8 -6
- package/dist/types/lib/index.d.ts +1 -0
- package/dist/types/src/db/index.d.ts +13 -0
- package/lib/index.ts +1 -0
- package/package.json +26 -25
- package/src/db/index.ts +36 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Dexie, { Table } from 'dexie';
|
|
2
|
+
export interface DexieRow {
|
|
3
|
+
id?: number;
|
|
4
|
+
key: string;
|
|
5
|
+
value: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class SubDexie extends Dexie {
|
|
8
|
+
rows: Table<DexieRow>;
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare const db: SubDexie;
|
|
12
|
+
export declare const get: (key: string, value?: boolean) => import("dexie").PromiseExtended<any>;
|
|
13
|
+
export declare const set: (key: string, value: any) => Promise<void>;
|
package/lib/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@rainte/js",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "dist/index.umd.cjs",
|
|
6
|
-
"module": "dist/index.js",
|
|
7
|
-
"typings": "dist/types/lib/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"dev": "vite",
|
|
10
|
-
"build": "vite build && tsc",
|
|
11
|
-
"release": "pnpm build && npm version patch && npm publish --access public --registry=https://registry.npmjs.org",
|
|
12
|
-
"preview": "vite preview"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@types/jsan": "^3.1.5",
|
|
16
|
-
"@types/node": "^22.13.5",
|
|
17
|
-
"typescript": "^5.7.3",
|
|
18
|
-
"vite": "^6.1.1"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"axios": "^1.7.9",
|
|
22
|
-
"dayjs": "^1.11.13",
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@rainte/js",
|
|
3
|
+
"version": "0.0.17",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.umd.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"typings": "dist/types/lib/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite",
|
|
10
|
+
"build": "vite build && tsc",
|
|
11
|
+
"release": "pnpm build && npm version patch && npm publish --access public --registry=https://registry.npmjs.org",
|
|
12
|
+
"preview": "vite preview"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/jsan": "^3.1.5",
|
|
16
|
+
"@types/node": "^22.13.5",
|
|
17
|
+
"typescript": "^5.7.3",
|
|
18
|
+
"vite": "^6.1.1"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "^1.7.9",
|
|
22
|
+
"dayjs": "^1.11.13",
|
|
23
|
+
"dexie": "^4.0.11",
|
|
24
|
+
"jsan": "^3.1.14"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/db/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Dexie, { Table } from 'dexie'
|
|
2
|
+
|
|
3
|
+
export interface DexieRow {
|
|
4
|
+
id?: number
|
|
5
|
+
key: string
|
|
6
|
+
value: any
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class SubDexie extends Dexie {
|
|
10
|
+
rows!: Table<DexieRow>
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super('db')
|
|
14
|
+
this.version(1).stores({
|
|
15
|
+
rows: '++id, key'
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const db = new SubDexie()
|
|
21
|
+
|
|
22
|
+
export const get = (key: string, value = true) => {
|
|
23
|
+
return db.rows
|
|
24
|
+
.where({ key })
|
|
25
|
+
.first()
|
|
26
|
+
.then((res) => (value ? res?.value : res))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const set = async (key: string, value: any) => {
|
|
30
|
+
const ok = await get(key, false)
|
|
31
|
+
if (ok) {
|
|
32
|
+
await db.rows.where({ key }).modify({ value })
|
|
33
|
+
} else {
|
|
34
|
+
await db.rows.add({ key, value })
|
|
35
|
+
}
|
|
36
|
+
}
|