@aiao/rxdb-query-builder 0.0.11 → 0.0.12
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 +145 -145
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { v4 as U } from "uuid";
|
|
2
2
|
import { BehaviorSubject as W, map as k, distinctUntilChanged as $ } from "rxjs";
|
|
3
3
|
import { RelationKind as B, PropertyType as g } from "@aiao/rxdb";
|
|
4
|
-
function v(
|
|
5
|
-
return "combinator" in
|
|
4
|
+
function v(n) {
|
|
5
|
+
return "combinator" in n && "rules" in n;
|
|
6
6
|
}
|
|
7
|
-
function M(
|
|
8
|
-
return "field" in
|
|
7
|
+
function M(n) {
|
|
8
|
+
return "field" in n && "operator" in n;
|
|
9
9
|
}
|
|
10
10
|
const O = [
|
|
11
11
|
// 相等操作符
|
|
@@ -136,41 +136,41 @@ const O = [
|
|
|
136
136
|
applicableTypes: ["relation"]
|
|
137
137
|
}
|
|
138
138
|
];
|
|
139
|
-
function ye(
|
|
140
|
-
return e.filter((t) => t.applicableTypes.includes(
|
|
139
|
+
function ye(n, e = O) {
|
|
140
|
+
return e.filter((t) => t.applicableTypes.includes(n));
|
|
141
141
|
}
|
|
142
|
-
function D(
|
|
143
|
-
return
|
|
142
|
+
function D(n) {
|
|
143
|
+
return n == null || Array.isArray(n);
|
|
144
144
|
}
|
|
145
145
|
const Y = [
|
|
146
146
|
{
|
|
147
147
|
name: "stringType",
|
|
148
148
|
appliesTo: ["string"],
|
|
149
149
|
message: "值必须是字符串类型",
|
|
150
|
-
validate: (
|
|
150
|
+
validate: (n) => D(n.value) ? !0 : typeof n.value == "string"
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
153
|
name: "numberType",
|
|
154
154
|
appliesTo: ["number"],
|
|
155
155
|
message: "值必须是数字类型",
|
|
156
|
-
validate: (
|
|
156
|
+
validate: (n) => D(n.value) ? !0 : typeof n.value == "number" && !isNaN(n.value)
|
|
157
157
|
},
|
|
158
158
|
{
|
|
159
159
|
name: "booleanType",
|
|
160
160
|
appliesTo: ["boolean"],
|
|
161
161
|
message: "值必须是布尔类型",
|
|
162
|
-
validate: (
|
|
162
|
+
validate: (n) => D(n.value) ? !0 : typeof n.value == "boolean"
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
name: "dateType",
|
|
166
166
|
appliesTo: ["date"],
|
|
167
167
|
message: "值必须是有效日期",
|
|
168
|
-
validate: (
|
|
169
|
-
if (D(
|
|
170
|
-
if (
|
|
171
|
-
return !isNaN(
|
|
172
|
-
if (typeof
|
|
173
|
-
const e = new Date(
|
|
168
|
+
validate: (n) => {
|
|
169
|
+
if (D(n.value)) return !0;
|
|
170
|
+
if (n.value instanceof Date)
|
|
171
|
+
return !isNaN(n.value.getTime());
|
|
172
|
+
if (typeof n.value == "string") {
|
|
173
|
+
const e = new Date(n.value);
|
|
174
174
|
return !isNaN(e.getTime());
|
|
175
175
|
}
|
|
176
176
|
return !1;
|
|
@@ -188,8 +188,8 @@ const Y = [
|
|
|
188
188
|
keyValue: "object",
|
|
189
189
|
json: "object"
|
|
190
190
|
};
|
|
191
|
-
function z(
|
|
192
|
-
return e?.displayName ? e.displayName :
|
|
191
|
+
function z(n, e) {
|
|
192
|
+
return e?.displayName ? e.displayName : n.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUpperCase()).trim();
|
|
193
193
|
}
|
|
194
194
|
class x {
|
|
195
195
|
options;
|
|
@@ -221,18 +221,18 @@ class x {
|
|
|
221
221
|
for (const r of e.properties) {
|
|
222
222
|
if (!this.options.includeForeignKeys && e.isForeignKey(r.name))
|
|
223
223
|
continue;
|
|
224
|
-
const
|
|
225
|
-
|
|
224
|
+
const s = this.parseProperty(r);
|
|
225
|
+
s && this.options.fieldFilter(s) && t.push(s);
|
|
226
226
|
}
|
|
227
227
|
if (this.options.includeComputedProperties)
|
|
228
228
|
for (const r of e.computedProperties) {
|
|
229
|
-
const
|
|
230
|
-
|
|
229
|
+
const s = this.parseProperty(r);
|
|
230
|
+
s && this.options.fieldFilter(s) && t.push(s);
|
|
231
231
|
}
|
|
232
232
|
if (this.options.includeRelations && e.relations)
|
|
233
233
|
for (const r of e.relations) {
|
|
234
|
-
const
|
|
235
|
-
|
|
234
|
+
const s = this.parseRelation(r);
|
|
235
|
+
s && this.options.fieldFilter(s) && t.push(s);
|
|
236
236
|
}
|
|
237
237
|
return t;
|
|
238
238
|
}
|
|
@@ -244,8 +244,8 @@ class x {
|
|
|
244
244
|
*/
|
|
245
245
|
parseMany(e) {
|
|
246
246
|
const t = /* @__PURE__ */ new Map();
|
|
247
|
-
for (const [r,
|
|
248
|
-
t.set(r, this.parse(
|
|
247
|
+
for (const [r, s] of e)
|
|
248
|
+
t.set(r, this.parse(s));
|
|
249
249
|
return t;
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
@@ -282,21 +282,21 @@ class x {
|
|
|
282
282
|
relationKind: e.kind
|
|
283
283
|
};
|
|
284
284
|
if (this.options.entityMetadataMap) {
|
|
285
|
-
const r = e.mappedEntity,
|
|
286
|
-
if (
|
|
285
|
+
const r = e.mappedEntity, s = this.options.entityMetadataMap.get(r);
|
|
286
|
+
if (s) {
|
|
287
287
|
const a = new x({
|
|
288
288
|
...this.options,
|
|
289
289
|
includeRelations: !1
|
|
290
290
|
// 防止无限递归
|
|
291
291
|
});
|
|
292
|
-
t.relationFields = a.parse(
|
|
292
|
+
t.relationFields = a.parse(s);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
return t;
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
function _(
|
|
299
|
-
return new x(
|
|
298
|
+
function _(n) {
|
|
299
|
+
return new x(n);
|
|
300
300
|
}
|
|
301
301
|
function E() {
|
|
302
302
|
return U();
|
|
@@ -383,8 +383,8 @@ class Z {
|
|
|
383
383
|
};
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
function H(
|
|
387
|
-
return new Z(
|
|
386
|
+
function H(n) {
|
|
387
|
+
return new Z(n);
|
|
388
388
|
}
|
|
389
389
|
class C {
|
|
390
390
|
operators;
|
|
@@ -479,8 +479,8 @@ class C {
|
|
|
479
479
|
getForField(e) {
|
|
480
480
|
const t = this.getForType(e.type);
|
|
481
481
|
if (e.nullable) {
|
|
482
|
-
const r = t.some((o) => o.key === "null"),
|
|
483
|
-
return !r && a && i.push(a), !
|
|
482
|
+
const r = t.some((o) => o.key === "null"), s = t.some((o) => o.key === "notNull"), a = this.operators.get("null"), l = this.operators.get("notNull"), i = [...t];
|
|
483
|
+
return !r && a && i.push(a), !s && l && i.push(l), i;
|
|
484
484
|
}
|
|
485
485
|
return t;
|
|
486
486
|
}
|
|
@@ -530,19 +530,19 @@ class C {
|
|
|
530
530
|
this.operators.set(e.key, e);
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
|
-
function J(
|
|
534
|
-
return new C(
|
|
533
|
+
function J(n) {
|
|
534
|
+
return new C(n);
|
|
535
535
|
}
|
|
536
536
|
let P = null;
|
|
537
537
|
function ee() {
|
|
538
538
|
return P || (P = new C()), P;
|
|
539
539
|
}
|
|
540
|
-
function te(
|
|
541
|
-
return typeof
|
|
540
|
+
function te(n) {
|
|
541
|
+
return typeof n == "object" && n !== null && "where" in n;
|
|
542
542
|
}
|
|
543
|
-
function j(
|
|
544
|
-
if ("value" in
|
|
545
|
-
return
|
|
543
|
+
function j(n) {
|
|
544
|
+
if ("value" in n)
|
|
545
|
+
return n.value;
|
|
546
546
|
}
|
|
547
547
|
class re {
|
|
548
548
|
rules;
|
|
@@ -559,10 +559,10 @@ class re {
|
|
|
559
559
|
* 校验单条规则
|
|
560
560
|
*/
|
|
561
561
|
validateRule(e, t) {
|
|
562
|
-
const r = [],
|
|
562
|
+
const r = [], s = j(e), a = {
|
|
563
563
|
fieldType: t.type,
|
|
564
564
|
operator: e.operator,
|
|
565
|
-
value:
|
|
565
|
+
value: s
|
|
566
566
|
};
|
|
567
567
|
this.operatorRegistry.isOperatorSupportedForField(e.operator, t) || r.push({
|
|
568
568
|
field: e.field,
|
|
@@ -598,7 +598,7 @@ class re {
|
|
|
598
598
|
});
|
|
599
599
|
}
|
|
600
600
|
} else {
|
|
601
|
-
const i = this.validateValueType(
|
|
601
|
+
const i = this.validateValueType(s, l, e.field, t.displayName);
|
|
602
602
|
i && r.push(i);
|
|
603
603
|
}
|
|
604
604
|
for (const i of this.rules.values()) {
|
|
@@ -620,21 +620,21 @@ class re {
|
|
|
620
620
|
*/
|
|
621
621
|
validateGroup(e, t) {
|
|
622
622
|
const r = [];
|
|
623
|
-
for (const
|
|
624
|
-
if (v(
|
|
625
|
-
const a = this.validateGroup(
|
|
623
|
+
for (const s of e.rules)
|
|
624
|
+
if (v(s)) {
|
|
625
|
+
const a = this.validateGroup(s, t);
|
|
626
626
|
!a.valid && a.errors && r.push(...a.errors);
|
|
627
|
-
} else if (M(
|
|
628
|
-
const a = t.get(
|
|
627
|
+
} else if (M(s)) {
|
|
628
|
+
const a = t.get(s.field);
|
|
629
629
|
if (!a) {
|
|
630
630
|
r.push({
|
|
631
|
-
field:
|
|
631
|
+
field: s.field,
|
|
632
632
|
rule: "fieldExists",
|
|
633
|
-
message: `字段 "${
|
|
633
|
+
message: `字段 "${s.field}" 不存在`
|
|
634
634
|
});
|
|
635
635
|
continue;
|
|
636
636
|
}
|
|
637
|
-
const l = this.validateRule(
|
|
637
|
+
const l = this.validateRule(s, a);
|
|
638
638
|
!l.valid && l.errors && r.push(...l.errors);
|
|
639
639
|
}
|
|
640
640
|
return {
|
|
@@ -663,19 +663,19 @@ class re {
|
|
|
663
663
|
/**
|
|
664
664
|
* 校验值类型
|
|
665
665
|
*/
|
|
666
|
-
validateValueType(e, t, r,
|
|
666
|
+
validateValueType(e, t, r, s) {
|
|
667
667
|
return t === "none" || t === "subquery" ? null : t === "array" ? !Array.isArray(e) || e.length === 0 ? {
|
|
668
668
|
field: r,
|
|
669
669
|
rule: "valueType",
|
|
670
|
-
message: `${
|
|
670
|
+
message: `${s || r}需要提供一个或多个值`
|
|
671
671
|
} : null : t === "range" ? !Array.isArray(e) || e.length !== 2 ? {
|
|
672
672
|
field: r,
|
|
673
673
|
rule: "valueType",
|
|
674
|
-
message: `${
|
|
674
|
+
message: `${s || r}需要提供两个值(范围)`
|
|
675
675
|
} : null : e == null || e === "" ? {
|
|
676
676
|
field: r,
|
|
677
677
|
rule: "valueType",
|
|
678
|
-
message: `${
|
|
678
|
+
message: `${s || r}需要提供一个值`
|
|
679
679
|
} : null;
|
|
680
680
|
}
|
|
681
681
|
/**
|
|
@@ -689,10 +689,10 @@ class re {
|
|
|
689
689
|
const t = [];
|
|
690
690
|
for (const r of e.rules)
|
|
691
691
|
if (v(r)) {
|
|
692
|
-
const
|
|
693
|
-
t.push(...
|
|
692
|
+
const s = this.validateSubqueryRules(r);
|
|
693
|
+
t.push(...s);
|
|
694
694
|
} else if (M(r)) {
|
|
695
|
-
const
|
|
695
|
+
const s = j(r), a = this.operatorRegistry.getValueType(r.operator), l = this.validateValueType(s, a, r.field);
|
|
696
696
|
if (l && t.push(l), a === "subquery") {
|
|
697
697
|
const i = r;
|
|
698
698
|
if ("where" in i && i.where) {
|
|
@@ -720,22 +720,22 @@ class re {
|
|
|
720
720
|
return t;
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
function se(
|
|
724
|
-
return new re(
|
|
723
|
+
function se(n) {
|
|
724
|
+
return new re(n);
|
|
725
725
|
}
|
|
726
|
-
function w(
|
|
727
|
-
if (
|
|
728
|
-
if (
|
|
729
|
-
if (Array.isArray(
|
|
730
|
-
if (!Array.isArray(e) ||
|
|
731
|
-
for (let t = 0; t <
|
|
732
|
-
if (!w(
|
|
726
|
+
function w(n, e) {
|
|
727
|
+
if (n === e) return !0;
|
|
728
|
+
if (n === null || e === null || typeof n != typeof e) return !1;
|
|
729
|
+
if (Array.isArray(n)) {
|
|
730
|
+
if (!Array.isArray(e) || n.length !== e.length) return !1;
|
|
731
|
+
for (let t = 0; t < n.length; t++)
|
|
732
|
+
if (!w(n[t], e[t])) return !1;
|
|
733
733
|
return !0;
|
|
734
734
|
}
|
|
735
|
-
if (typeof
|
|
736
|
-
const t =
|
|
737
|
-
if (
|
|
738
|
-
for (const l of
|
|
735
|
+
if (typeof n == "object") {
|
|
736
|
+
const t = n, r = e, s = Object.keys(t), a = Object.keys(r);
|
|
737
|
+
if (s.length !== a.length) return !1;
|
|
738
|
+
for (const l of s)
|
|
739
739
|
if (!Object.prototype.hasOwnProperty.call(r, l) || !w(t[l], r[l])) return !1;
|
|
740
740
|
return !0;
|
|
741
741
|
}
|
|
@@ -785,10 +785,10 @@ class ie {
|
|
|
785
785
|
$()
|
|
786
786
|
), this.validation$ = this.state$.pipe(
|
|
787
787
|
k((r) => this.validationService.validateGroup(r.rootGroup, this.fieldsMap)),
|
|
788
|
-
$((r,
|
|
788
|
+
$((r, s) => r.valid === s.valid && w(r.errors, s.errors))
|
|
789
789
|
), this.query$ = this.state$.pipe(
|
|
790
790
|
k((r) => this.queryConverter.toRxDBQuery(r)),
|
|
791
|
-
$((r,
|
|
791
|
+
$((r, s) => w(r, s))
|
|
792
792
|
);
|
|
793
793
|
}
|
|
794
794
|
/**
|
|
@@ -839,36 +839,36 @@ class ie {
|
|
|
839
839
|
field: t?.field ?? "",
|
|
840
840
|
operator: t?.operator ?? "=",
|
|
841
841
|
...t && "value" in t ? { value: t.value } : { value: "" }
|
|
842
|
-
},
|
|
842
|
+
}, s = this.getState(), a = this.addItemToGroup(s.rootGroup, e ?? s.rootGroup.id, r);
|
|
843
843
|
return this.stateSubject.next({ rootGroup: a }), r.id;
|
|
844
844
|
}
|
|
845
845
|
/**
|
|
846
846
|
* 添加规则组
|
|
847
847
|
*/
|
|
848
848
|
addGroup(e = null, t = V) {
|
|
849
|
-
const r = this.getState(),
|
|
849
|
+
const r = this.getState(), s = e ?? r.rootGroup.id, a = this.getGroupDepth(r.rootGroup, s), l = this.getMaxNestingLevel();
|
|
850
850
|
if (a >= l)
|
|
851
851
|
throw new Error(`已达到最大嵌套深度 ${l}`);
|
|
852
852
|
const i = {
|
|
853
853
|
id: E(),
|
|
854
854
|
combinator: t,
|
|
855
855
|
rules: []
|
|
856
|
-
}, o = this.addItemToGroup(r.rootGroup,
|
|
856
|
+
}, o = this.addItemToGroup(r.rootGroup, s, i);
|
|
857
857
|
return this.stateSubject.next({ rootGroup: o }), i.id;
|
|
858
858
|
}
|
|
859
859
|
/**
|
|
860
860
|
* 更新规则
|
|
861
861
|
*/
|
|
862
862
|
updateRule(e, t) {
|
|
863
|
-
const r = this.getState(),
|
|
864
|
-
this.stateSubject.next({ rootGroup:
|
|
863
|
+
const r = this.getState(), s = this.updateItemInGroup(r.rootGroup, e, t);
|
|
864
|
+
this.stateSubject.next({ rootGroup: s });
|
|
865
865
|
}
|
|
866
866
|
/**
|
|
867
867
|
* 更新组的组合器
|
|
868
868
|
*/
|
|
869
869
|
updateGroupCombinator(e, t) {
|
|
870
|
-
const r = this.getState(),
|
|
871
|
-
this.stateSubject.next({ rootGroup:
|
|
870
|
+
const r = this.getState(), s = this.updateItemInGroup(r.rootGroup, e, { combinator: t });
|
|
871
|
+
this.stateSubject.next({ rootGroup: s });
|
|
872
872
|
}
|
|
873
873
|
/**
|
|
874
874
|
* 删除规则或组
|
|
@@ -926,13 +926,13 @@ class ie {
|
|
|
926
926
|
rules: [...e.rules, r]
|
|
927
927
|
} : {
|
|
928
928
|
...e,
|
|
929
|
-
rules: e.rules.map((
|
|
929
|
+
rules: e.rules.map((s) => v(s) ? this.addItemToGroup(s, t, r) : s)
|
|
930
930
|
};
|
|
931
931
|
}
|
|
932
932
|
updateItemInGroup(e, t, r) {
|
|
933
933
|
return e.id === t ? { ...e, ...r } : {
|
|
934
934
|
...e,
|
|
935
|
-
rules: e.rules.map((
|
|
935
|
+
rules: e.rules.map((s) => v(s) ? s.id === t ? { ...s, ...r } : this.updateItemInGroup(s, t, r) : M(s) && s.id === t ? { ...s, ...r } : s)
|
|
936
936
|
};
|
|
937
937
|
}
|
|
938
938
|
removeItemFromGroup(e, t) {
|
|
@@ -944,21 +944,21 @@ class ie {
|
|
|
944
944
|
getGroupDepth(e, t, r = 1) {
|
|
945
945
|
if (e.id === t)
|
|
946
946
|
return r;
|
|
947
|
-
for (const
|
|
948
|
-
if (v(
|
|
949
|
-
const a = this.getGroupDepth(
|
|
947
|
+
for (const s of e.rules)
|
|
948
|
+
if (v(s)) {
|
|
949
|
+
const a = this.getGroupDepth(s, t, r + 1);
|
|
950
950
|
if (a > 0)
|
|
951
951
|
return a;
|
|
952
952
|
}
|
|
953
953
|
return 0;
|
|
954
954
|
}
|
|
955
955
|
}
|
|
956
|
-
function de(
|
|
957
|
-
return new ie(
|
|
956
|
+
function de(n) {
|
|
957
|
+
return new ie(n);
|
|
958
958
|
}
|
|
959
959
|
const q = "__exists__";
|
|
960
|
-
function he(
|
|
961
|
-
const e = /* @__PURE__ */ new Set(), t =
|
|
960
|
+
function he(n) {
|
|
961
|
+
const e = /* @__PURE__ */ new Set(), t = n.filter((i) => e.has(i.name) ? !1 : (e.add(i.name), !0)), r = [], s = /* @__PURE__ */ new Map(), a = [...t].sort((i, o) => {
|
|
962
962
|
const f = (i.name.match(/\./g) || []).length, y = (o.name.match(/\./g) || []).length;
|
|
963
963
|
return f - y;
|
|
964
964
|
}), l = /* @__PURE__ */ new Map();
|
|
@@ -982,10 +982,10 @@ function he(s) {
|
|
|
982
982
|
// 关系字段复制 relationFields 用于子查询
|
|
983
983
|
...i.relationFields && { relationFields: i.relationFields }
|
|
984
984
|
};
|
|
985
|
-
if (
|
|
985
|
+
if (s.set(i.name, p), o.length === 1)
|
|
986
986
|
r.push(p);
|
|
987
987
|
else {
|
|
988
|
-
const m = o.slice(0, -1).join("."), b =
|
|
988
|
+
const m = o.slice(0, -1).join("."), b = s.get(m);
|
|
989
989
|
if (b)
|
|
990
990
|
b.children = b.children ?? [], b.children.push(p);
|
|
991
991
|
else {
|
|
@@ -993,7 +993,7 @@ function he(s) {
|
|
|
993
993
|
for (let T = 0; T < o.length - 1; T++) {
|
|
994
994
|
const R = o[T];
|
|
995
995
|
d = d ? `${d}.${R}` : R;
|
|
996
|
-
let h =
|
|
996
|
+
let h = s.get(d);
|
|
997
997
|
if (!h) {
|
|
998
998
|
const S = l.get(d) ?? R;
|
|
999
999
|
h = {
|
|
@@ -1003,7 +1003,7 @@ function he(s) {
|
|
|
1003
1003
|
type: "relation",
|
|
1004
1004
|
isRelation: !0,
|
|
1005
1005
|
children: []
|
|
1006
|
-
},
|
|
1006
|
+
}, s.set(d, h), N.push(h);
|
|
1007
1007
|
}
|
|
1008
1008
|
h.children = h.children ?? [], N = h.children;
|
|
1009
1009
|
}
|
|
@@ -1013,9 +1013,9 @@ function he(s) {
|
|
|
1013
1013
|
}
|
|
1014
1014
|
return Q(r, t), r;
|
|
1015
1015
|
}
|
|
1016
|
-
function Q(
|
|
1016
|
+
function Q(n, e) {
|
|
1017
1017
|
const t = new Map(e.map((r) => [r.name, r]));
|
|
1018
|
-
for (const r of
|
|
1018
|
+
for (const r of n) {
|
|
1019
1019
|
if (r.isRelation && r.children && r.children.length > 0 && !r.children.some((a) => a.label === q)) {
|
|
1020
1020
|
const l = t.get(r.value)?.relationFields;
|
|
1021
1021
|
r.children.unshift({
|
|
@@ -1033,8 +1033,8 @@ function Q(s, e) {
|
|
|
1033
1033
|
r.children && Q(r.children, e);
|
|
1034
1034
|
}
|
|
1035
1035
|
}
|
|
1036
|
-
function ae(
|
|
1037
|
-
for (const t of
|
|
1036
|
+
function ae(n, e) {
|
|
1037
|
+
for (const t of n) {
|
|
1038
1038
|
if (t.value === e)
|
|
1039
1039
|
return t;
|
|
1040
1040
|
if (t.children) {
|
|
@@ -1043,28 +1043,28 @@ function ae(s, e) {
|
|
|
1043
1043
|
}
|
|
1044
1044
|
}
|
|
1045
1045
|
}
|
|
1046
|
-
function me(
|
|
1046
|
+
function me(n) {
|
|
1047
1047
|
const e = /* @__PURE__ */ new Map(), t = (r) => {
|
|
1048
|
-
for (const
|
|
1049
|
-
e.set(
|
|
1048
|
+
for (const s of r)
|
|
1049
|
+
e.set(s.value, s), s.children && t(s.children);
|
|
1050
1050
|
};
|
|
1051
|
-
return t(
|
|
1051
|
+
return t(n), e;
|
|
1052
1052
|
}
|
|
1053
|
-
function ge(
|
|
1054
|
-
return Array(
|
|
1053
|
+
function ge(n = 10) {
|
|
1054
|
+
return Array(n).fill("children");
|
|
1055
1055
|
}
|
|
1056
|
-
function be(
|
|
1056
|
+
function be(n, e) {
|
|
1057
1057
|
const t = e.split("."), r = [];
|
|
1058
|
-
let
|
|
1058
|
+
let s = n;
|
|
1059
1059
|
for (let a = 0; a < t.length; a++) {
|
|
1060
|
-
const l = t.slice(0, a + 1).join("."), i =
|
|
1061
|
-
i ? (r.push(i.displayName || i.label),
|
|
1060
|
+
const l = t.slice(0, a + 1).join("."), i = s.find((o) => o.value === l);
|
|
1061
|
+
i ? (r.push(i.displayName || i.label), s = i.children ?? []) : r.push(t[a]);
|
|
1062
1062
|
}
|
|
1063
1063
|
return r.join(".");
|
|
1064
1064
|
}
|
|
1065
1065
|
const oe = 4, L = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"];
|
|
1066
|
-
function G(
|
|
1067
|
-
switch (
|
|
1066
|
+
function G(n) {
|
|
1067
|
+
switch (n) {
|
|
1068
1068
|
case g.uuid:
|
|
1069
1069
|
return "string";
|
|
1070
1070
|
case g.string:
|
|
@@ -1086,19 +1086,19 @@ function G(s) {
|
|
|
1086
1086
|
return "string";
|
|
1087
1087
|
}
|
|
1088
1088
|
}
|
|
1089
|
-
function le(
|
|
1090
|
-
return
|
|
1089
|
+
function le(n) {
|
|
1090
|
+
return n.kind === B.ONE_TO_MANY || n.kind === B.MANY_TO_MANY ? [n.mappedProperty] : [];
|
|
1091
1091
|
}
|
|
1092
|
-
function ve(
|
|
1093
|
-
return K(
|
|
1092
|
+
function ve(n, e, t = {}) {
|
|
1093
|
+
return K(n, e, t, n, [], "", /* @__PURE__ */ new Set(), 0);
|
|
1094
1094
|
}
|
|
1095
|
-
function K(
|
|
1095
|
+
function K(n, e, t, r, s, a, l, i) {
|
|
1096
1096
|
const o = [], f = t.relationQueryDeep ?? oe, y = t.systemFields ?? L;
|
|
1097
|
-
if (l.has(
|
|
1097
|
+
if (l.has(n.name))
|
|
1098
1098
|
return o;
|
|
1099
1099
|
if (!a)
|
|
1100
1100
|
for (const u of y) {
|
|
1101
|
-
const c =
|
|
1101
|
+
const c = n.properties.find((p) => p.name === u);
|
|
1102
1102
|
c && o.push({
|
|
1103
1103
|
name: u,
|
|
1104
1104
|
displayName: c.displayName ?? u,
|
|
@@ -1106,7 +1106,7 @@ function K(s, e, t, r, n, a, l, i) {
|
|
|
1106
1106
|
nullable: c.nullable ?? !1
|
|
1107
1107
|
});
|
|
1108
1108
|
}
|
|
1109
|
-
for (const [u, c] of
|
|
1109
|
+
for (const [u, c] of n.propertyMap) {
|
|
1110
1110
|
const p = a ? `${a}.${u}` : u;
|
|
1111
1111
|
o.push({
|
|
1112
1112
|
name: p,
|
|
@@ -1115,10 +1115,10 @@ function K(s, e, t, r, n, a, l, i) {
|
|
|
1115
1115
|
nullable: c.nullable ?? !1
|
|
1116
1116
|
});
|
|
1117
1117
|
}
|
|
1118
|
-
for (const u of
|
|
1118
|
+
for (const u of n.foreignKeyNames) {
|
|
1119
1119
|
const c = a ? `${a}.${u}` : u;
|
|
1120
1120
|
if (!o.some((p) => p.name === c)) {
|
|
1121
|
-
const p = u.slice(0, -2), m =
|
|
1121
|
+
const p = u.slice(0, -2), m = n.foreignKeyRelationMap.get(p), b = m?.displayName ?? p, d = m && "nullable" in m ? m.nullable ?? !1 : !1;
|
|
1122
1122
|
o.push({
|
|
1123
1123
|
name: c,
|
|
1124
1124
|
displayName: `${b}ID`,
|
|
@@ -1128,8 +1128,8 @@ function K(s, e, t, r, n, a, l, i) {
|
|
|
1128
1128
|
}
|
|
1129
1129
|
}
|
|
1130
1130
|
if (i < f)
|
|
1131
|
-
for (const [u, c] of
|
|
1132
|
-
if (
|
|
1131
|
+
for (const [u, c] of n.relationMap) {
|
|
1132
|
+
if (s.includes(u)) continue;
|
|
1133
1133
|
const p = e.get(c.mappedEntity);
|
|
1134
1134
|
if (!p || i > 0 && p.metadata === r || l.has(p.metadata.name)) continue;
|
|
1135
1135
|
const m = a ? `${a}.${u}` : u, b = c.displayName || u, d = ue(p.metadata, t);
|
|
@@ -1142,7 +1142,7 @@ function K(s, e, t, r, n, a, l, i) {
|
|
|
1142
1142
|
relationFields: d
|
|
1143
1143
|
});
|
|
1144
1144
|
const N = le(c), T = new Set(l);
|
|
1145
|
-
T.add(
|
|
1145
|
+
T.add(n.name);
|
|
1146
1146
|
const R = K(
|
|
1147
1147
|
p.metadata,
|
|
1148
1148
|
e,
|
|
@@ -1166,29 +1166,29 @@ function K(s, e, t, r, n, a, l, i) {
|
|
|
1166
1166
|
}
|
|
1167
1167
|
return o;
|
|
1168
1168
|
}
|
|
1169
|
-
function ue(
|
|
1169
|
+
function ue(n, e = {}) {
|
|
1170
1170
|
const t = [], r = e.systemFields ?? L;
|
|
1171
|
-
for (const
|
|
1172
|
-
const a =
|
|
1171
|
+
for (const s of r) {
|
|
1172
|
+
const a = n.properties.find((l) => l.name === s);
|
|
1173
1173
|
a && t.push({
|
|
1174
|
-
name:
|
|
1175
|
-
displayName: a.displayName ??
|
|
1174
|
+
name: s,
|
|
1175
|
+
displayName: a.displayName ?? s,
|
|
1176
1176
|
type: G(a.type),
|
|
1177
1177
|
nullable: a.nullable ?? !1
|
|
1178
1178
|
});
|
|
1179
1179
|
}
|
|
1180
|
-
for (const [
|
|
1180
|
+
for (const [s, a] of n.propertyMap)
|
|
1181
1181
|
t.push({
|
|
1182
|
-
name:
|
|
1183
|
-
displayName: a.displayName ??
|
|
1182
|
+
name: s,
|
|
1183
|
+
displayName: a.displayName ?? s,
|
|
1184
1184
|
type: G(a.type),
|
|
1185
1185
|
nullable: a.nullable ?? !1
|
|
1186
1186
|
});
|
|
1187
|
-
for (const
|
|
1188
|
-
if (!t.some((a) => a.name ===
|
|
1189
|
-
const a =
|
|
1187
|
+
for (const s of n.foreignKeyNames)
|
|
1188
|
+
if (!t.some((a) => a.name === s)) {
|
|
1189
|
+
const a = s.slice(0, -2), l = n.foreignKeyRelationMap.get(a), i = l?.displayName ?? a, o = l && "nullable" in l ? l.nullable ?? !1 : !1;
|
|
1190
1190
|
t.push({
|
|
1191
|
-
name:
|
|
1191
|
+
name: s,
|
|
1192
1192
|
displayName: `${i}ID`,
|
|
1193
1193
|
type: "string",
|
|
1194
1194
|
nullable: o
|
|
@@ -1196,17 +1196,17 @@ function ue(s, e = {}) {
|
|
|
1196
1196
|
}
|
|
1197
1197
|
return t;
|
|
1198
1198
|
}
|
|
1199
|
-
function Te(
|
|
1200
|
-
return [...
|
|
1201
|
-
const r = (e.name.match(/\./g) || []).length,
|
|
1202
|
-
return r !==
|
|
1199
|
+
function Te(n) {
|
|
1200
|
+
return [...n].sort((e, t) => {
|
|
1201
|
+
const r = (e.name.match(/\./g) || []).length, s = (t.name.match(/\./g) || []).length;
|
|
1202
|
+
return r !== s ? r - s : e.name.localeCompare(t.name);
|
|
1203
1203
|
});
|
|
1204
1204
|
}
|
|
1205
|
-
function Re(
|
|
1206
|
-
return _(e).parse(
|
|
1205
|
+
function Re(n, e) {
|
|
1206
|
+
return _(e).parse(n);
|
|
1207
1207
|
}
|
|
1208
|
-
function Ne(
|
|
1209
|
-
return _(e).parseMany(
|
|
1208
|
+
function Ne(n, e) {
|
|
1209
|
+
return _(e).parseMany(n);
|
|
1210
1210
|
}
|
|
1211
1211
|
export {
|
|
1212
1212
|
Y as BUILTIN_VALIDATION_RULES,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiao/rxdb-query-builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"rxjs": "^7.8.2",
|
|
32
32
|
"uuid": "^13.0.0",
|
|
33
|
-
"@aiao/rxdb": "0.0.
|
|
33
|
+
"@aiao/rxdb": "0.0.12"
|
|
34
34
|
}
|
|
35
35
|
}
|