@nest-yalc-2/app 1.3.3
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/LICENSE +661 -0
- package/README.md +49 -0
- package/package.json +33 -0
- package/src/__tests__/app-bootstrap-base.helper.spec.ts +38 -0
- package/src/__tests__/app-bootstrap-standalone.helper.spec.ts +35 -0
- package/src/__tests__/app-bootstrap.helper.spec.ts +98 -0
- package/src/__tests__/app-config.service.spec.ts +55 -0
- package/src/__tests__/app-context.service.spec.ts +28 -0
- package/src/__tests__/app.events.spec.ts +12 -0
- package/src/__tests__/app.helper.spec.ts +204 -0
- package/src/__tests__/base-app-module.helper.spec.ts +231 -0
- package/src/__tests__/base-app.controller.spec.ts +72 -0
- package/src/__tests__/base-app.service.spec.ts +39 -0
- package/src/__tests__/cls.module.spec.ts +33 -0
- package/src/__tests__/life-cycle-handler.service.spec.ts +48 -0
- package/src/__tests__/tsconfig.json +3 -0
- package/src/__tests__/unwrap-result.interceptor.spec.ts +52 -0
- package/src/app-bootstrap-base.helper.d.ts +41 -0
- package/src/app-bootstrap-base.helper.js +108 -0
- package/src/app-bootstrap-base.helper.js.map +1 -0
- package/src/app-bootstrap-base.helper.ts +199 -0
- package/src/app-bootstrap-standalone.helper.d.ts +15 -0
- package/src/app-bootstrap-standalone.helper.js +45 -0
- package/src/app-bootstrap-standalone.helper.js.map +1 -0
- package/src/app-bootstrap-standalone.helper.ts +60 -0
- package/src/app-bootstrap.helper.d.ts +43 -0
- package/src/app-bootstrap.helper.js +164 -0
- package/src/app-bootstrap.helper.js.map +1 -0
- package/src/app-bootstrap.helper.ts +263 -0
- package/src/app-config.service.d.ts +14 -0
- package/src/app-config.service.js +45 -0
- package/src/app-config.service.js.map +1 -0
- package/src/app-config.service.ts +61 -0
- package/src/app-context.module.d.ts +2 -0
- package/src/app-context.module.js +19 -0
- package/src/app-context.module.js.map +1 -0
- package/src/app-context.module.ts +6 -0
- package/src/app-context.service.d.ts +7 -0
- package/src/app-context.service.js +26 -0
- package/src/app-context.service.js.map +1 -0
- package/src/app-context.service.ts +16 -0
- package/src/app-imports.factory.d.ts +19 -0
- package/src/app-imports.factory.js +223 -0
- package/src/app-imports.factory.js.map +1 -0
- package/src/app-imports.factory.ts +320 -0
- package/src/app.events.d.ts +5 -0
- package/src/app.events.js +10 -0
- package/src/app.events.js.map +1 -0
- package/src/app.events.ts +8 -0
- package/src/app.helper.d.ts +17 -0
- package/src/app.helper.js +26 -0
- package/src/app.helper.js.map +1 -0
- package/src/app.helper.ts +73 -0
- package/src/base-app-module.helper.d.ts +24 -0
- package/src/base-app-module.helper.js +326 -0
- package/src/base-app-module.helper.js.map +1 -0
- package/src/base-app-module.helper.ts +447 -0
- package/src/base-app.controller.d.ts +9 -0
- package/src/base-app.controller.js +56 -0
- package/src/base-app.controller.js.map +1 -0
- package/src/base-app.controller.ts +43 -0
- package/src/base-app.interface.d.ts +33 -0
- package/src/base-app.interface.js +3 -0
- package/src/base-app.interface.js.map +1 -0
- package/src/base-app.interface.ts +55 -0
- package/src/base-app.service.d.ts +7 -0
- package/src/base-app.service.js +78 -0
- package/src/base-app.service.js.map +1 -0
- package/src/base-app.service.ts +29 -0
- package/src/cls.module.d.ts +15 -0
- package/src/cls.module.js +51 -0
- package/src/cls.module.js.map +1 -0
- package/src/cls.module.ts +68 -0
- package/src/conf.type.d.ts +21 -0
- package/src/conf.type.js +3 -0
- package/src/conf.type.js.map +1 -0
- package/src/conf.type.ts +22 -0
- package/src/db-conf.helper.ts-off +93 -0
- package/src/def.const.d.ts +10 -0
- package/src/def.const.js +14 -0
- package/src/def.const.js.map +1 -0
- package/src/def.const.ts +33 -0
- package/src/global.enum.d.ts +6 -0
- package/src/global.enum.js +11 -0
- package/src/global.enum.js.map +1 -0
- package/src/global.enum.ts +6 -0
- package/src/index.d.ts +0 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +0 -0
- package/src/life-cycle-handler.service.d.ts +13 -0
- package/src/life-cycle-handler.service.js +47 -0
- package/src/life-cycle-handler.service.js.map +1 -0
- package/src/life-cycle-handler.service.ts +58 -0
- package/src/unwrap-result.interceptor.d.ts +5 -0
- package/src/unwrap-result.interceptor.js +36 -0
- package/src/unwrap-result.interceptor.js.map +1 -0
- package/src/unwrap-result.interceptor.ts +32 -0
- package/src/yalc-controller.interface.d.ts +3 -0
- package/src/yalc-controller.interface.js +3 -0
- package/src/yalc-controller.interface.js.map +1 -0
- package/src/yalc-controller.interface.ts +6 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.AppDependencyFactory = AppDependencyFactory;
|
|
37
|
+
const common_1 = require("@nestjs/common");
|
|
38
|
+
const axios_1 = require("@nestjs/axios");
|
|
39
|
+
const config_1 = require("@nestjs/config");
|
|
40
|
+
const wrap_1 = require("@graphql-tools/wrap");
|
|
41
|
+
const app_context_module_js_1 = require("./app-context.module.js");
|
|
42
|
+
const app_context_service_js_1 = require("./app-context.service.js");
|
|
43
|
+
const conn_helper_js_1 = require("@nest-yalc-2/database/conn.helper.js");
|
|
44
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
45
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
46
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
47
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
48
|
+
const error_1 = require("graphql/error");
|
|
49
|
+
const typeorm_logger_js_1 = require("@nest-yalc-2/logger/typeorm-logger.js");
|
|
50
|
+
const def_const_js_1 = require("./def.const.js");
|
|
51
|
+
const app_events_js_1 = require("./app.events.js");
|
|
52
|
+
const gql_complexity_plugin_js_1 = require("@nest-yalc-2/graphql/plugins/gql-complexity.plugin.js");
|
|
53
|
+
const class_helper_js_1 = require("@nest-yalc-2/utils/class.helper.js");
|
|
54
|
+
const apollo_1 = require("@nestjs/apollo");
|
|
55
|
+
const dotenv = __importStar(require("dotenv"));
|
|
56
|
+
dotenv.config();
|
|
57
|
+
function AppDependencyFactory(_context, confs, dbConnNames, gqlModules, options) {
|
|
58
|
+
const { setupEvents = true, setupJwt = true, keepDBConnectionAlive = false, buildSchemaOptions = {}, disablePlayground = false, } = options ?? {};
|
|
59
|
+
const envPath = [];
|
|
60
|
+
if (!options?.envPath) {
|
|
61
|
+
envPath.push('.env');
|
|
62
|
+
if (process.env.NODE_ENV) {
|
|
63
|
+
envPath.push(`.env.${process.env.NODE_ENV}`);
|
|
64
|
+
if (process.env.NODE_ENV !== 'production')
|
|
65
|
+
envPath.push('conf/dist/.env.shared');
|
|
66
|
+
if (process.env.DOCKER_CONTAINER === '1')
|
|
67
|
+
envPath.push(`conf/dist/.env.docker.${process.env.NODE_ENV}`);
|
|
68
|
+
else {
|
|
69
|
+
envPath.push(`conf/dist/.env.local.${process.env.NODE_ENV}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
common_1.Logger.debug?.(`Using ${envPath}, for environment: ${process.env.NODE_ENV}`);
|
|
74
|
+
const configModule = config_1.ConfigModule.forRoot({
|
|
75
|
+
load: confs,
|
|
76
|
+
envFilePath: envPath,
|
|
77
|
+
});
|
|
78
|
+
const imports = [
|
|
79
|
+
configModule,
|
|
80
|
+
app_context_module_js_1.AppContextModule,
|
|
81
|
+
axios_1.HttpModule,
|
|
82
|
+
];
|
|
83
|
+
if (dbConnNames.length) {
|
|
84
|
+
dbConnNames.forEach((connName) => {
|
|
85
|
+
imports.push(typeorm_1.TypeOrmModule.forRootAsync({
|
|
86
|
+
inject: [config_1.ConfigService, typeorm_logger_js_1.TypeORMLogger],
|
|
87
|
+
name: connName,
|
|
88
|
+
useFactory: async (configService, logger) => {
|
|
89
|
+
const conf = configService.get((0, conn_helper_js_1.getConfNameByConnection)(connName));
|
|
90
|
+
logger.log?.('log', `Connecting DB ${connName} to host: ${conf?.host}`);
|
|
91
|
+
return {
|
|
92
|
+
...conf,
|
|
93
|
+
logger: conf?.logging ? logger : undefined,
|
|
94
|
+
maxQueryExecutionTime: 1000,
|
|
95
|
+
keepConnectionAlive: keepDBConnectionAlive,
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const providers = [];
|
|
102
|
+
class ApolloPluginsModule {
|
|
103
|
+
static forRoot() {
|
|
104
|
+
return {
|
|
105
|
+
module: ApolloPluginsModule,
|
|
106
|
+
providers: [
|
|
107
|
+
{
|
|
108
|
+
provide: 'APOLLO_PLUGINS',
|
|
109
|
+
useFactory: (...gqlPlugins) => {
|
|
110
|
+
return gqlPlugins;
|
|
111
|
+
},
|
|
112
|
+
inject: [...(options?.gqlPlugin ?? [])],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
exports: ['APOLLO_PLUGINS'],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (gqlModules.length) {
|
|
120
|
+
imports.push(graphql_1.GraphQLModule.forRootAsync({
|
|
121
|
+
driver: apollo_1.ApolloFederationDriver,
|
|
122
|
+
imports: [ApolloPluginsModule.forRoot()],
|
|
123
|
+
useFactory: async (configService, appContext, eventEmitter, gqlPluginList) => {
|
|
124
|
+
const conf = configService.get(def_const_js_1.CURAPP_CONF_ALIAS);
|
|
125
|
+
return {
|
|
126
|
+
autoSchemaFile: true,
|
|
127
|
+
buildSchemaOptions,
|
|
128
|
+
fieldResolverEnhancers: ['interceptors', 'guards', 'filters'],
|
|
129
|
+
transformAutoSchemaFile: true,
|
|
130
|
+
transformSchema: (graphQLSchema) => {
|
|
131
|
+
const opPrefix = options?.operationPrefix ?? conf?.operationPrefix;
|
|
132
|
+
const rename = (name) => {
|
|
133
|
+
if (!opPrefix || name.startsWith('_'))
|
|
134
|
+
return name;
|
|
135
|
+
if (options?.buildSchemaOptions?.orphanedTypes?.some((cl) => (0, class_helper_js_1.isClass)(cl) && cl.name === name))
|
|
136
|
+
return name;
|
|
137
|
+
return `${opPrefix}_${name}`;
|
|
138
|
+
};
|
|
139
|
+
const transformed = (0, wrap_1.wrapSchema)({
|
|
140
|
+
schema: graphQLSchema,
|
|
141
|
+
transforms: [
|
|
142
|
+
new wrap_1.RenameInputObjectFields((_, name) => rename(name)),
|
|
143
|
+
new wrap_1.RenameInterfaceFields((_, name) => rename(name)),
|
|
144
|
+
new wrap_1.RenameRootTypes((name) => rename(name)),
|
|
145
|
+
new wrap_1.RenameTypes((name) => rename(name)),
|
|
146
|
+
new wrap_1.RenameRootFields((_operationName, name) => rename(name)),
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
appContext.setSchema(transformed);
|
|
150
|
+
return transformed;
|
|
151
|
+
},
|
|
152
|
+
include: gqlModules,
|
|
153
|
+
useGlobalPrefix: true,
|
|
154
|
+
formatError: (formattedError, error) => {
|
|
155
|
+
const graphQLError = error instanceof error_1.GraphQLError ? error : undefined;
|
|
156
|
+
const exception = graphQLError?.extensions?.exception;
|
|
157
|
+
const message = exception?.response?.message ||
|
|
158
|
+
graphQLError?.message ||
|
|
159
|
+
formattedError.message;
|
|
160
|
+
if (conf && (conf.isDev || conf.isTest)) {
|
|
161
|
+
return {
|
|
162
|
+
...formattedError,
|
|
163
|
+
message,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const productionError = {
|
|
167
|
+
message,
|
|
168
|
+
extensions: {
|
|
169
|
+
path: formattedError.path,
|
|
170
|
+
code: formattedError.extensions?.code,
|
|
171
|
+
exception: graphQLError?.originalError,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
return productionError;
|
|
175
|
+
},
|
|
176
|
+
playground: conf?.isDev && !disablePlayground
|
|
177
|
+
? {
|
|
178
|
+
endpoint: `${conf?.apiPrefix}/graphql`,
|
|
179
|
+
settings: { 'request.credentials': 'include' },
|
|
180
|
+
}
|
|
181
|
+
: false,
|
|
182
|
+
debug: conf?.isDev,
|
|
183
|
+
context: async ({ request, reply, ...rest }) => {
|
|
184
|
+
await eventEmitter.emitAsync(app_events_js_1.AppEvents.BEFORE_GQL_CONTEXT_MIDDLEWARE, request, reply);
|
|
185
|
+
return {
|
|
186
|
+
request,
|
|
187
|
+
response: reply,
|
|
188
|
+
...rest,
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
plugins: [new gql_complexity_plugin_js_1.GqlComplexityPlugin(), ...gqlPluginList],
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
inject: [
|
|
195
|
+
config_1.ConfigService,
|
|
196
|
+
app_context_service_js_1.AppContextService,
|
|
197
|
+
event_emitter_1.EventEmitter2,
|
|
198
|
+
'APOLLO_PLUGINS',
|
|
199
|
+
],
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
if (setupEvents) {
|
|
203
|
+
imports.push(event_emitter_1.EventEmitterModule.forRoot());
|
|
204
|
+
}
|
|
205
|
+
if (setupJwt) {
|
|
206
|
+
imports.push(jwt_1.JwtModule.registerAsync({
|
|
207
|
+
imports: [configModule],
|
|
208
|
+
useFactory: async (configService) => ({
|
|
209
|
+
secret: configService.get(def_const_js_1.CURAPP_CONF_ALIAS)?.jwtSecretPrivate,
|
|
210
|
+
signOptions: {
|
|
211
|
+
expiresIn: 3600,
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
inject: [config_1.ConfigService],
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
imports,
|
|
219
|
+
providers,
|
|
220
|
+
exports: [],
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=app-imports.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-imports.factory.js","sourceRoot":"","sources":["app-imports.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,oDA+PC;AA5TD,2CAAkE;AAClE,yCAA2C;AAC3C,2CAA6D;AAE7D,8CAO6B;AAC7B,mEAA2D;AAC3D,qEAA6D;AAE7D,yEAA+E;AAC/E,6CAAgD;AAChD,6CAAoE;AACpE,qCAAwC;AACxC,yDAA0E;AAE1E,yCAA6C;AAG7C,6EAAsE;AACtE,iDAAmD;AACnD,mDAA4C;AAC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CAAC;SACxB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO;QACP,SAAS;QACT,OAAO,EAAE,EAAE;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
|
|
3
|
+
import { ImportType } from '@nest-yalc-2/interfaces/nestjs.type.js';
|
|
4
|
+
import { Logger, ModuleMetadata, Provider } from '@nestjs/common';
|
|
5
|
+
import { HttpModule } from '@nestjs/axios';
|
|
6
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
7
|
+
import { GraphQLSchema } from 'graphql';
|
|
8
|
+
import {
|
|
9
|
+
wrapSchema,
|
|
10
|
+
RenameTypes,
|
|
11
|
+
RenameRootFields,
|
|
12
|
+
RenameRootTypes,
|
|
13
|
+
RenameInterfaceFields,
|
|
14
|
+
RenameInputObjectFields,
|
|
15
|
+
} from '@graphql-tools/wrap';
|
|
16
|
+
import { AppContextModule } from './app-context.module.js';
|
|
17
|
+
import { AppContextService } from './app-context.service.js';
|
|
18
|
+
import { IDbConfType } from '@nest-yalc-2/database/conf.interface.js';
|
|
19
|
+
import { getConfNameByConnection } from '@nest-yalc-2/database/conn.helper.js';
|
|
20
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
21
|
+
import { BuildSchemaOptions, GraphQLModule } from '@nestjs/graphql';
|
|
22
|
+
import { JwtModule } from '@nestjs/jwt';
|
|
23
|
+
import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
|
|
24
|
+
import { IServiceConf } from './conf.type.js';
|
|
25
|
+
import { GraphQLError } from 'graphql/error';
|
|
26
|
+
import { GraphQLFormattedError } from 'graphql/error';
|
|
27
|
+
// import { AppLoggerModule } from '@nest-yalc-2/logger/app-logger.module.js';
|
|
28
|
+
import { TypeORMLogger } from '@nest-yalc-2/logger/typeorm-logger.js';
|
|
29
|
+
import { CURAPP_CONF_ALIAS } from './def.const.js';
|
|
30
|
+
import { AppEvents } from './app.events.js';
|
|
31
|
+
import { GqlComplexityPlugin } from '@nest-yalc-2/graphql/plugins/gql-complexity.plugin.js';
|
|
32
|
+
import { ClassType } from '@nest-yalc-2/types/globals.d.js';
|
|
33
|
+
import { isClass } from '@nest-yalc-2/utils/class.helper.js';
|
|
34
|
+
import {
|
|
35
|
+
ApolloFederationDriver,
|
|
36
|
+
ApolloFederationDriverConfig,
|
|
37
|
+
} from '@nestjs/apollo';
|
|
38
|
+
|
|
39
|
+
import * as dotenv from 'dotenv';
|
|
40
|
+
dotenv.config(); // preload .env root file before all the others
|
|
41
|
+
|
|
42
|
+
type ApolloServerPlugin = NonNullable<
|
|
43
|
+
ApolloFederationDriverConfig['plugins']
|
|
44
|
+
>[number];
|
|
45
|
+
|
|
46
|
+
export interface IAppImportsFactory {
|
|
47
|
+
envPath?: string | string[];
|
|
48
|
+
setupEvents?: boolean;
|
|
49
|
+
setupJwt?: boolean;
|
|
50
|
+
keepDBConnectionAlive?: boolean;
|
|
51
|
+
operationPrefix?: string;
|
|
52
|
+
buildSchemaOptions?: BuildSchemaOptions;
|
|
53
|
+
gqlPlugin?: ClassType<ApolloServerPlugin>[];
|
|
54
|
+
disablePlayground?: boolean;
|
|
55
|
+
}
|
|
56
|
+
type PickModuleMetadata = 'imports' | 'providers' | 'exports';
|
|
57
|
+
export type AppModuleMetadata = Required<
|
|
58
|
+
Pick<ModuleMetadata, PickModuleMetadata>
|
|
59
|
+
>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This factory function can be reused within tests to
|
|
63
|
+
* create a test app module with the same imports of the actual app
|
|
64
|
+
*/
|
|
65
|
+
export function AppDependencyFactory(
|
|
66
|
+
_context: string,
|
|
67
|
+
confs: any[],
|
|
68
|
+
dbConnNames: string[],
|
|
69
|
+
gqlModules: any[],
|
|
70
|
+
options?: IAppImportsFactory,
|
|
71
|
+
): AppModuleMetadata {
|
|
72
|
+
const {
|
|
73
|
+
setupEvents = true,
|
|
74
|
+
setupJwt = true,
|
|
75
|
+
keepDBConnectionAlive = false,
|
|
76
|
+
buildSchemaOptions = {},
|
|
77
|
+
disablePlayground = false,
|
|
78
|
+
} = options ?? {};
|
|
79
|
+
|
|
80
|
+
const envPath: string[] = [];
|
|
81
|
+
|
|
82
|
+
if (!options?.envPath) {
|
|
83
|
+
envPath.push('.env'); // user-defined env (git-ignored)
|
|
84
|
+
|
|
85
|
+
if (process.env.NODE_ENV) {
|
|
86
|
+
envPath.push(`.env.${process.env.NODE_ENV}`); // user-defined env (git-ignored)
|
|
87
|
+
|
|
88
|
+
// .env.shared is always loaded except in production
|
|
89
|
+
if (process.env.NODE_ENV !== 'production')
|
|
90
|
+
envPath.push('conf/dist/.env.shared');
|
|
91
|
+
|
|
92
|
+
if (process.env.DOCKER_CONTAINER === '1')
|
|
93
|
+
envPath.push(`conf/dist/.env.docker.${process.env.NODE_ENV}`);
|
|
94
|
+
else {
|
|
95
|
+
envPath.push(`conf/dist/.env.local.${process.env.NODE_ENV}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Logger.debug?.(`Using ${envPath}, for environment: ${process.env.NODE_ENV}`);
|
|
101
|
+
|
|
102
|
+
const configModule = ConfigModule.forRoot({
|
|
103
|
+
load: confs,
|
|
104
|
+
envFilePath: envPath,
|
|
105
|
+
// isGlobal: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// configModule and AppContextModule must be global to avoid
|
|
109
|
+
// import (re-instantiating) them when they are required by other modules
|
|
110
|
+
const imports: ImportType[] = [
|
|
111
|
+
configModule,
|
|
112
|
+
// AppLoggerModule.forRoot(context, configModule),
|
|
113
|
+
AppContextModule,
|
|
114
|
+
HttpModule,
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
if (dbConnNames.length) {
|
|
118
|
+
dbConnNames.forEach((connName) => {
|
|
119
|
+
imports.push(
|
|
120
|
+
TypeOrmModule.forRootAsync({
|
|
121
|
+
inject: [ConfigService, TypeORMLogger],
|
|
122
|
+
name: connName,
|
|
123
|
+
useFactory: async (
|
|
124
|
+
configService: ConfigService,
|
|
125
|
+
logger: TypeORMLogger,
|
|
126
|
+
) => {
|
|
127
|
+
const conf = configService.get<IDbConfType>(
|
|
128
|
+
getConfNameByConnection(connName),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
logger.log?.(
|
|
132
|
+
'log',
|
|
133
|
+
`Connecting DB ${connName} to host: ${conf?.host}`,
|
|
134
|
+
);
|
|
135
|
+
return {
|
|
136
|
+
...conf,
|
|
137
|
+
logger: conf?.logging ? logger : undefined,
|
|
138
|
+
maxQueryExecutionTime: 1000,
|
|
139
|
+
keepConnectionAlive: keepDBConnectionAlive,
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const providers: Provider<any>[] = [];
|
|
148
|
+
|
|
149
|
+
class ApolloPluginsModule {
|
|
150
|
+
static forRoot() {
|
|
151
|
+
return {
|
|
152
|
+
module: ApolloPluginsModule,
|
|
153
|
+
providers: [
|
|
154
|
+
{
|
|
155
|
+
provide: 'APOLLO_PLUGINS',
|
|
156
|
+
useFactory: (...gqlPlugins: ApolloServerPlugin[]) => {
|
|
157
|
+
return gqlPlugins;
|
|
158
|
+
},
|
|
159
|
+
inject: [...(options?.gqlPlugin ?? [])],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
exports: ['APOLLO_PLUGINS'],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (gqlModules.length) {
|
|
168
|
+
imports.push(
|
|
169
|
+
GraphQLModule.forRootAsync<ApolloFederationDriverConfig>({
|
|
170
|
+
driver: ApolloFederationDriver,
|
|
171
|
+
imports: [ApolloPluginsModule.forRoot()],
|
|
172
|
+
useFactory: async (
|
|
173
|
+
configService: ConfigService,
|
|
174
|
+
appContext: AppContextService,
|
|
175
|
+
eventEmitter: EventEmitter2,
|
|
176
|
+
gqlPluginList: ApolloServerPlugin[],
|
|
177
|
+
) => {
|
|
178
|
+
const conf = configService.get<IServiceConf>(CURAPP_CONF_ALIAS);
|
|
179
|
+
return {
|
|
180
|
+
autoSchemaFile: true,
|
|
181
|
+
buildSchemaOptions,
|
|
182
|
+
// can cause performance issues (https://docs.nestjs.com/graphql/other-features#execute-enhancers-at-the-field-resolver-level)
|
|
183
|
+
// be careful
|
|
184
|
+
fieldResolverEnhancers: ['interceptors', 'guards', 'filters'],
|
|
185
|
+
transformAutoSchemaFile: true,
|
|
186
|
+
transformSchema: (graphQLSchema: GraphQLSchema) => {
|
|
187
|
+
const opPrefix =
|
|
188
|
+
options?.operationPrefix ?? conf?.operationPrefix;
|
|
189
|
+
|
|
190
|
+
const rename = (name: string) => {
|
|
191
|
+
// _service, _entities etc. are used by federation and must not be renamed
|
|
192
|
+
if (!opPrefix || name.startsWith('_')) return name;
|
|
193
|
+
|
|
194
|
+
// orphaned types must keep their non-prefixed name
|
|
195
|
+
if (
|
|
196
|
+
options?.buildSchemaOptions?.orphanedTypes?.some(
|
|
197
|
+
(cl) => isClass(cl) && cl.name === name,
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
return name;
|
|
201
|
+
|
|
202
|
+
return `${opPrefix}_${name}`;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const transformed = wrapSchema({
|
|
206
|
+
schema: graphQLSchema,
|
|
207
|
+
transforms: [
|
|
208
|
+
new RenameInputObjectFields((_, name) => rename(name)),
|
|
209
|
+
new RenameInterfaceFields((_, name) => rename(name)),
|
|
210
|
+
new RenameRootTypes((name) => rename(name)),
|
|
211
|
+
new RenameTypes((name) => rename(name)),
|
|
212
|
+
new RenameRootFields((_operationName, name) => rename(name)),
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
appContext.setSchema(transformed);
|
|
217
|
+
|
|
218
|
+
return transformed;
|
|
219
|
+
},
|
|
220
|
+
include: gqlModules,
|
|
221
|
+
useGlobalPrefix: true,
|
|
222
|
+
// Makes sure not too much info. is revealed when reporting errors in non-dev stages
|
|
223
|
+
// @url: https://github.com/nestjs/graphql/issues/1053#issuecomment-740739410
|
|
224
|
+
formatError: (
|
|
225
|
+
formattedError: GraphQLFormattedError,
|
|
226
|
+
error: unknown,
|
|
227
|
+
) => {
|
|
228
|
+
const graphQLError =
|
|
229
|
+
error instanceof GraphQLError ? error : undefined;
|
|
230
|
+
const exception: any = graphQLError?.extensions?.exception;
|
|
231
|
+
const message =
|
|
232
|
+
exception?.response?.message ||
|
|
233
|
+
graphQLError?.message ||
|
|
234
|
+
formattedError.message;
|
|
235
|
+
|
|
236
|
+
if (conf && (conf.isDev || conf.isTest)) {
|
|
237
|
+
return {
|
|
238
|
+
...formattedError,
|
|
239
|
+
message, // override the message with meaningful info
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// throw only essential error info in production
|
|
244
|
+
const productionError: GraphQLFormattedError = {
|
|
245
|
+
message,
|
|
246
|
+
extensions: {
|
|
247
|
+
path: formattedError.path,
|
|
248
|
+
code: formattedError.extensions?.code,
|
|
249
|
+
exception: graphQLError?.originalError, // error without stacktrace
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
return productionError;
|
|
254
|
+
},
|
|
255
|
+
playground:
|
|
256
|
+
conf?.isDev && !disablePlayground
|
|
257
|
+
? {
|
|
258
|
+
endpoint: `${conf?.apiPrefix}/graphql`,
|
|
259
|
+
settings: { 'request.credentials': 'include' },
|
|
260
|
+
}
|
|
261
|
+
: false,
|
|
262
|
+
debug: conf?.isDev,
|
|
263
|
+
context: async ({
|
|
264
|
+
request,
|
|
265
|
+
reply,
|
|
266
|
+
...rest
|
|
267
|
+
}: {
|
|
268
|
+
request: any;
|
|
269
|
+
reply: any;
|
|
270
|
+
}) => {
|
|
271
|
+
await eventEmitter.emitAsync(
|
|
272
|
+
AppEvents.BEFORE_GQL_CONTEXT_MIDDLEWARE,
|
|
273
|
+
request,
|
|
274
|
+
reply,
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
request,
|
|
279
|
+
response: reply,
|
|
280
|
+
...rest,
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
plugins: [new GqlComplexityPlugin(), ...gqlPluginList],
|
|
284
|
+
};
|
|
285
|
+
},
|
|
286
|
+
inject: [
|
|
287
|
+
ConfigService,
|
|
288
|
+
AppContextService,
|
|
289
|
+
EventEmitter2,
|
|
290
|
+
'APOLLO_PLUGINS',
|
|
291
|
+
],
|
|
292
|
+
}),
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (setupEvents) {
|
|
297
|
+
imports.push(EventEmitterModule.forRoot());
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (setupJwt) {
|
|
301
|
+
imports.push(
|
|
302
|
+
JwtModule.registerAsync({
|
|
303
|
+
imports: [configModule],
|
|
304
|
+
useFactory: async (configService: ConfigService) => ({
|
|
305
|
+
secret: configService.get<any>(CURAPP_CONF_ALIAS)?.jwtSecretPrivate,
|
|
306
|
+
signOptions: {
|
|
307
|
+
expiresIn: 3600,
|
|
308
|
+
},
|
|
309
|
+
}),
|
|
310
|
+
inject: [ConfigService],
|
|
311
|
+
}),
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
imports,
|
|
317
|
+
providers,
|
|
318
|
+
exports: [],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppEvents = void 0;
|
|
4
|
+
var AppEvents;
|
|
5
|
+
(function (AppEvents) {
|
|
6
|
+
AppEvents["BEFORE_ALL_ROUTES"] = "app.before_all_routes";
|
|
7
|
+
AppEvents["AFTER_ALL_ROUTES"] = "app.after_all_routes";
|
|
8
|
+
AppEvents["BEFORE_GQL_CONTEXT_MIDDLEWARE"] = "app.before_gql_context_middleware";
|
|
9
|
+
})(AppEvents || (exports.AppEvents = AppEvents = {}));
|
|
10
|
+
//# sourceMappingURL=app.events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.events.js","sourceRoot":"","sources":["app.events.ts"],"names":[],"mappings":";;;AAGA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,wDAA2C,CAAA;IAC3C,sDAAyC,CAAA;IACzC,gFAAmE,CAAA;AACrE,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ClassType } from '@nest-yalc-2/types/globals.d.js';
|
|
2
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
3
|
+
import { BaseAppBootstrap, IGlobalOptions } from './app-bootstrap-base.helper.js';
|
|
4
|
+
export declare function isDynamicModule(module: any): module is DynamicModule;
|
|
5
|
+
export declare const executeFunctionForApp: (app: BaseAppBootstrap<any>, serviceType: any, fn: {
|
|
6
|
+
(service: any): Promise<any>;
|
|
7
|
+
}, options: {
|
|
8
|
+
closeApp?: boolean;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
export declare const curriedExecuteStandaloneFunction: <TOptions extends IGlobalOptions>(module: any, options?: TOptions) => Promise<import("lodash").CurriedFunction3<any, (service: any) => Promise<any>, {
|
|
11
|
+
closeApp?: boolean;
|
|
12
|
+
}, Promise<void>>>;
|
|
13
|
+
export declare const executeStandaloneFunction: <TService, TOptions extends IGlobalOptions>(module: DynamicModule | Type<any>, serviceType: ClassType<TService>, fn: {
|
|
14
|
+
(service: TService): Promise<any>;
|
|
15
|
+
}, options?: TOptions, executeOptions?: {
|
|
16
|
+
closeApp?: boolean;
|
|
17
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeStandaloneFunction = exports.curriedExecuteStandaloneFunction = exports.executeFunctionForApp = void 0;
|
|
4
|
+
exports.isDynamicModule = isDynamicModule;
|
|
5
|
+
const app_bootstrap_standalone_helper_js_1 = require("./app-bootstrap-standalone.helper.js");
|
|
6
|
+
const lodash_es_1 = require("lodash-es");
|
|
7
|
+
function isDynamicModule(module) {
|
|
8
|
+
return module.module !== undefined;
|
|
9
|
+
}
|
|
10
|
+
const executeFunctionForApp = async (app, serviceType, fn, options) => {
|
|
11
|
+
const nestApp = await app.getApp();
|
|
12
|
+
await nestApp.init();
|
|
13
|
+
const service = await nestApp.resolve(serviceType);
|
|
14
|
+
await fn(service).finally(async () => {
|
|
15
|
+
if (options.closeApp)
|
|
16
|
+
await app.closeApp();
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
exports.executeFunctionForApp = executeFunctionForApp;
|
|
20
|
+
const curriedExecuteStandaloneFunction = async (module, options) => (0, lodash_es_1.curry)(exports.executeFunctionForApp)(await new app_bootstrap_standalone_helper_js_1.StandaloneAppBootstrap(isDynamicModule(module) ? module.module.name : module.name, module, options).initApp());
|
|
21
|
+
exports.curriedExecuteStandaloneFunction = curriedExecuteStandaloneFunction;
|
|
22
|
+
const executeStandaloneFunction = async (module, serviceType, fn, options, executeOptions = {}) => {
|
|
23
|
+
return (await (0, exports.curriedExecuteStandaloneFunction)(module, options))(serviceType, fn, executeOptions);
|
|
24
|
+
};
|
|
25
|
+
exports.executeStandaloneFunction = executeStandaloneFunction;
|
|
26
|
+
//# sourceMappingURL=app.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.helper.js","sourceRoot":"","sources":["app.helper.ts"],"names":[],"mappings":";;;AASA,0CAEC;AATD,6FAA8E;AAC9E,yCAAkC;AAMlC,SAAgB,eAAe,CAAC,MAAW;IACzC,OAAO,MAAM,CAAC,MAAM,KAAK,S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