@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.
Files changed (24) hide show
  1. package/base-components/components/model-form/model-form.component.d.ts +7 -2
  2. package/base-components/components/model-form-sub/model-form-sub.component.d.ts +7 -3
  3. package/base-components/components/refence-input/refence-input.component.d.ts +10 -4
  4. package/esm2020/base-components/components/model-form/model-form.component.mjs +56 -12
  5. package/esm2020/base-components/components/model-form-sub/model-form-sub.component.mjs +9 -3
  6. package/esm2020/base-components/components/model-table/model-table.component.mjs +4 -4
  7. package/esm2020/base-components/components/refence-input/refence-input.component.mjs +28 -22
  8. package/esm2020/base-components/components/tags/tags.component.mjs +2 -2
  9. package/esm2020/base-components/components/upload-image/upload-image.component.mjs +3 -3
  10. package/esm2020/shared/classes/graphql-meta.class.mjs +52 -28
  11. package/esm2020/shared/classes/graphql-type.class.mjs +2 -1
  12. package/esm2020/shared/services/graphql.service.mjs +30 -36
  13. package/fesm2015/lenne.tech-ng-base-base-components.mjs +110 -56
  14. package/fesm2015/lenne.tech-ng-base-base-components.mjs.map +1 -1
  15. package/fesm2015/lenne.tech-ng-base-shared.mjs +81 -61
  16. package/fesm2015/lenne.tech-ng-base-shared.mjs.map +1 -1
  17. package/fesm2020/lenne.tech-ng-base-base-components.mjs +95 -40
  18. package/fesm2020/lenne.tech-ng-base-base-components.mjs.map +1 -1
  19. package/fesm2020/lenne.tech-ng-base-shared.mjs +81 -61
  20. package/fesm2020/lenne.tech-ng-base-shared.mjs.map +1 -1
  21. package/package.json +1 -1
  22. package/shared/classes/graphql-meta.class.d.ts +7 -4
  23. package/shared/classes/graphql-type.class.d.ts +1 -0
  24. 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 = new WeakMap(), setMetaData = false) {
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 preparedObject = {};
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.get(type);
628
+ const preparedType = prepared[typeName];
629
+ // Work with cached type
607
630
  if (preparedType) {
608
- const clone = cloneDeep(preparedType);
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
- prepared.set(type, preparedObject);
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(preparedObject, ofTypeResult);
649
- return ofTypeResult;
677
+ Object.assign(graphQLType, ofTypeResult);
678
+ return graphQLType;
650
679
  }
651
680
  // Process fields
652
681
  if (type._fields) {
653
- const result = {};
682
+ const fields = {};
654
683
  for (const [key, value] of Object.entries(type._fields)) {
655
- result[key] = this.getDeepType(value, prepared, true);
684
+ fields[key] = this.getDeepType(value, prepared, true);
656
685
  }
657
- Object.assign(preparedObject, result);
658
- return result;
686
+ // Assign and not replace to preserve updates in the cache
687
+ Object.assign(graphQLType.fields, fields);
688
+ return graphQLType;
659
689
  }
660
- // Get type name
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(preparedObject, typeResult);
695
- return typeResult;
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
- graphqlType.isEnum = true;
729
+ graphQLType.isEnum = true;
704
730
  for (const [key, value] of Object.entries(type._nameLookup)) {
705
731
  if (!value.isDeprecated) {
706
- graphqlType.validEnums.push(key);
732
+ graphQLType.validEnums.push(key);
707
733
  }
708
734
  }
709
735
  }
710
736
  // Finish
711
- prepared.set(type, graphqlType);
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.graphQLTypeCollectionToStringArray(allowedFields).filter((field) => !fieldsData.usedFields.includes(field));
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.graphQLTypeCollectionToStringArray(allowedArgs)
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
- graphQLTypeCollectionToStringArray(collection, current = '', result = [], cacheNode = []) {
1382
- if (collection) {
1383
- if (collection instanceof GraphQLType) {
1384
- result.push(current);
1385
- }
1386
- else {
1387
- if (current?.includes('.')) {
1388
- cacheNode.push(current.split('.')[1]);
1389
- }
1390
- else if (current) {
1391
- cacheNode.push(current);
1392
- }
1393
- for (const key of Object.keys(collection)) {
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 (allowed.length < 1) {
1449
+ if (!allowedKeys || allowedKeys.length < 1) {
1429
1450
  break;
1430
1451
  }
1431
- key = allowedKeys?.shift();
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?.[item]) {
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: typeof allowed?.[item] === 'object' && !(allowed?.[item] instanceof GraphQLType) ? allowed?.[item] : item,
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: typeof allowed?.[key] === 'object' && !(allowed?.[key] instanceof GraphQLType) ? allowed?.[key] : key,
1653
+ allowed: allowed.fields[key],
1634
1654
  parent: currentPath + '.',
1635
1655
  spaces,
1636
1656
  schemaFields,