@aiao/rxdb-query-builder 0.0.10 → 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.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +333 -315
- package/dist/models/config.interface.d.ts +0 -48
- package/dist/models/config.interface.d.ts.map +1 -1
- package/dist/models/validation.interface.d.ts.map +1 -1
- package/dist/services/query-builder.service.d.ts.map +1 -1
- package/dist/services/query-converter.service.d.ts +0 -4
- package/dist/services/query-converter.service.d.ts.map +1 -1
- package/dist/services/validation.service.d.ts.map +1 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/metadata-field-extractor.d.ts +2 -7
- package/dist/utils/metadata-field-extractor.d.ts.map +1 -1
- package/dist/utils/structural-equal.d.ts +9 -0
- package/dist/utils/structural-equal.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { v4 as
|
|
2
|
-
import { BehaviorSubject as
|
|
1
|
+
import { v4 as U } from "uuid";
|
|
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
|
|
4
|
+
function v(n) {
|
|
5
5
|
return "combinator" in n && "rules" in n;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function M(n) {
|
|
8
8
|
return "field" in n && "operator" in n;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const O = [
|
|
11
11
|
// 相等操作符
|
|
12
12
|
{
|
|
13
13
|
key: "=",
|
|
@@ -136,35 +136,37 @@ const k = [
|
|
|
136
136
|
applicableTypes: ["relation"]
|
|
137
137
|
}
|
|
138
138
|
];
|
|
139
|
-
function
|
|
140
|
-
return e.filter((
|
|
139
|
+
function ye(n, e = O) {
|
|
140
|
+
return e.filter((t) => t.applicableTypes.includes(n));
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
function D(n) {
|
|
143
|
+
return n == null || Array.isArray(n);
|
|
144
|
+
}
|
|
145
|
+
const Y = [
|
|
143
146
|
{
|
|
144
147
|
name: "stringType",
|
|
145
148
|
appliesTo: ["string"],
|
|
146
149
|
message: "值必须是字符串类型",
|
|
147
|
-
validate: (n) =>
|
|
150
|
+
validate: (n) => D(n.value) ? !0 : typeof n.value == "string"
|
|
148
151
|
},
|
|
149
152
|
{
|
|
150
153
|
name: "numberType",
|
|
151
154
|
appliesTo: ["number"],
|
|
152
155
|
message: "值必须是数字类型",
|
|
153
|
-
validate: (n) =>
|
|
156
|
+
validate: (n) => D(n.value) ? !0 : typeof n.value == "number" && !isNaN(n.value)
|
|
154
157
|
},
|
|
155
158
|
{
|
|
156
159
|
name: "booleanType",
|
|
157
160
|
appliesTo: ["boolean"],
|
|
158
161
|
message: "值必须是布尔类型",
|
|
159
|
-
validate: (n) =>
|
|
162
|
+
validate: (n) => D(n.value) ? !0 : typeof n.value == "boolean"
|
|
160
163
|
},
|
|
161
164
|
{
|
|
162
165
|
name: "dateType",
|
|
163
166
|
appliesTo: ["date"],
|
|
164
167
|
message: "值必须是有效日期",
|
|
165
168
|
validate: (n) => {
|
|
166
|
-
if (n.value
|
|
167
|
-
return !0;
|
|
169
|
+
if (D(n.value)) return !0;
|
|
168
170
|
if (n.value instanceof Date)
|
|
169
171
|
return !isNaN(n.value.getTime());
|
|
170
172
|
if (typeof n.value == "string") {
|
|
@@ -174,7 +176,7 @@ const K = [
|
|
|
174
176
|
return !1;
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
|
-
],
|
|
179
|
+
], X = {
|
|
178
180
|
uuid: "string",
|
|
179
181
|
string: "string",
|
|
180
182
|
number: "number",
|
|
@@ -186,10 +188,10 @@ const K = [
|
|
|
186
188
|
keyValue: "object",
|
|
187
189
|
json: "object"
|
|
188
190
|
};
|
|
189
|
-
function
|
|
190
|
-
return e?.displayName ? e.displayName : n.replace(/([A-Z])/g, " $1").replace(/^./, (
|
|
191
|
+
function z(n, e) {
|
|
192
|
+
return e?.displayName ? e.displayName : n.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUpperCase()).trim();
|
|
191
193
|
}
|
|
192
|
-
class
|
|
194
|
+
class x {
|
|
193
195
|
options;
|
|
194
196
|
constructor(e = {}) {
|
|
195
197
|
this.options = {
|
|
@@ -198,7 +200,7 @@ class P {
|
|
|
198
200
|
includeRelations: e.includeRelations ?? !1,
|
|
199
201
|
entityMetadataMap: e.entityMetadataMap,
|
|
200
202
|
fieldFilter: e.fieldFilter ?? (() => !0),
|
|
201
|
-
displayNameGenerator: e.displayNameGenerator ??
|
|
203
|
+
displayNameGenerator: e.displayNameGenerator ?? z
|
|
202
204
|
};
|
|
203
205
|
}
|
|
204
206
|
/**
|
|
@@ -215,24 +217,24 @@ class P {
|
|
|
215
217
|
* ```
|
|
216
218
|
*/
|
|
217
219
|
parse(e) {
|
|
218
|
-
const
|
|
219
|
-
for (const
|
|
220
|
-
if (!this.options.includeForeignKeys && e.isForeignKey(
|
|
220
|
+
const t = [];
|
|
221
|
+
for (const r of e.properties) {
|
|
222
|
+
if (!this.options.includeForeignKeys && e.isForeignKey(r.name))
|
|
221
223
|
continue;
|
|
222
|
-
const s = this.parseProperty(
|
|
223
|
-
s && this.options.fieldFilter(s) &&
|
|
224
|
+
const s = this.parseProperty(r);
|
|
225
|
+
s && this.options.fieldFilter(s) && t.push(s);
|
|
224
226
|
}
|
|
225
227
|
if (this.options.includeComputedProperties)
|
|
226
|
-
for (const
|
|
227
|
-
const s = this.parseProperty(
|
|
228
|
-
s && this.options.fieldFilter(s) &&
|
|
228
|
+
for (const r of e.computedProperties) {
|
|
229
|
+
const s = this.parseProperty(r);
|
|
230
|
+
s && this.options.fieldFilter(s) && t.push(s);
|
|
229
231
|
}
|
|
230
232
|
if (this.options.includeRelations && e.relations)
|
|
231
|
-
for (const
|
|
232
|
-
const s = this.parseRelation(
|
|
233
|
-
s && this.options.fieldFilter(s) &&
|
|
233
|
+
for (const r of e.relations) {
|
|
234
|
+
const s = this.parseRelation(r);
|
|
235
|
+
s && this.options.fieldFilter(s) && t.push(s);
|
|
234
236
|
}
|
|
235
|
-
return
|
|
237
|
+
return t;
|
|
236
238
|
}
|
|
237
239
|
/**
|
|
238
240
|
* 从多个 EntityMetadata 批量解析
|
|
@@ -241,37 +243,37 @@ class P {
|
|
|
241
243
|
* @returns 实体名称到字段数组的映射
|
|
242
244
|
*/
|
|
243
245
|
parseMany(e) {
|
|
244
|
-
const
|
|
245
|
-
for (const [
|
|
246
|
-
|
|
247
|
-
return
|
|
246
|
+
const t = /* @__PURE__ */ new Map();
|
|
247
|
+
for (const [r, s] of e)
|
|
248
|
+
t.set(r, this.parse(s));
|
|
249
|
+
return t;
|
|
248
250
|
}
|
|
249
251
|
/**
|
|
250
252
|
* 解析单个属性
|
|
251
253
|
*/
|
|
252
254
|
parseProperty(e) {
|
|
253
|
-
const
|
|
254
|
-
if (!
|
|
255
|
+
const t = this.mapPropertyType(e.type);
|
|
256
|
+
if (!t)
|
|
255
257
|
return null;
|
|
256
|
-
const
|
|
258
|
+
const r = {
|
|
257
259
|
name: e.name,
|
|
258
260
|
displayName: this.options.displayNameGenerator(e.name, e),
|
|
259
|
-
type:
|
|
261
|
+
type: t
|
|
260
262
|
};
|
|
261
|
-
return e.nullable !== void 0 && (
|
|
263
|
+
return e.nullable !== void 0 && (r.required = !e.nullable), e.description && (r.description = e.description), e.enum && Array.isArray(e.enum) && (r.enum = e.enum), e.pattern && (r.pattern = e.pattern), r;
|
|
262
264
|
}
|
|
263
265
|
/**
|
|
264
266
|
* 将 RxDB PropertyType 映射到 QueryBuilder 类型
|
|
265
267
|
*/
|
|
266
268
|
mapPropertyType(e) {
|
|
267
|
-
const
|
|
268
|
-
return
|
|
269
|
+
const t = typeof e == "string" ? e : String(e);
|
|
270
|
+
return X[t] ?? null;
|
|
269
271
|
}
|
|
270
272
|
/**
|
|
271
273
|
* 解析关系字段
|
|
272
274
|
*/
|
|
273
275
|
parseRelation(e) {
|
|
274
|
-
const
|
|
276
|
+
const t = {
|
|
275
277
|
name: e.name,
|
|
276
278
|
displayName: this.options.displayNameGenerator(e.name, e),
|
|
277
279
|
type: "relation",
|
|
@@ -280,29 +282,29 @@ class P {
|
|
|
280
282
|
relationKind: e.kind
|
|
281
283
|
};
|
|
282
284
|
if (this.options.entityMetadataMap) {
|
|
283
|
-
const
|
|
285
|
+
const r = e.mappedEntity, s = this.options.entityMetadataMap.get(r);
|
|
284
286
|
if (s) {
|
|
285
|
-
const a = new
|
|
287
|
+
const a = new x({
|
|
286
288
|
...this.options,
|
|
287
289
|
includeRelations: !1
|
|
288
290
|
// 防止无限递归
|
|
289
291
|
});
|
|
290
|
-
|
|
292
|
+
t.relationFields = a.parse(s);
|
|
291
293
|
}
|
|
292
294
|
}
|
|
293
|
-
return
|
|
295
|
+
return t;
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
|
-
function
|
|
297
|
-
return new
|
|
298
|
+
function _(n) {
|
|
299
|
+
return new x(n);
|
|
298
300
|
}
|
|
299
|
-
function
|
|
300
|
-
return
|
|
301
|
+
function E() {
|
|
302
|
+
return U();
|
|
301
303
|
}
|
|
302
|
-
class
|
|
304
|
+
class Z {
|
|
303
305
|
idGenerator;
|
|
304
306
|
constructor(e = {}) {
|
|
305
|
-
this.idGenerator = e.idGenerator ??
|
|
307
|
+
this.idGenerator = e.idGenerator ?? E;
|
|
306
308
|
}
|
|
307
309
|
/**
|
|
308
310
|
* 将 QueryBuilder 状态转换为 RxDB Query
|
|
@@ -341,12 +343,12 @@ class Y {
|
|
|
341
343
|
* 转换单个规则组到 RxDB 格式
|
|
342
344
|
*/
|
|
343
345
|
convertGroupToRxDB(e) {
|
|
344
|
-
const
|
|
345
|
-
for (const
|
|
346
|
-
|
|
346
|
+
const t = [];
|
|
347
|
+
for (const r of e.rules)
|
|
348
|
+
v(r) ? t.push(this.convertGroupToRxDB(r)) : t.push(this.convertRuleToRxDB(r));
|
|
347
349
|
return {
|
|
348
350
|
combinator: e.combinator,
|
|
349
|
-
rules:
|
|
351
|
+
rules: t
|
|
350
352
|
};
|
|
351
353
|
}
|
|
352
354
|
/**
|
|
@@ -354,20 +356,20 @@ class Y {
|
|
|
354
356
|
* 移除 QueryBuilder 特有的 id 字段
|
|
355
357
|
*/
|
|
356
358
|
convertRuleToRxDB(e) {
|
|
357
|
-
const { id:
|
|
358
|
-
return
|
|
359
|
+
const { id: t, ...r } = e;
|
|
360
|
+
return r;
|
|
359
361
|
}
|
|
360
362
|
/**
|
|
361
363
|
* 从 RxDB 格式转换规则组
|
|
362
364
|
*/
|
|
363
365
|
convertGroupFromRxDB(e) {
|
|
364
|
-
const
|
|
365
|
-
for (const
|
|
366
|
-
|
|
366
|
+
const t = [];
|
|
367
|
+
for (const r of e.rules)
|
|
368
|
+
"combinator" in r && "rules" in r ? t.push(this.convertGroupFromRxDB(r)) : t.push(this.convertRuleFromRxDB(r));
|
|
367
369
|
return {
|
|
368
370
|
id: this.idGenerator(),
|
|
369
371
|
combinator: e.combinator,
|
|
370
|
-
rules:
|
|
372
|
+
rules: t
|
|
371
373
|
};
|
|
372
374
|
}
|
|
373
375
|
/**
|
|
@@ -380,17 +382,11 @@ class Y {
|
|
|
380
382
|
...e
|
|
381
383
|
};
|
|
382
384
|
}
|
|
383
|
-
/**
|
|
384
|
-
* 判断是否为 RxDB RuleGroup
|
|
385
|
-
*/
|
|
386
|
-
isRxDBRuleGroup(e) {
|
|
387
|
-
return typeof e == "object" && e !== null && "combinator" in e && "rules" in e && Array.isArray(e.rules);
|
|
388
|
-
}
|
|
389
385
|
}
|
|
390
|
-
function
|
|
391
|
-
return new
|
|
386
|
+
function H(n) {
|
|
387
|
+
return new Z(n);
|
|
392
388
|
}
|
|
393
|
-
class
|
|
389
|
+
class C {
|
|
394
390
|
operators;
|
|
395
391
|
/**
|
|
396
392
|
* 获取操作符数量
|
|
@@ -400,11 +396,11 @@ class q {
|
|
|
400
396
|
}
|
|
401
397
|
constructor(e = {}) {
|
|
402
398
|
if (this.operators = /* @__PURE__ */ new Map(), e.useDefaultOperators !== !1)
|
|
403
|
-
for (const
|
|
404
|
-
this.operators.set(
|
|
399
|
+
for (const t of O)
|
|
400
|
+
this.operators.set(t.key, t);
|
|
405
401
|
if (e.operators)
|
|
406
|
-
for (const
|
|
407
|
-
this.operators.set(
|
|
402
|
+
for (const t of e.operators)
|
|
403
|
+
this.operators.set(t.key, t);
|
|
408
404
|
}
|
|
409
405
|
/**
|
|
410
406
|
* 注册新操作符
|
|
@@ -430,8 +426,8 @@ class q {
|
|
|
430
426
|
* @param operators - 操作符定义数组
|
|
431
427
|
*/
|
|
432
428
|
registerMany(e) {
|
|
433
|
-
for (const
|
|
434
|
-
this.register(
|
|
429
|
+
for (const t of e)
|
|
430
|
+
this.register(t);
|
|
435
431
|
}
|
|
436
432
|
/**
|
|
437
433
|
* 移除操作符
|
|
@@ -472,7 +468,7 @@ class q {
|
|
|
472
468
|
* ```
|
|
473
469
|
*/
|
|
474
470
|
getForType(e) {
|
|
475
|
-
return Array.from(this.operators.values()).filter((
|
|
471
|
+
return Array.from(this.operators.values()).filter((t) => t.applicableTypes.includes(e));
|
|
476
472
|
}
|
|
477
473
|
/**
|
|
478
474
|
* 根据字段元数据获取适用的操作符
|
|
@@ -481,12 +477,12 @@ class q {
|
|
|
481
477
|
* @returns 适用的操作符数组
|
|
482
478
|
*/
|
|
483
479
|
getForField(e) {
|
|
484
|
-
const
|
|
480
|
+
const t = this.getForType(e.type);
|
|
485
481
|
if (e.nullable) {
|
|
486
|
-
const
|
|
487
|
-
return !
|
|
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;
|
|
488
484
|
}
|
|
489
|
-
return
|
|
485
|
+
return t;
|
|
490
486
|
}
|
|
491
487
|
/**
|
|
492
488
|
* 检查操作符是否支持指定类型
|
|
@@ -495,9 +491,9 @@ class q {
|
|
|
495
491
|
* @param fieldType - 字段类型
|
|
496
492
|
* @returns 是否支持
|
|
497
493
|
*/
|
|
498
|
-
isOperatorSupportedForType(e,
|
|
499
|
-
const
|
|
500
|
-
return
|
|
494
|
+
isOperatorSupportedForType(e, t) {
|
|
495
|
+
const r = this.operators.get(e);
|
|
496
|
+
return r ? r.applicableTypes.includes(t) : !1;
|
|
501
497
|
}
|
|
502
498
|
/**
|
|
503
499
|
* 检查操作符是否支持指定字段
|
|
@@ -506,9 +502,9 @@ class q {
|
|
|
506
502
|
* @param field - 字段元数据
|
|
507
503
|
* @returns 是否支持
|
|
508
504
|
*/
|
|
509
|
-
isOperatorSupportedForField(e,
|
|
510
|
-
const
|
|
511
|
-
return
|
|
505
|
+
isOperatorSupportedForField(e, t) {
|
|
506
|
+
const r = this.operators.get(e);
|
|
507
|
+
return r ? (e === "null" || e === "notNull") && t.nullable ? !0 : r.applicableTypes.includes(t.type) : !1;
|
|
512
508
|
}
|
|
513
509
|
/**
|
|
514
510
|
* 获取操作符的值类型
|
|
@@ -530,63 +526,63 @@ class q {
|
|
|
530
526
|
*/
|
|
531
527
|
reset() {
|
|
532
528
|
this.clear();
|
|
533
|
-
for (const e of
|
|
529
|
+
for (const e of O)
|
|
534
530
|
this.operators.set(e.key, e);
|
|
535
531
|
}
|
|
536
532
|
}
|
|
537
533
|
function J(n) {
|
|
538
|
-
return new
|
|
534
|
+
return new C(n);
|
|
539
535
|
}
|
|
540
|
-
let
|
|
541
|
-
function
|
|
542
|
-
return
|
|
536
|
+
let P = null;
|
|
537
|
+
function ee() {
|
|
538
|
+
return P || (P = new C()), P;
|
|
543
539
|
}
|
|
544
|
-
function
|
|
540
|
+
function te(n) {
|
|
545
541
|
return typeof n == "object" && n !== null && "where" in n;
|
|
546
542
|
}
|
|
547
|
-
function
|
|
543
|
+
function j(n) {
|
|
548
544
|
if ("value" in n)
|
|
549
545
|
return n.value;
|
|
550
546
|
}
|
|
551
|
-
class
|
|
547
|
+
class re {
|
|
552
548
|
rules;
|
|
553
549
|
operatorRegistry;
|
|
554
550
|
constructor(e = {}) {
|
|
555
|
-
if (this.rules = /* @__PURE__ */ new Map(), this.operatorRegistry = e.operatorRegistry ??
|
|
556
|
-
for (const
|
|
557
|
-
this.rules.set(
|
|
551
|
+
if (this.rules = /* @__PURE__ */ new Map(), this.operatorRegistry = e.operatorRegistry ?? ee(), e.useBuiltinRules !== !1)
|
|
552
|
+
for (const t of Y)
|
|
553
|
+
this.rules.set(t.name, t);
|
|
558
554
|
if (e.customRules)
|
|
559
|
-
for (const
|
|
560
|
-
this.rules.set(
|
|
555
|
+
for (const t of e.customRules)
|
|
556
|
+
this.rules.set(t.name, t);
|
|
561
557
|
}
|
|
562
558
|
/**
|
|
563
559
|
* 校验单条规则
|
|
564
560
|
*/
|
|
565
|
-
validateRule(e,
|
|
566
|
-
const
|
|
567
|
-
fieldType:
|
|
561
|
+
validateRule(e, t) {
|
|
562
|
+
const r = [], s = j(e), a = {
|
|
563
|
+
fieldType: t.type,
|
|
568
564
|
operator: e.operator,
|
|
569
565
|
value: s
|
|
570
566
|
};
|
|
571
|
-
this.operatorRegistry.isOperatorSupportedForField(e.operator,
|
|
567
|
+
this.operatorRegistry.isOperatorSupportedForField(e.operator, t) || r.push({
|
|
572
568
|
field: e.field,
|
|
573
569
|
rule: "operatorTypeMatch",
|
|
574
|
-
message: `操作符 "${e.operator}" 不支持字段 "${
|
|
570
|
+
message: `操作符 "${e.operator}" 不支持字段 "${t.name}"`
|
|
575
571
|
});
|
|
576
572
|
const l = this.operatorRegistry.getValueType(e.operator);
|
|
577
573
|
if (l === "subquery") {
|
|
578
|
-
if (
|
|
574
|
+
if (te(e) && e.where !== void 0 && e.where !== null) {
|
|
579
575
|
const i = e.where;
|
|
580
576
|
if (typeof i == "object" && "combinator" in i && "rules" in i)
|
|
581
577
|
if (!i.rules || i.rules.length === 0)
|
|
582
|
-
|
|
578
|
+
r.push({
|
|
583
579
|
field: e.field,
|
|
584
580
|
rule: "valueType",
|
|
585
581
|
message: "EXISTS 子查询条件不能为空"
|
|
586
582
|
});
|
|
587
583
|
else {
|
|
588
584
|
const o = this.validateSubqueryRules(i);
|
|
589
|
-
o.length > 0 &&
|
|
585
|
+
o.length > 0 && r.push(
|
|
590
586
|
...o.map((f) => ({
|
|
591
587
|
...f,
|
|
592
588
|
field: `${e.field}.${f.field}`
|
|
@@ -595,43 +591,43 @@ class H {
|
|
|
595
591
|
);
|
|
596
592
|
}
|
|
597
593
|
else
|
|
598
|
-
|
|
594
|
+
r.push({
|
|
599
595
|
field: e.field,
|
|
600
596
|
rule: "valueType",
|
|
601
597
|
message: "EXISTS 子查询格式无效"
|
|
602
598
|
});
|
|
603
599
|
}
|
|
604
600
|
} else {
|
|
605
|
-
const i = this.validateValueType(s, l, e.field,
|
|
606
|
-
i &&
|
|
601
|
+
const i = this.validateValueType(s, l, e.field, t.displayName);
|
|
602
|
+
i && r.push(i);
|
|
607
603
|
}
|
|
608
604
|
for (const i of this.rules.values()) {
|
|
609
|
-
if (i.appliesTo && !i.appliesTo.includes(
|
|
605
|
+
if (i.appliesTo && !i.appliesTo.includes(t.type))
|
|
610
606
|
continue;
|
|
611
|
-
i.validate(a) ||
|
|
607
|
+
i.validate(a) || r.push({
|
|
612
608
|
field: e.field,
|
|
613
609
|
rule: i.name,
|
|
614
610
|
message: i.message
|
|
615
611
|
});
|
|
616
612
|
}
|
|
617
613
|
return {
|
|
618
|
-
valid:
|
|
619
|
-
errors:
|
|
614
|
+
valid: r.length === 0,
|
|
615
|
+
errors: r.length > 0 ? r : void 0
|
|
620
616
|
};
|
|
621
617
|
}
|
|
622
618
|
/**
|
|
623
619
|
* 校验整个规则组
|
|
624
620
|
*/
|
|
625
|
-
validateGroup(e,
|
|
626
|
-
const
|
|
621
|
+
validateGroup(e, t) {
|
|
622
|
+
const r = [];
|
|
627
623
|
for (const s of e.rules)
|
|
628
|
-
if (
|
|
629
|
-
const a = this.validateGroup(s,
|
|
630
|
-
!a.valid && a.errors &&
|
|
631
|
-
} else if (
|
|
632
|
-
const a =
|
|
624
|
+
if (v(s)) {
|
|
625
|
+
const a = this.validateGroup(s, t);
|
|
626
|
+
!a.valid && a.errors && r.push(...a.errors);
|
|
627
|
+
} else if (M(s)) {
|
|
628
|
+
const a = t.get(s.field);
|
|
633
629
|
if (!a) {
|
|
634
|
-
|
|
630
|
+
r.push({
|
|
635
631
|
field: s.field,
|
|
636
632
|
rule: "fieldExists",
|
|
637
633
|
message: `字段 "${s.field}" 不存在`
|
|
@@ -639,11 +635,11 @@ class H {
|
|
|
639
635
|
continue;
|
|
640
636
|
}
|
|
641
637
|
const l = this.validateRule(s, a);
|
|
642
|
-
!l.valid && l.errors &&
|
|
638
|
+
!l.valid && l.errors && r.push(...l.errors);
|
|
643
639
|
}
|
|
644
640
|
return {
|
|
645
|
-
valid:
|
|
646
|
-
errors:
|
|
641
|
+
valid: r.length === 0,
|
|
642
|
+
errors: r.length > 0 ? r : void 0
|
|
647
643
|
};
|
|
648
644
|
}
|
|
649
645
|
/**
|
|
@@ -667,19 +663,19 @@ class H {
|
|
|
667
663
|
/**
|
|
668
664
|
* 校验值类型
|
|
669
665
|
*/
|
|
670
|
-
validateValueType(e,
|
|
671
|
-
return
|
|
672
|
-
field:
|
|
666
|
+
validateValueType(e, t, r, s) {
|
|
667
|
+
return t === "none" || t === "subquery" ? null : t === "array" ? !Array.isArray(e) || e.length === 0 ? {
|
|
668
|
+
field: r,
|
|
673
669
|
rule: "valueType",
|
|
674
|
-
message: `${s ||
|
|
675
|
-
} : null :
|
|
676
|
-
field:
|
|
670
|
+
message: `${s || r}需要提供一个或多个值`
|
|
671
|
+
} : null : t === "range" ? !Array.isArray(e) || e.length !== 2 ? {
|
|
672
|
+
field: r,
|
|
677
673
|
rule: "valueType",
|
|
678
|
-
message: `${s ||
|
|
674
|
+
message: `${s || r}需要提供两个值(范围)`
|
|
679
675
|
} : null : e == null || e === "" ? {
|
|
680
|
-
field:
|
|
676
|
+
field: r,
|
|
681
677
|
rule: "valueType",
|
|
682
|
-
message: `${s ||
|
|
678
|
+
message: `${s || r}需要提供一个值`
|
|
683
679
|
} : null;
|
|
684
680
|
}
|
|
685
681
|
/**
|
|
@@ -690,52 +686,70 @@ class H {
|
|
|
690
686
|
* 因此只验证规则的基本结构和值类型,不验证字段是否存在或操作符是否匹配。
|
|
691
687
|
*/
|
|
692
688
|
validateSubqueryRules(e) {
|
|
693
|
-
const
|
|
694
|
-
for (const
|
|
695
|
-
if (
|
|
696
|
-
const s = this.validateSubqueryRules(
|
|
697
|
-
|
|
698
|
-
} else if (
|
|
699
|
-
const s =
|
|
700
|
-
if (l &&
|
|
701
|
-
const i =
|
|
689
|
+
const t = [];
|
|
690
|
+
for (const r of e.rules)
|
|
691
|
+
if (v(r)) {
|
|
692
|
+
const s = this.validateSubqueryRules(r);
|
|
693
|
+
t.push(...s);
|
|
694
|
+
} else if (M(r)) {
|
|
695
|
+
const s = j(r), a = this.operatorRegistry.getValueType(r.operator), l = this.validateValueType(s, a, r.field);
|
|
696
|
+
if (l && t.push(l), a === "subquery") {
|
|
697
|
+
const i = r;
|
|
702
698
|
if ("where" in i && i.where) {
|
|
703
699
|
const o = i.where;
|
|
704
700
|
if (typeof o == "object" && "combinator" in o && "rules" in o)
|
|
705
701
|
if (!o.rules || o.rules.length === 0)
|
|
706
|
-
|
|
707
|
-
field:
|
|
702
|
+
t.push({
|
|
703
|
+
field: r.field,
|
|
708
704
|
rule: "valueType",
|
|
709
705
|
message: "EXISTS 子查询条件不能为空"
|
|
710
706
|
});
|
|
711
707
|
else {
|
|
712
708
|
const f = this.validateSubqueryRules(o);
|
|
713
|
-
|
|
709
|
+
t.push(...f);
|
|
714
710
|
}
|
|
715
711
|
else
|
|
716
|
-
|
|
717
|
-
field:
|
|
712
|
+
t.push({
|
|
713
|
+
field: r.field,
|
|
718
714
|
rule: "valueType",
|
|
719
715
|
message: "EXISTS 子查询格式无效"
|
|
720
716
|
});
|
|
721
717
|
}
|
|
722
718
|
}
|
|
723
719
|
}
|
|
724
|
-
return
|
|
720
|
+
return t;
|
|
725
721
|
}
|
|
726
722
|
}
|
|
727
|
-
function
|
|
728
|
-
return new
|
|
723
|
+
function se(n) {
|
|
724
|
+
return new re(n);
|
|
725
|
+
}
|
|
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
|
+
return !0;
|
|
734
|
+
}
|
|
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
|
+
if (!Object.prototype.hasOwnProperty.call(r, l) || !w(t[l], r[l])) return !1;
|
|
740
|
+
return !0;
|
|
741
|
+
}
|
|
742
|
+
return !1;
|
|
729
743
|
}
|
|
730
|
-
const
|
|
744
|
+
const ne = 5, V = "and";
|
|
731
745
|
function I() {
|
|
732
746
|
return {
|
|
733
|
-
id:
|
|
734
|
-
combinator:
|
|
747
|
+
id: E(),
|
|
748
|
+
combinator: V,
|
|
735
749
|
rules: []
|
|
736
750
|
};
|
|
737
751
|
}
|
|
738
|
-
class
|
|
752
|
+
class ie {
|
|
739
753
|
stateSubject;
|
|
740
754
|
fieldsMap;
|
|
741
755
|
config;
|
|
@@ -759,22 +773,22 @@ class re {
|
|
|
759
773
|
*/
|
|
760
774
|
query$;
|
|
761
775
|
constructor(e = {}) {
|
|
762
|
-
if (this.operatorRegistry = e.operatorRegistry ?? J(), this.validationService = e.validationService ??
|
|
776
|
+
if (this.operatorRegistry = e.operatorRegistry ?? J(), this.validationService = e.validationService ?? se({
|
|
763
777
|
operatorRegistry: this.operatorRegistry
|
|
764
|
-
}), this.queryConverter = e.queryConverter ??
|
|
765
|
-
for (const
|
|
766
|
-
this.fieldsMap.set(
|
|
778
|
+
}), this.queryConverter = e.queryConverter ?? H(), this.fieldsMap = /* @__PURE__ */ new Map(), e.fields)
|
|
779
|
+
for (const r of e.fields)
|
|
780
|
+
this.fieldsMap.set(r.name, r);
|
|
767
781
|
this.config = e.config ?? {};
|
|
768
|
-
let
|
|
769
|
-
e.initialState ?
|
|
770
|
-
|
|
771
|
-
|
|
782
|
+
let t;
|
|
783
|
+
e.initialState ? t = e.initialState : e.initialQuery ? t = this.queryConverter.fromRxDBQuery(e.initialQuery) : e.config?.initialQuery ? t = { rootGroup: e.config.initialQuery } : t = { rootGroup: I() }, this.stateSubject = new W(t), this.state$ = this.stateSubject.asObservable(), this.rootGroup$ = this.state$.pipe(
|
|
784
|
+
k((r) => r.rootGroup),
|
|
785
|
+
$()
|
|
772
786
|
), this.validation$ = this.state$.pipe(
|
|
773
|
-
|
|
774
|
-
|
|
787
|
+
k((r) => this.validationService.validateGroup(r.rootGroup, this.fieldsMap)),
|
|
788
|
+
$((r, s) => r.valid === s.valid && w(r.errors, s.errors))
|
|
775
789
|
), this.query$ = this.state$.pipe(
|
|
776
|
-
|
|
777
|
-
|
|
790
|
+
k((r) => this.queryConverter.toRxDBQuery(r)),
|
|
791
|
+
$((r, s) => w(r, s))
|
|
778
792
|
);
|
|
779
793
|
}
|
|
780
794
|
/**
|
|
@@ -793,7 +807,7 @@ class re {
|
|
|
793
807
|
* 获取最大嵌套层级
|
|
794
808
|
*/
|
|
795
809
|
getMaxNestingLevel() {
|
|
796
|
-
return this.config.maxNestingLevel ??
|
|
810
|
+
return this.config.maxNestingLevel ?? ne;
|
|
797
811
|
}
|
|
798
812
|
/**
|
|
799
813
|
* 获取字段列表
|
|
@@ -806,8 +820,8 @@ class re {
|
|
|
806
820
|
*/
|
|
807
821
|
setFields(e) {
|
|
808
822
|
this.fieldsMap.clear();
|
|
809
|
-
for (const
|
|
810
|
-
this.fieldsMap.set(
|
|
823
|
+
for (const t of e)
|
|
824
|
+
this.fieldsMap.set(t.name, t);
|
|
811
825
|
}
|
|
812
826
|
/**
|
|
813
827
|
* 获取操作符注册表
|
|
@@ -819,52 +833,52 @@ class re {
|
|
|
819
833
|
/**
|
|
820
834
|
* 添加规则
|
|
821
835
|
*/
|
|
822
|
-
addRule(e = null,
|
|
823
|
-
const
|
|
824
|
-
id:
|
|
825
|
-
field:
|
|
826
|
-
operator:
|
|
827
|
-
|
|
828
|
-
}, s = this.getState(), a = this.addItemToGroup(s.rootGroup, e ?? s.rootGroup.id,
|
|
829
|
-
return this.stateSubject.next({ rootGroup: a }),
|
|
836
|
+
addRule(e = null, t) {
|
|
837
|
+
const r = {
|
|
838
|
+
id: E(),
|
|
839
|
+
field: t?.field ?? "",
|
|
840
|
+
operator: t?.operator ?? "=",
|
|
841
|
+
...t && "value" in t ? { value: t.value } : { value: "" }
|
|
842
|
+
}, s = this.getState(), a = this.addItemToGroup(s.rootGroup, e ?? s.rootGroup.id, r);
|
|
843
|
+
return this.stateSubject.next({ rootGroup: a }), r.id;
|
|
830
844
|
}
|
|
831
845
|
/**
|
|
832
846
|
* 添加规则组
|
|
833
847
|
*/
|
|
834
|
-
addGroup(e = null,
|
|
835
|
-
const
|
|
848
|
+
addGroup(e = null, t = V) {
|
|
849
|
+
const r = this.getState(), s = e ?? r.rootGroup.id, a = this.getGroupDepth(r.rootGroup, s), l = this.getMaxNestingLevel();
|
|
836
850
|
if (a >= l)
|
|
837
851
|
throw new Error(`已达到最大嵌套深度 ${l}`);
|
|
838
852
|
const i = {
|
|
839
|
-
id:
|
|
840
|
-
combinator:
|
|
853
|
+
id: E(),
|
|
854
|
+
combinator: t,
|
|
841
855
|
rules: []
|
|
842
|
-
}, o = this.addItemToGroup(
|
|
856
|
+
}, o = this.addItemToGroup(r.rootGroup, s, i);
|
|
843
857
|
return this.stateSubject.next({ rootGroup: o }), i.id;
|
|
844
858
|
}
|
|
845
859
|
/**
|
|
846
860
|
* 更新规则
|
|
847
861
|
*/
|
|
848
|
-
updateRule(e,
|
|
849
|
-
const
|
|
862
|
+
updateRule(e, t) {
|
|
863
|
+
const r = this.getState(), s = this.updateItemInGroup(r.rootGroup, e, t);
|
|
850
864
|
this.stateSubject.next({ rootGroup: s });
|
|
851
865
|
}
|
|
852
866
|
/**
|
|
853
867
|
* 更新组的组合器
|
|
854
868
|
*/
|
|
855
|
-
updateGroupCombinator(e,
|
|
856
|
-
const
|
|
869
|
+
updateGroupCombinator(e, t) {
|
|
870
|
+
const r = this.getState(), s = this.updateItemInGroup(r.rootGroup, e, { combinator: t });
|
|
857
871
|
this.stateSubject.next({ rootGroup: s });
|
|
858
872
|
}
|
|
859
873
|
/**
|
|
860
874
|
* 删除规则或组
|
|
861
875
|
*/
|
|
862
876
|
remove(e) {
|
|
863
|
-
const
|
|
864
|
-
if (e ===
|
|
877
|
+
const t = this.getState();
|
|
878
|
+
if (e === t.rootGroup.id)
|
|
865
879
|
throw new Error("不能删除根组");
|
|
866
|
-
const
|
|
867
|
-
this.stateSubject.next({ rootGroup:
|
|
880
|
+
const r = this.removeItemFromGroup(t.rootGroup, e);
|
|
881
|
+
this.stateSubject.next({ rootGroup: r });
|
|
868
882
|
}
|
|
869
883
|
/**
|
|
870
884
|
* 清空所有规则
|
|
@@ -889,8 +903,8 @@ class re {
|
|
|
889
903
|
* 从 RxDB Query 加载
|
|
890
904
|
*/
|
|
891
905
|
fromRxDBQuery(e) {
|
|
892
|
-
const
|
|
893
|
-
this.stateSubject.next(
|
|
906
|
+
const t = this.queryConverter.fromRxDBQuery(e);
|
|
907
|
+
this.stateSubject.next(t);
|
|
894
908
|
}
|
|
895
909
|
// ==================== 校验方法 ====================
|
|
896
910
|
/**
|
|
@@ -906,49 +920,49 @@ class re {
|
|
|
906
920
|
return this.validate().valid;
|
|
907
921
|
}
|
|
908
922
|
// ==================== 私有辅助方法 ====================
|
|
909
|
-
addItemToGroup(e,
|
|
910
|
-
return e.id ===
|
|
923
|
+
addItemToGroup(e, t, r) {
|
|
924
|
+
return e.id === t ? {
|
|
911
925
|
...e,
|
|
912
|
-
rules: [...e.rules,
|
|
926
|
+
rules: [...e.rules, r]
|
|
913
927
|
} : {
|
|
914
928
|
...e,
|
|
915
|
-
rules: e.rules.map((s) =>
|
|
929
|
+
rules: e.rules.map((s) => v(s) ? this.addItemToGroup(s, t, r) : s)
|
|
916
930
|
};
|
|
917
931
|
}
|
|
918
|
-
updateItemInGroup(e,
|
|
919
|
-
return e.id ===
|
|
932
|
+
updateItemInGroup(e, t, r) {
|
|
933
|
+
return e.id === t ? { ...e, ...r } : {
|
|
920
934
|
...e,
|
|
921
|
-
rules: e.rules.map((s) =>
|
|
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)
|
|
922
936
|
};
|
|
923
937
|
}
|
|
924
|
-
removeItemFromGroup(e,
|
|
938
|
+
removeItemFromGroup(e, t) {
|
|
925
939
|
return {
|
|
926
940
|
...e,
|
|
927
|
-
rules: e.rules.filter((
|
|
941
|
+
rules: e.rules.filter((r) => v(r) || M(r) ? r.id !== t : !0).map((r) => v(r) ? this.removeItemFromGroup(r, t) : r)
|
|
928
942
|
};
|
|
929
943
|
}
|
|
930
|
-
getGroupDepth(e,
|
|
931
|
-
if (e.id ===
|
|
932
|
-
return
|
|
944
|
+
getGroupDepth(e, t, r = 1) {
|
|
945
|
+
if (e.id === t)
|
|
946
|
+
return r;
|
|
933
947
|
for (const s of e.rules)
|
|
934
|
-
if (
|
|
935
|
-
const a = this.getGroupDepth(s,
|
|
948
|
+
if (v(s)) {
|
|
949
|
+
const a = this.getGroupDepth(s, t, r + 1);
|
|
936
950
|
if (a > 0)
|
|
937
951
|
return a;
|
|
938
952
|
}
|
|
939
953
|
return 0;
|
|
940
954
|
}
|
|
941
955
|
}
|
|
942
|
-
function
|
|
943
|
-
return new
|
|
956
|
+
function de(n) {
|
|
957
|
+
return new ie(n);
|
|
944
958
|
}
|
|
945
|
-
const
|
|
946
|
-
function
|
|
947
|
-
const e = /* @__PURE__ */ new Set(),
|
|
959
|
+
const q = "__exists__";
|
|
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) => {
|
|
948
962
|
const f = (i.name.match(/\./g) || []).length, y = (o.name.match(/\./g) || []).length;
|
|
949
963
|
return f - y;
|
|
950
964
|
}), l = /* @__PURE__ */ new Map();
|
|
951
|
-
for (const i of
|
|
965
|
+
for (const i of t)
|
|
952
966
|
if (i.displayName) {
|
|
953
967
|
const o = i.name.split("."), f = i.displayName.split(".");
|
|
954
968
|
let y = "";
|
|
@@ -969,23 +983,23 @@ function ye(n) {
|
|
|
969
983
|
...i.relationFields && { relationFields: i.relationFields }
|
|
970
984
|
};
|
|
971
985
|
if (s.set(i.name, p), o.length === 1)
|
|
972
|
-
|
|
986
|
+
r.push(p);
|
|
973
987
|
else {
|
|
974
|
-
const m = o.slice(0, -1).join("."),
|
|
975
|
-
if (
|
|
976
|
-
|
|
988
|
+
const m = o.slice(0, -1).join("."), b = s.get(m);
|
|
989
|
+
if (b)
|
|
990
|
+
b.children = b.children ?? [], b.children.push(p);
|
|
977
991
|
else {
|
|
978
|
-
let d = "", N =
|
|
992
|
+
let d = "", N = r;
|
|
979
993
|
for (let T = 0; T < o.length - 1; T++) {
|
|
980
994
|
const R = o[T];
|
|
981
995
|
d = d ? `${d}.${R}` : R;
|
|
982
996
|
let h = s.get(d);
|
|
983
997
|
if (!h) {
|
|
984
|
-
const
|
|
998
|
+
const S = l.get(d) ?? R;
|
|
985
999
|
h = {
|
|
986
1000
|
label: R,
|
|
987
1001
|
value: d,
|
|
988
|
-
displayName:
|
|
1002
|
+
displayName: S,
|
|
989
1003
|
type: "relation",
|
|
990
1004
|
isRelation: !0,
|
|
991
1005
|
children: []
|
|
@@ -997,58 +1011,58 @@ function ye(n) {
|
|
|
997
1011
|
}
|
|
998
1012
|
}
|
|
999
1013
|
}
|
|
1000
|
-
return
|
|
1014
|
+
return Q(r, t), r;
|
|
1001
1015
|
}
|
|
1002
|
-
function
|
|
1003
|
-
const
|
|
1004
|
-
for (const
|
|
1005
|
-
if (
|
|
1006
|
-
const l =
|
|
1007
|
-
|
|
1008
|
-
label:
|
|
1009
|
-
value:
|
|
1016
|
+
function Q(n, e) {
|
|
1017
|
+
const t = new Map(e.map((r) => [r.name, r]));
|
|
1018
|
+
for (const r of n) {
|
|
1019
|
+
if (r.isRelation && r.children && r.children.length > 0 && !r.children.some((a) => a.label === q)) {
|
|
1020
|
+
const l = t.get(r.value)?.relationFields;
|
|
1021
|
+
r.children.unshift({
|
|
1022
|
+
label: q,
|
|
1023
|
+
value: r.value,
|
|
1010
1024
|
// 使用父节点的值,这样选择它就等于选择关系字段本身
|
|
1011
1025
|
displayName: "(存在性检查)",
|
|
1012
1026
|
type: "relation",
|
|
1013
1027
|
isRelation: !0,
|
|
1014
|
-
description: `检查 ${
|
|
1028
|
+
description: `检查 ${r.displayName} 是否存在`,
|
|
1015
1029
|
relationFields: l
|
|
1016
1030
|
// 复制 relationFields,确保 EXISTS 查询可以访问关联实体字段
|
|
1017
1031
|
});
|
|
1018
1032
|
}
|
|
1019
|
-
|
|
1033
|
+
r.children && Q(r.children, e);
|
|
1020
1034
|
}
|
|
1021
1035
|
}
|
|
1022
|
-
function
|
|
1023
|
-
for (const
|
|
1024
|
-
if (
|
|
1025
|
-
return
|
|
1026
|
-
if (
|
|
1027
|
-
const
|
|
1028
|
-
if (
|
|
1036
|
+
function ae(n, e) {
|
|
1037
|
+
for (const t of n) {
|
|
1038
|
+
if (t.value === e)
|
|
1039
|
+
return t;
|
|
1040
|
+
if (t.children) {
|
|
1041
|
+
const r = ae(t.children, e);
|
|
1042
|
+
if (r) return r;
|
|
1029
1043
|
}
|
|
1030
1044
|
}
|
|
1031
1045
|
}
|
|
1032
|
-
function
|
|
1033
|
-
const e = /* @__PURE__ */ new Map(),
|
|
1034
|
-
for (const s of
|
|
1035
|
-
e.set(s.value, s), s.children &&
|
|
1046
|
+
function me(n) {
|
|
1047
|
+
const e = /* @__PURE__ */ new Map(), t = (r) => {
|
|
1048
|
+
for (const s of r)
|
|
1049
|
+
e.set(s.value, s), s.children && t(s.children);
|
|
1036
1050
|
};
|
|
1037
|
-
return
|
|
1051
|
+
return t(n), e;
|
|
1038
1052
|
}
|
|
1039
|
-
function
|
|
1053
|
+
function ge(n = 10) {
|
|
1040
1054
|
return Array(n).fill("children");
|
|
1041
1055
|
}
|
|
1042
|
-
function
|
|
1043
|
-
const
|
|
1056
|
+
function be(n, e) {
|
|
1057
|
+
const t = e.split("."), r = [];
|
|
1044
1058
|
let s = n;
|
|
1045
|
-
for (let a = 0; a <
|
|
1046
|
-
const l =
|
|
1047
|
-
i ? (
|
|
1059
|
+
for (let a = 0; a < t.length; a++) {
|
|
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]);
|
|
1048
1062
|
}
|
|
1049
|
-
return
|
|
1063
|
+
return r.join(".");
|
|
1050
1064
|
}
|
|
1051
|
-
const
|
|
1065
|
+
const oe = 4, L = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"];
|
|
1052
1066
|
function G(n) {
|
|
1053
1067
|
switch (n) {
|
|
1054
1068
|
case g.uuid:
|
|
@@ -1072,12 +1086,15 @@ function G(n) {
|
|
|
1072
1086
|
return "string";
|
|
1073
1087
|
}
|
|
1074
1088
|
}
|
|
1075
|
-
function
|
|
1076
|
-
return n.kind === B.ONE_TO_MANY || n.kind === B.MANY_TO_MANY ?
|
|
1089
|
+
function le(n) {
|
|
1090
|
+
return n.kind === B.ONE_TO_MANY || n.kind === B.MANY_TO_MANY ? [n.mappedProperty] : [];
|
|
1091
|
+
}
|
|
1092
|
+
function ve(n, e, t = {}) {
|
|
1093
|
+
return K(n, e, t, n, [], "", /* @__PURE__ */ new Set(), 0);
|
|
1077
1094
|
}
|
|
1078
|
-
function
|
|
1079
|
-
const o = [], f =
|
|
1080
|
-
if (
|
|
1095
|
+
function K(n, e, t, r, s, a, l, i) {
|
|
1096
|
+
const o = [], f = t.relationQueryDeep ?? oe, y = t.systemFields ?? L;
|
|
1097
|
+
if (l.has(n.name))
|
|
1081
1098
|
return o;
|
|
1082
1099
|
if (!a)
|
|
1083
1100
|
for (const u of y) {
|
|
@@ -1101,10 +1118,10 @@ function ae(n, e, r = {}, t, s = [], a = "", l = /* @__PURE__ */ new Set(), i =
|
|
|
1101
1118
|
for (const u of n.foreignKeyNames) {
|
|
1102
1119
|
const c = a ? `${a}.${u}` : u;
|
|
1103
1120
|
if (!o.some((p) => p.name === c)) {
|
|
1104
|
-
const p = u.slice(0, -2), m = n.foreignKeyRelationMap.get(p),
|
|
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;
|
|
1105
1122
|
o.push({
|
|
1106
1123
|
name: c,
|
|
1107
|
-
displayName: `${
|
|
1124
|
+
displayName: `${b}ID`,
|
|
1108
1125
|
type: "string",
|
|
1109
1126
|
nullable: d
|
|
1110
1127
|
});
|
|
@@ -1114,46 +1131,46 @@ function ae(n, e, r = {}, t, s = [], a = "", l = /* @__PURE__ */ new Set(), i =
|
|
|
1114
1131
|
for (const [u, c] of n.relationMap) {
|
|
1115
1132
|
if (s.includes(u)) continue;
|
|
1116
1133
|
const p = e.get(c.mappedEntity);
|
|
1117
|
-
if (!p || i > 0 && p.metadata ===
|
|
1118
|
-
const m = a ? `${a}.${u}` : u,
|
|
1134
|
+
if (!p || i > 0 && p.metadata === r || l.has(p.metadata.name)) continue;
|
|
1135
|
+
const m = a ? `${a}.${u}` : u, b = c.displayName || u, d = ue(p.metadata, t);
|
|
1119
1136
|
o.push({
|
|
1120
1137
|
name: m,
|
|
1121
|
-
displayName: `${
|
|
1138
|
+
displayName: `${b} (${c.kind})`,
|
|
1122
1139
|
type: "relation",
|
|
1123
1140
|
isRelation: !0,
|
|
1124
1141
|
relationTarget: c.mappedEntity,
|
|
1125
1142
|
relationFields: d
|
|
1126
1143
|
});
|
|
1127
|
-
const N =
|
|
1144
|
+
const N = le(c), T = new Set(l);
|
|
1128
1145
|
T.add(n.name);
|
|
1129
|
-
const R =
|
|
1146
|
+
const R = K(
|
|
1130
1147
|
p.metadata,
|
|
1131
1148
|
e,
|
|
1132
|
-
r,
|
|
1133
1149
|
t,
|
|
1150
|
+
r,
|
|
1134
1151
|
N,
|
|
1135
1152
|
m,
|
|
1136
1153
|
T,
|
|
1137
1154
|
i + 1
|
|
1138
1155
|
);
|
|
1139
1156
|
for (const h of y) {
|
|
1140
|
-
const
|
|
1141
|
-
|
|
1142
|
-
name:
|
|
1143
|
-
displayName: `${
|
|
1144
|
-
type: G(
|
|
1145
|
-
nullable:
|
|
1157
|
+
const S = `${m}.${h}`, F = p.metadata.properties.find((A) => A.name === h);
|
|
1158
|
+
F && !o.some((A) => A.name === S) && o.push({
|
|
1159
|
+
name: S,
|
|
1160
|
+
displayName: `${b}.${F.displayName ?? h}`,
|
|
1161
|
+
type: G(F.type),
|
|
1162
|
+
nullable: F.nullable ?? !1
|
|
1146
1163
|
});
|
|
1147
1164
|
}
|
|
1148
1165
|
o.push(...R);
|
|
1149
1166
|
}
|
|
1150
1167
|
return o;
|
|
1151
1168
|
}
|
|
1152
|
-
function
|
|
1153
|
-
const
|
|
1154
|
-
for (const s of
|
|
1169
|
+
function ue(n, e = {}) {
|
|
1170
|
+
const t = [], r = e.systemFields ?? L;
|
|
1171
|
+
for (const s of r) {
|
|
1155
1172
|
const a = n.properties.find((l) => l.name === s);
|
|
1156
|
-
a &&
|
|
1173
|
+
a && t.push({
|
|
1157
1174
|
name: s,
|
|
1158
1175
|
displayName: a.displayName ?? s,
|
|
1159
1176
|
type: G(a.type),
|
|
@@ -1161,64 +1178,65 @@ function oe(n, e = {}) {
|
|
|
1161
1178
|
});
|
|
1162
1179
|
}
|
|
1163
1180
|
for (const [s, a] of n.propertyMap)
|
|
1164
|
-
|
|
1181
|
+
t.push({
|
|
1165
1182
|
name: s,
|
|
1166
1183
|
displayName: a.displayName ?? s,
|
|
1167
1184
|
type: G(a.type),
|
|
1168
1185
|
nullable: a.nullable ?? !1
|
|
1169
1186
|
});
|
|
1170
1187
|
for (const s of n.foreignKeyNames)
|
|
1171
|
-
if (!
|
|
1188
|
+
if (!t.some((a) => a.name === s)) {
|
|
1172
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;
|
|
1173
|
-
|
|
1190
|
+
t.push({
|
|
1174
1191
|
name: s,
|
|
1175
1192
|
displayName: `${i}ID`,
|
|
1176
1193
|
type: "string",
|
|
1177
1194
|
nullable: o
|
|
1178
1195
|
});
|
|
1179
1196
|
}
|
|
1180
|
-
return
|
|
1197
|
+
return t;
|
|
1181
1198
|
}
|
|
1182
|
-
function
|
|
1183
|
-
return n.sort((e,
|
|
1184
|
-
const
|
|
1185
|
-
return
|
|
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);
|
|
1186
1203
|
});
|
|
1187
1204
|
}
|
|
1188
|
-
function
|
|
1189
|
-
return
|
|
1205
|
+
function Re(n, e) {
|
|
1206
|
+
return _(e).parse(n);
|
|
1190
1207
|
}
|
|
1191
|
-
function
|
|
1192
|
-
return
|
|
1208
|
+
function Ne(n, e) {
|
|
1209
|
+
return _(e).parseMany(n);
|
|
1193
1210
|
}
|
|
1194
1211
|
export {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1212
|
+
Y as BUILTIN_VALIDATION_RULES,
|
|
1213
|
+
O as DEFAULT_OPERATORS,
|
|
1214
|
+
C as OperatorRegistry,
|
|
1215
|
+
ie as QueryBuilderService,
|
|
1216
|
+
Z as QueryConverter,
|
|
1217
|
+
x as SchemaParser,
|
|
1218
|
+
re as ValidationService,
|
|
1219
|
+
he as buildFieldTree,
|
|
1220
|
+
me as createFieldNodeMap,
|
|
1204
1221
|
J as createOperatorRegistry,
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
+
de as createQueryBuilderService,
|
|
1223
|
+
H as createQueryConverter,
|
|
1224
|
+
Ne as createSchemaFromEntities,
|
|
1225
|
+
Re as createSchemaFromEntity,
|
|
1226
|
+
_ as createSchemaParser,
|
|
1227
|
+
se as createValidationService,
|
|
1228
|
+
ve as extractFieldsFromMetadata,
|
|
1229
|
+
ue as extractRelationTargetFields,
|
|
1230
|
+
ae as findNodeByValue,
|
|
1231
|
+
E as generateId,
|
|
1232
|
+
ee as getDefaultOperatorRegistry,
|
|
1233
|
+
be as getDisplayNamePath,
|
|
1234
|
+
ye as getOperatorsForType,
|
|
1235
|
+
ge as getOptionGroupChildren,
|
|
1236
|
+
le as getRelationIgnoreKeys,
|
|
1237
|
+
M as isRule,
|
|
1238
|
+
v as isRuleGroup,
|
|
1222
1239
|
G as mapPropertyType,
|
|
1223
|
-
|
|
1240
|
+
Te as organizeFields,
|
|
1241
|
+
w as structuralEqual
|
|
1224
1242
|
};
|