@qrvey/cd-package-registry 1.0.0-beta
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 +203 -0
- package/dist/cjs/index.js +5152 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.mjs +5094 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +1139 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# @qrvey/cd-package-registry
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
**@qrvey/cd-package-registry** is a package that validates assets and their dependencies.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
You can install the **@qrvey/cd-package-registry** package via npm. Run the following command in your terminal:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @qrvey/cd-package-registry
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## API Documentation
|
|
17
|
+
|
|
18
|
+
### Available assets in the library to validate
|
|
19
|
+
|
|
20
|
+
- `Application`
|
|
21
|
+
- `Automation`
|
|
22
|
+
- `Connection`
|
|
23
|
+
- `Formula`
|
|
24
|
+
- `Page Flow`
|
|
25
|
+
- `Dashboard Asset`
|
|
26
|
+
- `Global Preference`
|
|
27
|
+
- `Page Tab`
|
|
28
|
+
- `Bucket`
|
|
29
|
+
- `Dashboard Content Element`
|
|
30
|
+
- `Dashboard Content`
|
|
31
|
+
- `Metric`
|
|
32
|
+
- `Report Section`
|
|
33
|
+
- `Report`
|
|
34
|
+
- `Chart Theme`
|
|
35
|
+
- `Chart`
|
|
36
|
+
- `Dataset`
|
|
37
|
+
- `Builder Configuration`
|
|
38
|
+
- `Tokens`
|
|
39
|
+
|
|
40
|
+
## Example Usage
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { ApplicationValidatorService, ChartValidatorService } from '@qrvey/cd-package-registry';
|
|
44
|
+
|
|
45
|
+
const applicationValidationService = new ApplicationValidatorService();
|
|
46
|
+
const applicationPayload = {
|
|
47
|
+
appid: '123456',
|
|
48
|
+
name: 'app name',
|
|
49
|
+
userid: '123456'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const applicationValidationResult = applicationValidationService.validate(applicationPayload)
|
|
53
|
+
const applicationBatchValidationResult = applicationValidationService.batchValidate([applicationPayload])
|
|
54
|
+
|
|
55
|
+
// Validation with dependencies
|
|
56
|
+
|
|
57
|
+
const chartPayload = {
|
|
58
|
+
chartId: '123456'
|
|
59
|
+
appid: '123456',
|
|
60
|
+
title: 'chart title',
|
|
61
|
+
userid: '123456'
|
|
62
|
+
}
|
|
63
|
+
const options = {
|
|
64
|
+
domain: 'http://example.com'
|
|
65
|
+
apiKey: '123456'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const chartValidatorService = new ChartValidatorService({ userId: userid, appId: appid }, options)
|
|
69
|
+
|
|
70
|
+
const chartValidationResults = chartValidatorService.validate(chartPayload)
|
|
71
|
+
const chartBatchValidationResults = chartValidatorService.batchValidate([chartPayload])
|
|
72
|
+
```
|
|
73
|
+
## Extend functionality
|
|
74
|
+
|
|
75
|
+
You can create your custom validators extending from the library functionality. You need to create your DTOs using class-validator. Example of a custom validator without dependencies
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
class CustomAssetDto {
|
|
79
|
+
@IsString()
|
|
80
|
+
@IsDefined()
|
|
81
|
+
id: string;
|
|
82
|
+
|
|
83
|
+
@IsString()
|
|
84
|
+
@IsDefined()
|
|
85
|
+
name: string;
|
|
86
|
+
|
|
87
|
+
@IsString()
|
|
88
|
+
@IsDefined()
|
|
89
|
+
lastName: string;
|
|
90
|
+
|
|
91
|
+
@IsNumber()
|
|
92
|
+
@IsOptional()
|
|
93
|
+
age: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class CustomValidatorWithoutDependencies extends BaseAssetService<CustomAssetDto> {
|
|
97
|
+
private static readonly _logger = new LoggerService(CustomValidatorWithoutDependencies.name)
|
|
98
|
+
protected get idKey(): keyof CustomAssetDto {
|
|
99
|
+
return 'id';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
protected getAssetType(): new () => object {
|
|
103
|
+
return CustomAssetDto;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
protected get logger(): LoggerService {
|
|
107
|
+
return CustomValidatorWithoutDependencies._logger;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Example of a custom validator with dependencies
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
class CustomAssetDto {
|
|
116
|
+
@IsString()
|
|
117
|
+
@IsDefined()
|
|
118
|
+
id: string;
|
|
119
|
+
|
|
120
|
+
@IsString()
|
|
121
|
+
@IsDefined()
|
|
122
|
+
name: string;
|
|
123
|
+
|
|
124
|
+
@IsString()
|
|
125
|
+
@IsDefined()
|
|
126
|
+
lastName: string;
|
|
127
|
+
|
|
128
|
+
@IsNumber()
|
|
129
|
+
@IsOptional()
|
|
130
|
+
age: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class CustomValidatorWithDependencies extends BaseAssetWithDependenciesService<CustomAssetDto> {
|
|
134
|
+
protected get idKey(): keyof CustomAssetDto {
|
|
135
|
+
return 'id';
|
|
136
|
+
}
|
|
137
|
+
protected dependencyValidator: IAssetDependencyValidatorService<CustomAssetDto>;
|
|
138
|
+
private static readonly _logger: LoggerService = new LoggerService(
|
|
139
|
+
CustomValidatorWithDependencies.name,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
constructor(params: { userId: string; appId: string }, options?: Options) {
|
|
143
|
+
super();
|
|
144
|
+
this.dependencyValidator = new CustomDependencyValidator(
|
|
145
|
+
params,
|
|
146
|
+
options,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
protected getAssetType(): new () => object {
|
|
151
|
+
return CustomAssetDto;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
protected get logger(): LoggerService {
|
|
155
|
+
return CustomValidatorWithoutDependencies._logger;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
class CustomDependencyValidator
|
|
160
|
+
implements IAssetDependencyValidatorService<CustomAssetDto>
|
|
161
|
+
{
|
|
162
|
+
constructor(private readonly params: any, private readonly options: Option)
|
|
163
|
+
{}
|
|
164
|
+
getDependencyKeys(input: Partial<CustomAssetDto>): {
|
|
165
|
+
keys: Record<string, any>[];
|
|
166
|
+
} {
|
|
167
|
+
return {
|
|
168
|
+
keys: [{ qrveyId: input.qrveyid! }],
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async fetchDependencies(
|
|
172
|
+
keys: Record<string, any>[],
|
|
173
|
+
): Promise<DependencyContext> {
|
|
174
|
+
const args = uniqueBy(keys ?? [], 'id');
|
|
175
|
+
|
|
176
|
+
const dependencies = await fetchDependencies(args);
|
|
177
|
+
|
|
178
|
+
const dependenciesMap = new Map(dependencies.map((d) => [d.id, d]));
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
dependencies: dependenciesMap,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
validateWithContext(
|
|
185
|
+
input: Partial<ChartAssetDto>,
|
|
186
|
+
context: DependencyContext,
|
|
187
|
+
): ValidationError[] {
|
|
188
|
+
const errors: ValidationError[] = [];
|
|
189
|
+
|
|
190
|
+
const dependency = context.dependencies.get(input.id);
|
|
191
|
+
|
|
192
|
+
if (!dependency) {
|
|
193
|
+
errors.push({
|
|
194
|
+
field: 'id',
|
|
195
|
+
message: `Custom error message`,
|
|
196
|
+
value: input,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return errors;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|