@aiao/rxdb-plugin-workspace 0.0.6 → 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.
@@ -1,4 +1,4 @@
1
- import { EntityType, RxDB, UUID, IRxDBPlugin, Plugin, RxDBEntityCreatedEventData, RxDBEntityEventData, RxDBPluginBase } from '../packages/rxdb/src/index.ts';
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, options?: RxDBPluginWorkspaceOptions);
18
- install(): Promise<void>;
19
- destroy(): Promise<void>;
17
+ constructor(rxdb: RxDB, _options?: RxDBPluginWorkspaceOptions);
18
+ install(): void;
19
+ destroy(): void;
20
20
  /**
21
21
  * 添加实体到暂存区
22
22
  */
23
- stagedChange<T extends EntityType>(entity: RxDBEntityCreatedEventData): void;
23
+ stagedChange<_T extends EntityType>(entity: RxDBEntityLocalCreatedEventData): void;
24
24
  /**
25
25
  * 从暂存区移除实体
26
26
  */
27
- unstageChange<T extends EntityType>(entity: RxDBEntityCreatedEventData): void;
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: RxDBEntityEventData) => CacheId;
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,0BAA0B,EAC1B,mBAAmB,EACnB,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;gBAEtC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,0BAA0B;IA2B5D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB;;OAEG;IACH,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,0BAA0B;IAOrE;;OAEG;IACH,aAAa,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,0BAA0B;IAKtE;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM;CAuDnB;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,mBAAmB,KACc,OAAO,CAAC"}
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 c, ENTITY_NEW_EVENT as a, ENTITY_REMOVE_EVENT as h, ENTITY_CREATE_EVENT as d } from "@aiao/rxdb";
2
- import { createStore as l, entries as m, setMany as E, delMany as p } from "idb-keyval";
3
- import { Subject as _, debounceTime as u } from "rxjs";
4
- class b extends c {
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
- #r = /* @__PURE__ */ new Map();
12
+ #a = /* @__PURE__ */ new Map();
13
13
  // 暂存区 ids
14
- #a = /* @__PURE__ */ new Set();
15
- #h = !1;
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(a, this.#d), this.rxdb.addEventListener(h, this.#d), this.rxdb.addEventListener(d, this.#d);
19
- const n = this.rxdb.options.dbName;
20
- this.#s = l(n, this.name), m(this.#s).then(
21
- (s) => s.forEach(([f, o]) => o)
22
- ), this.#i.asObservable().pipe(u(0)).subscribe(() => this.#c());
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 = r(e);
35
- this.#r.has(t) && this.#a.add(t);
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 = r(e);
42
- this.#a.delete(t);
45
+ const t = a(e);
46
+ this.#h.delete(t);
43
47
  }
44
48
  /**
45
49
  * 提交变化
46
50
  */
47
51
  commit(e) {
48
- this.#a.size > 0 && console.log("commit", e);
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 = r(n);
57
+ const s = a(n);
54
58
  switch (e.type) {
55
- case a:
56
- this.#n.add(s), this.#r.set(s, e), this.#t.set(s, e), this.#i.next();
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 h:
62
- this.#o(s);
65
+ case r:
66
+ this.#c(s);
63
67
  break;
64
68
  }
65
69
  });
66
70
  };
67
- #o(e) {
68
- this.#n.delete(e), this.#r.delete(e), this.#e.add(e), this.#i.next();
71
+ #c(e) {
72
+ this.#n.delete(e), this.#a.delete(e), this.#e.add(e), this.#i.next();
69
73
  }
70
- async #c() {
71
- if (!(this.#h || this.#t.size === 0 && this.#e.size === 0)) {
72
- if (this.#h = !0, this.#t.size) {
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 p(Array.from(this.#e), this.#s), this.#e.clear()), this.#h = !1;
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 b(i, e), r = (i) => i.namespace + ":" + i.entity + ":" + i.id;
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.6",
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.6"
30
+ "@aiao/rxdb": "0.0.7"
31
31
  }
32
32
  }