@steroidsjs/nest 1.4.42 → 1.4.44
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/package.json +14 -13
- package/src/infrastructure/commands/entity-generator/EntityCodeGenerateCommand.d.ts +3 -0
- package/src/infrastructure/commands/entity-generator/EntityCodeGenerateCommand.js +50 -0
- package/src/infrastructure/commands/entity-generator/EntityCodeGenerateCommand.js.map +1 -0
- package/src/infrastructure/commands/entity-generator/EntityCodeGenerator.d.ts +10 -0
- package/src/infrastructure/commands/entity-generator/EntityCodeGenerator.js +69 -0
- package/src/infrastructure/commands/entity-generator/EntityCodeGenerator.js.map +1 -0
- package/src/infrastructure/commands/entity-generator/templates/ModelTemplate.txt +3 -0
- package/src/infrastructure/commands/entity-generator/templates/RepositoryInterfaceTemplate.txt +6 -0
- package/src/infrastructure/commands/entity-generator/templates/RepositoryTemplate.txt +18 -0
- package/src/infrastructure/commands/entity-generator/templates/SaveDtoTemplate.txt +3 -0
- package/src/infrastructure/commands/entity-generator/templates/SearchDtoTemplate.txt +5 -0
- package/src/infrastructure/commands/entity-generator/templates/ServiceTemplate.txt +16 -0
- package/src/infrastructure/commands/entity-generator/templates/TableTemplate.txt +6 -0
- package/src/infrastructure/decorators/fields/RelationField.d.ts +1 -0
- package/src/infrastructure/decorators/fields/RelationField.js +7 -1
- package/src/infrastructure/decorators/fields/RelationField.js.map +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steroidsjs/nest",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.44",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"
|
|
5
|
+
"copy-assets": "copyfiles ./{package.json,LICENSE,README.md} dist/ && copyfiles src/infrastructure/commands/entity-generator/templates/*.txt dist/",
|
|
6
|
+
"build": "tsc && npm run copy-assets",
|
|
6
7
|
"watch": "tsc -p tsconfig-debug.json",
|
|
7
8
|
"test": "jest --config jest.e2e.config.ts"
|
|
8
9
|
},
|
|
@@ -24,32 +25,32 @@
|
|
|
24
25
|
"@nestjs/common": "^8.4.1",
|
|
25
26
|
"@nestjs/config": "^1.2.0",
|
|
26
27
|
"@nestjs/core": "^8.4.1",
|
|
28
|
+
"@nestjs/platform-express": "^8.4.1",
|
|
27
29
|
"@nestjs/swagger": "^5.2.0",
|
|
28
30
|
"@nestjs/typeorm": "^8.0.3",
|
|
29
|
-
"@nestjs/platform-express": "^8.4.1",
|
|
30
31
|
"@sqltools/formatter": "^1.2.3",
|
|
31
32
|
"class-transformer": "^0.5.1",
|
|
32
33
|
"class-validator": "^0.13.2",
|
|
34
|
+
"date-fns": "^2.28.0",
|
|
33
35
|
"express": "^4.17.3",
|
|
34
36
|
"lodash": "^4.17.21",
|
|
35
37
|
"nestjs-command": "^3.1.1",
|
|
36
38
|
"pluralize": "^8.0.0",
|
|
39
|
+
"rxjs": "^7.2.0",
|
|
37
40
|
"typedi": "^0.10.0",
|
|
38
41
|
"typeorm": "^0.2.45",
|
|
39
|
-
"uuid": "^8.3.2"
|
|
40
|
-
"date-fns": "^2.28.0",
|
|
41
|
-
"rxjs": "^7.2.0"
|
|
42
|
+
"uuid": "^8.3.2"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@
|
|
45
|
+
"@jest/globals": "^27.4.6",
|
|
46
|
+
"@types/jest": "^27.4.0",
|
|
47
|
+
"@types/node": "^18.7.23",
|
|
45
48
|
"copyfiles": "^2.4.1",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
49
|
+
"jest": "^27.4.7",
|
|
50
|
+
"pg": "^8.7.1",
|
|
48
51
|
"ts-jest": "^27.1.3",
|
|
49
52
|
"ts-node": "^10.0.0",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"@jest/globals": "^27.4.6",
|
|
53
|
-
"pg": "^8.7.1"
|
|
53
|
+
"tsconfig-paths": "^3.10.1",
|
|
54
|
+
"typescript": "^4.3.5"
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.EntityCodeGenerateCommand = void 0;
|
|
16
|
+
const nestjs_command_1 = require("nestjs-command");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const EntityCodeGenerator_1 = require("./EntityCodeGenerator");
|
|
19
|
+
let EntityCodeGenerateCommand = class EntityCodeGenerateCommand {
|
|
20
|
+
async index(entityName, moduleName) {
|
|
21
|
+
if (!entityName || !moduleName) {
|
|
22
|
+
throw new Error('Required parameters are not provided');
|
|
23
|
+
}
|
|
24
|
+
(new EntityCodeGenerator_1.EntityCodeGenerator(entityName, moduleName)).generate();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, nestjs_command_1.Command)({
|
|
29
|
+
command: 'entity:generate <entityName> <moduleName>',
|
|
30
|
+
describe: 'Generate code for entity (model, repository, dtos and so on...)',
|
|
31
|
+
}),
|
|
32
|
+
__param(0, (0, nestjs_command_1.Positional)({
|
|
33
|
+
name: 'entityName',
|
|
34
|
+
describe: 'A name of entity to generate',
|
|
35
|
+
type: 'string',
|
|
36
|
+
})),
|
|
37
|
+
__param(1, (0, nestjs_command_1.Positional)({
|
|
38
|
+
name: 'moduleName',
|
|
39
|
+
describe: 'A module to put the code in',
|
|
40
|
+
type: 'string',
|
|
41
|
+
})),
|
|
42
|
+
__metadata("design:type", Function),
|
|
43
|
+
__metadata("design:paramtypes", [String, String]),
|
|
44
|
+
__metadata("design:returntype", Promise)
|
|
45
|
+
], EntityCodeGenerateCommand.prototype, "index", null);
|
|
46
|
+
EntityCodeGenerateCommand = __decorate([
|
|
47
|
+
(0, common_1.Injectable)()
|
|
48
|
+
], EntityCodeGenerateCommand);
|
|
49
|
+
exports.EntityCodeGenerateCommand = EntityCodeGenerateCommand;
|
|
50
|
+
//# sourceMappingURL=EntityCodeGenerateCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityCodeGenerateCommand.js","sourceRoot":"","sources":["../../../../../src/infrastructure/commands/entity-generator/EntityCodeGenerateCommand.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mDAAmD;AACnD,2CAA0C;AAC1C,+DAA0D;AAI1D,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IASlC,KAAK,CAAC,KAAK,CAMH,UAAkB,EAMlB,UAAkB;QAEtB,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SAC3D;QAED,CAAC,IAAI,yCAAmB,CACpB,UAAU,EACV,UAAU,CACb,CAAC,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;CACJ,CAAA;AAvBG;IAJC,IAAA,wBAAO,EAAC;QACL,OAAO,EAAE,2CAA2C;QACpD,QAAQ,EAAE,iEAAiE;KAC9E,CAAC;IAEG,WAAA,IAAA,2BAAU,EAAC;QACR,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,8BAA8B;QACxC,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAA;IAED,WAAA,IAAA,2BAAU,EAAC;QACR,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,6BAA6B;QACvC,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAA;;;;sDAWL;AA/BQ,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAgCrC;AAhCY,8DAAyB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class EntityCodeGenerator {
|
|
2
|
+
readonly entityName: string;
|
|
3
|
+
readonly moduleName: string;
|
|
4
|
+
readonly projectRootPath: string;
|
|
5
|
+
readonly modulePath: string;
|
|
6
|
+
constructor(entityName: string, moduleName: string, rootPath?: string);
|
|
7
|
+
generate(): void;
|
|
8
|
+
private generateFileByType;
|
|
9
|
+
private findModulePath;
|
|
10
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityCodeGenerator = void 0;
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const ENTITY_NAME_PLACEHOLDER = '%entityName%';
|
|
8
|
+
const resultPaths = {
|
|
9
|
+
model: 'domain/models/%entityName%Model.ts',
|
|
10
|
+
repository: 'infrastructure/repositories/%entityName%Repository.ts',
|
|
11
|
+
repositoryInterface: 'domain/interfaces/I%entityName%Repository.ts',
|
|
12
|
+
table: 'infrastructure/tables/%entityName%Table.ts',
|
|
13
|
+
service: 'domain/services/%entityName%Service.ts',
|
|
14
|
+
saveDto: 'domain/dtos/%entityName%SaveDto.ts',
|
|
15
|
+
searchDto: 'domain/dtos/%entityName%SearchDto.ts',
|
|
16
|
+
};
|
|
17
|
+
const templates = {
|
|
18
|
+
model: 'ModelTemplate.txt',
|
|
19
|
+
repository: 'RepositoryTemplate.txt',
|
|
20
|
+
repositoryInterface: 'RepositoryInterfaceTemplate.txt',
|
|
21
|
+
table: 'TableTemplate.txt',
|
|
22
|
+
service: 'ServiceTemplate.txt',
|
|
23
|
+
saveDto: 'SaveDtoTemplate.txt',
|
|
24
|
+
searchDto: 'SearchDtoTemplate.txt',
|
|
25
|
+
};
|
|
26
|
+
class EntityCodeGenerator {
|
|
27
|
+
constructor(entityName, moduleName, rootPath = null) {
|
|
28
|
+
if (entityName[0].toUpperCase() !== entityName[0]) {
|
|
29
|
+
this.entityName = entityName.charAt(0).toUpperCase() + entityName.slice(1);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.entityName = entityName;
|
|
33
|
+
}
|
|
34
|
+
this.moduleName = moduleName;
|
|
35
|
+
this.projectRootPath = rootPath || process.cwd();
|
|
36
|
+
this.modulePath = this.findModulePath(moduleName);
|
|
37
|
+
}
|
|
38
|
+
generate() {
|
|
39
|
+
const allFileTypes = Object.keys(templates);
|
|
40
|
+
for (const fileType of allFileTypes) {
|
|
41
|
+
this.generateFileByType(fileType);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
generateFileByType(fileType) {
|
|
45
|
+
const templatePath = path.resolve(__dirname, 'templates');
|
|
46
|
+
let templateContent = fs.readFileSync(path.resolve(templatePath, templates[fileType]), 'utf8');
|
|
47
|
+
const resultFileContent = templateContent.replace(new RegExp(`${(0, lodash_1.escapeRegExp)(ENTITY_NAME_PLACEHOLDER)}`, 'g'), this.entityName);
|
|
48
|
+
let resultFilePath = path.resolve(this.modulePath, resultPaths[fileType].replace(ENTITY_NAME_PLACEHOLDER, this.entityName));
|
|
49
|
+
const resultFileDirPath = path.dirname(resultFilePath);
|
|
50
|
+
if (!fs.existsSync(resultFileDirPath)) {
|
|
51
|
+
fs.mkdirSync(resultFileDirPath, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
fs.writeFileSync(resultFilePath, resultFileContent);
|
|
54
|
+
}
|
|
55
|
+
findModulePath(moduleName) {
|
|
56
|
+
let possibleModulePaths = [
|
|
57
|
+
path.resolve(this.projectRootPath, 'src', moduleName),
|
|
58
|
+
path.resolve(this.projectRootPath, moduleName),
|
|
59
|
+
];
|
|
60
|
+
for (const path of possibleModulePaths) {
|
|
61
|
+
if (fs.existsSync(path)) {
|
|
62
|
+
return path;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw new Error('No module with a provided name is found');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.EntityCodeGenerator = EntityCodeGenerator;
|
|
69
|
+
//# sourceMappingURL=EntityCodeGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityCodeGenerator.js","sourceRoot":"","sources":["../../../../../src/infrastructure/commands/entity-generator/EntityCodeGenerator.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,6BAA6B;AAC7B,mCAAoC;AAEpC,MAAM,uBAAuB,GAAG,cAAc,CAAC;AAE/C,MAAM,WAAW,GAAG;IAChB,KAAK,EAAE,oCAAoC;IAC3C,UAAU,EAAE,uDAAuD;IACnE,mBAAmB,EAAE,8CAA8C;IACnE,KAAK,EAAE,4CAA4C;IACnD,OAAO,EAAE,wCAAwC;IACjD,OAAO,EAAE,oCAAoC;IAC7C,SAAS,EAAE,sCAAsC;CACpD,CAAA;AAED,MAAM,SAAS,GAAG;IACd,KAAK,EAAE,mBAAmB;IAC1B,UAAU,EAAE,wBAAwB;IACpC,mBAAmB,EAAE,iCAAiC;IACtD,KAAK,EAAE,mBAAmB;IAC1B,OAAO,EAAE,qBAAqB;IAC9B,OAAO,EAAE,qBAAqB;IAC9B,SAAS,EAAE,uBAAuB;CACrC,CAAA;AAED,MAAa,mBAAmB;IAM5B,YACI,UAAkB,EAClB,UAAkB,EAClB,WAAmB,IAAI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CAAC,UAAU,CAClB,CACJ,CAAC;QAEF,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACvD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAC;YAClC,EAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;SACtD;QAED,EAAE,CAAC,aAAa,CACZ,cAAc,EACd,iBAAiB,CACpB,CAAC;IACN,CAAC;IAEO,cAAc,CAAC,UAAU;QAC7B,IAAI,mBAAmB,GAAG;YACtB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,UAAU,CAAC;YACrD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC;SACjD,CAAA;QAED,KAAK,MAAM,IAAI,IAAI,mBAAmB,EAAE;YACpC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBACrB,OAAO,IAAI,CAAC;aACf;SACJ;QAED,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,CAAC;CACJ;AA7ED,kDA6EC"}
|
package/src/infrastructure/commands/entity-generator/templates/RepositoryInterfaceTemplate.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import {ICrudRepository} from '@steroidsjs/nest/src/usecases/interfaces/ICrudRepository';
|
|
2
|
+
import {%entityName%Model} from '../models/%entityName%Model';
|
|
3
|
+
|
|
4
|
+
export const I%entityName%Repository = 'I%entityName%Repository';
|
|
5
|
+
|
|
6
|
+
export type I%entityName%Repository = ICrudRepository<%entityName%Model>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {Repository} from 'typeorm';
|
|
2
|
+
import {Injectable} from '@nestjs/common';
|
|
3
|
+
import {InjectRepository} from '@nestjs/typeorm';
|
|
4
|
+
import {CrudRepository} from '@steroidsjs/nest/src/infrastructure/repositories/CrudRepository';
|
|
5
|
+
import {%entityName%Model} from '../../domain/models/%entityName%Model';
|
|
6
|
+
import {%entityName%Table} from '../tables/%entityName%Table';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class %entityName%Repository extends CrudRepository<%entityName%Model> {
|
|
10
|
+
constructor(
|
|
11
|
+
@InjectRepository(%entityName%Table)
|
|
12
|
+
public dbRepository: Repository<%entityName%Table>,
|
|
13
|
+
) {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected modelClass = %entityName%Model;
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {CrudService} from '@steroidsjs/nest/src/usecases/services/CrudService';
|
|
2
|
+
import {%entityName%SearchDto} from '../dtos/%entityName%SearchDto';
|
|
3
|
+
import {%entityName%SaveDto} from '../dtos/%entityName%SaveDto';
|
|
4
|
+
import {%entityName%Model} from '../models/%entityName%Model';
|
|
5
|
+
import {I%entityName%Repository} from '../interfaces/I%entityName%Repository';
|
|
6
|
+
|
|
7
|
+
export class %entityName%Service extends CrudService<%entityName%Model, %entityName%SearchDto, %entityName%SaveDto> {
|
|
8
|
+
protected modelClass = %entityName%Model;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
/** %entityName%Repository */
|
|
12
|
+
public repository: I%entityName%Repository,
|
|
13
|
+
) {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import {DeepPartial} from 'typeorm';
|
|
2
|
+
import {TableFromModel} from '@steroidsjs/nest/src/infrastructure/decorators/TableFromModel';
|
|
3
|
+
import {%entityName%Model} from '../../domain/models/%entityName%Model';
|
|
4
|
+
|
|
5
|
+
@TableFromModel(%entityName%Model, '%entityName%')
|
|
6
|
+
export class %entityName%Table implements DeepPartial<%entityName%Model> {}
|
|
@@ -10,6 +10,7 @@ export interface IRelationFieldManyToManyOptions extends IBaseFieldOptions {
|
|
|
10
10
|
isOwningSide: boolean;
|
|
11
11
|
relationClass: () => any;
|
|
12
12
|
inverseSide?: string | ((object: any) => any);
|
|
13
|
+
tableName?: string;
|
|
13
14
|
}
|
|
14
15
|
export interface IRelationFieldManyToOneOptions extends IBaseFieldOptions {
|
|
15
16
|
type: 'ManyToOne';
|
|
@@ -87,6 +87,12 @@ function RelationField(options) {
|
|
|
87
87
|
if (!options.transform) {
|
|
88
88
|
options.transform = exports.relationTransform;
|
|
89
89
|
}
|
|
90
|
+
let owningDecoratorOptions;
|
|
91
|
+
if ('tableName' in options) {
|
|
92
|
+
owningDecoratorOptions = {
|
|
93
|
+
name: options.tableName,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
90
96
|
return (0, common_1.applyDecorators)(...[
|
|
91
97
|
(0, BaseField_1.BaseField)(options, {
|
|
92
98
|
decoratorName: 'RelationField',
|
|
@@ -95,7 +101,7 @@ function RelationField(options) {
|
|
|
95
101
|
isArray: ['ManyToMany', 'OneToMany'].includes(options.type),
|
|
96
102
|
}),
|
|
97
103
|
getRelationDecorator(options.type)(() => (0, TableFromModel_1.getTableFromModel)(options.relationClass()), options.inverseSide, { cascade: ['insert', 'update'], onUpdate: 'CASCADE' }),
|
|
98
|
-
OwningDecorator && OwningDecorator(),
|
|
104
|
+
OwningDecorator && OwningDecorator(owningDecoratorOptions),
|
|
99
105
|
(0, class_validator_1.ValidateIf)((object, value) => !!value),
|
|
100
106
|
(0, class_validator_1.ValidateNested)({ each: true }),
|
|
101
107
|
(0, class_transformer_1.Type)(options.relationClass),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationField.js","sourceRoot":"","sources":["../../../../../src/infrastructure/decorators/fields/RelationField.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAC/C,qCAA0F;AAC1F,qDAA2D;AAC3D,yDAAuC;AACvC,2CAA4G;AAC5G,sDAAoD;AACpD,4CAAqF;AACrF,qEAAgE;
|
|
1
|
+
{"version":3,"file":"R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