@solidstarters/solid-core 1.2.82 → 1.2.84
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/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/helpers/module-metadata-helper.service.d.ts +5 -1
- package/dist/helpers/module-metadata-helper.service.d.ts.map +1 -1
- package/dist/helpers/module-metadata-helper.service.js +24 -4
- package/dist/helpers/module-metadata-helper.service.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/repository/field.repository.d.ts +9 -0
- package/dist/repository/field.repository.d.ts.map +1 -0
- package/dist/repository/field.repository.js +46 -0
- package/dist/repository/field.repository.js.map +1 -0
- package/dist/services/field-metadata.service.js +1 -1
- package/dist/services/field-metadata.service.js.map +1 -1
- package/dist/services/file.service.d.ts +1 -0
- package/dist/services/file.service.d.ts.map +1 -1
- package/dist/services/file.service.js +9 -0
- package/dist/services/file.service.js.map +1 -1
- package/dist/services/mediaStorageProviders/file-storage-provider.js +1 -1
- package/dist/services/mediaStorageProviders/file-storage-provider.js.map +1 -1
- package/dist/services/model-metadata.service.js +3 -3
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/module-metadata.service.js +2 -2
- package/dist/services/module-metadata.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +3 -0
- package/dist/solid-core.module.js.map +1 -1
- package/dist/subscribers/security-rule.subscriber.js +2 -2
- package/dist/subscribers/security-rule.subscriber.js.map +1 -1
- package/dist/subscribers/view-metadata.subscriber.js +1 -1
- package/dist/subscribers/view-metadata.subscriber.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/constants.ts +3 -1
- package/src/helpers/module-metadata-helper.service.ts +17 -3
- package/src/index.ts +1 -0
- package/src/repository/field.repository.ts +30 -0
- package/src/services/field-metadata.service.ts +1 -1
- package/src/services/file.service.ts +10 -0
- package/src/services/mediaStorageProviders/file-storage-provider.ts +1 -1
- package/src/services/model-metadata.service.ts +3 -3
- package/src/services/module-metadata.service.ts +2 -2
- package/src/solid-core.module.ts +3 -0
- package/src/subscribers/security-rule.subscriber.ts +2 -2
- package/src/subscribers/view-metadata.subscriber.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidstarters/solid-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.84",
|
|
4
4
|
"description": "This module is a NestJS module containing all the required core providers required by a Solid application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/constants.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Injectable,
|
|
1
|
+
import { Injectable, Logger } from "@nestjs/common";
|
|
2
2
|
import * as fs from 'fs/promises'; // Use the Promise-based version of fs for async/await
|
|
3
3
|
import * as path from 'path'; // To handle file paths
|
|
4
|
-
import {
|
|
4
|
+
import { SOLID_CORE_MODULE_NAME } from "src/constants";
|
|
5
|
+
import { FileService } from "src/services/file.service";
|
|
5
6
|
|
|
6
7
|
@Injectable()
|
|
7
8
|
export class ModuleMetadataHelperService {
|
|
9
|
+
private readonly logger = new Logger(ModuleMetadataHelperService.name);
|
|
10
|
+
constructor(private readonly fileService: FileService) {}
|
|
8
11
|
// async getModuleMetadataConfig(moduleName: string): Promise<ModuleMetadata> {
|
|
9
12
|
// const filePath = this.getModuleMetadataFilePath(moduleName);
|
|
10
13
|
// const metadata = await this.getModuleMetadata(filePath);
|
|
@@ -16,9 +19,20 @@ export class ModuleMetadataHelperService {
|
|
|
16
19
|
return JSON.parse(fileContent);
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
getModuleMetadataFilePath(moduleName: string): string {
|
|
22
|
+
async getModuleMetadataFilePath(moduleName: string): Promise<string> {
|
|
20
23
|
const folderPath = path.resolve(process.cwd(), 'module-metadata', moduleName);
|
|
21
24
|
const filePath = path.join(folderPath, `${moduleName}-metadata.json`);
|
|
25
|
+
// Check if filePath exists
|
|
26
|
+
const fileExists = await this.fileService.fileExists(filePath);
|
|
27
|
+
this.logger.debug(`File exists: ${fileExists} at ${filePath}`);
|
|
28
|
+
if (!fileExists) {
|
|
29
|
+
// If the module is solid-core, try the fallback path, in case the current root directory is the solid core project
|
|
30
|
+
if (moduleName === SOLID_CORE_MODULE_NAME) {
|
|
31
|
+
const fallbackPath = path.resolve(process.cwd(), 'src', 'seeders', 'seed-data', `${moduleName}-metadata.json`);
|
|
32
|
+
this.logger.debug(`Fallback path: ${fallbackPath}`);
|
|
33
|
+
return fallbackPath;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
22
36
|
return filePath;
|
|
23
37
|
}
|
|
24
38
|
|
package/src/index.ts
CHANGED
|
@@ -233,6 +233,7 @@ export * from './services/chatter-message-details.service'
|
|
|
233
233
|
// Repositories
|
|
234
234
|
export * from './repository/solid-base.repository'
|
|
235
235
|
export * from './repository/security-rule.repository'
|
|
236
|
+
export * from './repository/field.repository'
|
|
236
237
|
|
|
237
238
|
|
|
238
239
|
//softDeleteAwareEventSubscriber.subscriber.ts
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Repository, DataSource } from 'typeorm';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { FieldMetadata } from 'src/entities/field-metadata.entity';
|
|
4
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class FieldRepository extends Repository<FieldMetadata> {
|
|
8
|
+
constructor(
|
|
9
|
+
private dataSource: DataSource,
|
|
10
|
+
@InjectRepository(FieldMetadata)
|
|
11
|
+
private readonly fieldMetadataRepo: Repository<FieldMetadata>,
|
|
12
|
+
|
|
13
|
+
) {
|
|
14
|
+
super(FieldMetadata, dataSource.createEntityManager());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async findFieldMetadata(fieldName: string, modelName: string) {
|
|
18
|
+
const fileMediaField = await this.fieldMetadataRepo.findOne({
|
|
19
|
+
where: {
|
|
20
|
+
name: fieldName,
|
|
21
|
+
model: {
|
|
22
|
+
singularName: modelName
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
relations: ['model', 'mediaStorageProvider'],
|
|
26
|
+
});
|
|
27
|
+
return fileMediaField;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -1056,7 +1056,7 @@ export class FieldMetadataService {
|
|
|
1056
1056
|
|
|
1057
1057
|
private async updateRelationInverseFieldInFile(savedInverseField: FieldMetadata, inverseModelName: string, moduleName: string) {
|
|
1058
1058
|
try {
|
|
1059
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);
|
|
1059
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);
|
|
1060
1060
|
const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
|
|
1061
1061
|
|
|
1062
1062
|
// Create the config object for the inverse field
|
|
@@ -189,4 +189,14 @@ export class FileService {
|
|
|
189
189
|
});
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
|
+
|
|
193
|
+
public async fileExists(filePath: string): Promise<boolean> {
|
|
194
|
+
try {
|
|
195
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
196
|
+
return true;
|
|
197
|
+
} catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
192
202
|
}
|
|
@@ -69,7 +69,7 @@ export class FileStorageProvider<T> implements MediaStorageProvider<T> {
|
|
|
69
69
|
streamPairs.forEach(async (pair) => {
|
|
70
70
|
const stream = pair[0];
|
|
71
71
|
const fileName = pair[1];
|
|
72
|
-
this.fileService.writeStreamToFile(stream, fileName);
|
|
72
|
+
this.fileService.writeStreamToFile(stream, this.getFullFilePath(fileName));
|
|
73
73
|
const mediaEntity = await this.mediaRepository.createMedia({
|
|
74
74
|
entityId: entity.id,
|
|
75
75
|
modelMetadataId: mediaFieldMetadata.model.id,
|
|
@@ -247,7 +247,7 @@ export class ModelMetadataService {
|
|
|
247
247
|
relations: ["fields", "fields.mediaStorageProvider", "module", "parentModel"], //FIXME: Check with jenender and change to relations to avoid confusion
|
|
248
248
|
});
|
|
249
249
|
|
|
250
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(model.module.name);
|
|
250
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(model.module.name);
|
|
251
251
|
const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
|
|
252
252
|
|
|
253
253
|
const modelMetaData = {
|
|
@@ -406,7 +406,7 @@ export class ModelMetadataService {
|
|
|
406
406
|
relations: ["fields", "fields.mediaStorageProvider", "module", "parentModel"], //FIXME: Check with jenender and change to relations to avoid confusion
|
|
407
407
|
});
|
|
408
408
|
|
|
409
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(model.module.name);
|
|
409
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(model.module.name);
|
|
410
410
|
const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
|
|
411
411
|
|
|
412
412
|
const modelMetaData = {
|
|
@@ -557,7 +557,7 @@ export class ModelMetadataService {
|
|
|
557
557
|
|
|
558
558
|
private async populateVAMConfigInFile(model: ModelMetadata) {
|
|
559
559
|
try {
|
|
560
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(model.module.name);
|
|
560
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(model.module.name);
|
|
561
561
|
const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
|
|
562
562
|
|
|
563
563
|
const listViewLayoutFields = [{ type: "field", attrs: { name: `id`, sortable: true, filterable: true } }];
|
|
@@ -158,7 +158,7 @@ export class ModuleMetadataService {
|
|
|
158
158
|
|
|
159
159
|
// Create the folder path inside 'module-metadata'
|
|
160
160
|
const folderPath = path.resolve(process.cwd(), 'module-metadata', module.name);
|
|
161
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(module.name);
|
|
161
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(module.name);
|
|
162
162
|
|
|
163
163
|
// Ensure the folder exists
|
|
164
164
|
await fs.mkdir(folderPath, { recursive: true });
|
|
@@ -211,7 +211,7 @@ export class ModuleMetadataService {
|
|
|
211
211
|
|
|
212
212
|
async updateInFile(module: ModuleMetadata) {
|
|
213
213
|
try {
|
|
214
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(module.name);
|
|
214
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(module.name);
|
|
215
215
|
|
|
216
216
|
// Read the existing JSON file
|
|
217
217
|
let metaData;
|
package/src/solid-core.module.ts
CHANGED
|
@@ -170,6 +170,7 @@ import { ExportTransactionController } from './controllers/export-transaction.co
|
|
|
170
170
|
import { ExcelService } from './services/excel.service';
|
|
171
171
|
import { CsvService } from './services/csv.service';
|
|
172
172
|
import { ClsModule } from 'nestjs-cls';
|
|
173
|
+
import { FieldRepository } from './repository/field.repository';
|
|
173
174
|
|
|
174
175
|
|
|
175
176
|
@Global()
|
|
@@ -369,6 +370,7 @@ import { ClsModule } from 'nestjs-cls';
|
|
|
369
370
|
ExportTransactionService,
|
|
370
371
|
ExcelService,
|
|
371
372
|
CsvService,
|
|
373
|
+
FieldRepository
|
|
372
374
|
],
|
|
373
375
|
exports: [
|
|
374
376
|
ModuleMetadataService,
|
|
@@ -398,6 +400,7 @@ import { ClsModule } from 'nestjs-cls';
|
|
|
398
400
|
RefreshModuleCommand,
|
|
399
401
|
RequestContextService,
|
|
400
402
|
SecurityRuleRepository,
|
|
403
|
+
FieldRepository
|
|
401
404
|
],
|
|
402
405
|
})
|
|
403
406
|
export class SolidCoreModule { }
|
|
@@ -49,7 +49,7 @@ export class SecurityRuleSubscriber implements EntitySubscriberInterface<Securit
|
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(populatedModelMetadata.module.name);
|
|
52
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(populatedModelMetadata.module.name);
|
|
53
53
|
try {
|
|
54
54
|
await fs.access(filePath);
|
|
55
55
|
} catch (error) {
|
|
@@ -59,7 +59,7 @@ export class SecurityRuleSubscriber implements EntitySubscriberInterface<Securit
|
|
|
59
59
|
}
|
|
60
60
|
const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
|
|
61
61
|
|
|
62
|
-
if (metaData.
|
|
62
|
+
if (metaData.securityRules) {
|
|
63
63
|
const securityRuleIndex = metaData.securityRules?.findIndex((ruleFromFile: { name: string }) => ruleFromFile.name === securityRule.name);
|
|
64
64
|
const {id, roleId, modelMetadataId, ...requiredDto} = await this.securityRuleRepo.toDto(securityRule)
|
|
65
65
|
metaData.securityRules[securityRuleIndex] = {requiredDto, securityRuleConfig: JSON.parse(securityRule.securityRuleConfig)}
|
|
@@ -37,7 +37,7 @@ export class ViewMetadataSubsciber implements EntitySubscriberInterface<ViewMeta
|
|
|
37
37
|
if (!viewMetadata) {
|
|
38
38
|
throw new Error(`View metadata not found for id ${event.entity.id}`);
|
|
39
39
|
}
|
|
40
|
-
const filePath = this.moduleMetadataHelperService.getModuleMetadataFilePath(viewMetadata.model.module.name);
|
|
40
|
+
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(viewMetadata.model.module.name);
|
|
41
41
|
try {
|
|
42
42
|
await fs.access(filePath);
|
|
43
43
|
} catch (error) {
|