@lenne.tech/ng-base 14.0.2 → 14.0.5
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/base-components/components/model-form/model-form.component.d.ts +7 -2
- package/base-components/components/model-form-sub/model-form-sub.component.d.ts +7 -3
- package/base-components/components/refence-input/refence-input.component.d.ts +10 -4
- package/base-components/components/upload-image/upload-image.component.d.ts +3 -1
- package/esm2020/base-components/components/model-form/model-form.component.mjs +56 -12
- package/esm2020/base-components/components/model-form-sub/model-form-sub.component.mjs +9 -3
- package/esm2020/base-components/components/model-table/model-table.component.mjs +4 -4
- package/esm2020/base-components/components/refence-input/refence-input.component.mjs +28 -22
- package/esm2020/base-components/components/tags/tags.component.mjs +2 -2
- package/esm2020/base-components/components/upload-image/upload-image.component.mjs +22 -9
- package/esm2020/shared/classes/graphql-meta.class.mjs +52 -28
- package/esm2020/shared/classes/graphql-type.class.mjs +2 -1
- package/esm2020/shared/services/graphql.service.mjs +30 -36
- package/fesm2015/lenne.tech-ng-base-base-components.mjs +127 -61
- package/fesm2015/lenne.tech-ng-base-base-components.mjs.map +1 -1
- package/fesm2015/lenne.tech-ng-base-shared.mjs +81 -61
- package/fesm2015/lenne.tech-ng-base-shared.mjs.map +1 -1
- package/fesm2020/lenne.tech-ng-base-base-components.mjs +112 -45
- package/fesm2020/lenne.tech-ng-base-base-components.mjs.map +1 -1
- package/fesm2020/lenne.tech-ng-base-shared.mjs +81 -61
- package/fesm2020/lenne.tech-ng-base-shared.mjs.map +1 -1
- package/package.json +1 -1
- package/shared/classes/graphql-meta.class.d.ts +7 -4
- package/shared/classes/graphql-type.class.d.ts +1 -0
- package/shared/services/graphql.service.d.ts +4 -4
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { GraphQLInputObjectType, GraphQLNonNull, GraphQLList, buildClientSchema, getIntrospectionQuery } from 'graphql';
|
|
2
|
-
import { cloneDeep } from '@apollo/client/utilities';
|
|
1
|
+
import { GraphQLInputObjectType, GraphQLScalarType, GraphQLEnumType, GraphQLNonNull, GraphQLList, buildClientSchema, getIntrospectionQuery } from 'graphql';
|
|
3
2
|
import * as i0 from '@angular/core';
|
|
4
3
|
import { Directive, Inject, Input, HostListener, Injectable, InjectionToken } from '@angular/core';
|
|
5
4
|
import * as i2 from '@angular/common';
|
|
@@ -419,6 +418,7 @@ class GraphQLType extends Standard {
|
|
|
419
418
|
constructor() {
|
|
420
419
|
super(...arguments);
|
|
421
420
|
this.type = '';
|
|
421
|
+
this.fields = {};
|
|
422
422
|
this.isRequired = false;
|
|
423
423
|
this.isItemRequired = false;
|
|
424
424
|
this.isList = false;
|
|
@@ -506,10 +506,10 @@ class GraphQLMeta {
|
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
const func = this.getFunction(functionName, { type });
|
|
509
|
-
const result =
|
|
509
|
+
const result = new GraphQLType();
|
|
510
510
|
if (func === null || func === void 0 ? void 0 : func.args) {
|
|
511
511
|
func.args.forEach((item) => {
|
|
512
|
-
result[item.name] = this.getDeepType(item.type);
|
|
512
|
+
result.fields[item.name] = this.getDeepType(item.type);
|
|
513
513
|
});
|
|
514
514
|
}
|
|
515
515
|
// Set cache
|
|
@@ -572,22 +572,48 @@ class GraphQLMeta {
|
|
|
572
572
|
getType(name) {
|
|
573
573
|
return this.schema.getType(name);
|
|
574
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* Get (deep) type name
|
|
577
|
+
*/
|
|
578
|
+
getTypeName(type) {
|
|
579
|
+
if (type instanceof GraphQLInputObjectType ||
|
|
580
|
+
type instanceof GraphQLScalarType ||
|
|
581
|
+
type instanceof GraphQLEnumType) {
|
|
582
|
+
return type.name;
|
|
583
|
+
}
|
|
584
|
+
else if (type.type) {
|
|
585
|
+
return this.getTypeName(type.type);
|
|
586
|
+
}
|
|
587
|
+
else if (type.ofType) {
|
|
588
|
+
return this.getTypeName(type.ofType);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
return type.name;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
575
594
|
/**
|
|
576
595
|
* Get deep type data
|
|
577
596
|
*/
|
|
578
|
-
getDeepType(type, prepared =
|
|
597
|
+
getDeepType(type, prepared = {}, setMetaData = false) {
|
|
579
598
|
var _a, _b;
|
|
580
599
|
// Check type
|
|
581
600
|
if (!type) {
|
|
582
601
|
return type;
|
|
583
602
|
}
|
|
584
603
|
// Infinite regress protection
|
|
585
|
-
const
|
|
604
|
+
const typeName = this.getTypeName(type);
|
|
605
|
+
const graphQLType = GraphQLType.map({
|
|
606
|
+
type: this.getTypeName(type),
|
|
607
|
+
});
|
|
586
608
|
// Check prepared
|
|
587
609
|
if (typeof type === 'object') {
|
|
588
|
-
const preparedType = prepared
|
|
610
|
+
const preparedType = prepared[typeName];
|
|
611
|
+
// Work with cached type
|
|
589
612
|
if (preparedType) {
|
|
590
|
-
|
|
613
|
+
// Create a new object to protect own isXXX information
|
|
614
|
+
const clone = Object.assign({}, preparedType);
|
|
615
|
+
// But use fields as reference to get future changes via prepared caching
|
|
616
|
+
clone.fields = preparedType.fields;
|
|
591
617
|
// Disable meta flags for sub objects
|
|
592
618
|
if ((type === null || type === void 0 ? void 0 : type.type) instanceof GraphQLInputObjectType ||
|
|
593
619
|
((type === null || type === void 0 ? void 0 : type.type) instanceof GraphQLNonNull && ((_a = type === null || type === void 0 ? void 0 : type.type) === null || _a === void 0 ? void 0 : _a.ofType) instanceof GraphQLInputObjectType && setMetaData)) {
|
|
@@ -621,25 +647,29 @@ class GraphQLMeta {
|
|
|
621
647
|
}
|
|
622
648
|
return clone;
|
|
623
649
|
}
|
|
624
|
-
// Set prepared
|
|
625
|
-
|
|
650
|
+
// Set prepared cache for GraphQL types
|
|
651
|
+
// (type names start with uppercase letters as opposed to property names that start with lowercase letters)
|
|
652
|
+
if (type.name && type.name[0].toUpperCase() === type.name[0] && !prepared[type.name]) {
|
|
653
|
+
prepared[type.name] = graphQLType;
|
|
654
|
+
}
|
|
626
655
|
}
|
|
627
656
|
// Search deeper
|
|
628
657
|
if (type.ofType) {
|
|
629
658
|
const ofTypeResult = this.getDeepType(type.ofType, prepared, setMetaData);
|
|
630
|
-
Object.assign(
|
|
631
|
-
return
|
|
659
|
+
Object.assign(graphQLType, ofTypeResult);
|
|
660
|
+
return graphQLType;
|
|
632
661
|
}
|
|
633
662
|
// Process fields
|
|
634
663
|
if (type._fields) {
|
|
635
|
-
const
|
|
664
|
+
const fields = {};
|
|
636
665
|
for (const [key, value] of Object.entries(type._fields)) {
|
|
637
|
-
|
|
666
|
+
fields[key] = this.getDeepType(value, prepared, true);
|
|
638
667
|
}
|
|
639
|
-
|
|
640
|
-
|
|
668
|
+
// Assign and not replace to preserve updates in the cache
|
|
669
|
+
Object.assign(graphQLType.fields, fields);
|
|
670
|
+
return graphQLType;
|
|
641
671
|
}
|
|
642
|
-
//
|
|
672
|
+
// Process type
|
|
643
673
|
if (type.type) {
|
|
644
674
|
const typeResult = this.getDeepType(type.type, prepared, setMetaData);
|
|
645
675
|
// Disable meta flags for sub objects
|
|
@@ -673,25 +703,20 @@ class GraphQLMeta {
|
|
|
673
703
|
}
|
|
674
704
|
}
|
|
675
705
|
}
|
|
676
|
-
Object.assign(
|
|
677
|
-
return
|
|
706
|
+
Object.assign(graphQLType, typeResult);
|
|
707
|
+
return graphQLType;
|
|
678
708
|
}
|
|
679
|
-
// Initialize GraphQLType
|
|
680
|
-
const graphqlType = GraphQLType.map({
|
|
681
|
-
type: type.name,
|
|
682
|
-
});
|
|
683
709
|
// Set enum values
|
|
684
710
|
if (!!type._values) {
|
|
685
|
-
|
|
711
|
+
graphQLType.isEnum = true;
|
|
686
712
|
for (const [key, value] of Object.entries(type._nameLookup)) {
|
|
687
713
|
if (!value.isDeprecated) {
|
|
688
|
-
|
|
714
|
+
graphQLType.validEnums.push(key);
|
|
689
715
|
}
|
|
690
716
|
}
|
|
691
717
|
}
|
|
692
718
|
// Finish
|
|
693
|
-
|
|
694
|
-
return graphqlType;
|
|
719
|
+
return graphQLType;
|
|
695
720
|
}
|
|
696
721
|
}
|
|
697
722
|
|
|
@@ -1259,7 +1284,7 @@ class GraphQLService {
|
|
|
1259
1284
|
fieldsData.usedFields.sort();
|
|
1260
1285
|
fieldsData.schemaFields.sort();
|
|
1261
1286
|
const filtered = fieldsData.schemaFields.filter((field) => !fieldsData.usedFields.includes(field));
|
|
1262
|
-
const unused = this.
|
|
1287
|
+
const unused = this.graphQLTypeToStringArray(allowedFields).filter((field) => !fieldsData.usedFields.includes(field));
|
|
1263
1288
|
console.log({ fieldsData, filtered, unused });
|
|
1264
1289
|
}
|
|
1265
1290
|
fields = fieldsData.fieldsString;
|
|
@@ -1285,7 +1310,7 @@ class GraphQLService {
|
|
|
1285
1310
|
argsData.usedArgs.sort();
|
|
1286
1311
|
argsData.schemaArgs.sort();
|
|
1287
1312
|
const filtered = argsData.schemaArgs.filter((field) => !argsData.usedArgs.includes(field));
|
|
1288
|
-
const unused = this.
|
|
1313
|
+
const unused = this.graphQLTypeToStringArray(allowedArgs)
|
|
1289
1314
|
.sort()
|
|
1290
1315
|
.filter((field) => !argsData.usedArgs.includes(field));
|
|
1291
1316
|
console.log({ argsData, filtered, unused });
|
|
@@ -1353,25 +1378,21 @@ class GraphQLService {
|
|
|
1353
1378
|
/**
|
|
1354
1379
|
* Get fields / args from IGraphQLTypeCollection
|
|
1355
1380
|
*/
|
|
1356
|
-
|
|
1357
|
-
if (
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
if (current === key || cacheNode.includes(key)) {
|
|
1370
|
-
continue;
|
|
1371
|
-
}
|
|
1372
|
-
this.graphQLTypeCollectionToStringArray(collection[key], current ? current + '.' + key : key, result, cacheNode);
|
|
1373
|
-
}
|
|
1381
|
+
graphQLTypeToStringArray(graphQLType, current = '', result = [], cacheNode = []) {
|
|
1382
|
+
if (!graphQLType) {
|
|
1383
|
+
return result;
|
|
1384
|
+
}
|
|
1385
|
+
if (current === null || current === void 0 ? void 0 : current.includes('.')) {
|
|
1386
|
+
cacheNode.push(current.split('.')[1]);
|
|
1387
|
+
}
|
|
1388
|
+
else if (current) {
|
|
1389
|
+
cacheNode.push(current);
|
|
1390
|
+
}
|
|
1391
|
+
for (const key of Object.keys(graphQLType.fields)) {
|
|
1392
|
+
if (current === key || cacheNode.includes(key)) {
|
|
1393
|
+
continue;
|
|
1374
1394
|
}
|
|
1395
|
+
this.graphQLTypeToStringArray(graphQLType.fields[key], current ? current + '.' + key : key, result, cacheNode);
|
|
1375
1396
|
}
|
|
1376
1397
|
return result;
|
|
1377
1398
|
}
|
|
@@ -1389,18 +1410,18 @@ class GraphQLService {
|
|
|
1389
1410
|
const result = [];
|
|
1390
1411
|
// Process array
|
|
1391
1412
|
if (Array.isArray(args)) {
|
|
1392
|
-
const allowedKeys = allowed ? Object.keys(allowed) : null;
|
|
1413
|
+
const allowedKeys = allowed ? Object.keys(allowed.fields) : null;
|
|
1393
1414
|
for (const item of args) {
|
|
1394
1415
|
let key = null;
|
|
1395
1416
|
if (allowed) {
|
|
1396
|
-
if (
|
|
1417
|
+
if (!allowedKeys || allowedKeys.length < 1) {
|
|
1397
1418
|
break;
|
|
1398
1419
|
}
|
|
1399
|
-
key = allowedKeys
|
|
1420
|
+
key = allowedKeys.shift();
|
|
1400
1421
|
}
|
|
1401
1422
|
// Process value
|
|
1402
1423
|
result.push(this.prepareArguments(item, {
|
|
1403
|
-
allowed: key ? allowed[key] : null,
|
|
1424
|
+
allowed: key ? allowed.fields[key] : null,
|
|
1404
1425
|
level: level + 1,
|
|
1405
1426
|
parent: parent + key + '.',
|
|
1406
1427
|
schemaArgs,
|
|
@@ -1432,7 +1453,7 @@ class GraphQLService {
|
|
|
1432
1453
|
schemaArgs.push(currentKey);
|
|
1433
1454
|
// If the allowed key handling is enabled and the current key is not included in the list of allowed keys,
|
|
1434
1455
|
// the current key will be skipped
|
|
1435
|
-
if (allowed && !allowed[key]) {
|
|
1456
|
+
if (allowed && !allowed.fields[key]) {
|
|
1436
1457
|
continue;
|
|
1437
1458
|
}
|
|
1438
1459
|
// Skip value if not exists
|
|
@@ -1455,7 +1476,7 @@ class GraphQLService {
|
|
|
1455
1476
|
result.push(key +
|
|
1456
1477
|
': [' +
|
|
1457
1478
|
value.map((item) => this.prepareArguments(item, {
|
|
1458
|
-
allowed: allowed[key],
|
|
1479
|
+
allowed: allowed.fields[key],
|
|
1459
1480
|
level: level + 1,
|
|
1460
1481
|
parent: currentKey + '.',
|
|
1461
1482
|
schemaArgs,
|
|
@@ -1473,7 +1494,7 @@ class GraphQLService {
|
|
|
1473
1494
|
// Value is a string
|
|
1474
1495
|
else if (typeof value === 'string') {
|
|
1475
1496
|
// Enum (doesn't need quotation marks)
|
|
1476
|
-
if (allowed[key].isEnum) {
|
|
1497
|
+
if (allowed.fields[key].isEnum) {
|
|
1477
1498
|
additionalResult += value;
|
|
1478
1499
|
}
|
|
1479
1500
|
// String
|
|
@@ -1488,7 +1509,7 @@ class GraphQLService {
|
|
|
1488
1509
|
// Others
|
|
1489
1510
|
else {
|
|
1490
1511
|
additionalResult += this.prepareArguments(value, {
|
|
1491
|
-
allowed: allowed[key],
|
|
1512
|
+
allowed: allowed.fields[key],
|
|
1492
1513
|
level: level + 1,
|
|
1493
1514
|
parent: currentKey + '.',
|
|
1494
1515
|
schemaArgs,
|
|
@@ -1529,8 +1550,7 @@ class GraphQLService {
|
|
|
1529
1550
|
}
|
|
1530
1551
|
// Process string
|
|
1531
1552
|
if (typeof fields === 'string') {
|
|
1532
|
-
if (allowed &&
|
|
1533
|
-
((typeof allowed === 'string' && allowed !== fields) || (typeof allowed === 'object' && !allowed[fields]))) {
|
|
1553
|
+
if (allowed && !allowed.fields[fields]) {
|
|
1534
1554
|
return { fieldsString, schemaFields, usedFields };
|
|
1535
1555
|
}
|
|
1536
1556
|
return { fieldsString: '\n' + ' '.repeat(spaces).repeat(tab) + fields, schemaFields, usedFields };
|
|
@@ -1553,14 +1573,14 @@ class GraphQLService {
|
|
|
1553
1573
|
}
|
|
1554
1574
|
const currentPath = parent + item;
|
|
1555
1575
|
schemaFields.push(currentPath);
|
|
1556
|
-
if (allowed && !
|
|
1576
|
+
if (allowed && !allowed.fields[item]) {
|
|
1557
1577
|
continue;
|
|
1558
1578
|
}
|
|
1559
1579
|
usedFields.push(currentPath);
|
|
1560
1580
|
fieldsString =
|
|
1561
1581
|
fieldsString +
|
|
1562
1582
|
this.prepareFields(item, {
|
|
1563
|
-
allowed:
|
|
1583
|
+
allowed: null,
|
|
1564
1584
|
parent: currentPath + '.',
|
|
1565
1585
|
spaces,
|
|
1566
1586
|
schemaFields,
|
|
@@ -1574,7 +1594,7 @@ class GraphQLService {
|
|
|
1574
1594
|
for (const [key, val] of Object.entries(fields)) {
|
|
1575
1595
|
const currentPath = parent + key;
|
|
1576
1596
|
schemaFields.push(currentPath);
|
|
1577
|
-
if (allowed && !allowed[key]) {
|
|
1597
|
+
if (allowed && !allowed.fields[key]) {
|
|
1578
1598
|
continue;
|
|
1579
1599
|
}
|
|
1580
1600
|
usedFields.push(currentPath);
|
|
@@ -1590,7 +1610,7 @@ class GraphQLService {
|
|
|
1590
1610
|
' ' +
|
|
1591
1611
|
'{' +
|
|
1592
1612
|
this.prepareFields(val, {
|
|
1593
|
-
allowed:
|
|
1613
|
+
allowed: allowed.fields[key],
|
|
1594
1614
|
parent: currentPath + '.',
|
|
1595
1615
|
spaces,
|
|
1596
1616
|
schemaFields,
|