@solidstarters/solid-core 1.2.40 → 1.2.42

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.
@@ -853,7 +853,9 @@ export class FieldMetadataService {
853
853
  "encrypt",
854
854
  "encryptionType",
855
855
  "decryptWhen",
856
- "columnName"
856
+ "columnName",
857
+ "isUserKey"
858
+
857
859
  ];
858
860
 
859
861
  case SolidFieldType.selectionDynamic:
@@ -874,7 +876,9 @@ export class FieldMetadataService {
874
876
  "encrypt",
875
877
  "encryptionType",
876
878
  "decryptWhen",
877
- "columnName"
879
+ "columnName",
880
+ "isUserKey"
881
+
878
882
  ];
879
883
  case SolidFieldType.computed:
880
884
  return [
@@ -894,7 +898,8 @@ export class FieldMetadataService {
894
898
  "encrypt",
895
899
  "encryptionType",
896
900
  "decryptWhen",
897
- "columnName"
901
+ "columnName",
902
+ "isUserKey"
898
903
  ];
899
904
 
900
905
  case SolidFieldType.uuid:
@@ -140,6 +140,7 @@ import { ConcatComputedFieldProvider } from './services/computed-fields/concat-c
140
140
  import { FileS3StorageProvider } from './services/mediaStorageProviders/file-s3-storage-provider';
141
141
  import { FileStorageProvider } from './services/mediaStorageProviders/file-storage-provider';
142
142
  import { MediaRepository } from './repository/media.repository';
143
+ import { ViewMetadataSubsciber } from './subscribers/view-metadata.subscriber';
143
144
 
144
145
 
145
146
  @Global()
@@ -302,6 +303,7 @@ import { MediaRepository } from './repository/media.repository';
302
303
  FileStorageProvider,
303
304
  FileS3StorageProvider,
304
305
  MediaRepository,
306
+ ViewMetadataSubsciber
305
307
  ],
306
308
  exports: [
307
309
  ModuleMetadataService,
@@ -0,0 +1,58 @@
1
+ import { InjectDataSource } from "@nestjs/typeorm";
2
+ import { ViewMetadata } from "src/entities/view-metadata.entity";
3
+ import { ModuleMetadataHelperService } from "src/helpers/module-metadata-helper.service";
4
+ import { DataSource, EntitySubscriberInterface, UpdateEvent } from "typeorm";
5
+ import { Injectable, Logger, NotFoundException } from '@nestjs/common';
6
+ import * as fs from 'fs/promises'; // Use the Promise-based version of fs for async/await
7
+
8
+
9
+ export class ViewMetadataSubsciber implements EntitySubscriberInterface<ViewMetadata> {
10
+ private readonly logger = new Logger(ViewMetadataSubsciber.name);
11
+ constructor(
12
+ @InjectDataSource()
13
+ private readonly dataSource: DataSource,
14
+ readonly moduleMetadataHelperService: ModuleMetadataHelperService,
15
+
16
+ ) {
17
+ this.dataSource.subscribers.push(this);
18
+ }
19
+
20
+ listenTo() {
21
+ return ViewMetadata;
22
+ }
23
+
24
+ async afterUpdate(event: UpdateEvent<ViewMetadata>): Promise<void> {
25
+ // Update the metadata json after updating the view
26
+ const viewMetadataRepo = event.manager.getRepository(ViewMetadata);
27
+ const viewMetadata = await viewMetadataRepo.findOne({
28
+ where: {
29
+ id: event.entity.id
30
+ },
31
+ relations: {
32
+ model: {
33
+ module: true
34
+ }
35
+ }
36
+ });
37
+ if (!viewMetadata) {
38
+ throw new Error(`View metadata not found for id ${event.entity.id}`);
39
+ }
40
+ const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(viewMetadata.model.module.name);
41
+ try {
42
+ await fs.access(filePath);
43
+ } catch (error) {
44
+ this.logger.error(`File not found at path: ${filePath}`);
45
+ return;
46
+ }
47
+ const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
48
+
49
+ // Update the view metadata in the module metadata
50
+ const viewMetadataIndex = metaData.views.findIndex((view: { name: string }) => view.name === event.entity.name);
51
+ if (viewMetadataIndex !== -1) {
52
+ metaData.views[viewMetadataIndex].layout = JSON.parse(event.entity.layout);
53
+ }
54
+ // Write the updated object back to the file
55
+ const updatedContent = JSON.stringify(metaData, null, 2);
56
+ await fs.writeFile(filePath, updatedContent);
57
+ }
58
+ }