@aiao/rxdb-plugin-workspace 0.0.6 → 0.0.8
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityType, RxDB, UUID, IRxDBPlugin, Plugin,
|
|
1
|
+
import { EntityType, RxDB, UUID, IRxDBPlugin, Plugin, RxDBEntityLocalCreatedEventData, RxDBEntityLocalEventData, RxDBPluginBase } from '../packages/rxdb/src/index.ts';
|
|
2
2
|
interface RxDBPluginWorkspaceOptions {
|
|
3
3
|
/**
|
|
4
4
|
* 自动保存
|
|
@@ -14,17 +14,17 @@ interface RxDBPluginWorkspaceOptions {
|
|
|
14
14
|
export declare class RxDBPluginWorkspace extends RxDBPluginBase implements IRxDBPlugin {
|
|
15
15
|
#private;
|
|
16
16
|
readonly name: Uncapitalize<string>;
|
|
17
|
-
constructor(rxdb: RxDB,
|
|
18
|
-
install():
|
|
19
|
-
destroy():
|
|
17
|
+
constructor(rxdb: RxDB, _options?: RxDBPluginWorkspaceOptions);
|
|
18
|
+
install(): void;
|
|
19
|
+
destroy(): void;
|
|
20
20
|
/**
|
|
21
21
|
* 添加实体到暂存区
|
|
22
22
|
*/
|
|
23
|
-
stagedChange<
|
|
23
|
+
stagedChange<_T extends EntityType>(entity: RxDBEntityLocalCreatedEventData): void;
|
|
24
24
|
/**
|
|
25
25
|
* 从暂存区移除实体
|
|
26
26
|
*/
|
|
27
|
-
unstageChange<
|
|
27
|
+
unstageChange<_T extends EntityType>(entity: RxDBEntityLocalCreatedEventData): void;
|
|
28
28
|
/**
|
|
29
29
|
* 提交变化
|
|
30
30
|
*/
|
|
@@ -37,6 +37,6 @@ declare module '../packages/rxdb/src/index.ts' {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
type CacheId = `${string}:${string}:${UUID}`;
|
|
40
|
-
export declare const get_cache_id: (eventData:
|
|
40
|
+
export declare const get_cache_id: (eventData: RxDBEntityLocalEventData) => CacheId;
|
|
41
41
|
export {};
|
|
42
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,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAOL,WAAW,EACX,MAAM,EACN,
|
|
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
11
|
#n = /* @__PURE__ */ new Set();
|
|
12
|
-
#
|
|
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 n = this.rxdb.
|
|
20
|
-
this.#s =
|
|
21
|
-
(s) =>
|
|
22
|
-
|
|
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());
|
|
23
27
|
}
|
|
24
28
|
install() {
|
|
25
|
-
return Promise.resolve();
|
|
26
29
|
}
|
|
27
30
|
destroy() {
|
|
28
|
-
return Promise.resolve();
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
31
33
|
* 添加实体到暂存区
|
|
32
34
|
*/
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
33
36
|
stagedChange(e) {
|
|
34
|
-
const t =
|
|
35
|
-
this.#
|
|
37
|
+
const t = a(e);
|
|
38
|
+
this.#a.has(t) && this.#h.add(t);
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* 从暂存区移除实体
|
|
39
42
|
*/
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
44
|
unstageChange(e) {
|
|
41
|
-
const t =
|
|
42
|
-
this.#
|
|
45
|
+
const t = a(e);
|
|
46
|
+
this.#h.delete(t);
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
45
49
|
* 提交变化
|
|
46
50
|
*/
|
|
47
51
|
commit(e) {
|
|
48
|
-
this.#
|
|
52
|
+
this.#h.size > 0 && console.log("commit", e);
|
|
49
53
|
}
|
|
50
54
|
#d = (e) => {
|
|
51
55
|
const { entities: t } = e;
|
|
52
56
|
t.forEach((n) => {
|
|
53
|
-
const s =
|
|
57
|
+
const s = a(n);
|
|
54
58
|
switch (e.type) {
|
|
55
|
-
case
|
|
56
|
-
this.#n.add(s), this.#
|
|
59
|
+
case h:
|
|
60
|
+
this.#n.add(s), this.#a.set(s, e), this.#t.set(s, e), this.#i.next();
|
|
57
61
|
break;
|
|
58
62
|
case d:
|
|
59
63
|
this.#n.add(s), this.#e.add(s), this.#i.next();
|
|
60
64
|
break;
|
|
61
|
-
case
|
|
62
|
-
this.#
|
|
65
|
+
case r:
|
|
66
|
+
this.#c(s);
|
|
63
67
|
break;
|
|
64
68
|
}
|
|
65
69
|
});
|
|
66
70
|
};
|
|
67
|
-
#
|
|
68
|
-
this.#n.delete(e), 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.#
|
|
74
|
+
async #o() {
|
|
75
|
+
if (!(this.#r || this.#t.size === 0 && this.#e.size === 0)) {
|
|
76
|
+
if (this.#r = !0, this.#t.size) {
|
|
73
77
|
const e = Array.from(this.#t.entries()).map(([t, n]) => [
|
|
74
78
|
t,
|
|
75
79
|
{ ...n }
|
|
76
80
|
]);
|
|
77
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 w = (i, e) => new
|
|
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.8",
|
|
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.8"
|
|
31
31
|
}
|
|
32
32
|
}
|