@lenne.tech/ng-base 14.0.4 → 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/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 +3 -3
- 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 +110 -56
- 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 +95 -40
- 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';
|
|
@@ -423,6 +422,7 @@ class GraphQLType extends Standard {
|
|
|
423
422
|
constructor() {
|
|
424
423
|
super(...arguments);
|
|
425
424
|
this.type = '';
|
|
425
|
+
this.fields = {};
|
|
426
426
|
this.isRequired = false;
|
|
427
427
|
this.isItemRequired = false;
|
|
428
428
|
this.isList = false;
|
|
@@ -515,10 +515,10 @@ class GraphQLMeta {
|
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
517
|
const func = this.getFunction(functionName, { type });
|
|
518
|
-
const result =
|
|
518
|
+
const result = new GraphQLType();
|
|
519
519
|
if (func?.args) {
|
|
520
520
|
func.args.forEach((item) => {
|
|
521
|
-
result[item.name] = this.getDeepType(item.type);
|
|
521
|
+
result.fields[item.name] = this.getDeepType(item.type);
|
|
522
522
|
});
|
|
523
523
|
}
|
|
524
524
|
// Set cache
|
|
@@ -591,21 +591,47 @@ class GraphQLMeta {
|
|
|
591
591
|
getType(name) {
|
|
592
592
|
return this.schema.getType(name);
|
|
593
593
|
}
|
|
594
|
+
/**
|
|
595
|
+
* Get (deep) type name
|
|
596
|
+
*/
|
|
597
|
+
getTypeName(type) {
|
|
598
|
+
if (type instanceof GraphQLInputObjectType ||
|
|
599
|
+
type instanceof GraphQLScalarType ||
|
|
600
|
+
type instanceof GraphQLEnumType) {
|
|
601
|
+
return type.name;
|
|
602
|
+
}
|
|
603
|
+
else if (type.type) {
|
|
604
|
+
return this.getTypeName(type.type);
|
|
605
|
+
}
|
|
606
|
+
else if (type.ofType) {
|
|
607
|
+
return this.getTypeName(type.ofType);
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
return type.name;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
594
613
|
/**
|
|
595
614
|
* Get deep type data
|
|
596
615
|
*/
|
|
597
|
-
getDeepType(type, prepared =
|
|
616
|
+
getDeepType(type, prepared = {}, setMetaData = false) {
|
|
598
617
|
// Check type
|
|
599
618
|
if (!type) {
|
|
600
619
|
return type;
|
|
601
620
|
}
|
|
602
621
|
// Infinite regress protection
|
|
603
|
-
const
|
|
622
|
+
const typeName = this.getTypeName(type);
|
|
623
|
+
const graphQLType = GraphQLType.map({
|
|
624
|
+
type: this.getTypeName(type),
|
|
625
|
+
});
|
|
604
626
|
// Check prepared
|
|
605
627
|
if (typeof type === 'object') {
|
|
606
|
-
const preparedType = prepared
|
|
628
|
+
const preparedType = prepared[typeName];
|
|
629
|
+
// Work with cached type
|
|
607
630
|
if (preparedType) {
|
|
608
|
-
|
|
631
|
+
// Create a new object to protect own isXXX information
|
|
632
|
+
const clone = Object.assign({}, preparedType);
|
|
633
|
+
// But use fields as reference to get future changes via prepared caching
|
|
634
|
+
clone.fields = preparedType.fields;
|
|
609
635
|
// Disable meta flags for sub objects
|
|
610
636
|
if (type?.type instanceof GraphQLInputObjectType ||
|
|
611
637
|
(type?.type instanceof GraphQLNonNull && type?.type?.ofType instanceof GraphQLInputObjectType && setMetaData)) {
|
|
@@ -639,25 +665,29 @@ class GraphQLMeta {
|
|
|
639
665
|
}
|
|
640
666
|
return clone;
|
|
641
667
|
}
|
|
642
|
-
// Set prepared
|
|
643
|
-
|
|
668
|
+
// Set prepared cache for GraphQL types
|
|
669
|
+
// (type names start with uppercase letters as opposed to property names that start with lowercase letters)
|
|
670
|
+
if (type.name && type.name[0].toUpperCase() === type.name[0] && !prepared[type.name]) {
|
|
671
|
+
prepared[type.name] = graphQLType;
|
|
672
|
+
}
|
|
644
673
|
}
|
|
645
674
|
// Search deeper
|
|
646
675
|
if (type.ofType) {
|
|
647
676
|
const ofTypeResult = this.getDeepType(type.ofType, prepared, setMetaData);
|
|
648
|
-
Object.assign(
|
|
649
|
-
return
|
|
677
|
+
Object.assign(graphQLType, ofTypeResult);
|
|
678
|
+
return graphQLType;
|
|
650
679
|
}
|
|
651
680
|
// Process fields
|
|
652
681
|
if (type._fields) {
|
|
653
|
-
const
|
|
682
|
+
const fields = {};
|
|
654
683
|
for (const [key, value] of Object.entries(type._fields)) {
|
|
655
|
-
|
|
684
|
+
fields[key] = this.getDeepType(value, prepared, true);
|
|
656
685
|
}
|
|
657
|
-
|
|
658
|
-
|
|
686
|
+
// Assign and not replace to preserve updates in the cache
|
|
687
|
+
Object.assign(graphQLType.fields, fields);
|
|
688
|
+
return graphQLType;
|
|
659
689
|
}
|
|
660
|
-
//
|
|
690
|
+
// Process type
|
|
661
691
|
if (type.type) {
|
|
662
692
|
const typeResult = this.getDeepType(type.type, prepared, setMetaData);
|
|
663
693
|
// Disable meta flags for sub objects
|
|
@@ -691,25 +721,20 @@ class GraphQLMeta {
|
|
|
691
721
|
}
|
|
692
722
|
}
|
|
693
723
|
}
|
|
694
|
-
Object.assign(
|
|
695
|
-
return
|
|
724
|
+
Object.assign(graphQLType, typeResult);
|
|
725
|
+
return graphQLType;
|
|
696
726
|
}
|
|
697
|
-
// Initialize GraphQLType
|
|
698
|
-
const graphqlType = GraphQLType.map({
|
|
699
|
-
type: type.name,
|
|
700
|
-
});
|
|
701
727
|
// Set enum values
|
|
702
728
|
if (!!type._values) {
|
|
703
|
-
|
|
729
|
+
graphQLType.isEnum = true;
|
|
704
730
|
for (const [key, value] of Object.entries(type._nameLookup)) {
|
|
705
731
|
if (!value.isDeprecated) {
|
|
706
|
-
|
|
732
|
+
graphQLType.validEnums.push(key);
|
|
707
733
|
}
|
|
708
734
|
}
|
|
709
735
|
}
|
|
710
736
|
// Finish
|
|
711
|
-
|
|
712
|
-
return graphqlType;
|
|
737
|
+
return graphQLType;
|
|
713
738
|
}
|
|
714
739
|
}
|
|
715
740
|
|
|
@@ -1285,7 +1310,7 @@ class GraphQLService {
|
|
|
1285
1310
|
fieldsData.usedFields.sort();
|
|
1286
1311
|
fieldsData.schemaFields.sort();
|
|
1287
1312
|
const filtered = fieldsData.schemaFields.filter((field) => !fieldsData.usedFields.includes(field));
|
|
1288
|
-
const unused = this.
|
|
1313
|
+
const unused = this.graphQLTypeToStringArray(allowedFields).filter((field) => !fieldsData.usedFields.includes(field));
|
|
1289
1314
|
console.log({ fieldsData, filtered, unused });
|
|
1290
1315
|
}
|
|
1291
1316
|
fields = fieldsData.fieldsString;
|
|
@@ -1311,7 +1336,7 @@ class GraphQLService {
|
|
|
1311
1336
|
argsData.usedArgs.sort();
|
|
1312
1337
|
argsData.schemaArgs.sort();
|
|
1313
1338
|
const filtered = argsData.schemaArgs.filter((field) => !argsData.usedArgs.includes(field));
|
|
1314
|
-
const unused = this.
|
|
1339
|
+
const unused = this.graphQLTypeToStringArray(allowedArgs)
|
|
1315
1340
|
.sort()
|
|
1316
1341
|
.filter((field) => !argsData.usedArgs.includes(field));
|
|
1317
1342
|
console.log({ argsData, filtered, unused });
|
|
@@ -1378,25 +1403,21 @@ class GraphQLService {
|
|
|
1378
1403
|
/**
|
|
1379
1404
|
* Get fields / args from IGraphQLTypeCollection
|
|
1380
1405
|
*/
|
|
1381
|
-
|
|
1382
|
-
if (
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
if (current === key || cacheNode.includes(key)) {
|
|
1395
|
-
continue;
|
|
1396
|
-
}
|
|
1397
|
-
this.graphQLTypeCollectionToStringArray(collection[key], current ? current + '.' + key : key, result, cacheNode);
|
|
1398
|
-
}
|
|
1406
|
+
graphQLTypeToStringArray(graphQLType, current = '', result = [], cacheNode = []) {
|
|
1407
|
+
if (!graphQLType) {
|
|
1408
|
+
return result;
|
|
1409
|
+
}
|
|
1410
|
+
if (current?.includes('.')) {
|
|
1411
|
+
cacheNode.push(current.split('.')[1]);
|
|
1412
|
+
}
|
|
1413
|
+
else if (current) {
|
|
1414
|
+
cacheNode.push(current);
|
|
1415
|
+
}
|
|
1416
|
+
for (const key of Object.keys(graphQLType.fields)) {
|
|
1417
|
+
if (current === key || cacheNode.includes(key)) {
|
|
1418
|
+
continue;
|
|
1399
1419
|
}
|
|
1420
|
+
this.graphQLTypeToStringArray(graphQLType.fields[key], current ? current + '.' + key : key, result, cacheNode);
|
|
1400
1421
|
}
|
|
1401
1422
|
return result;
|
|
1402
1423
|
}
|
|
@@ -1421,18 +1442,18 @@ class GraphQLService {
|
|
|
1421
1442
|
const result = [];
|
|
1422
1443
|
// Process array
|
|
1423
1444
|
if (Array.isArray(args)) {
|
|
1424
|
-
const allowedKeys = allowed ? Object.keys(allowed) : null;
|
|
1445
|
+
const allowedKeys = allowed ? Object.keys(allowed.fields) : null;
|
|
1425
1446
|
for (const item of args) {
|
|
1426
1447
|
let key = null;
|
|
1427
1448
|
if (allowed) {
|
|
1428
|
-
if (
|
|
1449
|
+
if (!allowedKeys || allowedKeys.length < 1) {
|
|
1429
1450
|
break;
|
|
1430
1451
|
}
|
|
1431
|
-
key = allowedKeys
|
|
1452
|
+
key = allowedKeys.shift();
|
|
1432
1453
|
}
|
|
1433
1454
|
// Process value
|
|
1434
1455
|
result.push(this.prepareArguments(item, {
|
|
1435
|
-
allowed: key ? allowed[key] : null,
|
|
1456
|
+
allowed: key ? allowed.fields[key] : null,
|
|
1436
1457
|
level: level + 1,
|
|
1437
1458
|
parent: parent + key + '.',
|
|
1438
1459
|
schemaArgs,
|
|
@@ -1464,7 +1485,7 @@ class GraphQLService {
|
|
|
1464
1485
|
schemaArgs.push(currentKey);
|
|
1465
1486
|
// If the allowed key handling is enabled and the current key is not included in the list of allowed keys,
|
|
1466
1487
|
// the current key will be skipped
|
|
1467
|
-
if (allowed && !allowed[key]) {
|
|
1488
|
+
if (allowed && !allowed.fields[key]) {
|
|
1468
1489
|
continue;
|
|
1469
1490
|
}
|
|
1470
1491
|
// Skip value if not exists
|
|
@@ -1487,7 +1508,7 @@ class GraphQLService {
|
|
|
1487
1508
|
result.push(key +
|
|
1488
1509
|
': [' +
|
|
1489
1510
|
value.map((item) => this.prepareArguments(item, {
|
|
1490
|
-
allowed: allowed[key],
|
|
1511
|
+
allowed: allowed.fields[key],
|
|
1491
1512
|
level: level + 1,
|
|
1492
1513
|
parent: currentKey + '.',
|
|
1493
1514
|
schemaArgs,
|
|
@@ -1505,7 +1526,7 @@ class GraphQLService {
|
|
|
1505
1526
|
// Value is a string
|
|
1506
1527
|
else if (typeof value === 'string') {
|
|
1507
1528
|
// Enum (doesn't need quotation marks)
|
|
1508
|
-
if (allowed[key].isEnum) {
|
|
1529
|
+
if (allowed.fields[key].isEnum) {
|
|
1509
1530
|
additionalResult += value;
|
|
1510
1531
|
}
|
|
1511
1532
|
// String
|
|
@@ -1520,7 +1541,7 @@ class GraphQLService {
|
|
|
1520
1541
|
// Others
|
|
1521
1542
|
else {
|
|
1522
1543
|
additionalResult += this.prepareArguments(value, {
|
|
1523
|
-
allowed: allowed[key],
|
|
1544
|
+
allowed: allowed.fields[key],
|
|
1524
1545
|
level: level + 1,
|
|
1525
1546
|
parent: currentKey + '.',
|
|
1526
1547
|
schemaArgs,
|
|
@@ -1569,8 +1590,7 @@ class GraphQLService {
|
|
|
1569
1590
|
}
|
|
1570
1591
|
// Process string
|
|
1571
1592
|
if (typeof fields === 'string') {
|
|
1572
|
-
if (allowed &&
|
|
1573
|
-
((typeof allowed === 'string' && allowed !== fields) || (typeof allowed === 'object' && !allowed[fields]))) {
|
|
1593
|
+
if (allowed && !allowed.fields[fields]) {
|
|
1574
1594
|
return { fieldsString, schemaFields, usedFields };
|
|
1575
1595
|
}
|
|
1576
1596
|
return { fieldsString: '\n' + ' '.repeat(spaces).repeat(tab) + fields, schemaFields, usedFields };
|
|
@@ -1593,14 +1613,14 @@ class GraphQLService {
|
|
|
1593
1613
|
}
|
|
1594
1614
|
const currentPath = parent + item;
|
|
1595
1615
|
schemaFields.push(currentPath);
|
|
1596
|
-
if (allowed && !allowed
|
|
1616
|
+
if (allowed && !allowed.fields[item]) {
|
|
1597
1617
|
continue;
|
|
1598
1618
|
}
|
|
1599
1619
|
usedFields.push(currentPath);
|
|
1600
1620
|
fieldsString =
|
|
1601
1621
|
fieldsString +
|
|
1602
1622
|
this.prepareFields(item, {
|
|
1603
|
-
allowed:
|
|
1623
|
+
allowed: null,
|
|
1604
1624
|
parent: currentPath + '.',
|
|
1605
1625
|
spaces,
|
|
1606
1626
|
schemaFields,
|
|
@@ -1614,7 +1634,7 @@ class GraphQLService {
|
|
|
1614
1634
|
for (const [key, val] of Object.entries(fields)) {
|
|
1615
1635
|
const currentPath = parent + key;
|
|
1616
1636
|
schemaFields.push(currentPath);
|
|
1617
|
-
if (allowed && !allowed[key]) {
|
|
1637
|
+
if (allowed && !allowed.fields[key]) {
|
|
1618
1638
|
continue;
|
|
1619
1639
|
}
|
|
1620
1640
|
usedFields.push(currentPath);
|
|
@@ -1630,7 +1650,7 @@ class GraphQLService {
|
|
|
1630
1650
|
' ' +
|
|
1631
1651
|
'{' +
|
|
1632
1652
|
this.prepareFields(val, {
|
|
1633
|
-
allowed:
|
|
1653
|
+
allowed: allowed.fields[key],
|
|
1634
1654
|
parent: currentPath + '.',
|
|
1635
1655
|
spaces,
|
|
1636
1656
|
schemaFields,
|