@aiao/rxdb-plugin-workspace 0.0.5 → 0.0.7
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/RxDBPluginWorkspace.d.ts +11 -7
- package/dist/RxDBPluginWorkspace.d.ts.map +1 -1
- package/dist/index.js +51 -47
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityType, RxDB, IRxDBPlugin, Plugin, RxDBPluginBase } from '
|
|
1
|
+
import { EntityType, RxDB, UUID, IRxDBPlugin, Plugin, RxDBEntityLocalCreatedEventData, RxDBEntityLocalEventData, RxDBPluginBase } from '../packages/rxdb/src/index.ts';
|
|
2
2
|
interface RxDBPluginWorkspaceOptions {
|
|
3
3
|
/**
|
|
4
4
|
* 自动保存
|
|
@@ -8,31 +8,35 @@ interface RxDBPluginWorkspaceOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* 工作区
|
|
10
10
|
* 所有实体会暂存 IndexedDB
|
|
11
|
+
* 1,当前只是把 new 的实体保存到 IndexedDB, remove 的实体从 IndexedDB 删除.
|
|
12
|
+
* 2. 用户关闭浏览器后重新打开时,会从 IndexedDB 读取实体数据到内存
|
|
11
13
|
*/
|
|
12
14
|
export declare class RxDBPluginWorkspace extends RxDBPluginBase implements IRxDBPlugin {
|
|
13
15
|
#private;
|
|
14
16
|
readonly name: Uncapitalize<string>;
|
|
15
|
-
constructor(rxdb: RxDB,
|
|
16
|
-
install():
|
|
17
|
-
destroy():
|
|
17
|
+
constructor(rxdb: RxDB, _options?: RxDBPluginWorkspaceOptions);
|
|
18
|
+
install(): void;
|
|
19
|
+
destroy(): void;
|
|
18
20
|
/**
|
|
19
21
|
* 添加实体到暂存区
|
|
20
22
|
*/
|
|
21
|
-
stagedChange<
|
|
23
|
+
stagedChange<_T extends EntityType>(entity: RxDBEntityLocalCreatedEventData): void;
|
|
22
24
|
/**
|
|
23
25
|
* 从暂存区移除实体
|
|
24
26
|
*/
|
|
25
|
-
unstageChange<
|
|
27
|
+
unstageChange<_T extends EntityType>(entity: RxDBEntityLocalCreatedEventData): void;
|
|
26
28
|
/**
|
|
27
29
|
* 提交变化
|
|
28
30
|
*/
|
|
29
31
|
commit(msg: string): void;
|
|
30
32
|
}
|
|
31
33
|
export declare const rxDBPluginWorkspace: Plugin<RxDBPluginWorkspaceOptions>;
|
|
32
|
-
declare module '
|
|
34
|
+
declare module '../packages/rxdb/src/index.ts' {
|
|
33
35
|
interface RxDB {
|
|
34
36
|
workspace: RxDBPluginWorkspace;
|
|
35
37
|
}
|
|
36
38
|
}
|
|
39
|
+
type CacheId = `${string}:${string}:${UUID}`;
|
|
40
|
+
export declare const get_cache_id: (eventData: RxDBEntityLocalEventData) => CacheId;
|
|
37
41
|
export {};
|
|
38
42
|
//# sourceMappingURL=RxDBPluginWorkspace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RxDBPluginWorkspace.d.ts","sourceRoot":"","sources":["../src/RxDBPluginWorkspace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"RxDBPluginWorkspace.d.ts","sourceRoot":"","sources":["../src/RxDBPluginWorkspace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAOL,WAAW,EACX,MAAM,EACN,+BAA+B,EAC/B,wBAAwB,EACxB,cAAc,EACf,MAAM,YAAY,CAAC;AAIpB,UAAU,0BAA0B;IAClC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,cAAe,YAAW,WAAW;;IAiB5E,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,CAAe;gBAGtC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,0BAA0B;IA6B7D,OAAO;IAIP,OAAO;IAIP;;OAEG;IAEH,YAAY,CAAC,EAAE,SAAS,UAAU,EAAE,MAAM,EAAE,+BAA+B;IAO3E;;OAEG;IAEH,aAAa,CAAC,EAAE,SAAS,UAAU,EAAE,MAAM,EAAE,+BAA+B;IAK5E;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM;CAwDnB;AAED,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,0BAA0B,CAKlE,CAAC;AAEF,OAAO,QAAQ,YAAY,CAAC;IAC1B,UAAU,IAAI;QACZ,SAAS,EAAE,mBAAmB,CAAC;KAChC;CACF;AAED,KAAK,OAAO,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;AAE7C,eAAO,MAAM,YAAY,GAAI,WAAW,wBAAwB,KACS,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,86 +1,90 @@
|
|
|
1
|
-
import { RxDBPluginBase as
|
|
2
|
-
import { createStore as
|
|
3
|
-
import { Subject as
|
|
4
|
-
class
|
|
1
|
+
import { RxDBPluginBase as o, ENTITY_LOCAL_NEW_EVENT as h, ENTITY_LOCAL_REMOVE_EVENT as r, ENTITY_LOCAL_CREATE_EVENT as d } from "@aiao/rxdb";
|
|
2
|
+
import { createStore as _, entries as l, setMany as E, delMany as m } from "idb-keyval";
|
|
3
|
+
import { Subject as p, debounceTime as b } from "rxjs";
|
|
4
|
+
class f extends o {
|
|
5
5
|
#s;
|
|
6
|
-
#i = new
|
|
6
|
+
#i = new p();
|
|
7
7
|
// 需要保存的实体
|
|
8
8
|
#t = /* @__PURE__ */ new Map();
|
|
9
9
|
#e = /* @__PURE__ */ new Set();
|
|
10
10
|
// 工作区所有实体
|
|
11
|
-
#
|
|
12
|
-
#
|
|
11
|
+
#n = /* @__PURE__ */ new Set();
|
|
12
|
+
#a = /* @__PURE__ */ new Map();
|
|
13
13
|
// 暂存区 ids
|
|
14
|
-
#
|
|
15
|
-
#
|
|
14
|
+
#h = /* @__PURE__ */ new Set();
|
|
15
|
+
#r = !1;
|
|
16
16
|
name = "workspace";
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
18
|
constructor(e, t) {
|
|
18
|
-
super(e), this.rxdb.addEventListener(
|
|
19
|
-
const
|
|
20
|
-
this.#s =
|
|
21
|
-
(s) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
), this.#i.asObservable().pipe(
|
|
19
|
+
super(e), this.rxdb.addEventListener(h, this.#d), this.rxdb.addEventListener(r, this.#d), this.rxdb.addEventListener(d, this.#d);
|
|
20
|
+
const n = this.rxdb.config.dbName;
|
|
21
|
+
this.#s = _(n, this.name), l(this.#s).then(
|
|
22
|
+
(s) => (
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
+
s.forEach(([u, c]) => c)
|
|
25
|
+
)
|
|
26
|
+
), this.#i.asObservable().pipe(b(0)).subscribe(() => this.#o());
|
|
26
27
|
}
|
|
27
28
|
install() {
|
|
28
|
-
return Promise.resolve();
|
|
29
29
|
}
|
|
30
30
|
destroy() {
|
|
31
|
-
return Promise.resolve();
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
33
|
* 添加实体到暂存区
|
|
35
34
|
*/
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
36
|
stagedChange(e) {
|
|
37
|
-
const t =
|
|
38
|
-
this.#
|
|
37
|
+
const t = a(e);
|
|
38
|
+
this.#a.has(t) && this.#h.add(t);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* 从暂存区移除实体
|
|
42
42
|
*/
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
44
|
unstageChange(e) {
|
|
44
|
-
const t =
|
|
45
|
-
this.#
|
|
45
|
+
const t = a(e);
|
|
46
|
+
this.#h.delete(t);
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* 提交变化
|
|
49
50
|
*/
|
|
50
51
|
commit(e) {
|
|
51
|
-
this.#
|
|
52
|
+
this.#h.size > 0 && console.log("commit", e);
|
|
52
53
|
}
|
|
53
54
|
#d = (e) => {
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
const { entities: t } = e;
|
|
56
|
+
t.forEach((n) => {
|
|
57
|
+
const s = a(n);
|
|
58
|
+
switch (e.type) {
|
|
59
|
+
case h:
|
|
60
|
+
this.#n.add(s), this.#a.set(s, e), this.#t.set(s, e), this.#i.next();
|
|
61
|
+
break;
|
|
62
|
+
case d:
|
|
63
|
+
this.#n.add(s), this.#e.add(s), this.#i.next();
|
|
64
|
+
break;
|
|
65
|
+
case r:
|
|
66
|
+
this.#c(s);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
66
70
|
};
|
|
67
|
-
#
|
|
68
|
-
this.#
|
|
71
|
+
#c(e) {
|
|
72
|
+
this.#n.delete(e), this.#a.delete(e), this.#e.add(e), this.#i.next();
|
|
69
73
|
}
|
|
70
|
-
async #
|
|
71
|
-
if (!(this.#
|
|
72
|
-
if (this.#
|
|
73
|
-
const e = Array.from(this.#t.entries()).map(([t,
|
|
74
|
+
async #o() {
|
|
75
|
+
if (!(this.#r || this.#t.size === 0 && this.#e.size === 0)) {
|
|
76
|
+
if (this.#r = !0, this.#t.size) {
|
|
77
|
+
const e = Array.from(this.#t.entries()).map(([t, n]) => [
|
|
74
78
|
t,
|
|
75
|
-
{ ...
|
|
79
|
+
{ ...n }
|
|
76
80
|
]);
|
|
77
|
-
await
|
|
81
|
+
await E(e, this.#s), this.#t.clear();
|
|
78
82
|
}
|
|
79
|
-
this.#e.size && (await
|
|
83
|
+
this.#e.size && (await m(Array.from(this.#e), this.#s), this.#e.clear()), this.#r = !1;
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
|
-
const
|
|
87
|
+
const w = (i, e) => new f(i, e), a = (i) => i.namespace + ":" + i.entity + ":" + i.id;
|
|
84
88
|
export {
|
|
85
|
-
|
|
89
|
+
w as rxDBPluginWorkspace
|
|
86
90
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiao/rxdb-plugin-workspace",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"rxjs": "^7.8.2",
|
|
29
29
|
"idb-keyval": "^6.2.2",
|
|
30
|
-
"@aiao/rxdb": "0.0.
|
|
30
|
+
"@aiao/rxdb": "0.0.7"
|
|
31
31
|
}
|
|
32
32
|
}
|