@x-fiber-sys/dev-tool 0.1.0
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 +11 -0
- package/dist/_cjs/common/action-kind.js +17 -0
- package/dist/_cjs/common/constants.js +8 -0
- package/dist/_cjs/common/document-kind.js +32 -0
- package/dist/_cjs/common/envs-kind.js +142 -0
- package/dist/_cjs/common/index.js +25 -0
- package/dist/_cjs/common/libraries-kind.js +116 -0
- package/dist/_cjs/common/menu-items.js +8 -0
- package/dist/_cjs/common/protocol-kind.js +62 -0
- package/dist/_cjs/common/symbols-kind.js +45 -0
- package/dist/_cjs/common/typings-kind.js +9 -0
- package/dist/_cjs/debug.js +195 -0
- package/dist/_cjs/index.js +5 -0
- package/dist/_cjs/initiator.js +28 -0
- package/dist/_cjs/schemas/generate.schema.js +2 -0
- package/dist/_cjs/schemas/index.js +18 -0
- package/dist/_cjs/schemas/row.schema.js +2 -0
- package/dist/_cjs/services/generator.js +107 -0
- package/dist/_cjs/services/index.js +19 -0
- package/dist/_cjs/services/installer.js +46 -0
- package/dist/_cjs/services/navigator.js +69 -0
- package/dist/_cjs/services/runner.js +20 -0
- package/dist/_cjs/templates/cache.template.js +58 -0
- package/dist/_cjs/templates/envs.template.js +115 -0
- package/dist/_cjs/templates/index.js +26 -0
- package/dist/_cjs/templates/index.template.js +38 -0
- package/dist/_cjs/templates/initiator.template.js +750 -0
- package/dist/_cjs/templates/ioc.template.js +107 -0
- package/dist/_cjs/templates/module.template.js +132 -0
- package/dist/_cjs/templates/pg-repository.template.js +432 -0
- package/dist/_cjs/templates/sys.template.js +110 -0
- package/dist/_cjs/templates/transport.template.js +490 -0
- package/dist/_cjs/templates/validator.template.js +16 -0
- package/dist/_cjs/types/index.js +2 -0
- package/dist/_cjs/types/module.js +2 -0
- package/dist/_cjs/types/service.js +2 -0
- package/dist/_cjs/utils/hello.js +17 -0
- package/dist/_cjs/utils/index.js +18 -0
- package/dist/_cjs/utils/ts-utils.js +7 -0
- package/dist/_types/common/action-kind.d.ts +15 -0
- package/dist/_types/common/constants.d.ts +5 -0
- package/dist/_types/common/document-kind.d.ts +29 -0
- package/dist/_types/common/envs-kind.d.ts +390 -0
- package/dist/_types/common/index.d.ts +9 -0
- package/dist/_types/common/libraries-kind.d.ts +115 -0
- package/dist/_types/common/menu-items.d.ts +7 -0
- package/dist/_types/common/protocol-kind.d.ts +59 -0
- package/dist/_types/common/symbols-kind.d.ts +44 -0
- package/dist/_types/common/typings-kind.d.ts +6 -0
- package/dist/_types/debug.d.ts +19 -0
- package/dist/_types/index.d.ts +2 -0
- package/dist/_types/initiator.d.ts +7 -0
- package/dist/_types/schemas/generate.schema.d.ts +38 -0
- package/dist/_types/schemas/index.d.ts +2 -0
- package/dist/_types/schemas/row.schema.d.ts +20 -0
- package/dist/_types/services/generator.d.ts +15 -0
- package/dist/_types/services/index.d.ts +3 -0
- package/dist/_types/services/installer.d.ts +5 -0
- package/dist/_types/services/navigator.d.ts +10 -0
- package/dist/_types/services/runner.d.ts +3 -0
- package/dist/_types/templates/cache.template.d.ts +8 -0
- package/dist/_types/templates/envs.template.d.ts +5 -0
- package/dist/_types/templates/index.d.ts +10 -0
- package/dist/_types/templates/index.template.d.ts +7 -0
- package/dist/_types/templates/initiator.template.d.ts +33 -0
- package/dist/_types/templates/ioc.template.d.ts +9 -0
- package/dist/_types/templates/module.template.d.ts +8 -0
- package/dist/_types/templates/pg-repository.template.d.ts +19 -0
- package/dist/_types/templates/sys.template.d.ts +23 -0
- package/dist/_types/templates/transport.template.d.ts +15 -0
- package/dist/_types/templates/validator.template.d.ts +7 -0
- package/dist/_types/types/index.d.ts +2 -0
- package/dist/_types/types/module.d.ts +10 -0
- package/dist/_types/types/service.d.ts +21 -0
- package/dist/_types/utils/hello.d.ts +1 -0
- package/dist/_types/utils/index.d.ts +2 -0
- package/dist/_types/utils/ts-utils.d.ts +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IocTemplate = void 0;
|
|
4
|
+
const morphix_1 = require("@terra-versity/morphix");
|
|
5
|
+
const ts_morph_1 = require("ts-morph");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
class IocTemplate {
|
|
8
|
+
constructor(path, concept) {
|
|
9
|
+
this._imports = new morphix_1.ImportsSculptor();
|
|
10
|
+
this._variables = new morphix_1.VariablesSculptor();
|
|
11
|
+
this._path = path;
|
|
12
|
+
this._concept = concept;
|
|
13
|
+
}
|
|
14
|
+
generate() {
|
|
15
|
+
const { libraries } = this._concept;
|
|
16
|
+
let source = new ts_morph_1.Project().createSourceFile(this._path, '', { overwrite: true });
|
|
17
|
+
const symbols = {
|
|
18
|
+
Registry: 'Registry',
|
|
19
|
+
Config: 'Config',
|
|
20
|
+
Logger: 'Logger',
|
|
21
|
+
Context: 'Context',
|
|
22
|
+
Tracer: 'Tracer',
|
|
23
|
+
};
|
|
24
|
+
const imports = [
|
|
25
|
+
{
|
|
26
|
+
module: common_1.LibrariesKindMapping.be_common,
|
|
27
|
+
namedImports: common_1.CommonKindMapping.create_symbols,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
module: common_1.LibrariesKindMapping.reflection,
|
|
31
|
+
namedImports: [common_1.ReflectionKindMapping.locator, common_1.ReflectionKindMapping.registry],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
module: common_1.LibrariesKindMapping.be_config,
|
|
35
|
+
namedImports: common_1.ConfigKindMapping.config,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
module: common_1.LibrariesKindMapping.context,
|
|
39
|
+
namedImports: common_1.ContextKindMapping.context,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
module: common_1.LibrariesKindMapping.logger,
|
|
43
|
+
namedImports: common_1.LoggerKindMapping.logger,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
module: common_1.LibrariesKindMapping.tracer,
|
|
47
|
+
namedImports: common_1.TracerKindMapping.tracer,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
if (libraries.postgres) {
|
|
51
|
+
imports.push({ module: common_1.LibrariesKindMapping.sql, namedImports: common_1.SqlKindMapping.postgres });
|
|
52
|
+
symbols['Postgres'] = 'Postgres';
|
|
53
|
+
}
|
|
54
|
+
if (libraries.slack) {
|
|
55
|
+
imports.push({ module: common_1.LibrariesKindMapping.slack, namedImports: common_1.SlackKindMapping.slack });
|
|
56
|
+
symbols['Slack'] = 'Slack';
|
|
57
|
+
}
|
|
58
|
+
if (libraries.httpServer) {
|
|
59
|
+
imports.push({
|
|
60
|
+
module: common_1.LibrariesKindMapping.http_server,
|
|
61
|
+
namedImports: common_1.HttpServerKindMapping.http_server,
|
|
62
|
+
});
|
|
63
|
+
symbols['HttpServer'] = 'HttpServer';
|
|
64
|
+
}
|
|
65
|
+
if (libraries.scrambler) {
|
|
66
|
+
imports.push({
|
|
67
|
+
module: common_1.LibrariesKindMapping.scrambler,
|
|
68
|
+
namedImports: common_1.ScramblerKindMapping.scrambler,
|
|
69
|
+
});
|
|
70
|
+
symbols['Scrambler'] = 'Scrambler';
|
|
71
|
+
}
|
|
72
|
+
source = this._imports.addModule(source, imports);
|
|
73
|
+
source = this._variables.addVariable(source, {
|
|
74
|
+
name: common_1.SYMBOL_NAME,
|
|
75
|
+
value: (writer) => {
|
|
76
|
+
writer.write('createSymbols(');
|
|
77
|
+
for (const [_, symbol] of Object.entries(symbols)) {
|
|
78
|
+
writer.writeLine(`'${symbol}',`);
|
|
79
|
+
}
|
|
80
|
+
writer.write(')');
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
source = this._variables.addStatement(source, (writer) => {
|
|
84
|
+
writer.blankLine();
|
|
85
|
+
writer.write('locator.bindings({');
|
|
86
|
+
for (const [name, symbol] of Object.entries(symbols)) {
|
|
87
|
+
writer.writeLine(`[${common_1.SYMBOL_NAME}.${name}]: ${symbol},`);
|
|
88
|
+
}
|
|
89
|
+
writer.write('})');
|
|
90
|
+
writer.blankLine();
|
|
91
|
+
});
|
|
92
|
+
source = this._imports.addModule(source, { namedImports: 'Initiator', module: './initiator' });
|
|
93
|
+
source = this._variables.addStatement(source, (writer) => {
|
|
94
|
+
writer.writeLine(`locator.bindings({ [${common_1.SYMBOL_NAME}.Initiator]: 'Initiator' })`);
|
|
95
|
+
});
|
|
96
|
+
source = this._variables.addVariable(source, {
|
|
97
|
+
name: 'container',
|
|
98
|
+
value: (writer) => {
|
|
99
|
+
writer.blankLine();
|
|
100
|
+
writer.writeLine('locator.container');
|
|
101
|
+
},
|
|
102
|
+
isExportable: true,
|
|
103
|
+
});
|
|
104
|
+
source.saveSync();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.IocTemplate = IocTemplate;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleTemplate = void 0;
|
|
4
|
+
const morphix_1 = require("@terra-versity/morphix");
|
|
5
|
+
const ts_morph_1 = require("ts-morph");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
class ModuleTemplate {
|
|
9
|
+
constructor() {
|
|
10
|
+
this._imports = new morphix_1.ImportsSculptor();
|
|
11
|
+
this._class = new morphix_1.ClassSculptor();
|
|
12
|
+
}
|
|
13
|
+
content(ref, documents) {
|
|
14
|
+
let source = new ts_morph_1.Project().createSourceFile('./index.ts', '', { overwrite: true });
|
|
15
|
+
const imports = [
|
|
16
|
+
{ module: common_1.LibrariesKindMapping.reflection, namedImports: common_1.ReflectionKindMapping.module },
|
|
17
|
+
];
|
|
18
|
+
const transportImport = `${ref.class}${common_1.DocumentClassMapping.transport}`;
|
|
19
|
+
const controllerImport = `${ref.class}${common_1.DocumentClassMapping.controller}`;
|
|
20
|
+
const pgEntityImport = `${ref.class}${common_1.DocumentClassMapping.pg_entity}`;
|
|
21
|
+
const pgRepositoryImport = `${ref.class}${common_1.DocumentClassMapping.pg_repository}`;
|
|
22
|
+
const tmEntityImport = `${ref.class}${common_1.DocumentClassMapping.tm_entity}`;
|
|
23
|
+
const tmRepositoryImport = `${ref.class}${common_1.DocumentClassMapping.tm_repository}`;
|
|
24
|
+
const chEntityImport = `${ref.class}${common_1.DocumentClassMapping.ch_entity}`;
|
|
25
|
+
const chRepositoryImport = `${ref.class}${common_1.DocumentClassMapping.ch_repository}`;
|
|
26
|
+
if (documents.transport) {
|
|
27
|
+
imports.push({
|
|
28
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.transport}`,
|
|
29
|
+
namedImports: transportImport,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (documents.controller) {
|
|
33
|
+
imports.push({
|
|
34
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.controller}`,
|
|
35
|
+
namedImports: controllerImport,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (documents.pgEntity) {
|
|
39
|
+
imports.push({
|
|
40
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.pg_entity}`,
|
|
41
|
+
namedImports: pgEntityImport,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (documents.pgRepository) {
|
|
45
|
+
imports.push({
|
|
46
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.pg_repository}`,
|
|
47
|
+
namedImports: pgRepositoryImport,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (documents.tmEntity) {
|
|
51
|
+
imports.push({
|
|
52
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.tm_entity}`,
|
|
53
|
+
namedImports: tmEntityImport,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (documents.tmRepository) {
|
|
57
|
+
imports.push({
|
|
58
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.tm_repository}`,
|
|
59
|
+
namedImports: tmRepositoryImport,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (documents.chEntity) {
|
|
63
|
+
imports.push({
|
|
64
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.ch_entity}`,
|
|
65
|
+
namedImports: chEntityImport,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (documents.chRepository) {
|
|
69
|
+
imports.push({
|
|
70
|
+
module: `./${ref.domain}.${common_1.DocumentKindMapping.ch_repository}`,
|
|
71
|
+
namedImports: chRepositoryImport,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
imports.push({
|
|
75
|
+
module: (0, utils_1.getTypeAlias)(ref.service, common_1.TypingsKindMapping.service),
|
|
76
|
+
namedImports: common_1.ServiceTypingsKindMapping.domains,
|
|
77
|
+
isTypings: true,
|
|
78
|
+
});
|
|
79
|
+
source = this._imports.addModule(source, imports);
|
|
80
|
+
source = this._class.addClass(source, {
|
|
81
|
+
name: `${ref.class}${common_1.DocumentClassMapping.module}`,
|
|
82
|
+
options: { isExportable: true },
|
|
83
|
+
constructor: {},
|
|
84
|
+
decorators: {
|
|
85
|
+
name: common_1.ReflectionKindMapping.module,
|
|
86
|
+
typeArguments: [common_1.ServiceTypingsKindMapping.domains],
|
|
87
|
+
arguments: (writer) => {
|
|
88
|
+
writer.writeLine(`'${ref.domain}', {`);
|
|
89
|
+
if (documents.transport) {
|
|
90
|
+
writer.writeLine(`${common_1.DocumentKindMapping.transport}: ${transportImport},`);
|
|
91
|
+
}
|
|
92
|
+
if (documents.controller) {
|
|
93
|
+
writer.writeLine(`${common_1.DocumentKindMapping.controller}: ${controllerImport},`);
|
|
94
|
+
}
|
|
95
|
+
if (documents.pgEntity || documents.pgRepository) {
|
|
96
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.postgres}: {`);
|
|
97
|
+
if (documents.pgEntity) {
|
|
98
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.entity}: ${pgEntityImport},`);
|
|
99
|
+
}
|
|
100
|
+
if (documents.pgRepository) {
|
|
101
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.repository}: ${pgRepositoryImport},`);
|
|
102
|
+
}
|
|
103
|
+
writer.writeLine(`},`);
|
|
104
|
+
}
|
|
105
|
+
if (documents.tmEntity || documents.tmRepository) {
|
|
106
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.timescale}: {`);
|
|
107
|
+
if (documents.tmEntity) {
|
|
108
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.entity}: ${tmEntityImport},`);
|
|
109
|
+
}
|
|
110
|
+
if (documents.tmRepository) {
|
|
111
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.repository}: ${tmRepositoryImport},`);
|
|
112
|
+
}
|
|
113
|
+
writer.writeLine(`},`);
|
|
114
|
+
}
|
|
115
|
+
if (documents.chEntity || documents.chRepository) {
|
|
116
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.timescale}: {`);
|
|
117
|
+
if (documents.chEntity) {
|
|
118
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.entity}: ${chEntityImport},`);
|
|
119
|
+
}
|
|
120
|
+
if (documents.chRepository) {
|
|
121
|
+
writer.writeLine(`${common_1.ModuleBlockMapping.repository}: ${chRepositoryImport},`);
|
|
122
|
+
}
|
|
123
|
+
writer.writeLine(`},`);
|
|
124
|
+
}
|
|
125
|
+
writer.writeLine(`},`);
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
return source.getText();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.ModuleTemplate = ModuleTemplate;
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostgresRepositoryTemplate = void 0;
|
|
4
|
+
const morphix_1 = require("@terra-versity/morphix");
|
|
5
|
+
const ts_morph_1 = require("ts-morph");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
class PostgresRepositoryTemplate {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._imports = new morphix_1.ImportsSculptor();
|
|
10
|
+
this._class = new morphix_1.ClassSculptor();
|
|
11
|
+
}
|
|
12
|
+
content(concept) {
|
|
13
|
+
let source = new ts_morph_1.Project().createSourceFile('./index.ts', '', { overwrite: true });
|
|
14
|
+
const imports = [
|
|
15
|
+
{
|
|
16
|
+
module: common_1.LibrariesKindMapping.reflection,
|
|
17
|
+
namedImports: [
|
|
18
|
+
common_1.ReflectionKindMapping.bind,
|
|
19
|
+
common_1.ReflectionKindMapping.transport,
|
|
20
|
+
common_1.ReflectionKindMapping.extract,
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
source = this._imports.addModule(source, imports);
|
|
25
|
+
let constructor = undefined;
|
|
26
|
+
constructor = {
|
|
27
|
+
parameters: [
|
|
28
|
+
{
|
|
29
|
+
name: common_1.SymbolsAliasMapping.logger,
|
|
30
|
+
isReadonly: true,
|
|
31
|
+
scope: ts_morph_1.Scope.Private,
|
|
32
|
+
decorators: [
|
|
33
|
+
{
|
|
34
|
+
name: common_1.ReflectionKindMapping.extract,
|
|
35
|
+
arguments: (writer) => {
|
|
36
|
+
writer.writeLine(`${common_1.SYMBOL_NAME}.${common_1.SymbolsKindMapping.logger}`);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
type: (writer) => writer.writeLine(common_1.LoggerKindMapping.logger),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: common_1.SymbolsAliasMapping.postgres,
|
|
44
|
+
isReadonly: true,
|
|
45
|
+
scope: ts_morph_1.Scope.Private,
|
|
46
|
+
decorators: [
|
|
47
|
+
{
|
|
48
|
+
name: common_1.ReflectionKindMapping.extract,
|
|
49
|
+
arguments: (writer) => {
|
|
50
|
+
writer.writeLine(`${common_1.SYMBOL_NAME}.${common_1.SymbolsKindMapping.postgres}`);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
type: (writer) => writer.writeLine(common_1.SqlKindMapping.postgres),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
const methods = [];
|
|
59
|
+
if (concept.actions.createOne && concept.actions.createOne.modules.postresRepository) {
|
|
60
|
+
methods.push(this._publicCreateOne(concept.ref));
|
|
61
|
+
methods.push(this._privateCreateOne(concept.ref, concept.item));
|
|
62
|
+
}
|
|
63
|
+
if (concept.actions.updateById && concept.actions.updateById.modules.postresRepository) {
|
|
64
|
+
methods.push(this._publicUpdateById(concept.ref));
|
|
65
|
+
methods.push(this._privateUpdateById(concept.ref, concept.item));
|
|
66
|
+
}
|
|
67
|
+
if (concept.actions.patchById && concept.actions.patchById.modules.postresRepository) {
|
|
68
|
+
methods.push(this._publicPatchById(concept.ref));
|
|
69
|
+
methods.push(this._privatePatchById(concept.ref, concept.item));
|
|
70
|
+
}
|
|
71
|
+
const withSoftDelete = concept.actions.softDeleteById && concept.actions.softDeleteById.modules.postresRepository;
|
|
72
|
+
const withRestore = concept.actions.restoreById && concept.actions.restoreById.modules.postresRepository;
|
|
73
|
+
if (withSoftDelete || withRestore) {
|
|
74
|
+
methods.push(this._publicDeleteModifyById(concept.ref));
|
|
75
|
+
methods.push(this._privateDeleteModifyById(concept.ref, concept.item));
|
|
76
|
+
}
|
|
77
|
+
const withArchive = concept.actions.archiveById && concept.actions.archiveById.modules.postresRepository;
|
|
78
|
+
const withUnarchive = concept.actions.unarchiveById && concept.actions.unarchiveById.modules.postresRepository;
|
|
79
|
+
if (withArchive || withUnarchive) {
|
|
80
|
+
methods.push(this._publicArchiveModifyById(concept.ref));
|
|
81
|
+
methods.push(this._privateArchiveModifyById(concept.ref, concept.item));
|
|
82
|
+
}
|
|
83
|
+
source = this._class.addClass(source, {
|
|
84
|
+
name: `${concept.ref.class}${common_1.DocumentClassMapping.pg_repository}`,
|
|
85
|
+
options: { isExportable: true },
|
|
86
|
+
decorators: { name: common_1.ReflectionKindMapping.bind, arguments: () => void 0 },
|
|
87
|
+
constructor,
|
|
88
|
+
methods,
|
|
89
|
+
});
|
|
90
|
+
return source.getText();
|
|
91
|
+
}
|
|
92
|
+
_publicCreateOne(ref) {
|
|
93
|
+
return {
|
|
94
|
+
name: common_1.ActionKindMapping.create_one,
|
|
95
|
+
isAsync: true,
|
|
96
|
+
scope: ts_morph_1.Scope.Public,
|
|
97
|
+
parameters: [
|
|
98
|
+
{
|
|
99
|
+
name: 'ref',
|
|
100
|
+
type: (writer) => writer.writeLine(`${ref.class}Ref`),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'trx',
|
|
104
|
+
isOptional: true,
|
|
105
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
body: (writer) => {
|
|
109
|
+
writer.writeLine(`return this._${common_1.ActionKindMapping.create_one}({ ref, trx }).execute()`);
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
_privateCreateOne(ref, item) {
|
|
114
|
+
return {
|
|
115
|
+
name: `_${common_1.ActionKindMapping.create_one}`,
|
|
116
|
+
isAsync: false,
|
|
117
|
+
scope: ts_morph_1.Scope.Private,
|
|
118
|
+
parameters: [
|
|
119
|
+
{
|
|
120
|
+
name: 'row',
|
|
121
|
+
type: (writer) => writer.writeLine(`Created${ref.class}`),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'trx',
|
|
125
|
+
isOptional: true,
|
|
126
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
body: (writer) => {
|
|
130
|
+
writer.writeLine('const now = DateTime.now().toJSDate()');
|
|
131
|
+
writer.blankLine();
|
|
132
|
+
writer.writeLine(`return this.${common_1.SymbolsAliasMapping.postgres}.${common_1.SqlMethodKindMapping.repository}.${common_1.SqlMethodKindMapping.insert_row}(`);
|
|
133
|
+
writer.writeLine(`'${ref.entity}',`);
|
|
134
|
+
writer.writeLine('{');
|
|
135
|
+
for (const [name, { generator }] of Object.entries(item)) {
|
|
136
|
+
if (generator.isTimestampGenerate) {
|
|
137
|
+
writer.writeLine(`${name}: now,`);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (generator.isNullGenerate) {
|
|
141
|
+
writer.writeLine(`${name}: null,`);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
writer.writeLine(`${name}: row.${name},`);
|
|
145
|
+
}
|
|
146
|
+
writer.writeLine('},');
|
|
147
|
+
writer.writeLine('{');
|
|
148
|
+
writer.writeLine('trx,');
|
|
149
|
+
writer.writeLine(`returning: ['id'],`);
|
|
150
|
+
writer.writeLine('},');
|
|
151
|
+
writer.writeLine(')');
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
_publicUpdateById(ref) {
|
|
156
|
+
return {
|
|
157
|
+
name: common_1.ActionKindMapping.update_by_id,
|
|
158
|
+
isAsync: true,
|
|
159
|
+
scope: ts_morph_1.Scope.Public,
|
|
160
|
+
parameters: [
|
|
161
|
+
{
|
|
162
|
+
name: 'ref',
|
|
163
|
+
type: (writer) => writer.writeLine(`${ref.class}Ref`),
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: 'fields',
|
|
167
|
+
type: (writer) => writer.writeLine(`${ref.class}Updated`),
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'trx',
|
|
171
|
+
isOptional: true,
|
|
172
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
body: (writer) => {
|
|
176
|
+
writer.writeLine(`return this._${common_1.ActionKindMapping.update_by_id}({ ref, fields, trx }).execute()`);
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
_privateUpdateById(ref, item) {
|
|
181
|
+
return {
|
|
182
|
+
name: `_${common_1.ActionKindMapping.update_by_id}`,
|
|
183
|
+
isAsync: false,
|
|
184
|
+
scope: ts_morph_1.Scope.Private,
|
|
185
|
+
parameters: [
|
|
186
|
+
{
|
|
187
|
+
name: 'ref',
|
|
188
|
+
type: (writer) => writer.writeLine(`${ref.class}Ref`),
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: 'fields',
|
|
192
|
+
type: (writer) => writer.writeLine(`${ref.class}Updated`),
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'trx',
|
|
196
|
+
isOptional: true,
|
|
197
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
body: (writer) => {
|
|
201
|
+
writer.writeLine('const now = DateTime.now().toJSDate()');
|
|
202
|
+
writer.blankLine();
|
|
203
|
+
writer.writeLine(`return this.${common_1.SymbolsAliasMapping.postgres}.${common_1.SqlMethodKindMapping.repository}.${common_1.SqlMethodKindMapping.update_row}(`);
|
|
204
|
+
writer.writeLine(`'${ref.entity}',`);
|
|
205
|
+
writer.writeLine('{');
|
|
206
|
+
writer.writeLine(`${ref.item}_id: fields.${ref.item}_id,`);
|
|
207
|
+
for (const [_, { generator }] of Object.entries(item)) {
|
|
208
|
+
if (generator.partition) {
|
|
209
|
+
writer.writeLine(`${generator.sqlAlias}: fields.${generator.partition.key},`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
writer.writeLine('},');
|
|
213
|
+
writer.writeLine('{');
|
|
214
|
+
for (const [_, { generator }] of Object.entries(item)) {
|
|
215
|
+
if (generator.partition || !generator.isUpdated) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
writer.writeLine(`${generator.sqlAlias}: fields.${generator.sqlAlias},`);
|
|
219
|
+
}
|
|
220
|
+
writer.writeLine('},');
|
|
221
|
+
writer.writeLine('{');
|
|
222
|
+
writer.writeLine('trx,');
|
|
223
|
+
writer.writeLine(`returning: ['id'],`);
|
|
224
|
+
writer.writeLine(`strictness: 'weak',`);
|
|
225
|
+
writer.writeLine('},');
|
|
226
|
+
writer.writeLine(')');
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
_publicPatchById(ref) {
|
|
231
|
+
return {
|
|
232
|
+
name: common_1.ActionKindMapping.patch_by_id,
|
|
233
|
+
isAsync: true,
|
|
234
|
+
scope: ts_morph_1.Scope.Public,
|
|
235
|
+
parameters: [
|
|
236
|
+
{
|
|
237
|
+
name: 'ref',
|
|
238
|
+
type: (writer) => writer.writeLine(`${ref.class}Ref`),
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'fields',
|
|
242
|
+
type: (writer) => writer.writeLine(`Partial<${ref.class}Updated>`),
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: 'trx',
|
|
246
|
+
isOptional: true,
|
|
247
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
body: (writer) => {
|
|
251
|
+
writer.writeLine(`return this._${common_1.ActionKindMapping.patch_by_id}({ ref, fields, trx }).execute()`);
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
_privatePatchById(ref, item) {
|
|
256
|
+
return {
|
|
257
|
+
name: `_${common_1.ActionKindMapping.patch_by_id}`,
|
|
258
|
+
isAsync: false,
|
|
259
|
+
scope: ts_morph_1.Scope.Private,
|
|
260
|
+
parameters: [
|
|
261
|
+
{
|
|
262
|
+
name: 'ref',
|
|
263
|
+
type: (writer) => writer.writeLine(`${ref.class}Ref`),
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: 'fields',
|
|
267
|
+
type: (writer) => writer.writeLine(`Partial<${ref.class}Updated>`),
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: 'trx',
|
|
271
|
+
isOptional: true,
|
|
272
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
body: (writer) => {
|
|
276
|
+
writer.writeLine('const now = DateTime.now().toJSDate()');
|
|
277
|
+
writer.blankLine();
|
|
278
|
+
writer.writeLine(`return this.${common_1.SymbolsAliasMapping.postgres}.${common_1.SqlMethodKindMapping.repository}.${common_1.SqlMethodKindMapping.update_row}(`);
|
|
279
|
+
writer.writeLine(`'${ref.entity}',`);
|
|
280
|
+
writer.writeLine('{');
|
|
281
|
+
writer.writeLine(`${ref.item}_id: fields.${ref.item}_id,`);
|
|
282
|
+
for (const [_, { generator }] of Object.entries(item)) {
|
|
283
|
+
if (generator.partition) {
|
|
284
|
+
writer.writeLine(`${generator.sqlAlias}: fields.${generator.partition.key},`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
writer.writeLine('},');
|
|
288
|
+
writer.writeLine('{');
|
|
289
|
+
for (const [_, { generator }] of Object.entries(item)) {
|
|
290
|
+
if (generator.partition || !generator.isUpdated) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
writer.writeLine(`...(fields.${generator.sqlAlias} && { ${generator.sqlAlias}: fields.${generator.sqlAlias} }),`);
|
|
294
|
+
}
|
|
295
|
+
writer.writeLine('},');
|
|
296
|
+
writer.writeLine('{');
|
|
297
|
+
writer.writeLine('trx,');
|
|
298
|
+
writer.writeLine(`returning: ['id'],`);
|
|
299
|
+
writer.writeLine(`strictness: 'weak',`);
|
|
300
|
+
writer.writeLine('},');
|
|
301
|
+
writer.writeLine(')');
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
_publicDeleteModifyById(ref) {
|
|
306
|
+
return {
|
|
307
|
+
name: common_1.ActionKindMapping.delete_modify_by_id,
|
|
308
|
+
isAsync: true,
|
|
309
|
+
scope: ts_morph_1.Scope.Public,
|
|
310
|
+
parameters: [
|
|
311
|
+
{
|
|
312
|
+
name: 'ref',
|
|
313
|
+
type: (writer) => writer.writeLine(`${ref.class}Ref`),
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
name: 'mode',
|
|
317
|
+
type: (writer) => writer.writeLine(`'delete' | 'restore'`),
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: 'trx',
|
|
321
|
+
isOptional: true,
|
|
322
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
body: (writer) => {
|
|
326
|
+
writer.writeLine(`return this._${common_1.ActionKindMapping.delete_modify_by_id}({ ref, mode, trx }).execute()`);
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
_privateDeleteModifyById(ref, item) {
|
|
331
|
+
return {
|
|
332
|
+
name: `_${common_1.ActionKindMapping.delete_modify_by_id}`,
|
|
333
|
+
isAsync: false,
|
|
334
|
+
scope: ts_morph_1.Scope.Private,
|
|
335
|
+
parameters: [
|
|
336
|
+
{
|
|
337
|
+
name: 'args',
|
|
338
|
+
type: (writer) => {
|
|
339
|
+
writer.writeLine(`{ ref: ${ref.class}Ref, mode: 'delete' | 'restore', trx?: Knex.Transaction }`);
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
body: (writer) => {
|
|
344
|
+
writer.writeLine(`const { ref, mode, trx } = args`);
|
|
345
|
+
writer.writeLine('const now = DateTime.now().toJSDate()');
|
|
346
|
+
writer.blankLine();
|
|
347
|
+
writer.writeLine(`return this.${common_1.SymbolsAliasMapping.postgres}.${common_1.SqlMethodKindMapping.repository}.${common_1.SqlMethodKindMapping.update_row}(`);
|
|
348
|
+
writer.writeLine(`'${ref.entity}',`);
|
|
349
|
+
writer.writeLine('{');
|
|
350
|
+
writer.writeLine(`${ref.item}_id: fields.${ref.item}_id,`);
|
|
351
|
+
for (const [_, { generator }] of Object.entries(item)) {
|
|
352
|
+
if (generator.partition) {
|
|
353
|
+
writer.writeLine(`${generator.sqlAlias}: fields.${generator.partition.key},`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
writer.writeLine('},');
|
|
357
|
+
writer.writeLine('{');
|
|
358
|
+
writer.writeLine(`deleted_at: mode === 'restore' ? null : now,`);
|
|
359
|
+
writer.writeLine('updated_at: now');
|
|
360
|
+
writer.writeLine('},');
|
|
361
|
+
writer.writeLine('{');
|
|
362
|
+
writer.writeLine('trx,');
|
|
363
|
+
writer.writeLine('},');
|
|
364
|
+
writer.writeLine(')');
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
_publicArchiveModifyById(ref) {
|
|
369
|
+
return {
|
|
370
|
+
name: common_1.ActionKindMapping.archive_modify_by_id,
|
|
371
|
+
isAsync: true,
|
|
372
|
+
scope: ts_morph_1.Scope.Public,
|
|
373
|
+
parameters: [
|
|
374
|
+
{
|
|
375
|
+
name: 'ref',
|
|
376
|
+
type: (writer) => writer.writeLine(`${ref.class}Ref`),
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
name: 'mode',
|
|
380
|
+
type: (writer) => writer.writeLine(`'archive' | 'unarchive'`),
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: 'trx',
|
|
384
|
+
isOptional: true,
|
|
385
|
+
type: (writer) => writer.writeLine('Knex.Transaction'),
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
body: (writer) => {
|
|
389
|
+
writer.writeLine(`return this._${common_1.ActionKindMapping.archive_modify_by_id}({ ref, mode, trx }).execute()`);
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
_privateArchiveModifyById(ref, item) {
|
|
394
|
+
return {
|
|
395
|
+
name: `_${common_1.ActionKindMapping.archive_modify_by_id}`,
|
|
396
|
+
isAsync: false,
|
|
397
|
+
scope: ts_morph_1.Scope.Private,
|
|
398
|
+
parameters: [
|
|
399
|
+
{
|
|
400
|
+
name: 'args',
|
|
401
|
+
type: (writer) => {
|
|
402
|
+
writer.writeLine(`{ ref: ${ref.class}Ref, mode: 'archive' | 'unarchive', trx?: Knex.Transaction }`);
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
body: (writer) => {
|
|
407
|
+
writer.writeLine(`const { ref, mode, trx } = args`);
|
|
408
|
+
writer.writeLine('const now = DateTime.now().toJSDate()');
|
|
409
|
+
writer.blankLine();
|
|
410
|
+
writer.writeLine(`return this.${common_1.SymbolsAliasMapping.postgres}.${common_1.SqlMethodKindMapping.repository}.${common_1.SqlMethodKindMapping.update_row}(`);
|
|
411
|
+
writer.writeLine(`'${ref.entity}',`);
|
|
412
|
+
writer.writeLine('{');
|
|
413
|
+
writer.writeLine(`${ref.item}_id: fields.${ref.item}_id,`);
|
|
414
|
+
for (const [_, { generator }] of Object.entries(item)) {
|
|
415
|
+
if (generator.partition) {
|
|
416
|
+
writer.writeLine(`${generator.sqlAlias}: fields.${generator.partition.key},`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
writer.writeLine('},');
|
|
420
|
+
writer.writeLine('{');
|
|
421
|
+
writer.writeLine(`archive_at: mode === 'unarchive' ? null : now,`);
|
|
422
|
+
writer.writeLine('updated_at: now');
|
|
423
|
+
writer.writeLine('},');
|
|
424
|
+
writer.writeLine('{');
|
|
425
|
+
writer.writeLine('trx,');
|
|
426
|
+
writer.writeLine('},');
|
|
427
|
+
writer.writeLine(')');
|
|
428
|
+
},
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
exports.PostgresRepositoryTemplate = PostgresRepositoryTemplate;
|