@aiao/rxdb 0.0.1 → 0.0.2
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/RxDBError.d.ts +0 -8
- package/entity/@TreeEntity.d.ts +1 -26
- package/entity/entity-metadata-options.interface.d.ts +29 -5
- package/index.js +200 -204
- package/package.json +2 -2
- package/rxdb-utils.d.ts +1 -1
- package/rxdb.interface.d.ts +4 -1
- package/rxdb.private.d.ts +25 -0
package/RxDBError.d.ts
CHANGED
|
@@ -2,12 +2,4 @@
|
|
|
2
2
|
* RxDB 基础错误类型
|
|
3
3
|
*/
|
|
4
4
|
export declare class RxDBError extends Error {
|
|
5
|
-
messageTemplate: string;
|
|
6
|
-
data: {
|
|
7
|
-
[name: string]: string | number;
|
|
8
|
-
};
|
|
9
|
-
constructor(messageTemplate: string, data?: {
|
|
10
|
-
[name: string]: string | number;
|
|
11
|
-
});
|
|
12
|
-
toString(): string;
|
|
13
5
|
}
|
package/entity/@TreeEntity.d.ts
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
1
1
|
import { EntityMetadataOptions } from './entity-metadata-options.interface';
|
|
2
|
-
/**
|
|
3
|
-
* 树形结构类型
|
|
4
|
-
*
|
|
5
|
-
* 目前仅支持邻接表模型,未来可能支持其他模型:
|
|
6
|
-
* - 'closure-table': 闭包表模型
|
|
7
|
-
* - 'nested-set': 嵌套集模型
|
|
8
|
-
* - 'materialized-path': 物化路径模型
|
|
9
|
-
*
|
|
10
|
-
* 参考资料:
|
|
11
|
-
* - https://www.slideshare.net/slideshow/models-for-hierarchical-data/4179181
|
|
12
|
-
* - https://schinckel.net/2014/09/13/long-live-adjacency-lists/
|
|
13
|
-
*/
|
|
14
|
-
type TreeType = 'adjacency-list';
|
|
15
|
-
/**
|
|
16
|
-
* 树形实体元数据选项接口
|
|
17
|
-
* 扩展基本实体元数据,添加树形结构特定配置
|
|
18
|
-
*/
|
|
19
|
-
interface TreeEntityMetadataOptions extends EntityMetadataOptions {
|
|
20
|
-
/**
|
|
21
|
-
* 树形结构类型
|
|
22
|
-
* 指定使用哪种树形结构模型
|
|
23
|
-
*/
|
|
24
|
-
treeType: TreeType;
|
|
25
|
-
}
|
|
26
2
|
/**
|
|
27
3
|
* 树形实体装饰器
|
|
28
4
|
* 用于将类标记为树形结构实体,并处理树形特定的元数据
|
|
@@ -46,5 +22,4 @@ interface TreeEntityMetadataOptions extends EntityMetadataOptions {
|
|
|
46
22
|
* }
|
|
47
23
|
* ```
|
|
48
24
|
*/
|
|
49
|
-
export declare const TreeEntity: (metadataOptions:
|
|
50
|
-
export {};
|
|
25
|
+
export declare const TreeEntity: (metadataOptions: EntityMetadataOptions) => <T extends import('./entity.interface').EntityType | import('./entity.interface').AbstractEntityType>(target: T) => T extends import('./entity.interface').EntityType ? new (initData?: Partial<InstanceType<T>> | undefined) => InstanceType<T> : abstract new (initData?: Partial<InstanceType<T>> | undefined) => InstanceType<T>;
|
|
@@ -310,8 +310,14 @@ export interface EntityMetadataOptions {
|
|
|
310
310
|
* 名称
|
|
311
311
|
*/
|
|
312
312
|
name: Capitalize<string>;
|
|
313
|
+
/**
|
|
314
|
+
* 显示名称
|
|
315
|
+
* @example "用户", "订单项"
|
|
316
|
+
*/
|
|
317
|
+
displayName?: string;
|
|
313
318
|
/**
|
|
314
319
|
* 自定义 repository
|
|
320
|
+
* @default "Repository"
|
|
315
321
|
*/
|
|
316
322
|
repository?: 'Repository' | 'TreeRepository' | string;
|
|
317
323
|
/**
|
|
@@ -326,11 +332,6 @@ export interface EntityMetadataOptions {
|
|
|
326
332
|
* 实体同步配置
|
|
327
333
|
*/
|
|
328
334
|
sync?: SyncOptions;
|
|
329
|
-
/**
|
|
330
|
-
* 显示名称
|
|
331
|
-
* @example "用户", "订单项"
|
|
332
|
-
*/
|
|
333
|
-
displayName?: string;
|
|
334
335
|
/**
|
|
335
336
|
* 是否为抽象实体
|
|
336
337
|
* 抽象类是不能被实例化的
|
|
@@ -359,6 +360,29 @@ export interface EntityMetadataOptions {
|
|
|
359
360
|
* 自己定义的索引,不包括继承的
|
|
360
361
|
*/
|
|
361
362
|
indexes?: EntityIndexMetadataOptions[];
|
|
363
|
+
/**
|
|
364
|
+
* 功能特性
|
|
365
|
+
*/
|
|
366
|
+
features?: EntityMetadataFeatures;
|
|
367
|
+
}
|
|
368
|
+
type TreeType = 'adjacency-list';
|
|
369
|
+
/**
|
|
370
|
+
* EntityMetadata 扩展特性
|
|
371
|
+
*/
|
|
372
|
+
export interface EntityMetadataFeatures {
|
|
373
|
+
/**
|
|
374
|
+
* 树形结构类型
|
|
375
|
+
*
|
|
376
|
+
* 目前仅支持邻接表模型,未来可能支持其他模型:
|
|
377
|
+
* - 'closure-table': 闭包表模型
|
|
378
|
+
* - 'nested-set': 嵌套集模型
|
|
379
|
+
* - 'materialized-path': 物化路径模型
|
|
380
|
+
*
|
|
381
|
+
* 参考资料:
|
|
382
|
+
* - https://www.slideshare.net/slideshow/models-for-hierarchical-data/4179181
|
|
383
|
+
* - https://schinckel.net/2014/09/13/long-live-adjacency-lists/
|
|
384
|
+
*/
|
|
385
|
+
treeType?: TreeType;
|
|
362
386
|
}
|
|
363
387
|
/**
|
|
364
388
|
* 同步适配器选项接口
|
package/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { v7 as
|
|
3
|
-
import { BehaviorSubject as
|
|
4
|
-
class
|
|
5
|
-
constructor(e, t = {}) {
|
|
6
|
-
super(oe(e, t)), this.messageTemplate = e, this.data = t;
|
|
7
|
-
}
|
|
8
|
-
toString() {
|
|
9
|
-
return JSON.stringify(this);
|
|
10
|
-
}
|
|
1
|
+
import { isFunction as oe, startCase as ce, get as le, isEqual as J, isSymbol as de, omitBy as he, deepFreeze as pe, isPromise as ue } from "@aiao/utils";
|
|
2
|
+
import { v7 as fe } from "uuid";
|
|
3
|
+
import { BehaviorSubject as N, filter as Y, distinctUntilChanged as I, switchMap as f, shareReplay as A, map as D, tap as b, firstValueFrom as S, of as j, defer as q } from "rxjs";
|
|
4
|
+
class v extends Error {
|
|
11
5
|
}
|
|
12
6
|
class T {
|
|
13
7
|
constructor(e) {
|
|
@@ -19,78 +13,78 @@ class U extends T {
|
|
|
19
13
|
super(e), this.error = t;
|
|
20
14
|
}
|
|
21
15
|
}
|
|
22
|
-
const
|
|
23
|
-
class
|
|
24
|
-
type =
|
|
16
|
+
const Ee = "ENTITY_NEW";
|
|
17
|
+
class ye extends T {
|
|
18
|
+
type = Ee;
|
|
25
19
|
}
|
|
26
|
-
const V = "ENTITY_CREATE",
|
|
27
|
-
class
|
|
20
|
+
const V = "ENTITY_CREATE", me = `${V}_SUCCESS`, _e = `${V}_ERROR`;
|
|
21
|
+
class ge extends T {
|
|
28
22
|
type = V;
|
|
29
23
|
}
|
|
30
|
-
class
|
|
31
|
-
type =
|
|
24
|
+
class be extends T {
|
|
25
|
+
type = me;
|
|
32
26
|
}
|
|
33
27
|
class ve extends U {
|
|
34
|
-
type =
|
|
28
|
+
type = _e;
|
|
35
29
|
}
|
|
36
|
-
const K = "ENTITY_UPDATE",
|
|
37
|
-
class
|
|
30
|
+
const K = "ENTITY_UPDATE", Te = `${K}_SUCCESS`, Ae = `${K}_ERROR`;
|
|
31
|
+
class Oe extends T {
|
|
38
32
|
type = K;
|
|
39
33
|
}
|
|
40
|
-
class
|
|
41
|
-
type =
|
|
34
|
+
class Re extends T {
|
|
35
|
+
type = Te;
|
|
42
36
|
}
|
|
43
37
|
class we extends U {
|
|
44
|
-
type =
|
|
38
|
+
type = Ae;
|
|
45
39
|
}
|
|
46
|
-
const W = "ENTITY_REMOVE",
|
|
47
|
-
class
|
|
40
|
+
const W = "ENTITY_REMOVE", Ne = `${W}_SUCCESS`, xe = `${W}_ERROR`;
|
|
41
|
+
class Me extends T {
|
|
48
42
|
type = W;
|
|
49
43
|
}
|
|
50
|
-
class
|
|
51
|
-
type =
|
|
44
|
+
class Se extends T {
|
|
45
|
+
type = Ne;
|
|
52
46
|
}
|
|
53
|
-
class
|
|
54
|
-
type =
|
|
47
|
+
class Ce extends U {
|
|
48
|
+
type = xe;
|
|
55
49
|
}
|
|
56
|
-
const
|
|
57
|
-
class
|
|
50
|
+
const Ie = "ENTITY_PATCH";
|
|
51
|
+
class De extends T {
|
|
58
52
|
constructor(e, t, s, n, i, a) {
|
|
59
53
|
super(e), this.patch = t, this.inversePatch = s, this.recordAt = n, this.timeStamp = i, this.updatedBy = a;
|
|
60
54
|
}
|
|
61
|
-
type =
|
|
55
|
+
type = Ie;
|
|
62
56
|
}
|
|
63
57
|
const F = "TRANSACTION_BEGIN", z = "TRANSACTION_COMMIT", H = "TRANSACTION_ROLLBACK";
|
|
64
|
-
class
|
|
58
|
+
class mt {
|
|
65
59
|
type = F;
|
|
66
60
|
}
|
|
67
|
-
class
|
|
61
|
+
class _t {
|
|
68
62
|
type = z;
|
|
69
63
|
}
|
|
70
|
-
class
|
|
64
|
+
class gt {
|
|
71
65
|
type = H;
|
|
72
66
|
}
|
|
73
|
-
const ee = "DATABASE_DELETE",
|
|
74
|
-
class
|
|
67
|
+
const ee = "DATABASE_DELETE", Be = "DATABASE_INSERT", $e = "DATABASE_UPDATE";
|
|
68
|
+
class G {
|
|
75
69
|
constructor(e, t) {
|
|
76
70
|
this.EntityType = e, this.data = t;
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
|
-
class
|
|
73
|
+
class bt extends G {
|
|
80
74
|
type = ee;
|
|
81
75
|
}
|
|
82
|
-
class
|
|
83
|
-
type =
|
|
76
|
+
class vt extends G {
|
|
77
|
+
type = Be;
|
|
84
78
|
}
|
|
85
|
-
class
|
|
86
|
-
type =
|
|
79
|
+
class Tt extends G {
|
|
80
|
+
type = $e;
|
|
87
81
|
}
|
|
88
|
-
const te = Symbol("ɵProxy"), L = Symbol("ɵMetadata"), se = Symbol("ɵStatus"), B = Symbol("ɵStatusCheck"), ne = Symbol("ɵEntityManager"), re = Symbol("ɵEntityDeleteCheck"), x = Symbol("ɵUpdateBy"), Pe = "SYSTEM",
|
|
82
|
+
const te = Symbol("ɵProxy"), L = Symbol("ɵMetadata"), se = Symbol("ɵStatus"), B = Symbol("ɵStatusCheck"), ne = Symbol("ɵEntityManager"), re = Symbol("ɵEntityDeleteCheck"), x = Symbol("ɵUpdateBy"), Pe = "SYSTEM", Ye = "USER", je = (r, e) => e.sync.local?.adapter === r, Le = (r) => [F, z, H].includes(r.type), O = (r) => r[L] || r.constructor[L], m = (r) => r[se], At = (r, e, t, s) => {
|
|
89
83
|
let n = s > 1 ? void 0 : s ? Object.getOwnPropertyDescriptor(e, t) : e;
|
|
90
84
|
for (let i = r.length - 1, a; i >= 0; i--)
|
|
91
85
|
(a = r[i]) && (n = a(n) || n);
|
|
92
86
|
return n;
|
|
93
|
-
},
|
|
87
|
+
}, ke = () => fe(), Ue = [
|
|
94
88
|
"id",
|
|
95
89
|
"createdAt",
|
|
96
90
|
"updatedAt",
|
|
@@ -98,7 +92,7 @@ const te = Symbol("ɵProxy"), L = Symbol("ɵMetadata"), se = Symbol("ɵStatus"),
|
|
|
98
92
|
"createdBy",
|
|
99
93
|
"updatedBy",
|
|
100
94
|
"removedBy"
|
|
101
|
-
],
|
|
95
|
+
], Ve = ["rev"], Ot = (r) => !!(Ue.includes(r) || Ve.includes(r) || r.startsWith("_")), u = (r, e, t) => Object.defineProperty(r, e, {
|
|
102
96
|
value: t,
|
|
103
97
|
enumerable: !1,
|
|
104
98
|
configurable: !1,
|
|
@@ -108,7 +102,7 @@ const te = Symbol("ɵProxy"), L = Symbol("ɵMetadata"), se = Symbol("ɵStatus"),
|
|
|
108
102
|
enumerable: !1,
|
|
109
103
|
configurable: !1,
|
|
110
104
|
writable: !0
|
|
111
|
-
}),
|
|
105
|
+
}), w = (r, e, t) => {
|
|
112
106
|
let s;
|
|
113
107
|
const n = {
|
|
114
108
|
get: () => (s = t(), n.get = () => s, s),
|
|
@@ -116,20 +110,20 @@ const te = Symbol("ɵProxy"), L = Symbol("ɵMetadata"), se = Symbol("ɵStatus"),
|
|
|
116
110
|
configurable: !1
|
|
117
111
|
};
|
|
118
112
|
return Object.defineProperty(r, e, n);
|
|
119
|
-
},
|
|
113
|
+
}, Ke = (r, e) => {
|
|
120
114
|
const t = {};
|
|
121
115
|
let s = !1;
|
|
122
116
|
r.defaultValueProperties.forEach((n) => {
|
|
123
|
-
e[n.name] === void 0 && (s = !0,
|
|
117
|
+
e[n.name] === void 0 && (s = !0, oe(n.default) ? t[n.name] = n.default() : t[n.name] = n.default);
|
|
124
118
|
}), s && Object.assign(e, t);
|
|
125
|
-
},
|
|
119
|
+
}, We = (r, e, t) => {
|
|
126
120
|
const { propertyMap: s, foreignKeyNames: n } = O(e);
|
|
127
121
|
Object.keys(t).forEach((i) => {
|
|
128
122
|
s.has(i) ? r.propertyMap.get(i)?.readonly !== !0 && (e[i] = t[i]) : n.includes(i) && (e[i] = t[i]);
|
|
129
123
|
});
|
|
130
124
|
};
|
|
131
|
-
var E = /* @__PURE__ */ ((r) => (r.uuid = "uuid", r.string = "string", r.number = "number", r.integer = "integer", r.boolean = "boolean", r.date = "date", r.json = "json", r))(E || {}), p = /* @__PURE__ */ ((r) => (r.ONE_TO_ONE = "1:1", r.ONE_TO_MANY = "1:m", r.MANY_TO_ONE = "m:1", r.MANY_TO_MANY = "m:n", r))(p || {}),
|
|
132
|
-
const
|
|
125
|
+
var E = /* @__PURE__ */ ((r) => (r.uuid = "uuid", r.string = "string", r.number = "number", r.integer = "integer", r.boolean = "boolean", r.date = "date", r.json = "json", r))(E || {}), p = /* @__PURE__ */ ((r) => (r.ONE_TO_ONE = "1:1", r.ONE_TO_MANY = "1:m", r.MANY_TO_ONE = "m:1", r.MANY_TO_MANY = "m:n", r))(p || {}), Fe = /* @__PURE__ */ ((r) => (r.Full = "full", r.Filter = "filter", r.None = "None", r))(Fe || {});
|
|
126
|
+
const ze = (r, e) => {
|
|
133
127
|
const t = [];
|
|
134
128
|
t.push(r);
|
|
135
129
|
const s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = { ...r };
|
|
@@ -141,7 +135,7 @@ const He = (r, e) => {
|
|
|
141
135
|
l.shift(), a.extends = l;
|
|
142
136
|
} else
|
|
143
137
|
a.extends = r.extends || [];
|
|
144
|
-
return a.displayName || (a.displayName =
|
|
138
|
+
return a.displayName || (a.displayName = ce(a.name).replace(" ", "")), a.relations.forEach((o) => {
|
|
145
139
|
o.mappedNamespace = o.mappedNamespace || "public";
|
|
146
140
|
}), t.reverse().forEach((o) => {
|
|
147
141
|
o.properties?.forEach((c) => {
|
|
@@ -153,26 +147,26 @@ const He = (r, e) => {
|
|
|
153
147
|
} else
|
|
154
148
|
n.set(c.name, c);
|
|
155
149
|
}), o.indexes?.forEach((c) => i.set(c.name, c));
|
|
156
|
-
}), u(a, "propertyMap", s), u(a, "relationMap", n), u(a, "indexMap", i),
|
|
150
|
+
}), u(a, "propertyMap", s), u(a, "relationMap", n), u(a, "indexMap", i), w(
|
|
157
151
|
a,
|
|
158
152
|
"defaultValueProperties",
|
|
159
153
|
() => Array.from(s.values()).filter((o) => o.default !== void 0)
|
|
160
|
-
),
|
|
154
|
+
), w(
|
|
161
155
|
a,
|
|
162
156
|
"foreignKeyRelations",
|
|
163
157
|
() => Array.from(a.relationMap.values()).filter(
|
|
164
158
|
(o) => o.kind === p.MANY_TO_ONE || o.kind === p.ONE_TO_ONE
|
|
165
159
|
)
|
|
166
|
-
),
|
|
160
|
+
), w(a, "foreignKeyRelationMap", () => {
|
|
167
161
|
const o = /* @__PURE__ */ new Map();
|
|
168
162
|
return a.foreignKeyRelations.forEach((c) => o.set(c.name, c)), o;
|
|
169
|
-
}),
|
|
163
|
+
}), w(a, "foreignKeyNames", () => a.foreignKeyRelations.map((o) => `${o.name}Id`)), u(
|
|
170
164
|
a,
|
|
171
165
|
"isForeignKey",
|
|
172
166
|
(o) => o && o.endsWith("Id") && a.foreignKeyNames.includes(o)
|
|
173
167
|
), a;
|
|
174
168
|
}, R = (r) => (e) => {
|
|
175
|
-
const t =
|
|
169
|
+
const t = ze(r, e);
|
|
176
170
|
if (u(e, L, t), r.abstract) return e;
|
|
177
171
|
const s = e;
|
|
178
172
|
return class extends s {
|
|
@@ -190,13 +184,23 @@ const He = (r, e) => {
|
|
|
190
184
|
constructor(n) {
|
|
191
185
|
super(n);
|
|
192
186
|
const i = this[ne];
|
|
193
|
-
if (!i) throw new
|
|
194
|
-
return
|
|
187
|
+
if (!i) throw new v("need init rxdb");
|
|
188
|
+
return Ke(t, this), n && We(t, this, n), i[te](this);
|
|
195
189
|
}
|
|
196
190
|
};
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
|
|
191
|
+
}, Rt = (r) => {
|
|
192
|
+
const e = r.features || {};
|
|
193
|
+
return R({
|
|
194
|
+
...r,
|
|
195
|
+
features: {
|
|
196
|
+
...e,
|
|
197
|
+
treeType: e.treeType || "adjacency-list"
|
|
198
|
+
},
|
|
199
|
+
repository: r.repository || "TreeRepository"
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
var He = Object.getOwnPropertyDescriptor, Ge = (r, e, t, s) => {
|
|
203
|
+
for (var n = s > 1 ? void 0 : s ? He(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
200
204
|
(a = r[i]) && (n = a(n) || n);
|
|
201
205
|
return n;
|
|
202
206
|
};
|
|
@@ -261,7 +265,7 @@ $ = Ge([
|
|
|
261
265
|
// 唯一索引
|
|
262
266
|
readonly: !0,
|
|
263
267
|
// 创建后不可修改
|
|
264
|
-
default: () =>
|
|
268
|
+
default: () => ke()
|
|
265
269
|
// 默认生成UUID
|
|
266
270
|
},
|
|
267
271
|
{
|
|
@@ -303,14 +307,14 @@ $ = Ge([
|
|
|
303
307
|
]
|
|
304
308
|
})
|
|
305
309
|
], $);
|
|
306
|
-
var
|
|
307
|
-
for (var n = s > 1 ? void 0 : s ?
|
|
310
|
+
var Je = Object.getOwnPropertyDescriptor, qe = (r, e, t, s) => {
|
|
311
|
+
for (var n = s > 1 ? void 0 : s ? Je(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
308
312
|
(a = r[i]) && (n = a(n) || n);
|
|
309
313
|
return n;
|
|
310
314
|
};
|
|
311
315
|
let X = class extends $ {
|
|
312
316
|
};
|
|
313
|
-
X =
|
|
317
|
+
X = qe([
|
|
314
318
|
R({
|
|
315
319
|
name: "TreeAdjacencyListEntityBase",
|
|
316
320
|
abstract: !0,
|
|
@@ -339,7 +343,7 @@ X = Qe([
|
|
|
339
343
|
]
|
|
340
344
|
})
|
|
341
345
|
], X);
|
|
342
|
-
const
|
|
346
|
+
const Qe = (r) => !!r.combinator, Xe = (r, e) => {
|
|
343
347
|
const t = e[r.field], { operator: s, value: n } = r;
|
|
344
348
|
switch (s) {
|
|
345
349
|
case "in":
|
|
@@ -363,9 +367,9 @@ const Xe = (r) => !!r.combinator, Ze = (r, e) => {
|
|
|
363
367
|
case "notEndWith":
|
|
364
368
|
return `${t}`.endsWith(`${n}`) === !1;
|
|
365
369
|
case "=":
|
|
366
|
-
return
|
|
370
|
+
return J(n, t);
|
|
367
371
|
case "!=":
|
|
368
|
-
return
|
|
372
|
+
return J(n, t) === !1;
|
|
369
373
|
case ">":
|
|
370
374
|
return t > n;
|
|
371
375
|
case ">=":
|
|
@@ -375,16 +379,16 @@ const Xe = (r) => !!r.combinator, Ze = (r, e) => {
|
|
|
375
379
|
case "<=":
|
|
376
380
|
return t <= n;
|
|
377
381
|
default:
|
|
378
|
-
throw new
|
|
382
|
+
throw new v(`Unknown operator: ${s}`);
|
|
379
383
|
}
|
|
380
384
|
}, k = (r, e) => {
|
|
381
|
-
if (
|
|
385
|
+
if (Qe(r)) {
|
|
382
386
|
const { combinator: t, rules: s } = r;
|
|
383
387
|
return t === "and" ? s.every((n) => k(n, e)) : s.some((n) => k(n, e));
|
|
384
388
|
} else
|
|
385
|
-
return
|
|
386
|
-
},
|
|
387
|
-
const { field: s, order: n } = t, i =
|
|
389
|
+
return Xe(r, e);
|
|
390
|
+
}, wt = (r, e) => k(e, r), Ze = (r, e, t) => {
|
|
391
|
+
const { field: s, order: n } = t, i = le(e, s);
|
|
388
392
|
if (n === "asc") {
|
|
389
393
|
if (r.some((c) => i < Reflect.get(c, s))) return !0;
|
|
390
394
|
if (r.every((c) => i > Reflect.get(c, s))) return !1;
|
|
@@ -392,10 +396,10 @@ const Xe = (r) => !!r.combinator, Ze = (r, e) => {
|
|
|
392
396
|
if (r.some((c) => i > Reflect.get(c, s))) return !0;
|
|
393
397
|
if (r.every((c) => i < Reflect.get(c, s))) return !1;
|
|
394
398
|
}
|
|
395
|
-
},
|
|
399
|
+
}, Nt = (r, e, t) => {
|
|
396
400
|
if (t.length === 0) return !1;
|
|
397
401
|
for (let s = 0; s < t.length; s++) {
|
|
398
|
-
const n = t[s], i =
|
|
402
|
+
const n = t[s], i = Ze(r, e, n);
|
|
399
403
|
if (i === void 0) {
|
|
400
404
|
if (s < t.length - 1) {
|
|
401
405
|
const { field: a } = n, o = Reflect.get(e, a);
|
|
@@ -405,8 +409,8 @@ const Xe = (r) => !!r.combinator, Ze = (r, e) => {
|
|
|
405
409
|
return i;
|
|
406
410
|
}
|
|
407
411
|
};
|
|
408
|
-
var
|
|
409
|
-
class
|
|
412
|
+
var et = /* @__PURE__ */ ((r) => (r.Synced = "Synced", r.Syncing = "Syncing", r.Never = "Never", r))(et || {});
|
|
413
|
+
class xt {
|
|
410
414
|
constructor(e, t) {
|
|
411
415
|
this.rxdb = e, this.EntityClass = t;
|
|
412
416
|
}
|
|
@@ -451,36 +455,36 @@ class ae {
|
|
|
451
455
|
/**
|
|
452
456
|
* 本地适配器
|
|
453
457
|
*/
|
|
454
|
-
localAdapterSub = new
|
|
458
|
+
localAdapterSub = new N("");
|
|
455
459
|
localAdapter$ = this.localAdapterSub.asObservable().pipe(
|
|
456
|
-
|
|
460
|
+
Y(Boolean),
|
|
457
461
|
I(),
|
|
458
462
|
f((e) => this.rxdb.getAdapter(e)),
|
|
459
|
-
|
|
463
|
+
A(1)
|
|
460
464
|
);
|
|
461
465
|
/**
|
|
462
466
|
* 本地仓库
|
|
463
467
|
*/
|
|
464
468
|
local$ = this.localAdapter$.pipe(
|
|
465
469
|
D((e) => e.getRepository(this.EntityType)),
|
|
466
|
-
|
|
470
|
+
A(1)
|
|
467
471
|
);
|
|
468
472
|
/**
|
|
469
473
|
* 远程适配器
|
|
470
474
|
*/
|
|
471
|
-
remoteAdapterSub = new
|
|
475
|
+
remoteAdapterSub = new N("");
|
|
472
476
|
remoteAdapter$ = this.remoteAdapterSub.asObservable().pipe(
|
|
473
|
-
|
|
477
|
+
Y(Boolean),
|
|
474
478
|
I(),
|
|
475
479
|
f((e) => this.rxdb.getAdapter(e)),
|
|
476
|
-
|
|
480
|
+
A(1)
|
|
477
481
|
);
|
|
478
482
|
/**
|
|
479
483
|
* 远程仓库
|
|
480
484
|
*/
|
|
481
485
|
remote$ = this.remoteAdapter$.pipe(
|
|
482
486
|
D((e) => e.getRepository(this.EntityType)),
|
|
483
|
-
|
|
487
|
+
A(1)
|
|
484
488
|
);
|
|
485
489
|
/**
|
|
486
490
|
* 同步配置
|
|
@@ -612,7 +616,7 @@ class ae {
|
|
|
612
616
|
_setLocalEntityStatus = (e) => m(e).local = !0;
|
|
613
617
|
_setLocalEntitiesStatus = (e) => e.forEach(this._setLocalEntityStatus);
|
|
614
618
|
}
|
|
615
|
-
class
|
|
619
|
+
class tt extends ae {
|
|
616
620
|
/**
|
|
617
621
|
* 查询子孙
|
|
618
622
|
*/
|
|
@@ -644,7 +648,7 @@ class st extends ae {
|
|
|
644
648
|
return this.local$.pipe(f((n) => n.countAncestors(e, t, s)));
|
|
645
649
|
}
|
|
646
650
|
}
|
|
647
|
-
const
|
|
651
|
+
const st = (r) => {
|
|
648
652
|
const e = m(r), t = r;
|
|
649
653
|
let s = [];
|
|
650
654
|
const n = () => {
|
|
@@ -668,17 +672,17 @@ const nt = (r) => {
|
|
|
668
672
|
*/
|
|
669
673
|
set: (o, c, l, d) => {
|
|
670
674
|
if (o[c] === l) return !0;
|
|
671
|
-
if (
|
|
672
|
-
const h = o[x] ||
|
|
675
|
+
if (de(c) === !1) {
|
|
676
|
+
const h = o[x] || Ye;
|
|
673
677
|
s.push({ updatedBy: h, prop: c, value: l, oldValue: o[c] }), e[B] = !0, e.modified = !0, clearTimeout(i), i = setTimeout(() => n(), 0);
|
|
674
678
|
}
|
|
675
679
|
return Reflect.set(o, c, l, d);
|
|
676
680
|
}
|
|
677
681
|
};
|
|
678
682
|
return new Proxy(r, a);
|
|
679
|
-
},
|
|
683
|
+
}, nt = (r, e, t) => {
|
|
680
684
|
const s = t.rxdb.schema.getEntityType(r.mappedEntity, r.mappedNamespace);
|
|
681
|
-
if (!s) throw new
|
|
685
|
+
if (!s) throw new v(`mapped entity not found: ${r.mappedEntity}`);
|
|
682
686
|
const n = r.name + "Id", i = r.name + "$";
|
|
683
687
|
let a;
|
|
684
688
|
switch (r.kind) {
|
|
@@ -690,9 +694,9 @@ const nt = (r) => {
|
|
|
690
694
|
case p.MANY_TO_ONE:
|
|
691
695
|
case p.ONE_TO_ONE:
|
|
692
696
|
a = function() {
|
|
693
|
-
const o = this, c = m(o), l = new
|
|
697
|
+
const o = this, c = m(o), l = new N(o[n]), d = l.asObservable().pipe(
|
|
694
698
|
f((h) => h ? t.getRepository(s).get(h) : j(null)),
|
|
695
|
-
|
|
699
|
+
A(1)
|
|
696
700
|
);
|
|
697
701
|
return u(d, "set", (h) => {
|
|
698
702
|
h || d.remove(), Reflect.get(o, n) != h.id && (c.addRelationEntity(r, h), l.next(h.id), Reflect.set(o, n, h.id));
|
|
@@ -747,7 +751,7 @@ const nt = (r) => {
|
|
|
747
751
|
case p.MANY_TO_MANY:
|
|
748
752
|
a = function() {
|
|
749
753
|
const o = this, c = m(o), l = r.name + "Id";
|
|
750
|
-
if (!r.junctionEntityType) throw new
|
|
754
|
+
if (!r.junctionEntityType) throw new v("junction entity not found");
|
|
751
755
|
const d = t.getRepository(r.junctionEntityType).findAll({
|
|
752
756
|
combinator: "and",
|
|
753
757
|
rules: [
|
|
@@ -796,13 +800,8 @@ const nt = (r) => {
|
|
|
796
800
|
enumerable: !1,
|
|
797
801
|
configurable: !1
|
|
798
802
|
});
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
[p.MANY_TO_ONE]: 1,
|
|
802
|
-
[p.ONE_TO_ONE]: -1,
|
|
803
|
-
[p.MANY_TO_MANY]: 1
|
|
804
|
-
});
|
|
805
|
-
class it {
|
|
803
|
+
};
|
|
804
|
+
class rt {
|
|
806
805
|
/**
|
|
807
806
|
* 创建实体状态实例
|
|
808
807
|
*
|
|
@@ -839,7 +838,7 @@ class it {
|
|
|
839
838
|
* 实体变更记录的可观察对象
|
|
840
839
|
* 用于发布实体变更通知
|
|
841
840
|
*/
|
|
842
|
-
#t = new
|
|
841
|
+
#t = new N([]);
|
|
843
842
|
/**
|
|
844
843
|
* 实体状态快照数组
|
|
845
844
|
* 用于存储实体在不同时间点的完整状态
|
|
@@ -964,7 +963,7 @@ class it {
|
|
|
964
963
|
*/
|
|
965
964
|
addEntityPatch(e, t, s, n = Date.now()) {
|
|
966
965
|
const i = performance.now(), a = { patch: e, inversePatch: t, recordAt: n, timeStamp: i, updatedBy: s };
|
|
967
|
-
this._patches.length === 0 && this.#s.push(Object.freeze(structuredClone(this.origin))),
|
|
966
|
+
this._patches.length === 0 && this.#s.push(Object.freeze(structuredClone(this.origin))), w(a, "snapshot", () => {
|
|
968
967
|
const c = this._patches.findIndex((h) => h === a), l = this.#s[c];
|
|
969
968
|
if (l) return l;
|
|
970
969
|
let d;
|
|
@@ -974,7 +973,7 @@ class it {
|
|
|
974
973
|
}
|
|
975
974
|
return d;
|
|
976
975
|
}), this._patches.push(a), this.#t.next(this._patches);
|
|
977
|
-
const o = new
|
|
976
|
+
const o = new De(this.proxyTarget, e, t, n, i, s);
|
|
978
977
|
this.rxdb.dispatchEvent(o);
|
|
979
978
|
}
|
|
980
979
|
/**
|
|
@@ -984,15 +983,12 @@ class it {
|
|
|
984
983
|
* @returns 需要保存的实体数组
|
|
985
984
|
*/
|
|
986
985
|
getNeedSaveRelationEntities() {
|
|
987
|
-
const e = /* @__PURE__ */ new
|
|
986
|
+
const e = /* @__PURE__ */ new Set([this.proxyTarget]);
|
|
988
987
|
return this.#e.forEach(
|
|
989
|
-
(
|
|
990
|
-
m(
|
|
988
|
+
(t) => t.forEach((s) => {
|
|
989
|
+
m(s).modified === !0 && e.add(s);
|
|
991
990
|
})
|
|
992
|
-
), Array.from(
|
|
993
|
-
const i = e.get(s) || 0, a = e.get(n) || 0;
|
|
994
|
-
return i - a;
|
|
995
|
-
});
|
|
991
|
+
), Array.from(e);
|
|
996
992
|
}
|
|
997
993
|
/**
|
|
998
994
|
* 添加关系实体
|
|
@@ -1050,7 +1046,7 @@ class it {
|
|
|
1050
1046
|
return t ? this.#e.get(e) : (t = /* @__PURE__ */ new Set(), this.#e.set(e, t), t);
|
|
1051
1047
|
}
|
|
1052
1048
|
}
|
|
1053
|
-
class
|
|
1049
|
+
class at {
|
|
1054
1050
|
/**
|
|
1055
1051
|
* 创建实体管理器实例
|
|
1056
1052
|
*
|
|
@@ -1074,11 +1070,11 @@ class ot {
|
|
|
1074
1070
|
);
|
|
1075
1071
|
}), Object.keys(Z).forEach(
|
|
1076
1072
|
(n) => u(t.prototype, n, Z[n](this, t))
|
|
1077
|
-
), s.relationMap.forEach((n) =>
|
|
1073
|
+
), s.relationMap.forEach((n) => nt(n, t, this));
|
|
1078
1074
|
}), u(this, te, (t) => {
|
|
1079
1075
|
const s = this.#i(t, { local: !1, remote: !1, modified: !0 });
|
|
1080
1076
|
this.addEntityCache(s);
|
|
1081
|
-
const n = new
|
|
1077
|
+
const n = new ye(s);
|
|
1082
1078
|
return this.rxdb.dispatchEvent(n), s;
|
|
1083
1079
|
}), u(this, re, (t) => {
|
|
1084
1080
|
const { EntityType: s, data: n } = t;
|
|
@@ -1208,12 +1204,12 @@ class ot {
|
|
|
1208
1204
|
*/
|
|
1209
1205
|
async remove(e) {
|
|
1210
1206
|
const t = e.constructor;
|
|
1211
|
-
this.rxdb.dispatchEvent(new
|
|
1207
|
+
this.rxdb.dispatchEvent(new Me(e));
|
|
1212
1208
|
try {
|
|
1213
1209
|
const s = await this.#n(t).remove(e);
|
|
1214
|
-
return this.rxdb.dispatchEvent(new
|
|
1210
|
+
return this.rxdb.dispatchEvent(new Se(s)), s;
|
|
1215
1211
|
} catch (s) {
|
|
1216
|
-
throw this.rxdb.dispatchEvent(new
|
|
1212
|
+
throw this.rxdb.dispatchEvent(new Ce(e, s)), s;
|
|
1217
1213
|
}
|
|
1218
1214
|
}
|
|
1219
1215
|
/**
|
|
@@ -1227,10 +1223,10 @@ class ot {
|
|
|
1227
1223
|
*/
|
|
1228
1224
|
async create(e) {
|
|
1229
1225
|
const t = e.constructor;
|
|
1230
|
-
this.rxdb.dispatchEvent(new
|
|
1226
|
+
this.rxdb.dispatchEvent(new ge(e));
|
|
1231
1227
|
try {
|
|
1232
1228
|
const s = await this.#n(t).create(e);
|
|
1233
|
-
return this.rxdb.dispatchEvent(new
|
|
1229
|
+
return this.rxdb.dispatchEvent(new be(s)), s;
|
|
1234
1230
|
} catch (s) {
|
|
1235
1231
|
throw this.rxdb.dispatchEvent(new ve(e, s)), s;
|
|
1236
1232
|
}
|
|
@@ -1247,11 +1243,11 @@ class ot {
|
|
|
1247
1243
|
async update(e) {
|
|
1248
1244
|
const t = e.constructor, s = m(e);
|
|
1249
1245
|
if (s.modified) {
|
|
1250
|
-
const n =
|
|
1251
|
-
this.rxdb.dispatchEvent(new
|
|
1246
|
+
const n = he(s.target, (i, a) => i === s.origin[a]);
|
|
1247
|
+
this.rxdb.dispatchEvent(new Oe(e));
|
|
1252
1248
|
try {
|
|
1253
1249
|
const i = await this.#n(t).update(e, n);
|
|
1254
|
-
return this.rxdb.dispatchEvent(new
|
|
1250
|
+
return this.rxdb.dispatchEvent(new Re(i)), i;
|
|
1255
1251
|
} catch (i) {
|
|
1256
1252
|
throw this.rxdb.dispatchEvent(new we(e, i)), i;
|
|
1257
1253
|
}
|
|
@@ -1288,10 +1284,10 @@ class ot {
|
|
|
1288
1284
|
s = new ae(this.rxdb, e);
|
|
1289
1285
|
break;
|
|
1290
1286
|
case "TreeRepository":
|
|
1291
|
-
s = new
|
|
1287
|
+
s = new tt(this.rxdb, e);
|
|
1292
1288
|
break;
|
|
1293
1289
|
default:
|
|
1294
|
-
throw new
|
|
1290
|
+
throw new v("repository must be 'Repository' or 'TreeRepository'");
|
|
1295
1291
|
}
|
|
1296
1292
|
return this.#e.set(e, s), s;
|
|
1297
1293
|
}
|
|
@@ -1330,9 +1326,9 @@ class ot {
|
|
|
1330
1326
|
*/
|
|
1331
1327
|
#i(e, t) {
|
|
1332
1328
|
Q(e, x, "");
|
|
1333
|
-
const s = new
|
|
1329
|
+
const s = new rt(this.rxdb, { target: e, ...t });
|
|
1334
1330
|
Q(e, se, s);
|
|
1335
|
-
const n =
|
|
1331
|
+
const n = st(e);
|
|
1336
1332
|
return u(s, "proxyTarget", n), n;
|
|
1337
1333
|
}
|
|
1338
1334
|
}
|
|
@@ -1343,7 +1339,7 @@ const Z = {
|
|
|
1343
1339
|
remove: (r) => function() {
|
|
1344
1340
|
return r.remove(this);
|
|
1345
1341
|
}
|
|
1346
|
-
},
|
|
1342
|
+
}, it = (r) => {
|
|
1347
1343
|
const [{ metadata: e, relation: t }, { metadata: s, relation: n }] = r, i = Array.from(/* @__PURE__ */ new Set([e.namespace, s.namespace])).sort().join("_") || void 0;
|
|
1348
1344
|
return {
|
|
1349
1345
|
name: Array.from(/* @__PURE__ */ new Set([e.name, s.name])).sort().join("_"),
|
|
@@ -1364,12 +1360,12 @@ const Z = {
|
|
|
1364
1360
|
]
|
|
1365
1361
|
};
|
|
1366
1362
|
};
|
|
1367
|
-
var
|
|
1368
|
-
for (var n = s > 1 ? void 0 : s ?
|
|
1363
|
+
var ot = Object.getOwnPropertyDescriptor, ct = (r, e, t, s) => {
|
|
1364
|
+
for (var n = s > 1 ? void 0 : s ? ot(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
1369
1365
|
(a = r[i]) && (n = a(n) || n);
|
|
1370
1366
|
return n;
|
|
1371
1367
|
};
|
|
1372
|
-
let
|
|
1368
|
+
let P = class {
|
|
1373
1369
|
id;
|
|
1374
1370
|
namespace;
|
|
1375
1371
|
entity;
|
|
@@ -1379,7 +1375,7 @@ let Y = class {
|
|
|
1379
1375
|
patch;
|
|
1380
1376
|
changedAt;
|
|
1381
1377
|
};
|
|
1382
|
-
|
|
1378
|
+
P = ct([
|
|
1383
1379
|
R({
|
|
1384
1380
|
name: "RxDBChange",
|
|
1385
1381
|
log: !1,
|
|
@@ -1431,9 +1427,9 @@ Y = dt([
|
|
|
1431
1427
|
}
|
|
1432
1428
|
]
|
|
1433
1429
|
})
|
|
1434
|
-
],
|
|
1435
|
-
var
|
|
1436
|
-
for (var n = s > 1 ? void 0 : s ?
|
|
1430
|
+
], P);
|
|
1431
|
+
var lt = Object.getOwnPropertyDescriptor, dt = (r, e, t, s) => {
|
|
1432
|
+
for (var n = s > 1 ? void 0 : s ? lt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
1437
1433
|
(a = r[i]) && (n = a(n) || n);
|
|
1438
1434
|
return n;
|
|
1439
1435
|
};
|
|
@@ -1442,7 +1438,7 @@ let M = class {
|
|
|
1442
1438
|
name;
|
|
1443
1439
|
executedAt;
|
|
1444
1440
|
};
|
|
1445
|
-
M =
|
|
1441
|
+
M = dt([
|
|
1446
1442
|
R({
|
|
1447
1443
|
name: "RxDBMigration",
|
|
1448
1444
|
log: !1,
|
|
@@ -1466,17 +1462,17 @@ M = pt([
|
|
|
1466
1462
|
]
|
|
1467
1463
|
})
|
|
1468
1464
|
], M);
|
|
1469
|
-
var
|
|
1470
|
-
for (var n = s > 1 ? void 0 : s ?
|
|
1465
|
+
var ht = Object.getOwnPropertyDescriptor, pt = (r, e, t, s) => {
|
|
1466
|
+
for (var n = s > 1 ? void 0 : s ? ht(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
1471
1467
|
(a = r[i]) && (n = a(n) || n);
|
|
1472
1468
|
return n;
|
|
1473
1469
|
};
|
|
1474
1470
|
const C = (r, e) => e + ":" + r;
|
|
1475
|
-
class
|
|
1471
|
+
class ut {
|
|
1476
1472
|
constructor(e) {
|
|
1477
1473
|
this.rxdb = e;
|
|
1478
1474
|
const { entities: t } = this.rxdb.options;
|
|
1479
|
-
[
|
|
1475
|
+
[P, M, ...t].forEach((s) => {
|
|
1480
1476
|
const n = O(s), { name: i, namespace: a } = n, o = C(i, a);
|
|
1481
1477
|
this.#e.set(o, n), this.#t.set(o, s);
|
|
1482
1478
|
}), this.#e.forEach((s) => {
|
|
@@ -1484,12 +1480,12 @@ class Et {
|
|
|
1484
1480
|
n.forEach((i) => {
|
|
1485
1481
|
if (i.kind === p.MANY_TO_MANY) {
|
|
1486
1482
|
const a = this.findMappedRelation(s, i);
|
|
1487
|
-
if (!a) throw new
|
|
1488
|
-
const o =
|
|
1483
|
+
if (!a) throw new v("mapped relation not found");
|
|
1484
|
+
const o = it([{ metadata: s, relation: i }, a]), c = C(o.name, o.namespace);
|
|
1489
1485
|
if (this.#e.has(c) === !1) {
|
|
1490
1486
|
let l = class extends $ {
|
|
1491
1487
|
};
|
|
1492
|
-
l =
|
|
1488
|
+
l = pt([
|
|
1493
1489
|
R(o)
|
|
1494
1490
|
], l);
|
|
1495
1491
|
const d = O(l);
|
|
@@ -1541,15 +1537,15 @@ class Et {
|
|
|
1541
1537
|
* @param field 查询条件的字段
|
|
1542
1538
|
*/
|
|
1543
1539
|
getFieldRelations(e, t) {
|
|
1544
|
-
if (t.includes(".") === !1) throw new
|
|
1540
|
+
if (t.includes(".") === !1) throw new v(`field '${t}' 必须是关属性查询`);
|
|
1545
1541
|
const s = [], n = t.split("."), i = n.length - 1;
|
|
1546
1542
|
let a = e, o, c = !1, l = "";
|
|
1547
1543
|
return n.length === 2 && n[1] == "id" && (c = a.foreignKeyRelationMap.has(n[0]), l = n[0] + "Id"), n.forEach((d, h) => {
|
|
1548
1544
|
if (h === i) {
|
|
1549
|
-
if (a.propertyMap.has(d) === !1) throw new
|
|
1545
|
+
if (a.propertyMap.has(d) === !1) throw new v(`property '${d}' not found`);
|
|
1550
1546
|
o = a.propertyMap.get(d);
|
|
1551
1547
|
} else {
|
|
1552
|
-
if (a.relationMap.has(d) === !1) throw new
|
|
1548
|
+
if (a.relationMap.has(d) === !1) throw new v(`relation '${d}' not found`);
|
|
1553
1549
|
const y = a.relationMap.get(d);
|
|
1554
1550
|
s.push({ relation: y, metadata: a }), a = this.getEntityMetadata(y.mappedEntity, y.mappedNamespace);
|
|
1555
1551
|
}
|
|
@@ -1575,7 +1571,7 @@ class Et {
|
|
|
1575
1571
|
return this.#t.get(s);
|
|
1576
1572
|
}
|
|
1577
1573
|
}
|
|
1578
|
-
class
|
|
1574
|
+
class Mt {
|
|
1579
1575
|
// 插件
|
|
1580
1576
|
#e = /* @__PURE__ */ new WeakSet();
|
|
1581
1577
|
// events
|
|
@@ -1585,8 +1581,8 @@ class Ct {
|
|
|
1585
1581
|
// 适配器
|
|
1586
1582
|
#r = /* @__PURE__ */ new Map();
|
|
1587
1583
|
#a = /* @__PURE__ */ new Map();
|
|
1588
|
-
#i = new
|
|
1589
|
-
#l = this.#i.asObservable().pipe(I(),
|
|
1584
|
+
#i = new N(0);
|
|
1585
|
+
#l = this.#i.asObservable().pipe(I(), A(1));
|
|
1590
1586
|
// 上下文
|
|
1591
1587
|
#c = {};
|
|
1592
1588
|
/**
|
|
@@ -1615,7 +1611,7 @@ class Ct {
|
|
|
1615
1611
|
},
|
|
1616
1612
|
e
|
|
1617
1613
|
)
|
|
1618
|
-
), this.schema = new
|
|
1614
|
+
), this.schema = new ut(this), this.em = new at(this), this.context = { ...this.options.context }, this.addEventListener(F, () => {
|
|
1619
1615
|
this.#n = !0;
|
|
1620
1616
|
}), this.addEventListener(z, () => {
|
|
1621
1617
|
this.#n = !1, this.#s.forEach((s) => this.dispatchEvent(s)), this.#s = [];
|
|
@@ -1623,7 +1619,7 @@ class Ct {
|
|
|
1623
1619
|
this.#n = !1, this.#s = [];
|
|
1624
1620
|
});
|
|
1625
1621
|
const t = this.em;
|
|
1626
|
-
this.addEventListener(ee, (s) => t[re](s)),
|
|
1622
|
+
this.addEventListener(ee, (s) => t[re](s)), pe(this.options);
|
|
1627
1623
|
}
|
|
1628
1624
|
/**
|
|
1629
1625
|
* 注册适配器
|
|
@@ -1637,12 +1633,12 @@ class Ct {
|
|
|
1637
1633
|
getAdapter(e) {
|
|
1638
1634
|
return this.#a.has(e) ? this.#a.get(e) : this.#l.pipe(
|
|
1639
1635
|
D(() => this.#r.get(e)),
|
|
1640
|
-
|
|
1636
|
+
Y(Boolean),
|
|
1641
1637
|
I(),
|
|
1642
1638
|
f((t) => {
|
|
1643
1639
|
if (!this.#a.has(e)) {
|
|
1644
1640
|
const s = t(this);
|
|
1645
|
-
|
|
1641
|
+
ue(s) ? this.#a.set(e, q(() => s).pipe(A(1))) : this.#a.set(e, j(s).pipe(A(1)));
|
|
1646
1642
|
}
|
|
1647
1643
|
return this.#a.get(e);
|
|
1648
1644
|
})
|
|
@@ -1667,9 +1663,9 @@ class Ct {
|
|
|
1667
1663
|
connect(e) {
|
|
1668
1664
|
return this.getAdapter(e).pipe(
|
|
1669
1665
|
f((t) => t.connect()),
|
|
1670
|
-
f((t) =>
|
|
1666
|
+
f((t) => je(e, this.options) ? q(async () => {
|
|
1671
1667
|
if (!await t.isTableExisted(M)) {
|
|
1672
|
-
await t.createTable(M), await t.createTable(
|
|
1668
|
+
await t.createTable(M), await t.createTable(P);
|
|
1673
1669
|
for (let n = 0; n < this.options.entities.length; n++) {
|
|
1674
1670
|
const i = this.options.entities[n];
|
|
1675
1671
|
try {
|
|
@@ -1689,7 +1685,7 @@ class Ct {
|
|
|
1689
1685
|
this.#o(e).delete(t);
|
|
1690
1686
|
}
|
|
1691
1687
|
dispatchEvent(e) {
|
|
1692
|
-
this.#n &&
|
|
1688
|
+
this.#n && Le(e) === !1 ? this.#s.push(e) : this.#o(e.type).forEach((t) => t.call(this, e));
|
|
1693
1689
|
}
|
|
1694
1690
|
#o(e) {
|
|
1695
1691
|
if (this.#t.has(e))
|
|
@@ -1705,79 +1701,79 @@ class ie {
|
|
|
1705
1701
|
this.rxdb = e;
|
|
1706
1702
|
}
|
|
1707
1703
|
}
|
|
1708
|
-
class
|
|
1704
|
+
class St extends ie {
|
|
1709
1705
|
}
|
|
1710
|
-
class
|
|
1706
|
+
class Ct extends ie {
|
|
1711
1707
|
}
|
|
1712
|
-
class
|
|
1708
|
+
class It {
|
|
1713
1709
|
constructor(e) {
|
|
1714
1710
|
this.rxdb = e;
|
|
1715
1711
|
}
|
|
1716
1712
|
}
|
|
1717
1713
|
export {
|
|
1718
1714
|
ee as DATABASE_DELETE,
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1715
|
+
Be as DATABASE_INSERT,
|
|
1716
|
+
$e as DATABASE_UPDATE,
|
|
1717
|
+
_e as ENTITY_CREATE_ERROR_EVENT,
|
|
1722
1718
|
V as ENTITY_CREATE_EVENT,
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1719
|
+
me as ENTITY_CREATE_SUCCESS_EVENT,
|
|
1720
|
+
Ee as ENTITY_NEW_EVENT,
|
|
1721
|
+
Ie as ENTITY_PATCH_EVENT,
|
|
1722
|
+
xe as ENTITY_REMOVE_ERROR_EVENT,
|
|
1727
1723
|
W as ENTITY_REMOVE_EVENT,
|
|
1728
|
-
|
|
1729
|
-
|
|
1724
|
+
Ne as ENTITY_REMOVE_SUCCESS_EVENT,
|
|
1725
|
+
Ae as ENTITY_UPDATE_ERROR_EVENT,
|
|
1730
1726
|
K as ENTITY_UPDATE_EVENT,
|
|
1731
|
-
|
|
1727
|
+
Te as ENTITY_UPDATE_SUCCESS_EVENT,
|
|
1732
1728
|
R as Entity,
|
|
1733
1729
|
$ as EntityBase,
|
|
1734
1730
|
ve as EntityCreateErrorEvent,
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1731
|
+
ge as EntityCreateEvent,
|
|
1732
|
+
be as EntityCreateSuccessEvent,
|
|
1733
|
+
ye as EntityNewEvent,
|
|
1734
|
+
De as EntityPatchEvent,
|
|
1735
|
+
Ce as EntityRemoveErrorEvent,
|
|
1736
|
+
Me as EntityRemoveEvent,
|
|
1737
|
+
Se as EntityRemoveSuccessEvent,
|
|
1742
1738
|
we as EntityUpdateErrorEvent,
|
|
1743
|
-
|
|
1744
|
-
|
|
1739
|
+
Oe as EntityUpdateEvent,
|
|
1740
|
+
Re as EntityUpdateSuccessEvent,
|
|
1745
1741
|
E as PropertyType,
|
|
1746
1742
|
p as RelationKind,
|
|
1747
|
-
|
|
1748
|
-
|
|
1743
|
+
xt as RepositoryBase,
|
|
1744
|
+
Mt as RxDB,
|
|
1749
1745
|
ie as RxDBAdapterBase,
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1746
|
+
bt as RxDBAdapterDeleteChangeEvent,
|
|
1747
|
+
vt as RxDBAdapterInsertChangeEvent,
|
|
1748
|
+
St as RxDBAdapterLocalBase,
|
|
1749
|
+
Ct as RxDBAdapterRemoteBase,
|
|
1750
|
+
Tt as RxDBAdapterUpdateChangeEvent,
|
|
1751
|
+
P as RxDBChange,
|
|
1752
|
+
v as RxDBError,
|
|
1757
1753
|
M as RxDBMigration,
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1754
|
+
It as RxDBPluginBase,
|
|
1755
|
+
et as SyncStatus,
|
|
1756
|
+
Fe as SyncType,
|
|
1761
1757
|
F as TRANSACTION_BEGIN,
|
|
1762
1758
|
z as TRANSACTION_COMMIT,
|
|
1763
1759
|
H as TRANSACTION_ROLLBACK,
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1760
|
+
mt as TransactionBeginEvent,
|
|
1761
|
+
_t as TransactionCommitEvent,
|
|
1762
|
+
gt as TransactionRollbackEvent,
|
|
1767
1763
|
X as TreeAdjacencyListEntityBase,
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1764
|
+
Rt as TreeEntity,
|
|
1765
|
+
At as __decorateClass,
|
|
1766
|
+
Ke as fillDefaultValue,
|
|
1767
|
+
We as fillInitValue,
|
|
1772
1768
|
O as getEntityMetadata,
|
|
1773
1769
|
m as getEntityStatus,
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1770
|
+
Nt as isEntityEffectOrderBy,
|
|
1771
|
+
Ot as isEntityInternalName,
|
|
1772
|
+
wt as isEntityMatchRuleGroup,
|
|
1773
|
+
Qe as isRuleGroup,
|
|
1778
1774
|
u as setSafeObjectKey,
|
|
1779
|
-
|
|
1775
|
+
w as setSafeObjectKeyLazyInitOnce,
|
|
1780
1776
|
Q as setSafeObjectWritableKey,
|
|
1781
|
-
|
|
1782
|
-
|
|
1777
|
+
ze as transitionMetadata,
|
|
1778
|
+
ke as uuid
|
|
1783
1779
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiao/rxdb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"uuid": "^11.1.0",
|
|
8
8
|
"type-fest": "^4.41.0",
|
|
9
|
-
"@aiao/utils": "0.0.
|
|
9
|
+
"@aiao/utils": "0.0.2",
|
|
10
10
|
"rxjs": "~7.8.0"
|
|
11
11
|
},
|
|
12
12
|
".": {
|
package/rxdb-utils.d.ts
CHANGED
|
@@ -15,6 +15,6 @@ export declare const getEntityStatus: <T extends EntityType>(target: InstanceTyp
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const __decorateClass: (decorators: any, target: any, key: any, kind: number) => any;
|
|
17
17
|
/**
|
|
18
|
-
* 生成 uuid
|
|
18
|
+
* 生成 uuid v7
|
|
19
19
|
*/
|
|
20
20
|
export declare const uuid: () => UUID;
|
package/rxdb.interface.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SyncOptions } from './entity/entity-metadata-options.interface';
|
|
2
2
|
import { EntityType } from './entity/entity.interface';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 升级脚本
|
|
5
5
|
*/
|
|
6
6
|
export interface MigrationType {
|
|
7
7
|
up(): Promise<void>;
|
|
@@ -11,6 +11,9 @@ export interface MigrationType {
|
|
|
11
11
|
* RxDB 环境上下文
|
|
12
12
|
*/
|
|
13
13
|
export interface RxDBContext {
|
|
14
|
+
/**
|
|
15
|
+
* 用户 ID
|
|
16
|
+
*/
|
|
14
17
|
userId?: string;
|
|
15
18
|
}
|
|
16
19
|
/**
|
package/rxdb.private.d.ts
CHANGED
|
@@ -23,9 +23,21 @@ export declare const STATUS_CHECK: unique symbol;
|
|
|
23
23
|
* 实体管理器
|
|
24
24
|
*/
|
|
25
25
|
export declare const ENTITY_MANAGER: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* 实体删除检查
|
|
28
|
+
*/
|
|
26
29
|
export declare const ɵEntityDeleteCheck: unique symbol;
|
|
30
|
+
/**
|
|
31
|
+
* 更新者
|
|
32
|
+
*/
|
|
27
33
|
export declare const UPDATED_BY: unique symbol;
|
|
34
|
+
/**
|
|
35
|
+
* 更新来自系统
|
|
36
|
+
*/
|
|
28
37
|
export declare const UPDATED_BY_SYSTEM: string;
|
|
38
|
+
/**
|
|
39
|
+
* 更新来自用户
|
|
40
|
+
*/
|
|
29
41
|
export declare const UPDATED_BY_USER: string;
|
|
30
42
|
export type UpdatedBy = typeof UPDATED_BY_SYSTEM | typeof UPDATED_BY_USER | UUID | null;
|
|
31
43
|
/**
|
|
@@ -44,7 +56,20 @@ export declare const isDatabaseEvent: (event: RxDBEvent) => boolean;
|
|
|
44
56
|
* 实体管理内部方法
|
|
45
57
|
*/
|
|
46
58
|
export type EntityManagerPrivate = {
|
|
59
|
+
/**
|
|
60
|
+
* 设置实体代理创建函数
|
|
61
|
+
* 用于创建新的实体代理对象,并初始化其状态
|
|
62
|
+
*
|
|
63
|
+
* @param entity - 要代理的实体
|
|
64
|
+
* @returns 代理后的实体实例
|
|
65
|
+
*/
|
|
47
66
|
[ɵProxy]: (entity: any) => any;
|
|
67
|
+
/**
|
|
68
|
+
* 设置实体删除检查函数
|
|
69
|
+
* 用于处理数据库适配器的删除事件,更新实体状态
|
|
70
|
+
*
|
|
71
|
+
* @param event - 删除事件
|
|
72
|
+
*/
|
|
48
73
|
[ɵEntityDeleteCheck]: (event: RxDBEvent) => void;
|
|
49
74
|
} & EntityManager;
|
|
50
75
|
/**
|