@processpuzzle/base-entity 0.7.8 → 0.7.9

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/README.md CHANGED
@@ -130,7 +130,7 @@ export const TestEntityStore = signalStore(
130
130
 
131
131
  ### 5. Describe the attributes
132
132
 
133
- Each visible field gets a `BaseEntityAttrDescriptor`. `FormControlType` covers `TEXT_BOX`, `TEXTAREA`, `CHECKBOX`, `DATE`, `DROPDOWN`, `LOOKUP`, `RADIO`, `TAGS`, `ARTIFACT`, `COMPONENTS`, `FOREIGN_KEY`, `LABEL`, `TITLE`, and `FLEX_BOX`. Use `FlexboxDescriptor` to lay attributes out in rows and columns, and `linkedEntityType` to attach a related entity's descriptor (used by `LOOKUP`, `FOREIGN_KEY`, and nested `COMPONENTS`).
133
+ Each visible field gets a `BaseEntityAttrDescriptor`. `FormControlType` covers `TEXT_BOX`, `TEXTAREA`, `CHECKBOX`, `DATE`, `DROPDOWN`, `LOOKUP`, `RADIO`, `TAGS`, `ARTIFACT`, `COMPONENTS`, `FOREIGN_KEY`, `LABEL`, `TITLE`, and `FLEX_BOX`. Use `FlexboxDescriptor` to lay attributes out in rows and columns, and `linkedEntityType` (a string — the related entity's name) to point at a related entity (used by `LOOKUP`, `FOREIGN_KEY`, and nested `COMPONENTS`). The descriptor is resolved at runtime through `BASE_ENTITY_FACADE_REGISTRY`.
134
134
 
135
135
  ```typescript
136
136
  function createTestEntityAttrDescriptors(): AbstractAttrDescriptor[] {
@@ -144,8 +144,8 @@ function createTestEntityAttrDescriptors(): AbstractAttrDescriptor[] {
144
144
  const enumAttr = new BaseEntityAttrDescriptor('enumValue', FormControlType.DROPDOWN, 'Enum', selectables);
145
145
  const componentsAttr = new BaseEntityAttrDescriptor('components', FormControlType.COMPONENTS, 'Components');
146
146
 
147
- lookupAttr.linkedEntityType = createTrunkDataDescriptor();
148
- componentsAttr.linkedEntityType = createTestEntityComponentDescriptor();
147
+ lookupAttr.linkedEntityType = 'Trunk Data';
148
+ componentsAttr.linkedEntityType = 'Test Entity Component';
149
149
 
150
150
  const column1 = new FlexboxDescriptor([nameAttr, descriptionAttr, booleanAttr], FlexDirection.COLUMN);
151
151
  const column2 = new FlexboxDescriptor([numberAttr, dateAttr, lookupAttr, enumAttr, componentsAttr], FlexDirection.COLUMN);
@@ -154,19 +154,14 @@ function createTestEntityAttrDescriptors(): AbstractAttrDescriptor[] {
154
154
  return [layout];
155
155
  }
156
156
 
157
- let cachedDescriptor: BaseEntityDescriptor | undefined;
158
-
159
157
  export function createTestEntityDescriptor(): BaseEntityDescriptor {
160
- if (cachedDescriptor) return cachedDescriptor;
161
- cachedDescriptor = new BaseEntityDescriptor({ entityName: 'Test Entity', attrDescriptors: [] });
162
- cachedDescriptor.attrDescriptors = createTestEntityAttrDescriptors();
163
- return cachedDescriptor;
158
+ return new BaseEntityDescriptor({ entityName: 'Test Entity', attrDescriptors: createTestEntityAttrDescriptors() });
164
159
  }
165
160
  ```
166
161
 
167
162
  A few notes:
168
163
 
169
- - Caching the descriptor in a module-level variable keeps a single instance shared across components and breaks circular references between bidirectionally linked entities.
164
+ - `linkedEntityType` is just the name of the related entity. The actual `BaseEntityDescriptor` is resolved at runtime through the facade registered in `BASE_ENTITY_FACADE_REGISTRY`.
170
165
  - `BaseEntityDescriptor` takes an options object (`{ entityName, attrDescriptors, store?, entityTitle? }`); `store` and `entityTitle` are usually set later in the host component.
171
166
 
172
167
  ### 6. Render the container
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, input, computed, Component, effect, InjectionToken, Inject, Directive, Injector, signal, HostBinding, Injectable, EventEmitter, Output, ViewChild, DestroyRef, untracked, isDevMode, runInInjectionContext } from '@angular/core';
2
+ import { inject, input, computed, Component, effect, InjectionToken, Inject, Directive, Injector, signal, Injectable, HostBinding, EventEmitter, Output, ViewChild, DestroyRef, untracked, isDevMode, runInInjectionContext } from '@angular/core';
3
3
  import { MatSnackBar } from '@angular/material/snack-bar';
4
4
  import * as i1 from '@angular/common';
5
5
  import { CommonModule, NgClass, NgStyle, NgIf, NgForOf, SlicePipe } from '@angular/common';
@@ -899,7 +899,7 @@ class EntityRegistryComponent {
899
899
  lines: attr.lines,
900
900
  options: attr.options,
901
901
  required: attr.required,
902
- linkedEntityType: attr.linkedEntityType ? { entityName: attr.linkedEntityType.entityName } : undefined,
902
+ linkedEntityType: attr.linkedEntityType,
903
903
  }),
904
904
  };
905
905
  }
@@ -914,6 +914,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.15", ngImpo
914
914
  }]
915
915
  }] });
916
916
 
917
+ class BaseEntityDescriptorRegistry {
918
+ registry = inject(BASE_ENTITY_FACADE_REGISTRY);
919
+ injector = inject(Injector);
920
+ getDescriptor(entityName) {
921
+ const facade = this.resolveFacade(entityName);
922
+ return facade?.descriptor;
923
+ }
924
+ getStore(entityName) {
925
+ const facade = this.resolveFacade(entityName);
926
+ return facade?.store;
927
+ }
928
+ resolveFacade(entityName) {
929
+ if (!entityName)
930
+ return undefined;
931
+ const facadeToken = this.registry[entityName];
932
+ if (!facadeToken)
933
+ return undefined;
934
+ return this.injector.get(facadeToken, undefined);
935
+ }
936
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BaseEntityDescriptorRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
937
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BaseEntityDescriptorRegistry, providedIn: 'root' });
938
+ }
939
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BaseEntityDescriptorRegistry, decorators: [{
940
+ type: Injectable,
941
+ args: [{ providedIn: 'root' }]
942
+ }] });
943
+
917
944
  function entityNameFromType(entityType) {
918
945
  return entityType.name ?? 'base-entity';
919
946
  }
@@ -940,14 +967,15 @@ class BaseFormControlComponent {
940
967
  formGroup;
941
968
  store;
942
969
  style = computed(() => this.config().style, ...(ngDevMode ? [{ debugName: "style" }] : /* istanbul ignore next */ []));
943
- linkedEntityType = computed(() => {
944
- const linkedEntityType = this.config().linkedEntityType;
945
- if (linkedEntityType === undefined) {
970
+ linkedEntityName = computed(() => {
971
+ const linkedEntityName = this.config().linkedEntityType;
972
+ if (linkedEntityName === undefined) {
946
973
  this.logger.error(`linkedEntityType should be defined for '${this.config().attrName}'.`);
947
974
  throw new Error(`linkedEntityType should be defined for '${this.config().attrName}'.`);
948
975
  }
949
- return linkedEntityType;
950
- }, ...(ngDevMode ? [{ debugName: "linkedEntityType" }] : /* istanbul ignore next */ []));
976
+ return linkedEntityName;
977
+ }, ...(ngDevMode ? [{ debugName: "linkedEntityName" }] : /* istanbul ignore next */ []));
978
+ linkedEntityDescriptor = computed(() => this.descriptorRegistry.getDescriptor(this.linkedEntityName()), ...(ngDevMode ? [{ debugName: "linkedEntityDescriptor" }] : /* istanbul ignore next */ []));
951
979
  value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
952
980
  get testId() {
953
981
  const attrName = this.config()?.attrName;
@@ -958,34 +986,7 @@ class BaseFormControlComponent {
958
986
  }
959
987
  logger = inject(NGXLogger);
960
988
  formNavigator = inject(BaseFormNavigatorSingletonStore);
961
- injector = inject(Injector);
962
- facadeRegistry = inject(BASE_ENTITY_FACADE_REGISTRY);
963
- // region Angular lifecycle hooks
964
- // endregion
965
- resolveRelatedEntityStore() {
966
- const entityName = this.config().linkedEntityType?.entityName;
967
- const facadeToken = entityName ? this.facadeRegistry[entityName] : undefined;
968
- if (facadeToken) {
969
- const facade = this.injector.get(facadeToken, undefined);
970
- return facade?.store;
971
- }
972
- const store = this.config().linkedEntityType?.store;
973
- if (!store) {
974
- return undefined;
975
- }
976
- if (this.isStoreInstance(store)) {
977
- return store;
978
- }
979
- try {
980
- return this.injector.get(store, undefined);
981
- }
982
- catch {
983
- return undefined;
984
- }
985
- }
986
- isStoreInstance(store) {
987
- return !!store && (typeof store === 'object' || typeof store === 'function') && ('load' in store || 'loadById' in store || 'entities' in store);
988
- }
989
+ descriptorRegistry = inject(BaseEntityDescriptorRegistry);
989
990
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BaseFormControlComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
990
991
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.15", type: BaseFormControlComponent, isStandalone: true, selector: "ng-component", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, entity: { classPropertyName: "entity", publicName: "entity", isSignal: true, isRequired: true, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "attr.data-testid": "this.testId" } }, ngImport: i0, template: ``, isInline: true, dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }] });
991
992
  }
@@ -1371,24 +1372,24 @@ class ForeignKeyComponent extends BaseFormControlComponent {
1371
1372
  this.hasFocus.set(!!currentTarget && !!relatedTarget && currentTarget.contains(relatedTarget));
1372
1373
  }
1373
1374
  navigateToRelated() {
1374
- this.formNavigator.navigateToRelated(this.linkedEntityType().entityName, this.foreignKeyId(), this.formNavigator.determineCurrentUrl());
1375
+ this.formNavigator.navigateToRelated(this.linkedEntityName(), this.foreignKeyId(), this.formNavigator.determineCurrentUrl());
1375
1376
  }
1376
1377
  navigateToRelatedList() {
1377
1378
  if (this.config().disabled) {
1378
1379
  return;
1379
1380
  }
1380
1381
  this.formNavigator.captureFormSnapshot(this.formGroup.getRawValue());
1381
- this.formNavigator.navigateToRelatedList(this.linkedEntityType().entityName, this.formNavigator.determineCurrentUrl(), {
1382
+ this.formNavigator.navigateToRelatedList(this.linkedEntityName(), this.formNavigator.determineCurrentUrl(), {
1382
1383
  command: NavigatorCommand.SELECT_OR_CREATE,
1383
1384
  attrName: this.config().attrName,
1384
1385
  });
1385
1386
  }
1386
1387
  // endregion
1387
1388
  selectEntityTitle() {
1388
- return 'Select ' + this.linkedEntityType().entityName;
1389
+ return 'Select ' + this.linkedEntityName();
1389
1390
  }
1390
1391
  foreignKeyLabel() {
1391
- return this.linkedEntityType().entityName;
1392
+ return this.linkedEntityName();
1392
1393
  }
1393
1394
  showSelectEntityButton() {
1394
1395
  return !this.config().disabled && this.hasFocus();
@@ -1401,8 +1402,8 @@ class ForeignKeyComponent extends BaseFormControlComponent {
1401
1402
  if (!relatedEntity) {
1402
1403
  return this.foreignKeyId();
1403
1404
  }
1404
- const attrName = this.linkedEntityType().componentIdentification();
1405
- const componentName = relatedEntity[attrName];
1405
+ const attrName = this.linkedEntityDescriptor()?.componentIdentification() ?? '';
1406
+ const componentName = attrName ? relatedEntity[attrName] : undefined;
1406
1407
  return componentName === undefined || componentName === null ? relatedEntity.id : String(componentName);
1407
1408
  }
1408
1409
  addSelectedComponentFromNavigatorResponse() {
@@ -1440,7 +1441,7 @@ class ForeignKeyComponent extends BaseFormControlComponent {
1440
1441
  }
1441
1442
  relatedEntityFromLinkedStore() {
1442
1443
  const id = this.foreignKeyId();
1443
- const linkedStore = this.resolveRelatedEntityStore();
1444
+ const linkedStore = this.descriptorRegistry.getStore(this.config().linkedEntityType);
1444
1445
  if (!id || !linkedStore) {
1445
1446
  return undefined;
1446
1447
  }
@@ -1748,7 +1749,7 @@ class EntityComponentsListComponent extends BaseFormControlComponent {
1748
1749
  }
1749
1750
  componentNameAttr() {
1750
1751
  return {
1751
- attrName: this.linkedEntityType().componentIdentification(),
1752
+ attrName: this.linkedEntityDescriptor()?.componentIdentification() ?? '',
1752
1753
  name: this.config().attrName,
1753
1754
  };
1754
1755
  }
@@ -1761,14 +1762,14 @@ class EntityComponentsListComponent extends BaseFormControlComponent {
1761
1762
  return value;
1762
1763
  }
1763
1764
  addComponentTitle() {
1764
- return 'Add ' + this.linkedEntityType().entityName;
1765
+ return 'Add ' + this.linkedEntityName();
1765
1766
  }
1766
1767
  navigateToRelatedList() {
1767
1768
  if (this.config().disabled) {
1768
1769
  return;
1769
1770
  }
1770
1771
  this.formNavigator.captureFormSnapshot(this.formGroup.getRawValue());
1771
- this.formNavigator.navigateToRelatedList(this.linkedEntityType().entityName, this.formNavigator.determineCurrentUrl(), {
1772
+ this.formNavigator.navigateToRelatedList(this.linkedEntityName(), this.formNavigator.determineCurrentUrl(), {
1772
1773
  command: NavigatorCommand.SELECT_OR_CREATE,
1773
1774
  attrName: this.config().attrName,
1774
1775
  context: this.components(),
@@ -1835,7 +1836,7 @@ class EntityComponentsListComponent extends BaseFormControlComponent {
1835
1836
  [componentNameAttr]="componentNameAttr()"
1836
1837
  [disabled]="config().disabled"
1837
1838
  [formGroup]="formGroup"
1838
- [linkedEntityType]="linkedEntityType().entityName"
1839
+ [linkedEntityType]="linkedEntityName()"
1839
1840
  />
1840
1841
  </li>
1841
1842
  }
@@ -1867,7 +1868,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.15", ngImpo
1867
1868
  [componentNameAttr]="componentNameAttr()"
1868
1869
  [disabled]="config().disabled"
1869
1870
  [formGroup]="formGroup"
1870
- [linkedEntityType]="linkedEntityType().entityName"
1871
+ [linkedEntityType]="linkedEntityName()"
1871
1872
  />
1872
1873
  </li>
1873
1874
  }
@@ -1888,7 +1889,7 @@ class LookupComponent extends BaseFormControlComponent {
1888
1889
  displayControl = new FormControl('', { nonNullable: true });
1889
1890
  filterText = signal('', ...(ngDevMode ? [{ debugName: "filterText" }] : /* istanbul ignore next */ []));
1890
1891
  destroyRef = inject(DestroyRef);
1891
- lookupStore = computed(() => this.resolveRelatedEntityStore(), ...(ngDevMode ? [{ debugName: "lookupStore" }] : /* istanbul ignore next */ []));
1892
+ lookupStore = computed(() => this.descriptorRegistry.getStore(this.config().linkedEntityType), ...(ngDevMode ? [{ debugName: "lookupStore" }] : /* istanbul ignore next */ []));
1892
1893
  lookupItems = computed(() => this.lookupStore()?.entities?.() ?? [], ...(ngDevMode ? [{ debugName: "lookupItems" }] : /* istanbul ignore next */ []));
1893
1894
  filteredLookupItems = computed(() => {
1894
1895
  const filterText = this.filterText().trim().toLocaleLowerCase();
@@ -1940,7 +1941,7 @@ class LookupComponent extends BaseFormControlComponent {
1940
1941
  if (!relatedEntityId) {
1941
1942
  return;
1942
1943
  }
1943
- this.formNavigator.navigateToRelated(this.linkedEntityType().entityName, relatedEntityId, this.formNavigator.determineCurrentUrl());
1944
+ this.formNavigator.navigateToRelated(this.linkedEntityName(), relatedEntityId, this.formNavigator.determineCurrentUrl());
1944
1945
  }
1945
1946
  canNavigateToRelated() {
1946
1947
  return !!(this.selectedLookupItem()?.id ?? this.lookupKey());
@@ -2223,10 +2224,10 @@ class BaseEntityDescriptor {
2223
2224
  const attrDescriptor = filterAttributeDescriptors(this.attrDescriptors).find((attrDescriptor) => attrDescriptor.isLinkToDetails === true);
2224
2225
  return attrDescriptor?.attrName ?? '';
2225
2226
  }
2226
- overwriteLinkedEntityAttr(attrName, linkedEntityDescr) {
2227
+ overwriteLinkedEntityAttr(attrName, linkedEntityName) {
2227
2228
  const attrDescriptor = filterAttributeDescriptors(this.attrDescriptors).find((attrDescriptor) => attrDescriptor.attrName === attrName);
2228
2229
  if (attrDescriptor) {
2229
- attrDescriptor.linkedEntityType = linkedEntityDescr;
2230
+ attrDescriptor.linkedEntityType = linkedEntityName;
2230
2231
  }
2231
2232
  }
2232
2233
  }
@@ -2270,8 +2271,6 @@ class BaseEntityListComponent {
2270
2271
  this.formNavigator.determineActiveRouteSegment();
2271
2272
  this.requestPayload = this.formNavigator.popRequestPayload();
2272
2273
  this.selectOrCreateMode.set(this.requestPayload?.command === NavigatorCommand.SELECT_OR_CREATE);
2273
- // eslint-disable-next-line no-console
2274
- console.debug('[BaseEntityListComponent] ngOnInit', { entityName: this.entityDescriptor().entityName, requestPayload: this.requestPayload, selectOrCreateMode: this.selectOrCreateMode() });
2275
2274
  this.logger.info('BaseEntityListComponent initialized with:', { columnDescriptors: this.columnDescriptors() });
2276
2275
  }
2277
2276
  // endregion
@@ -2291,7 +2290,7 @@ class BaseEntityListComponent {
2291
2290
  this.store.setCurrentEntity(entity.id);
2292
2291
  }
2293
2292
  onNavigateToRelated(config, entity) {
2294
- const relatedEntityName = config.linkedEntityType?.entityName;
2293
+ const relatedEntityName = config.linkedEntityType;
2295
2294
  if (!relatedEntityName)
2296
2295
  return;
2297
2296
  this.formNavigator.navigateToRelated(relatedEntityName, this.getPropertyValue(entity, config.attrName));
@@ -2746,7 +2745,6 @@ function BaseEntityTabsStore() {
2746
2745
  }
2747
2746
 
2748
2747
  class BaseEntityFacade {
2749
- entityTitle = "this.store.currentEntity() ? this.store.currentEntity().name : ''";
2750
2748
  serviceKind = 'rest';
2751
2749
  endpoint;
2752
2750
  backendRoot;
@@ -2775,6 +2773,15 @@ class BaseEntityFacade {
2775
2773
  }
2776
2774
  return this._descriptor;
2777
2775
  }
2776
+ get entityName() {
2777
+ return this.descriptor.entityName;
2778
+ }
2779
+ get attrDescriptors() {
2780
+ return this.descriptor.attrDescriptors;
2781
+ }
2782
+ get entityTitle() {
2783
+ return this.descriptor.entityTitle;
2784
+ }
2778
2785
  createMapper() {
2779
2786
  return new SimpleEntityMapper(this.entityType);
2780
2787
  }
@@ -2795,13 +2802,6 @@ class BaseEntityFacade {
2795
2802
  createStoreClass() {
2796
2803
  return signalStore({ providedIn: 'root' }, BaseEntityStore(this.entityType, () => this.service), BaseEntityTabsStore(), BaseEntityContainerStore());
2797
2804
  }
2798
- createDescriptor() {
2799
- return new BaseEntityDescriptor({
2800
- entityName: this.entityName,
2801
- entityTitle: this.entityTitle,
2802
- attrDescriptors: this.attrDescriptors,
2803
- });
2804
- }
2805
2805
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BaseEntityFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2806
2806
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BaseEntityFacade });
2807
2807
  }
@@ -2899,5 +2899,5 @@ const BASE_ENTITY_ROUTES = [
2899
2899
  * Generated bundle index. Do not edit.
2900
2900
  */
2901
2901
 
2902
- export { ACTIVE_ENTITY_FACADE, AbstractAttrDescriptor, BASE_ENTITY_FACADE_REGISTRY, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityDescriptor, BaseEntityFacade, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityRestService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorSingletonStore, BaseFormNavigatorStore, Entity, EntityRegistryComponent, FlexDirection, FlexboxDescriptor, FormControlType, Id, OrderByDirection, RouteSegments, SimpleEntityMapper, getEntityIds, getEntityOptions, getEnumKeyByValue, getEnumValueByKey };
2902
+ export { ACTIVE_ENTITY_FACADE, AbstractAttrDescriptor, BASE_ENTITY_FACADE_REGISTRY, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityDescriptor, BaseEntityDescriptorRegistry, BaseEntityFacade, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityRestService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorSingletonStore, BaseFormNavigatorStore, Entity, EntityRegistryComponent, FlexDirection, FlexboxDescriptor, FormControlType, Id, OrderByDirection, RouteSegments, SimpleEntityMapper, getEntityIds, getEntityOptions, getEnumKeyByValue, getEnumValueByKey };
2903
2903
  //# sourceMappingURL=processpuzzle-base-entity.mjs.map